How to use the pelita.game.apply_move 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
#0# ##################
    #1# #. ... .##.     3#
    #2# # # #  .  .### #1#
    #3# # # ##.   .      #
    #4# #      .   .## # #
    #5# #0# ###.  .  # # #
    #6# #2     .##. ... .#
    #7# ##################
    game_state = setup_specific_basic_gamestate()
    turn = setups[0]
    enemy_pos = setups[1]
    team = turn % 2
    game_state["turn"] = turn
    enemy_idx = (1, 3) if team == 0 else (0, 2)
    game_state["bots"][enemy_idx[0]] = enemy_pos
    game_state_new = apply_move(game_state, enemy_pos)
    # assert game_state_new["DEATHS"][team] == 5
    assert game_state_new["score"][team] == 5
github ASPP / pelita / test / test_game.py View on Github external
# specify which bot should move
    test_state = setup_random_basic_gamestate(turn=bot_to_move)

    bot_was_killed_flags = list(bot_was_killed_flags) # needs to be a list
    test_state['bot_was_killed'] = bot_was_killed_flags[:] # copy to avoid reference issues

    # create bot state for current turn
    current_bot_position = test_state['bots'][bot_to_move]
    bot_state = game.prepare_bot_state(test_state)

    # bot state should have proper bot_was_killed flag
    assert bot_state['team']['bot_was_killed'] == bot_was_killed_flags[team_id::2]

    # apply a dummy move that should reset bot_was_killed for the current bot
    new_test_state = game.apply_move(test_state, current_bot_position)

    # the bot_was_killed flag should be False again
    assert test_state['bot_was_killed'][bot_to_move] == False

    # the bot_was_killed flags for other bot should still be as before
    assert test_state['bot_was_killed'][other_bot] == bot_was_killed_flags[other_bot]

    # all bot_was_killed flags for other team should still be as before
    assert test_state['bot_was_killed'][other_team_id::2] == bot_was_killed_flags[other_team_id::2]
github ASPP / pelita / test / test_game.py View on Github external
### 012345678901234567
    #0# ##################
    #1# #. ... .##.     3#
    #2# # # #  .  .### #1#
    #3# # # ##.   .      #
    #4# #      .   .## # #
    #5# #0# ###.  .  # # #
    #6# #2     .##. ... .#
    #7# ##################
    game_state = setup_specific_basic_gamestate()
    team = turn % 2
    game_state["turn"] = turn
    enemy_idx = (1, 3) if team == 0 else(0, 2)
    (friend_idx,) = set([0, 1, 2, 3]) - set([*enemy_idx, turn])

    game_state_new = apply_move(game_state, game_state["bots"][friend_idx])
    # assert game_state_new["DEATHS"][team] == 5
    assert game_state_new["score"] == [0, 0]
    assert game_state_new["deaths"] == [0]*4
github ASPP / pelita / test / test_game.py View on Github external
#6# #2     .##. ... .#
    #7# ##################
    game_state = setup_specific_basic_gamestate(round=0, turn=turn)
    team = turn % 2
    prev_len_food = [len(team_food) for team_food in game_state["food"]]

    if which_food == 0:
        # Try to eat food on left side
        game_state["bots"][turn] = (6, 4)
        move = (7, 4)
    else:
        # Try to eat food on right side
        game_state["bots"][turn] = (11, 1)
        move = (10, 1)

    game_state_new = apply_move(game_state, move)

    if team == which_food:
        # No changes for either team
        assert game_state_new["score"][team] == 0
        assert game_state_new["score"][1 - team] == 0
        assert prev_len_food[team] == len(game_state_new["food"][team])
        assert prev_len_food[1 - team] == len(game_state_new["food"][1 - team])
    elif team != which_food:
        # Own team gains points, other team loses food
        assert game_state_new["score"][team] > 0
        assert game_state_new["score"][1 - team] == 0
        assert prev_len_food[team] == len(game_state_new["food"][team])
        assert prev_len_food[1 - team] > len(game_state_new["food"][1 - team])
github ASPP / pelita / test / test_game.py View on Github external
"turn": turn,
        "round": 0,
        "timeout": [],
        "gameover": False,
        "whowins": None,
        "team_say": "bla",
        "score": 0,
        "kills":[0]*4,
        "deaths": [0]*4,
        "bot_was_killed": [False]*4,
        "errors": [[], []],
        "fatal_errors": [{}, {}],
        "rnd": random.Random()
        }
    legal_positions = get_legal_positions(game_state["walls"], game_state["bots"][turn])
    game_state_new = apply_move(game_state, legal_positions[0])
    assert game_state_new["bots"][turn] == legal_positions[0]
github ASPP / pelita / test / test_game.py View on Github external
def test_play_turn_fatal(turn):
    """Checks that game quite after fatal error"""
    game_state = setup_random_basic_gamestate()
    game_state["turn"] = turn
    team = turn % 2
    fatal_list = [{}, {}]
    fatal_list[team] = {"error":True}
    game_state["fatal_errors"] = fatal_list
    move = get_legal_positions(game_state["walls"], game_state["bots"][turn])
    game_state_new = apply_move(game_state, move[0])
    assert game_state_new["gameover"]
    assert game_state_new["whowins"] == int(not team)
github ASPP / pelita / test / test_game.py View on Github external
# team 0 scores
        assert new_state['score'] == [5, 0]
#        # bots 1 and 3 are back to origin
        if bot == 1:
            assert new_state['bots'][1::2] == [(6, 2), (1, 2)]
        elif bot == 3:
            assert new_state['bots'][1::2] == [(3, 2), (6, 1)]

    parsed_l1 = layout.parse_layout(l1)
    for bot in (0, 2):
        game_state = setup_game([stopping, stopping], layout_dict=parsed_l1)

        game_state['turn'] = bot
        # get position of bot 3
        suicide_position = game_state['bots'][3]
        new_state = apply_move(game_state, suicide_position)
        # team 0 scores
        assert new_state['score'] == [0, 5]
github ASPP / pelita / test / test_game.py View on Github external
assert kill_position == game_state['bots'][3]
        new_state = apply_move(game_state, kill_position)
        # team 0 scores twice
        assert new_state['score'] == [10, 0]
        # bots 1 and 3 are back to origin
        assert new_state['bots'][1::2] == [(6, 2), (6, 1)]

    parsed_l1 = layout.parse_layout(l1)
    for bot in (1, 3):
        game_state = setup_game([stopping, stopping], layout_dict=parsed_l1)

        game_state['turn'] = bot
        # get position of bots 0 (and 2)
        kill_position = game_state['bots'][0]
        assert kill_position == game_state['bots'][2]
        new_state = apply_move(game_state, kill_position)
        # team 1 scores twice
        assert new_state['score'] == [0, 10]
        # bots 0 and 2 are back to origin
        assert new_state['bots'][0::2] == [(1, 1), (1, 2)]
github ASPP / pelita / test / test_game.py View on Github external
def test_play_turn_illegal_position(turn):
    """check that illegal moves are added to error dict and bot still takes move"""
    game_state = setup_random_basic_gamestate()
    game_state["turn"] = turn
    team = turn % 2
    illegal_position = game_state["walls"][0]
    game_state_new = apply_move(game_state, illegal_position)
    assert len(game_state_new["errors"][team]) == 1
    assert game_state_new["errors"][team][(1, turn)].keys() == set(["reason", "bot_position"])
    assert game_state_new["bots"][turn] in get_legal_positions(game_state["walls"], game_state["bots"][turn])