How to use the pelita.game.play_turn 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_player_base.py View on Github external
################ """)
        def init_rng_players():
            player_rngs = []
            def rng_test(bot, state):
                player_rngs.append(bot.random)
                return bot.position, state
            team = [
                rng_test,
                rng_test
            ]
            return team, player_rngs

        team0, player_rngs0 = init_rng_players()
        state = setup_game(team0, layout_dict=parse_layout(test_layout), max_rounds=5, seed=20)
        # play two steps
        play_turn(play_turn(state))
        assert len(player_rngs0) == 2
        # generate some random numbers for each player
        random_numbers0 = [rng.randint(0, 10000) for rng in player_rngs0]
        # teams should have generated a different number
        assert random_numbers0[0] != random_numbers0[1]

        team1, player_rngs1 = init_rng_players()
        state = setup_game(team1, layout_dict=parse_layout(test_layout), max_rounds=5, seed=20)
        # play two steps
        play_turn(play_turn(state))
        assert len(player_rngs1) == 2
        # generate some random numbers for each player
        random_numbers1 = [rng.randint(0, 10000) for rng in player_rngs1]
        # teams should have generated the same numbers as before
        assert random_numbers0 == random_numbers1
github ASPP / pelita / test / test_game.py View on Github external
def test_bot_does_not_eat_own_food():
    test_layout = """
        ######
        #0 .3#
        #.21 #
        ######
    """
    teams = [
        stepping_player('v', '<'),
        stepping_player('^', '<')
    ]
    state = setup_game(teams, layout_dict=layout.parse_layout(test_layout), max_rounds=2)
    assert state['bots'] == [(1, 1), (3, 2), (2, 2), (4, 1)]
    assert state['food'] == [{(1, 2)}, {(3, 1)}]
    for i in range(4):
        state = play_turn(state)
    assert state['bots'] == [(1, 2), (3, 1), (1, 2), (3, 1)]
    assert state['food'] == [{(1, 2)}, {(3, 1)}]
github ASPP / pelita / test / test_game.py View on Github external
#1     #
    ########
    """
    ]
    def move(bot, state):
        if bot.is_blue and bot.turn == 0 and bot.round == 1:
            return (1, 1)
        if bot.is_blue and bot.turn == 1 and bot.round == 1:
            return (5, 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 moves. Rescues itself
    assert state['bots'] == layouts[2]['bots']
github ASPP / pelita / test / test_game.py View on Github external
#  . #
            #.   #
            #    #
            ######
            ######
            # 2  #
            #0 1 #
            #   3#
            ###### """)

    assert test_sixth_round['bots'] == state['bots']
    assert test_sixth_round['food'] == list(state['food'][0]) + list(state['food'][1])
    assert state['score'] == [game.KILL_POINTS * 2, game.KILL_POINTS * 2+ 1]

    for i in range(3): # !! Only move three bots
        state = game.play_turn(state)

    test_seventh_round = layout.parse_layout(
        """ ######
            #    #
            #.   #
            #    #
            ######
            ######
            #  2 #
            #0 1 #
            #   3#
            ###### """)

    assert test_seventh_round['bots'] == state['bots']
    assert test_seventh_round['food'] == list(state['food'][0]) + list(state['food'][1])
    assert state['score'] == [game.KILL_POINTS * 2 + 1, game.KILL_POINTS * 2 + 1]
github ASPP / pelita / test / test_game.py View on Github external
""",
    """
    ########
    #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
########
    #3 ..  #
    #0   12#
    ########
    """
    ]
    def move(bot, state):
        if bot.is_blue and bot.turn == 0 and bot.round == 1:
            return (1, 2)
        if not bot.is_blue and bot.turn == 0 and bot.round == 1:
            return (5, 2)
        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 1. Bot 1 and 2 are on same spot
    assert state['bots'] == layouts[1]['bots']
    state = game.play_turn(state) # Bot 1 moves. Bot 2 is rescued.
    assert state['bots'] == layouts[2]['bots']
github ASPP / pelita / test / test_player_base.py View on Github external
#b        x#
            ############ """)
        num_rounds = 5
        teams = [
            stepping_player('>v<^-', '-----'),
            stepping_player('<^>v-', '-----')
        ]
        state = setup_game(teams, layout_dict=parse_layout(test_layout), max_rounds=5)
        player0_expected_positions = [(1,1), (2,1), (2,2), (1,2), (1,1), (1, 1)]
        player1_expected_positions = [(10,2), (9,2), (9,1), (10,1), (10,2), (10, 2)]

        assert state['bots'][0] == player0_expected_positions[0]
        assert state['bots'][1] == player1_expected_positions[0]
        for i in range(1, num_rounds+1):
            for step in range(4):
                state = play_turn(state)
            assert state['bots'][0] == player0_expected_positions[i]
            assert state['bots'][1] == player1_expected_positions[i]
github ASPP / pelita / test / test_game.py View on Github external
########
    #0 ..23#
    #1     #
    ########
    """
    ]
    def move(bot, state):
        if bot.is_blue and bot.turn == 0 and bot.round == 1:
            return (1, 1)
        if bot.is_blue and bot.turn == 1 and bot.round == 1:
            return (5, 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 moves. Rescues itself
    assert state['bots'] == layouts[2]['bots']
github ASPP / pelita / test / test_game.py View on Github external
########
    #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']