Question: For this assignment, you are required to write a MIPS program that allows users to play an interactive game of Tic Tac Toe (Naughts and
For this assignment, you are required to write a MIPS program that allows users to play an interactive game of Tic Tac Toe (Naughts and Crosses).
Represent your game board as a two-dimensional array of characters, with three rows and three columns. Other useful global variables include the following:
1. whoseMove: a character used to remember which player get to make the next move. The value of whoseMove should alternate between X and O as the game proceeds.
2. moveCount: an integer used to count the number of moves made during the current game.
At a minimum, your solution should include the following methods:
1. ResetBoard: this void method clears the Tic Tac Toe board, sets whoseMove to X, and sets moveCount to 0.
2. AddMove: this void method interactively prompts for and reads two integer values representing a selected row and column. Your method should display an appropriate error message and repeat the input process until the user enters row and column numbers between 1 and 3, inclusive, that specify an unoccupied board position. It should then place the current players token (X or O) in the selected position.
3. DisplayBoard: this void method displays the current content of the board on the screen.
4. IsAWin: this method returns a Boolean value that indicates whether the most recent move resulted in a win, which may occur in the current row, the current column, or along either diagonal.
I have the code in Java. How would I approach this assignment and translate my java into mips assembly code ?
import java.util.Scanner;
public class TicTacToe
{
private static char [][] board;
private static char whoseMove = 'X';
private static int row;
private static int col;
private static int moveCount = 1;
public static void main(String[] args)
{
System.out.println(" Welcome to Tic Tac Toe Game ");
board = new char[3][3];
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
board[row][col]= '_';
}
play();
CheckWinner(row, col);
}
public static void play()
{
PrintBoard();
System.out.println();
System.out.println("Player X please place your move ");
Scanner keyboard = new Scanner(System.in);
do
{
row = keyboard.nextInt()-1;
col = keyboard.nextInt()-1;
board[row][col] = whoseMove;
if(CheckWinner(row, col))
{
PrintBoard();
System.out.println("congratulation to player " + whoseMove + " you Won!");
break;
}
if(whoseMove == 'X')
whoseMove = 'O';
else
whoseMove = 'X';
moveCount++;
if(moveCount == 10)
{
PrintBoard();
System.out.println("It is a Draw!");
break;
}
PrintBoard();
System.out.println("Player " + whoseMove + " Please place your move");
}while(board[row][col] != '_' );
}
public static void PrintBoard()
{
System.out.print(" 1 2 3");
for (int row = 0; row < 3; row++)
{ System.out.println();
for (int col = 0; col < 3; col++)
{
if(col == 0)
System.out.print(row+ 1 + "| ");
System.out.print(board[row][col]+ " | ");
}
System.out.println();
}
}
public static boolean CheckWinner(int rMove, int cMove)
{
if(board[0][cMove] == board[1][cMove]&& board[0][cMove] == board[2][cMove])
return true;
if(board[rMove][0] == board[rMove][1]&& board[rMove][0] == board[rMove][2])
return true;
if (board[0][0] == board[1][1] && board[0][0] == board[2][2]&& board[1][1] != '_')
return true;
if (board[0][2] == board[1][1] && board[0][2] == board[2][0]&& board[1][1] != '_')
return true;
return false;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
