public void Turn_matrix2()
        {
            //Arrange
            var board = new[, ]
            {
                { 'X', ' ', ' ', ' ', 'X', ' ', ' ', ' ' },
                { ' ', 'O', ' ', ' ', 'O', ' ', ' ', 'X' },
                { ' ', ' ', 'O', ' ', 'O', ' ', 'O', ' ' },
                { ' ', ' ', ' ', 'O', 'O', 'O', ' ', ' ' },
                { 'X', 'O', 'O', 'O', ' ', 'O', 'O', 'X' },
                { ' ', ' ', ' ', 'O', 'O', 'O', ' ', ' ' },
                { ' ', ' ', 'O', ' ', 'O', ' ', 'O', ' ' },
                { ' ', 'X', ' ', ' ', 'X', ' ', ' ', 'X' },
            };
            var expected = new[, ]
            {
                { 'X', ' ', ' ', ' ', 'X', ' ', ' ', ' ' },
                { ' ', 'X', ' ', ' ', 'X', ' ', ' ', 'X' },
                { ' ', ' ', 'X', ' ', 'X', ' ', 'X', ' ' },
                { ' ', ' ', ' ', 'X', 'X', 'X', ' ', ' ' },
                { 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' },
                { ' ', ' ', ' ', 'X', 'X', 'X', ' ', ' ' },
                { ' ', ' ', 'X', ' ', 'X', ' ', 'X', ' ' },
                { ' ', 'X', ' ', ' ', 'X', ' ', ' ', 'X' },
            };

            //Act
            var newBoard = Reversi.Move(board, 4, 4, 'X');

            //Assert
            Assert.That(newBoard, Is.EqualTo(expected));
        }
        public void Placing_X_on_42_on_initial_board_should_return_a_board()
        {
            //Arrange
            var board = Reversi.GetInitialState();

            //Act
            var newBoard = Reversi.Move(board, 4, 2, 'X');

            //Assert
        }
        public void Placing_disc_on_occupied_space_should_throw()
        {
            //Arrange
            var board = Reversi.GetInitialState();

            //Act
            void newBoard() => Reversi.Move(board, 3, 3, 'X');

            //Assert
            Assert.Throws <ReversiException>(newBoard);
        }
        public void Placing_X_on_54_on_initial_board_should_throw()
        {
            //Arrange
            var board = Reversi.GetInitialState();

            //Act
            void newBoard() => Reversi.Move(board, 5, 4, 'X');

            //Assert
            Assert.Throws <ReversiException>(newBoard);
        }
        public void Placing_X_on_25_on_valid_board()
        {
            //Arrange
            var board = Reversi.GetInitialState();

            board[4, 3] = 'X';

            //Act
            void newBoard() => Reversi.Move(board, 2, 5, 'X');

            //Assert
            Assert.Throws <ReversiException>(newBoard);
        }
Esempio n. 6
0
        public string UpdateGameState(Model.Game gameSession, int x, int y)
        {
            if (gameSession.State == Model.Game.GameState.Finished)
            {
                throw new ReversiException($"Game has finished, scores are: {gameSession.PlayerOne}={gameSession.PlayerOneScore} - {gameSession.PlayerTwo}={gameSession.PlayerTwoScore}");
            }

            gameSession.State = Model.Game.GameState.Ongoing;
            var disc = gameSession.NextPlayer == gameSession.PlayerOne ? 'X' : 'O';

            try
            {
                if (x == -1 && y == -1)
                {
                    var moves = Reversi.GetMoves(gameSession.Board as char[, ], disc);
                    if (moves.Length != 0)
                    {
                        throw new ReversiException("Only allowed to skip when no moves are available");
                    }

                    // Two skips in a row = game finished
                    var lastMove = gameSession.Moves.Last();
                    if (lastMove.X == -1 && lastMove.Y == -1)
                    {
                        gameSession.State = Model.Game.GameState.Finished;
                    }
                }
                else
                {
                    gameSession.Board = Reversi.Move(gameSession.Board as char[, ], x, y, disc);
                }

                gameSession.Turn++;
                gameSession.Moves.Add(new Model.Game.Move {
                    Disc = disc, X = x, Y = y
                });

                var otherDisc = disc == 'X' ? 'O' : 'X';
                if (GetPossibleMoves(gameSession.Board as char[, ], disc).Length == 0 && GetPossibleMoves(gameSession.Board as char[, ], otherDisc).Length == 0)
                {
                    gameSession.State = Model.Game.GameState.Finished;
                }

                return(null);
            }
            catch (ReversiException e)
            {
                return($"You did somthing you shouldn't have done...{Environment.NewLine}{e.Message}");
            }
        }
        public void Placing_X_on_24_on_initial_board_turns_discs()
        {
            //Arrange
            var board    = Reversi.GetInitialState();
            var expected = Reversi.GetInitialState();

            expected[4, 2] = 'X';
            expected[4, 3] = 'X';

            //Act
            var newBoard = Reversi.Move(board, 2, 4, 'X');

            //Assert
            Assert.That(newBoard, Is.EqualTo(expected));
        }