Exemple #1
0
def test_mapping_objectives():
    """ Tests correct mapping of players' objective """
    game = _create_test_game()
    game_dto = mapper.game_state_to_dto(game)
    assert keys.OBJECTIVE in game_dto
    assert game_dto[
        keys.OBJECTIVE] == game.board.objective_maze_card.identifier
Exemple #2
0
def get_game_state(game_id):
    """ Returns the game state """
    _ = interactors.OverduePlayerInteractor(game_repository())
    interactor = interactors.ObserveGameInteractor(game_repository())
    game = _try(lambda: interactor.retrieve_game(game_id))
    game_state = mapper.game_state_to_dto(game)
    DatabaseGateway.get_instance().commit()
    return game_state
def test_mapping_enabled_shift_loctions():
    """ Tests correct mapping of enabled shift loctions """
    game = _create_test_game()
    game_dto = mapper.game_state_to_dto(game, timedelta(0))
    assert keys.ENABLED_SHIFT_LOCATIONS in game_dto
    assert len(game_dto[keys.ENABLED_SHIFT_LOCATIONS]) == 11
    for enabled_shift_location in game_dto[keys.ENABLED_SHIFT_LOCATIONS]:
        assert keys.ROW in enabled_shift_location
        assert keys.COLUMN in enabled_shift_location
Exemple #4
0
def get_game_state(game_id):
    """ Returns the game state """
    _ = interactors.OverduePlayerInteractor(game_repository(), logging.get_logger())
    _ = interactors.UpdateOnTurnChangeInteractor(game_repository())
    action_timeout = timedelta(seconds=int(current_app.config["OVERDUE_PLAYER_TIMEDELTA_S"]))
    interactor = interactors.ObserveGameInteractor(game_repository(), action_timeout=action_timeout)
    game, remaining_timedelta = _try(lambda: interactor.retrieve_game(game_id))
    game_state = mapper.game_state_to_dto(game, remaining_timedelta)
    DatabaseGateway.get_instance().commit()
    return game_state
def test_mapping_players_sort_order():
    """ Tests that players are sorted by piece index """
    game = _create_test_game()
    game.remove_player(1)
    game.add_player(Player(identifier=2))
    game.add_player(Player(identifier=1))
    game_dto = mapper.game_state_to_dto(game, timedelta(0))

    assert game_dto[keys.PLAYERS][0][keys.PIECE_INDEX] < game_dto[keys.PLAYERS][1][keys.PIECE_INDEX]
    assert game_dto[keys.PLAYERS][1][keys.PIECE_INDEX] < game_dto[keys.PLAYERS][2][keys.PIECE_INDEX]
def test_mapping_leftover():
    """ Tests correct mapping of leftover maze card """
    game = _create_test_game()
    game_dto = mapper.game_state_to_dto(game, timedelta(0))
    maze_cards = game_dto[keys.MAZE][keys.MAZE_CARDS]
    leftover_dtos = [maze_card for maze_card in maze_cards
                     if not maze_card[keys.LOCATION]]
    assert len(leftover_dtos) == 1
    leftover_dto = leftover_dtos[0]
    assert leftover_dto[keys.ID] == game.board.leftover_card.identifier
    assert leftover_dto[keys.OUT_PATHS] == game.board.leftover_card.out_paths
def test_mapping_players():
    """ Tests correct mapping of players """
    game = _create_test_game()
    game_dto = mapper.game_state_to_dto(game, timedelta(0))
    assert keys.PLAYERS in game_dto
    assert len(game_dto[keys.PLAYERS]) == len(game.board.pieces)
    assert len(game_dto[keys.PLAYERS]) == len(game.players)
    for player_dto in game_dto[keys.PLAYERS]:
        assert keys.ID in player_dto
        player_game = game.get_player(player_dto[keys.ID])
        assert player_game
        assert player_dto[keys.MAZE_CARD_ID] == player_game.piece.maze_card.identifier
        assert keys.OBJECTIVE not in player_dto
        assert keys.SCORE in player_dto
        assert player_dto[keys.SCORE] == player_game.score
        assert player_dto[keys.PIECE_INDEX] == player_game.piece.piece_index
def test_mapping_board():
    """ Tests correct mapping of current board state """
    game = _create_test_game()
    game_dto = mapper.game_state_to_dto(game, timedelta(0))
    maze_cards = game_dto[keys.MAZE][keys.MAZE_CARDS]
    maze_card_dtos = [maze_card_dto for maze_card_dto in maze_cards
                      if maze_card_dto[keys.LOCATION]]
    assert game_dto[keys.MAZE][keys.MAZE_SIZE] == game.board.maze.maze_size
    assert len(maze_card_dtos) == game.board.maze.maze_size * game.board.maze.maze_size
    ids = set()
    for maze_card_dto in maze_card_dtos:
        location = _assert_and_return_location_dto(maze_card_dto[keys.LOCATION])
        maze_card_game = game.board.maze[location]
        assert maze_card_dto[keys.ID] == maze_card_game.identifier
        assert maze_card_dto[keys.OUT_PATHS] == maze_card_game.out_paths
        assert maze_card_dto[keys.ROTATION] == maze_card_game.rotation
        ids.add(maze_card_dto[keys.ID])
    assert len(ids) == len(maze_card_dtos)
def test_mapping_identifier():
    """ Tests correct mapping of game's identifier """
    game = _create_test_game()
    game_dto = mapper.game_state_to_dto(game, timedelta(0))
    assert game_dto[keys.ID] == game.identifier