public void CheckForWinShouldReturnOIfThereAreThreeOsInARow()
        {
            //Three Across the Top
            BoardManager board = new BoardManager();
            Assert.AreEqual('\0', board.CheckForWin());
            board.ForceMove(new Tuple<int, int>(0, 0), 'O');
            board.ForceMove(new Tuple<int, int>(1, 0), 'O');
            board.ForceMove(new Tuple<int, int>(2, 0), 'O');
            Assert.AreEqual('O', board.CheckForWin());

            //Three Across the Middle
            board = new BoardManager();
            board.ForceMove(new Tuple<int, int>(0, 1), 'O');
            board.ForceMove(new Tuple<int, int>(1, 1), 'O');
            board.ForceMove(new Tuple<int, int>(2, 1), 'O');
            Assert.AreEqual('O', board.CheckForWin());

            //Three Across the Bottom
            board = new BoardManager();
            board.ForceMove(new Tuple<int, int>(0, 2), 'O');
            board.ForceMove(new Tuple<int, int>(1, 2), 'O');
            board.ForceMove(new Tuple<int, int>(2, 2), 'O');
            Assert.AreEqual('O', board.CheckForWin());

            //Three Down the Left Side
            board = new BoardManager();
            board.ForceMove(new Tuple<int, int>(0, 0), 'O');
            board.ForceMove(new Tuple<int, int>(0, 1), 'O');
            board.ForceMove(new Tuple<int, int>(0, 2), 'O');
            Assert.AreEqual('O', board.CheckForWin());

            //Three Down the Middle
            board = new BoardManager();
            board.ForceMove(new Tuple<int, int>(1, 0), 'O');
            board.ForceMove(new Tuple<int, int>(1, 1), 'O');
            board.ForceMove(new Tuple<int, int>(1, 2), 'O');
            Assert.AreEqual('O', board.CheckForWin());

            //Three Down the Right Side
            board = new BoardManager();
            board.ForceMove(new Tuple<int, int>(2, 0), 'O');
            board.ForceMove(new Tuple<int, int>(2, 1), 'O');
            board.ForceMove(new Tuple<int, int>(2, 2), 'O');
            Assert.AreEqual('O', board.CheckForWin());

            //Three In A Slash
            board = new BoardManager();
            board.ForceMove(new Tuple<int, int>(2, 0), 'O');
            board.ForceMove(new Tuple<int, int>(1, 1), 'O');
            board.ForceMove(new Tuple<int, int>(0, 2), 'O');
            Assert.AreEqual('O', board.CheckForWin());

            //Three In A Backslash
            board = new BoardManager();
            board.ForceMove(new Tuple<int, int>(0, 0), 'O');
            board.ForceMove(new Tuple<int, int>(1, 1), 'O');
            board.ForceMove(new Tuple<int, int>(2, 2), 'O');
            Assert.AreEqual('O', board.CheckForWin());
        }
 public void BoardManagerShouldBeAbleToCheckTheValidityOfAMove()
 {
     BoardManager target = new BoardManager();
     target.LogMove(new Tuple<int, int>(1, 1));
     bool expected = false;
     bool actual = target.IsMoveValid(new Tuple<int, int>(1, 1));
     Assert.AreEqual(expected, actual);
 }
 public void MakeMoveShouldReturnNull()
 {
     BoardManager board = new BoardManager();
     HumanPlayer playerOne = new HumanPlayer();
     Tuple<int,int> actual = playerOne.MakeMove(board.boardArray);
     Tuple<int,int> expected = null;
     Assert.AreEqual(expected, actual);
 }
        public void ComputerAIConstructorTest()
        {
            BoardManager board = new BoardManager();
            HumanPlayer playerOne = new HumanPlayer();
            ComputerPlayer playerTwo = new ComputerPlayer('O');
            board.LogMove(playerOne.MakeMove(0, 0));

            ComputerAI target = new ComputerAI(playerOne.identity, playerTwo.identity);

            Assert.AreEqual('X', target.enemyIdentity);
        }
 public void MakeMoveShouldGetRandomMoveOfMovesAvailable()
 {
     BoardManager board = new BoardManager();
     ComputerPlayer playerTwo = new ComputerPlayer('O');
     board.LogMove(new Tuple<int,int>(1,1));
     Tuple<int,int> playerChoice = playerTwo.MakeMove(board.boardArray);
     CreatedMove actual = new CreatedMove(playerChoice.Item1, playerChoice.Item2,playerTwo.identity);
     CreatedMove notExpected = new CreatedMove(1, 1, 'O');
     Assert.IsTrue(actual.xAxis >= 0 && actual.xAxis <= 2);
     Assert.IsTrue(actual.yAxis >= 0 && actual.yAxis <= 2);
     Assert.AreNotEqual(notExpected, actual);
 }
 public void GetRandomMoveShouldReturnARandomMoveFromAvailableSpaces()
 {
     BoardManager board = new BoardManager();
     HumanPlayer playerOne = new HumanPlayer();
     ComputerPlayer playerTwo = new ComputerPlayer('O');
     board.LogMove(playerOne.MakeMove(1, 1));
     ComputerAI target = new ComputerAI(playerOne.identity, playerTwo.identity);
     CreatedMove actual = target.GetRandomMove(board.boardArray);
     CreatedMove notExpected = new CreatedMove(1, 1, 'O');
     Assert.IsTrue(actual.xAxis >= 0 && actual.xAxis <= 2);
     Assert.IsTrue(actual.yAxis >= 0 && actual.yAxis <= 2);
     Assert.AreNotEqual(notExpected, actual);
 }
Example #7
0
 public Game(Player one, Player two, BoardManager ourManager)
 {
     xPlayer = one;
     if (xPlayer.identity != 'X')
     {
         xPlayer.identity = 'X';
     }
     oPlayer = two;
     if (oPlayer.identity != 'O')
     {
         oPlayer.identity = 'O';
     }
     board = ourManager;
 }
Example #8
0
 public Game(Player one, Player two)
 {
     xPlayer = one;
     if (xPlayer.identity != 'X')
     {
         xPlayer.identity = 'X';
     }
     oPlayer = two;
     if (oPlayer.identity != 'O')
     {
         oPlayer.identity = 'O';
     }
     board = new BoardManager();
 }
        public void BoardManagerShouldKnowIfThereIsATie()
        {
            BoardManager board = new BoardManager();
            HumanPlayer playerOne = new HumanPlayer('X');
            ComputerPlayer playerTwo = new ComputerPlayer('O');

            board.LogMove(new Tuple<int, int>(1, 1));
            board.LogMove(new Tuple<int, int>(0, 0));
            board.LogMove(new Tuple<int, int>(0, 1));
            board.LogMove(new Tuple<int, int>(2, 1));
            board.LogMove(new Tuple<int, int>(0, 2));
            board.LogMove(new Tuple<int, int>(2, 0));
            board.LogMove(new Tuple<int, int>(1, 0));
            board.LogMove(new Tuple<int, int>(1, 2));
            board.LogMove(new Tuple<int, int>(2, 2));

            Assert.AreEqual(true, board.CheckForTie());
        }
        public void BoardManagerShouldKnowIfThereIsATie()
        {
            BoardChecker target = new BoardChecker();
            BoardManager board = new BoardManager();
            HumanPlayer playerOne = new HumanPlayer('X');
            ComputerPlayer playerTwo = new ComputerPlayer('O');

            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerTwo.MakeMove(0, 0));
            board.LogMove(playerOne.MakeMove(0, 1));
            board.LogMove(playerTwo.MakeMove(2, 1));
            board.LogMove(playerOne.MakeMove(0, 2));
            board.LogMove(playerTwo.MakeMove(2, 0));
            board.LogMove(playerOne.MakeMove(1, 0));
            board.LogMove(playerTwo.MakeMove(1, 2));
            board.LogMove(playerOne.MakeMove(2, 2));

            Assert.AreEqual(true, target.CheckForTie(board.boardArray));
        }
        public void VariableBoardSizeConstructorTest()
        {
            BoardManager target = new BoardManager(3);
            CollectionAssert.AreEqual(new char[3, 3], target.boardArray);

            target = new BoardManager(5);
            CollectionAssert.AreEqual(new char[5, 5], target.boardArray);
        }
Example #12
0
 public Game()
 {
     board = new BoardManager();
 }
        public void CheckForWinShouldReturnTrueIfThereAreThreeOsInARow()
        {
            BoardChecker target = new BoardChecker();

            //Three Across the Top
            BoardManager board = new BoardManager();
            HumanPlayer playerOne = new HumanPlayer('o');
            board.LogMove(playerOne.MakeMove(0, 0));
            board.LogMove(playerOne.MakeMove(1, 0));
            board.LogMove(playerOne.MakeMove(2, 0));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Across the Middle
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 1));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(2, 1));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Across the Bottom
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 2));
            board.LogMove(playerOne.MakeMove(1, 2));
            board.LogMove(playerOne.MakeMove(2, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Down the Left Side
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 0));
            board.LogMove(playerOne.MakeMove(0, 1));
            board.LogMove(playerOne.MakeMove(0, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Down the Middle
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(1, 0));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(1, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three Down the Right Side
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(1, 0));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(1, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three In A Slash
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 2));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(2, 0));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));

            //Three In A Backslash
            board = new BoardManager();
            board.LogMove(playerOne.MakeMove(0, 0));
            board.LogMove(playerOne.MakeMove(1, 1));
            board.LogMove(playerOne.MakeMove(2, 2));
            Assert.AreEqual(true, target.CheckForWin(board.boardArray));
        }
 public void BoardManagerConstructorTest()
 {
     BoardManager target = new BoardManager();
 }
        public void ResetBoardShouldBlankAllBoardValues()
        {
            BoardManager target = new BoardManager();
            target.ResetBoard();

            CollectionAssert.AreEqual(new char[3, 3], target.boardArray);

            target = new BoardManager(5);
            target.ResetBoard();

            CollectionAssert.AreEqual(new char[5, 5], target.boardArray);
        }
 public void LogMoveShouldNotOverwriteMoves()
 {
     BoardManager target = new BoardManager();
     target.LogMove(new Tuple<int, int>(1, 1));
     target.LogMove(new Tuple<int, int>(1, 1));
     char expectedIdentity = 'X';
     char actualIdentity = target.boardArray[1, 1];
     Assert.AreEqual(expectedIdentity, actualIdentity);
 }
 public void LogMoveShouldLogACreatedMove()
 {
     BoardManager target = new BoardManager();
     target.LogMove(new Tuple<int, int>(1, 1));
     char actual = target.boardArray[1, 1];
     char expected = 'X';
     Assert.AreEqual(expected, actual);
 }