Question: I need help writing a unit test for this c# TicTacToeGame code. I need to test the isThereAWinner method. It can test the X's, O's,
I need help writing a unit test for this c# TicTacToeGame code. I need to test the isThereAWinner method. It can test the X's, O's, or draw(CAT game). Thank you!



using System;
namespace TicTacToeGame
{
public class Board
{
public const int MAX_ROWS = 3;
public const int MAX_COLS = 3;
public Square[,] board = new Square[MAX_ROWS, MAX_COLS];
private GameBrain gameBrian;
public Board()
{
gameBrian = new GameBrain();
for (int row = 0; row
{
for (int col = 0; col
{
board[row, col] = new Square(row, col);
board[row, col].occupiedBy = "";
}
}
}
public bool playerMakesMove(int row, int col)
{
bool isSuccesful = false;
if (board[row, col].occupiedBy == "")
{
board[row, col].occupiedBy = Square.PLAYER_MARKER;
isSuccesful = true;
}
return isSuccesful;
}
public bool systemMakesMove()
{
return gameBrian.systemMove(this);
}
public String isThereAWinner()
{
String winner = "";
winner = calculateWinner();
return winner;
}
private String calculateWinner()
{
// Empty string means nobody has won
String winner = "";
if (winnerCheck(Square.PLAYER_MARKER))
winner = Square.PLAYER_MARKER;
else if (winnerCheck(Square.SYSETM_MARKER))
winner = Square.SYSETM_MARKER;
else if (allTaken())
winner = Square.CAT_MARKER;
return winner;
}
private bool allTaken()
{
bool isAllTaken = true;
for (int row = 0; row
{
for (int col = 0; col
{
if (board[row, col].occupiedBy == "")
isAllTaken = false;
}
}
return isAllTaken;
}
private bool winnerCheck(String marker)
{
bool isWinner = false;
if (board[0,0].occupiedBy == marker
&& board[0,1].occupiedBy == marker
&& board[0,2].occupiedBy == marker)
{
// 1st row is all of a kind
isWinner = true;
} else if (board[1, 0].occupiedBy == marker
&& board[1, 1].occupiedBy == marker
&& board[1, 2].occupiedBy == marker)
{
// 2nd row is all of a kind
isWinner = true;
} else if (board[2, 0].occupiedBy == marker
&& board[2, 1].occupiedBy == marker
&& board[2, 2].occupiedBy == marker)
{
// 3rd row is all of a kind
isWinner = true;
} else if (board[0, 0].occupiedBy == marker
&& board[1, 0].occupiedBy == marker
&& board[2, 0].occupiedBy == marker)
{
// 1st column is all of a kind
isWinner = true;
}
else if (board[0, 1].occupiedBy == marker
&& board[1, 1].occupiedBy == marker
&& board[2, 1].occupiedBy == marker)
{
// 2nd column is all of a kind
isWinner = true;
} else if (board[0, 2].occupiedBy == marker
&& board[1, 2].occupiedBy == marker
&& board[2, 2].occupiedBy == marker)
{
// 3rd column is all of a kind
isWinner = true;
} else if (board[0, 0].occupiedBy == marker
&& board[1, 1].occupiedBy == marker
&& board[2, 2].occupiedBy == marker)
{
// 1st diagonal is all of a kind
isWinner = true;
} else if (board[0, 2].occupiedBy == marker
&& board[1, 1].occupiedBy == marker
&& board[2, 0].occupiedBy == marker)
{
// 2nd diagonal is all of a kind
isWinner = true;
}
return isWinner;
}
public String[,] getBoard()
{
String[,] pseudoBoard = new String[MAX_ROWS, MAX_COLS];
for (int row = 0; row
{
for (int col = 0; col
{
pseudoBoard[row, col] = board[row, col].occupiedBy;
}
}
return pseudoBoard;
}
}
}
1 using System; namespace TicTacToeGame 4. public class Board public const int MAX ROWS = 3; public const int MAX COLS = 3; public square[,] board = new Square(MAX ROWS, MAX COLS]; private GameBrain gameBrian; 9 public Board() 12 13 gameBrian = new GameBrain(); 16 17 for (int row = 0; row
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
