public void CheckForWinningSquare_WinIsNotPossible_ReturnsNull()
        {
            Board board = new Board();

            board.Squares[2, 2].State = SquareState.X;
            List <int[]> availableMoves = GameplayHelper.ListEmptySquares(board.Squares);

            var actual = GameplayHelper.CheckForWinningSquare(board.Squares, availableMoves, SquareState.X);

            Assert.Null(actual);
        }
        public void CheckForWinningSquare_WinIsPossible_ReturnsCorrectResult()
        {
            var   expected = new int[] { 0, 1 };
            Board board    = new Board();

            board.Squares[0, 0].State = SquareState.X;
            board.Squares[0, 2].State = SquareState.X;
            List <int[]> availableMoves = GameplayHelper.ListEmptySquares(board.Squares);

            var actual = GameplayHelper.CheckForWinningSquare(board.Squares, availableMoves, SquareState.X);

            Assert.Equal(expected, actual);
        }
        public void ListEmptySquares_AllSquaresFilled_ReturnsEmptyList()
        {
            var board = new Board();

            foreach (var square in board.Squares)
            {
                square.State = SquareState.O;
            }

            var actual = GameplayHelper.ListEmptySquares(board.Squares);

            Assert.Empty(actual);
        }
        public void ListEmptySquares_AllSquaresEmpty_ListContainsAllSquares()
        {
            var board    = new Board();
            var expected = new List <int[]>
            {
                new int[] { 0, 0 },
                new int[] { 0, 1 },
                new int[] { 0, 2 },
                new int[] { 1, 0 },
                new int[] { 1, 1 },
                new int[] { 1, 2 },
                new int[] { 2, 0 },
                new int[] { 2, 1 },
                new int[] { 2, 2 },
            };

            var actual = GameplayHelper.ListEmptySquares(board.Squares);

            Assert.Equal(expected, actual);
        }
Example #5
0
        public void MediumComputerPlayer_NeitherComputerNorHumanCanWin_ComputerMakesMove(int col1, int row1, int col2, int row2, int col3, int row3, int col4, int row4)
        {
            var board = new Board();

            board.Squares[col1, row1].State = SquareState.O;
            board.Squares[col2, row2].State = SquareState.O;
            board.Squares[col3, row3].State = SquareState.X;
            board.Squares[col4, row4].State = SquareState.X;

            List <int[]> emptySquaresBeforeMove = GameplayHelper.ListEmptySquares(board.Squares);

            Assert.Equal(5, emptySquaresBeforeMove.Count);

            var player = new MediumComputerPlayer();
            var actual = player.PlayerInput(board.Squares);

            List <int[]> emptySquaresAfterMove = GameplayHelper.ListEmptySquares(actual);

            Assert.Equal(4, emptySquaresAfterMove.Count);
        }
        public void ListEmptySquares_SomeSquaresFilled_ListContainsOnlyEmptySquares()
        {
            var board = new Board();

            board.Squares[0, 1].State = SquareState.O;
            board.Squares[0, 0].State = SquareState.O;
            board.Squares[1, 1].State = SquareState.X;
            board.Squares[2, 0].State = SquareState.X;

            var expected = new List <int[]>
            {
                new int[] { 0, 2 },
                new int[] { 1, 0 },
                new int[] { 1, 2 },
                new int[] { 2, 1 },
                new int[] { 2, 2 },
            };

            var actual = GameplayHelper.ListEmptySquares(board.Squares);

            Assert.Equal(expected, actual);
        }