コード例 #1
0
        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
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public string AssignGameAgainstRandomBot(string playerKey)
        {
            var gameKey = Guid.NewGuid().ToString();
            var g       = new Model.Game {
                Board = Reversi.GetInitialState(), PlayerOne = playerKey
            };

            var added = _database.TryAdd(gameKey, g);

            if (!added)
            {
                throw new ApplicationException("Game already added");
            }

            var botName = $"randy_{Guid.NewGuid().ToString().Replace("-", "")}";

            g.PlayerTwo = botName;

            return(gameKey);
        }
コード例 #7
0
        public string AssignGame(string playerKey)
        {
            var game = _database.FirstOrDefault(x => string.IsNullOrEmpty(x.Value.PlayerTwo));

            if (game.Key is default(string))
            {
                var gameKey = Guid.NewGuid().ToString();
                var g       = new Model.Game {
                    Board = Reversi.GetInitialState(), PlayerOne = playerKey
                };

                var added = _database.TryAdd(gameKey, g);
                if (!added)
                {
                    throw new ApplicationException("Game already added");
                }

                return(gameKey);
            }

            game.Value.PlayerTwo = playerKey;
            return(game.Key);
        }