Esempio n. 1
0
def test_play_turn_move():
    """Checks that bot is moved to intended space"""
    turn = 0
    l = layout.get_layout_by_name("small_100")
    parsed_l = layout.parse_layout(l)
    game_state = {
        "food": parsed_l["food"],
        "walls": parsed_l["walls"],
        "bots": parsed_l["bots"],
        "shape": parsed_l["shape"],
        "max_rounds": 300,
        "team_names": ("a", "b"),
        "turn": turn,
        "round": 0,
        "timeout": [],
        "gameover": False,
        "whowins": None,
        "team_say": "bla",
        "score": 0,
        "error_limit": 5,
        "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["shape"],
                                          game_state["bots"][turn])
    game_state_new = apply_move(game_state, legal_positions[0])
    assert game_state_new["bots"][turn] == legal_positions[0]
Esempio n. 2
0
def test_get_legal_positions_basic():
    """Check that the output of legal moves contains all legal moves for one example layout"""
    l = layout.get_layout_by_name(layout_name="small_100")
    parsed_l = layout.parse_layout(l)
    legal_positions = get_legal_positions(parsed_l["walls"], parsed_l["bots"][0])
    exp = [(1, 4), (1, 6), (1, 5)]
    assert legal_positions == exp
Esempio n. 3
0
def test_get_legal_positions_random(layout_t, bot_idx):
    """Check that the output of legal moves returns only moves that are 1 field away and not inside a wall"""
    layout_name, layout_string = layout_t # get_random_layout returns a tuple of name and string
    parsed_l = layout.parse_layout(layout_string)
    bot = parsed_l["bots"][bot_idx]
    legal_positions = get_legal_positions(parsed_l["walls"], bot)
    for move in legal_positions:
        assert move not in parsed_l["walls"]
        assert  abs((move[0] - bot[0])+(move[1] - bot[1])) <= 1
Esempio n. 4
0
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])
Esempio n. 5
0
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)