private static void CheckWinLoseDraw(Board gameBoard, ref bool drawnGame, ref bool wonGame, ref char winner) { if (gameBoard.IsFull()) { drawnGame = true; } switch (gameBoard.Score(Side1, false)) { case Board.Win: wonGame = true; winner = Side1; break; case Board.Lose: wonGame = true; winner = Side2; break; } }
private static int MakeAMoveHelper(char side, char playAs, Board gameBoard) { int score = gameBoard.Score(side, false); if (score != 0) { return score; } if (gameBoard.IsFull()) { return 0; } List<int> scores = new List<int>(3); for (int i = 0; i < 3; ++i) { scores.Add(Board.Lose); } for (int i = 0; i < 3; ++i) { if (!gameBoard.IsFull(i)) { gameBoard.Drop(i, side); scores[i] = (-(MakeAMoveHelper(side, side == Side1 ? Side2 : Side1, gameBoard))); gameBoard.Pop(i); } } return scores.IndexOf(scores.Max()); }
public void ScoreTest() { { Board target = new Board(); // TODO: Initialize to an appropriate value target.board = new char[,] { { 'a', 'a', 'a' }, { '.', '.', '.' }, { '.', '.', '.' }, { '.', '.', '.' } }; char side = 'a'; // TODO: Initialize to an appropriate value int expected = Board.Win; // TODO: Initialize to an appropriate value int actual; actual = target.Score(side, false); Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); } { Board target = new Board(); // TODO: Initialize to an appropriate value target.board = new char[,] { { 'a', '.', '.' }, { '.', 'a', '.' }, { '.', '.', 'a' }, { '.', '.', '.' } }; char side = 'b'; // TODO: Initialize to an appropriate value int expected = Board.Lose; // TODO: Initialize to an appropriate value int actual; actual = target.Score(side, false); Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); } { Board target = new Board(); // TODO: Initialize to an appropriate value target.board = new char[,] { { 'a', '.', '.' }, { 'a', '.', '.' }, { 'a', '.', '.' }, { '.', '.', '.' } }; char side = 'a'; // TODO: Initialize to an appropriate value int expected = Board.Win; // TODO: Initialize to an appropriate value int actual; actual = target.Score(side, false); Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); } { Board target = new Board(); // TODO: Initialize to an appropriate value target.board = new char[,] { { '.', '.', 'a' }, { '.', 'a', '.' }, { 'a', '.', '.' }, { '.', '.', '.' } }; char side = 'b'; // TODO: Initialize to an appropriate value int expected = Board.Lose; // TODO: Initialize to an appropriate value int actual; actual = target.Score(side, false); Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); } { Board target = new Board(); // TODO: Initialize to an appropriate value target.board = new char[,] { { 'a', 'a', '.' }, { 'a', 'a', '.' }, { '.', '.', '.' }, { '.', '.', '.' } }; char side = 'a'; // TODO: Initialize to an appropriate value int expected = 5; // TODO: Initialize to an appropriate value int actual; actual = target.Score(side, true); Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); } }