public void MakeMoveInFullColumn() { C4Board board = new C4Board(); //Fill a column up, so that any future moves in the column should cause an InvalidMoveException for (int i = 0; i < board.Height; i++) { board.MakeMove(new C4Move(1)); } //Attempt to make a move in the full column, which should throw an InvalidMoveException Assert.Throws <InvalidMoveException>(() => board.MakeMove(new C4Move(1))); }
public void MakeMoveTest() { //Create a new board and make a move in it C4Board board = new C4Board(); board.MakeMove(new C4Move(2)); //Check that the move was made correctly Assert.AreEqual(1, board.GetCell(2, 0)); //Make a move on the board for the second player board.MakeMove(new C4Move(2)); //Check that the move was made correctly Assert.AreEqual(2, board.GetCell(2, 1)); }
public void GetPossibleMovesOneFullColumn() { C4Board board = new C4Board(); for (int i = 0; i < board.Height; i++) { board.MakeMove(new C4Move(3)); } Assert.AreEqual(board.Width - 1, board.PossibleMoves().Count); }
public void NoWinnerTest() { C4Board board = new C4Board(); //Make a move, if there is a winner, the winner flag will be set, but there is no winner, so it shouldn't board.MakeMove(new C4Move(1)); //Check that the winner flag has not been set, as there is no winner Assert.AreEqual(-1, board.Winner); }
public void GetPossibleMovesFullBoard() { C4Board board = new C4Board(); for (int y = 0; y < board.Height; y++) { for (int x = 0; x < board.Width; x++) { board.MakeMove(new C4Move(x)); } } Assert.AreEqual(0, board.PossibleMoves().Count); }
public void DuplicateTest() { //Create a new board and make a move in it C4Board boardA = new C4Board(); boardA.MakeMove(new C4Move(3)); //Duplicate the board and store it in a new board instance C4Board boardB = (C4Board)boardA.Duplicate(); //Ensure the move made before duplication is present in both boards Assert.AreEqual(1, boardA.GetCell(3, 0)); Assert.AreEqual(1, boardB.GetCell(3, 0)); //These two board instances should share no memory, lets prove it by making moves in each of them and checking the other boardA.MakeMove(new C4Move(6)); Assert.AreEqual(2, boardA.GetCell(6, 0)); Assert.AreEqual(0, boardB.GetCell(6, 0)); boardB.MakeMove(new C4Move(3)); Assert.AreEqual(0, boardA.GetCell(3, 1)); Assert.AreEqual(2, boardB.GetCell(3, 1)); }
/// <summary> /// Makes a move on the current board /// </summary> /// <param name="move">The move to make</param> private void MakeMoveOnBoard(Move move) { if (board.CurrentPlayer == 2) { aiTurnProgressText.text = ""; } board.MakeMove(move); modelController.SetBoard(board); if (board.Winner != -1) { if (board.Winner == 0) { winnerText.text = "DRAW"; } else { winnerText.text = "WINNER IS PLAYER " + board.Winner; } gameOver = true; return; } if (board.CurrentPlayer == 1 && playMode == PlayMode.CLIENT) { moveButtons.SetActive(true); } if (board.CurrentPlayer == 2) { moveButtons.SetActive(false); //If the current playmode is client, don't start an AI turn, wait for server response instead if (playMode != PlayMode.CLIENT) { StartAITurn(); } } }
public void DrawTest() { //Create a full board with no winner C4Board board = new C4Board(); //Make moves until the board is full and there are no winners for (int y = 0; y < board.Height; y++) { board.MakeMove(new C4Move(0)); board.MakeMove(new C4Move(2)); board.MakeMove(new C4Move(1)); board.MakeMove(new C4Move(3)); board.MakeMove(new C4Move(4)); board.MakeMove(new C4Move(6)); board.MakeMove(new C4Move(5)); } //Check that the game has ended in a draw Assert.AreEqual(0, board.Winner); }