How to use the pelita.game.setup_game function in pelita

To help you get started, we’ve selected a few pelita examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ASPP / pelita / test / test_game.py View on Github external
#     2#
    ########
    """,
    """
    ########
    #0 .. 3#
    #2    1#
    ########
    """
    ]
    def move(bot, state):
        if not bot.is_blue and bot.turn == 1 and bot.round == 1:
            return (6, 1)
        return bot.position
    layouts = [layout.parse_layout(l) for l in cascade]
    state = setup_game([move, move], max_rounds=5, layout_dict=layout.parse_layout(cascade[0]))
    assert state['bots'] == layouts[0]['bots']
    state = game.play_turn(state) # Bot 0 stands
    assert state['bots'] == layouts[0]['bots']
    state = game.play_turn(state) # Bot 1 stands
    state = game.play_turn(state) # Bot 2 stands
    state = game.play_turn(state) # Bot 3 moves, kills 0. Bot 0 and 1 are on same spot
    assert state['bots'] == layouts[1]['bots']
    state = game.play_turn(state) # Bot 0 stands, kills 1. Bot 1 and 2 are on same spot
    assert state['bots'] == layouts[2]['bots']
    state = game.play_turn(state) # Bot 1 stands, kills 2.
    assert state['bots'] == layouts[3]['bots']
github ASPP / pelita / test / test_game.py View on Github external
#0#.  .  # .     #
        #2#####    #####3#
        #     . #  .  .#1#
        ################## """
    # remove bot x when bots_hidden[x] is True
    for x in range(4):
        if bots_hidden[x]:
            test_layout = test_layout.replace(str(x), ' ')
    parsed_layout = layout.parse_layout(test_layout)

    # dummy player
    stopping = lambda bot, s: (bot.position, s)

    if list(bots_hidden) == [False] * 4:
        # no bots are hidden. it should succeed
        setup_game([stopping, stopping], layout_dict=parsed_layout, max_rounds=10)
    else:
        with pytest.raises(ValueError):
            setup_game([stopping, stopping], layout_dict=parsed_layout, max_rounds=10)
github ASPP / pelita / test / test_game_master.py View on Github external
def test_setup_game_with_different_number_of_bots(self, bots):
        layout = """
        ######
        #  . #
        # .# #
        ######
        """
        bot_pos, should_succeed = bots
        parsed = parse_layout(layout)
        parsed['bots'] = bot_pos

        if should_succeed:
            state = setup_game([stopping_player] * 2, layout_dict=parsed, max_rounds=5)
            assert state['bots'] == bot_pos
            state = run_game([stopping_player] * 2, layout_dict=parsed, max_rounds=5)
            assert state['fatal_errors'] == [[], []]
            assert state['errors'] == [{}, {}]
        else:
            with pytest.raises(ValueError):
                setup_game([stopping_player] * 2, layout_dict=parsed, max_rounds=300)
github ASPP / pelita / test / test_game.py View on Github external
#     2#
    ########
    """,
    """
    ########
    #0 .. 3#
    #2    1#
    ########
    """
    ]
    def move(bot, state):
        if bot.is_blue and bot.turn == 0 and bot.round == 1:
            return (6, 1)
        return bot.position
    layouts = [layout.parse_layout(l) for l in cascade]
    state = setup_game([move, move], max_rounds=5, layout_dict=layout.parse_layout(cascade[0]))
    assert state['bots'] == layouts[0]['bots']
    state = game.play_turn(state) # Bot 0 moves onto 3. Gets killed. Bot 0 and 1 are on same spot.
    assert state['bots'] == layouts[1]['bots']
    state = game.play_turn(state) # Bot 1 moves, gets killed. Bot 1 and 2 are on same spot
    assert state['bots'] == layouts[2]['bots']
    state = game.play_turn(state) # Bot 2 moves, gets killed.
    assert state['bots'] == layouts[3]['bots']
github ASPP / pelita / test / test_game.py View on Github external
#2     #
    ########
    """,
    """
    ########
    #0 .. 3#
    #2    1#
    ########
    """
    ]
    def move(bot, state):
        if bot.is_blue and bot.turn == 0 and bot.round == 1:
            return (1, 1)
        return bot.position
    layouts = [layout.parse_layout(l) for l in cascade]
    state = setup_game([move, move], max_rounds=5, layout_dict=layout.parse_layout(cascade[0]))
    assert state['bots'] == layouts[0]['bots']
    state = game.play_turn(state) # Bot 0 moves, kills 3. Bot 2 and 3 are on same spot
    assert state['bots'] == layouts[1]['bots']
    state = game.play_turn(state) # Bot 1 stands. Bot 2 and 3 are on same spot
    assert state['bots'] == layouts[1]['bots']
    state = game.play_turn(state) # Bot 2 stands, gets killed. Bot 1 and 2 are on same spot
    assert state['bots'] == layouts[2]['bots']
    state = game.play_turn(state) # Bot 3 stands. Bot 1 and 2 are on same spot
    assert state['bots'] == layouts[2]['bots']
    state = game.play_turn(state) # Bot 0 stands. Bot 1 and 2 are on same spot
    assert state['bots'] == layouts[2]['bots']
    state = game.play_turn(state) # Bot 1 stands, kills 2.
    assert state['bots'] == layouts[3]['bots']
github ASPP / pelita / test / test_game.py View on Github external
def setup_random_basic_gamestate(*, round=1, turn=0):
    """helper function for testing play turn"""
    l = layout.get_layout_by_name("small_100")
    parsed_l = layout.parse_layout(l)

    stopping = lambda bot, s: (bot.position, s)

    game_state = setup_game([stopping, stopping], layout_dict=parsed_l)
    game_state['round'] = round
    game_state['turn'] = turn
    return game_state
github ASPP / pelita / test / test_game_master.py View on Github external
def test_too_few_registered_teams(self):
        test_layout_4 = (
        """ ##################
            #0#.  .  # .     #
            #2#####    #####1#
            #     . #  .  .#3#
            ################## """)
        team_1 = stopping_player
        with pytest.raises(ValueError):
            setup_game([team_1], layout_dict=parse_layout(test_layout_4), max_rounds=300)
github ASPP / pelita / test / test_game.py View on Github external
"""helper function for testing play turn"""
    l = """
##################
#. ... .##.     3#
# # #  .  .### #1#
# # ##.   .      #
#      .   .## # #
#0# ###.  .  # # #
#2     .##. ... .#
##################
"""
    parsed_l = layout.parse_layout(l)

    stopping = lambda bot, s: (bot.position, s)

    game_state = setup_game([stopping, stopping], layout_dict=parsed_l)
    game_state['round'] = round
    game_state['turn'] = turn
    return game_state
github ASPP / pelita / test / test_player_base.py View on Github external
def test_stepping_players(self):
        test_layout = (
        """ ############
            #a  .  .  x#
            #b        y#
            ############ """)
        movements_0 = [east, east]
        movements_1 = [west, west]
        teams = [
            stepping_player(movements_0, movements_0),
            stepping_player(movements_1, movements_1)
        ]
        state = setup_game(teams, layout_dict=parse_layout(test_layout), max_rounds=2)
        assert state['bots'] == [(1, 1), (10, 1), (1, 2), (10, 2)]
        state = run_game(teams, layout_dict=parse_layout(test_layout), max_rounds=2)
        assert state['bots'] == [(3, 1), (8, 1), (3, 2), (8, 2)]