Anúncio

((Note Assembly Language programming Please and format from book 8.docx

ajoy21
14 de Sep de 2022
((Note Assembly Language programming Please and format from book 8.docx
((Note Assembly Language programming Please and format from book 8.docx
((Note Assembly Language programming Please and format from book 8.docx
((Note Assembly Language programming Please and format from book 8.docx
Anúncio
((Note Assembly Language programming Please and format from book 8.docx
((Note Assembly Language programming Please and format from book 8.docx
Próximos SlideShares
python.pptxpython.pptx
Carregando em ... 3
1 de 6
Anúncio

Mais conteúdo relacionado

Similar a ((Note Assembly Language programming Please and format from book 8.docx(20)

Mais de ajoy21(20)

Anúncio

((Note Assembly Language programming Please and format from book 8.docx

  1. ((Note: Assembly Language programming Please and format from book *86 PROCESSORS. such as INCLUDE Irvine32.inc )) Problem: Write a program that simulates the game of Tic-Tac- Toe. The User will play against the computer (your assembly program) or the computer will play against itself. 1. You must use a two-dimensional array and Base-Index operands (Row-major order) throughout the game. The game board is created with characters. - | - | - - | - | - - | - | - This is an example of the empty board. - | x | - - | o | - - | - | - This is an example of a game in progress. 2. All Procedures will be called with PROTO/INVOKE/PROC. I will be checking for this. DO NOT USE USES as discussed in class. The only exception is the Irvine32 library. These must be called with CALL. 3. If the game is player vs computer, start the game by randomly choosing which of player or computer to make first move. The first player will be assigned the letter x. a. The computer chooses a move by selecting an open position randomly. (We are not developing Artificial Intelligence) i) However, if the game is player vs computer, and the center square is available on the computer’s first turn, the computer MUST chose that square (regardless of whether or not the computer the first or second player). ii) Afterwards, all moves by the computer will be random. b. The player will enter a move via the keyboard. i) You must check to see if it is a valid move, i.e. not an already occupied ‘square’, or a square that is non-existent. ii) Keep asking for a move until a valid move is entered.
  2. c. After each move clear the screen and redisplay the game with the new move entered. d. At the conclusion of each game of tic-tac-toe, ask if the player wishes to play again. Yes, even if it is computer vs computer. e. Have a menu option that allows the user to check statistics. i) How many games played ii) How many games won by Player 1 iii) How many games won by Player 2 iv) How many games resulted in a draw. f. When the user chooses to exit the above statistics should be displayed until a key is pressed. 4. If the game is computer vs computer after each move display the current state of the game for 2 seconds, before allowing another move to be made. The user just watch the game being played. 5. When the game ends, display who won or if the game was a draw. a. If someone (either player or computer) wins, highlight the winning path (either three x’s or three o’s) with black on yellow as the final display. 6. The game will start with a menu. The options are player vs computer, computer vs computer, and exit. 7. As always, variables used by a procedure must either be passed to that procedure or created within the procedure. Only Main PROC can directly access the variables initialized in .data. All others must be local to the procedures. 8. Style counts to include proper commenting. Solution Many computer games, such as strategy games, simulation
  3. games etc uses game boards that can be implemented as two dimensional arrays. In Java (and in many other languages) 2D arrays can be defined as an array of 1D arrays. For example a 2D matrix of characters (with dimensions 8x10) can be defined as follows. char[][] Board = new char[8][10] We can think of Board as a table with 8 rows (indexed from 0..7) and 10 columns(indexed from 0..9) Tic Tac Toe is played on a 3x3 board with two players alternating between X’s and O’s, alternatively placing their respective marks on the board. First player succeeding in getting three of his marks in a row, column or diagonally wins the game. How do we design the classes to implement a tictactoe game? Let us think of the objects in a tictactoe game environment. We can think of four types of objects, tictactoe board, human player, dumb (or random) player and smart player. In this program we will only implement human player and dumb player. As an extra credit assignment you are encouraged to write a smart player that can analyze the board and make the best move. However that is not necessary. Let us begin with the following classes and methods. Class Methods TicTacToe
  4. clearBoard( ) isWin(int), winner(), printBoard( ), putMark(int, int) Driver Main( ) HumanPlayer makeMove( TicTacToe B) ComputerPlayer (extra credit only) makeMove(TicTacToe B), findMove(TicTacToe B) DumbPlayer makeMove(TicTacToe B) The description of each method can be found in the source code. Your assignment is to complete the incomplete methods from TicTacToe, HumanPlayer and DumbPlayer classes. Testing your program You may use any kind of IDE such as eclipse to test your program. However, you need to make sure all programs run under Andrew linux. You should also check your program by creating different scenarios. Human vs Human First define, two human players and play them against each other. You can do this by initializing two HumanPlayers as follows. HumanPlayer Player1 = new HumanPlayer( ); HumanPlayer Player2 = new HumanPlayer( ); The program should prompt each player to enter position as a
  5. pair of “valid” integers. For example, two players taking turns can be shown as follows: > Player X : 0 1 > Player O : 1 1 Game should continue until one player wins or game is a draw. The program should correctly display the end of the game. For Example: Human vs Dumb Initialize a human player and a dumb player as follows. HumanPlayer Player1 = new HumanPlayer( ); DumbPlayer Player2 = new DumbPlayer( ); DumbPlayer will always make a random move. Therefore, human player should be able to usually beat the dumb player. Dumb vs Dumb First define, two dumb players and play them against each other. You can do this by initializing two DumbPlayers as follows. DumbPlayer Player1 = new DumbPlayer( ); DumbPlayer Player2 = new DumbPlayer( ); Class Methods TicTacToe clearBoard( ) isWin(int), winner(), printBoard( ), putMark(int, int) Driver
  6. Main( ) HumanPlayer makeMove( TicTacToe B) ComputerPlayer (extra credit only) makeMove(TicTacToe B), findMove(TicTacToe B) DumbPlayer makeMove(TicTacToe B)
Anúncio