Beispiel #1
0
 def test_get_moves_stalemate(self, board, try_move):
     try_move.return_value = True
     game = Game()
     game._board = board
     mocked_board_moves = {}
     board.in_check.return_value = False
     board.get_moves.return_value = mocked_board_moves
     all_game_moves = game.get_moves(constants.WHITE)
     self.assertEqual(game.status, constants.STALEMATE)
Beispiel #2
0
def set_up_test_game(board, turn=WHITE, history=None):
    """Helper method sets up a game for testing"""
    game = Game()
    game._board = board
    game._turn = turn
    if history:
        game._history.append(history)
    game.valid_moves = game.get_moves(game.turn)

    return game 
Beispiel #3
0
    def test_get_moves_no_special(self, board, try_move):

        invalid_position = Position(3, 3)

        def my_side_effect(*args):
            if args[1] == invalid_position:
                return False
            return True

        try_move.side_effect = my_side_effect
        game = Game()
        game._board = board
        rook = Rook(board, constants.WHITE, Position(4, 4))
        bishop = Bishop(board, constants.WHITE, Position(1, 1))
        knight = Knight(board, constants.WHITE, Position(7, 0))
        mocked_board_moves = {
            rook: {
                constants.MOVES: [Position(5, 4),
                                  Position(3, 4)],
                constants.SPECIAL_MOVES: {}
            },
            bishop: {
                constants.MOVES: [Position(2, 2), invalid_position],
                constants.SPECIAL_MOVES: {}
            },
            knight: {
                constants.MOVES: [],
                constants.SPECIAL_MOVES: {}
            }
        }
        valid_moves = {
            rook: {
                constants.MOVES: [Position(5, 4),
                                  Position(3, 4)],
                constants.SPECIAL_MOVES: {}
            },
            bishop: {
                constants.MOVES: [Position(2, 2)],
                constants.SPECIAL_MOVES: {}
            },
            knight: {
                constants.MOVES: [],
                constants.SPECIAL_MOVES: {}
            }
        }
        board.get_moves.return_value = mocked_board_moves
        all_game_moves = game.get_moves(constants.WHITE)
        self.assertEqual(len(mocked_board_moves), len(all_game_moves))
        for key in valid_moves.keys():
            self.assertIn(key, all_game_moves)
            self.assertEqual(len(valid_moves[key]), len(all_game_moves[key]))
            for move in mocked_board_moves[key]:
                self.assertIn(move, all_game_moves[key])
        self.assertEqual(game.status, constants.IN_PROGRESS)