コード例 #1
0
def test_stop_at_the_border():
    # do we stop at the border when we reach it?
    layout="""
    ########
    #    1.#
    #. 0E E#
    ########"""
    bot = setup_test_game(layout=layout, is_blue=True)
    next_pos, _ = move(bot, None)
    assert next_pos == bot.position
コード例 #2
0
def test_no_kamikaze_stop():
    # Check that we stop if escaping would kill us
    layout = """
    ########
    #  ###.#
    #1. E0E#
    ########
    """
    bot = setup_test_game(layout=layout, is_blue=True)
    next_pos, _ = move(bot, None)
    assert next_pos == (5, 2)
コード例 #3
0
def test_eat_food():
    # check that we indeed collect food when possible
    layout = """
    ########
    #E # .##
    #1.E 0 #
    ########
    """
    bot = setup_test_game(layout=layout, is_blue=True)
    next_pos, _ = move(bot, None)
    assert next_pos == (5, 1)
コード例 #4
0
def test_kill_enemy():
    # check that we indeed kill an enemy when possible
    layout = """
    ########
    #E###.##
    #0.  1E#
    ########
    """
    bot = setup_test_game(layout=layout, is_blue=True)
    next_pos, _ = move(bot, None)
    assert next_pos == (1, 1)
コード例 #5
0
def test_eat_food():
    # do we eat food when it's available?
    layout = """
    ########
    #    0.#
    #.1  EE#
    ########
    """
    bot = setup_test_game(layout=layout, is_blue=True)
    next_move, _ = move(bot, None)
    assert next_move == (6, 1)
コード例 #6
0
def test_do_not_step_on_enemy():
    # check that we don't step back on an enemy when we are fleeing
    layout = """
    ########
    #    E.#
    #.1 #0E#
    ########
    """
    bot = setup_test_game(layout=layout, is_blue=True)
    next_move, _ = move(bot, None)
    assert next_move == (5, 2)
コード例 #7
0
def test_no_kamikaze():
    # do we avoid enemies when they can kill us?
    layout = """
    ########
    #    E.#
    #.1  0E#
    ########
    """
    bot = setup_test_game(layout=layout, is_blue=True)
    next_move, _ = move(bot, None)
    assert next_move == (4, 2) or next_move == (5, 2)
コード例 #8
0
def test_kill_enemy():
    # do we kill enemies when possible?
    layout="""
    ########
    #    1.#
    #.0E  E#
    ########
    """
    bot = setup_test_game(layout=layout, is_blue=True)
    next_pos, _ = move(bot, None)
    assert next_pos == (3, 2)
コード例 #9
0
def test_face_the_enemy():
    # do we move along the border to face the enemy when it's still in its own
    # homezone?
    layout="""
    ########
    #  0 1.#
    #.  E E#
    ########"""
    bot = setup_test_game(layout=layout, is_blue=True)
    next_pos, _ = move(bot, None)
    assert next_pos == (3, 2)
コード例 #10
0
def test_legalmoves():
    # check that the only two valid moves are always returned
    # we try ten times, to test 10 different random streams
    layout = """
    ########
    #0######
    #1. .EE#
    ########
    """
    for i in range(10):
        bot = setup_test_game(layout=layout, is_blue=True)
        next_pos, _ = move(bot, None)
        assert next_pos in ((1, 2), (1, 1))
コード例 #11
0
def test_nostep():
    """Check that the bot never steps on its teammate."""

    layout = """
    ########
    #0 #####
    #1. .EE#
    ########
    """
    # run the test for ten random games
    for i in range(10):
        bot = setup_test_game(layout=layout, is_blue=True)
        next_pos, _ = move(bot, None)
        assert next_pos in ((1, 1), (2, 1))
コード例 #12
0
def test_always_legal_simple_layout():
    # Given a simple layout, verify that the bot always returns a valid position,
    # independent of its initial position.
    layout = """
    ########
    #     .#
    #.1  EE#
    ########
    """
    # generate all possible locations within the maze
    all_locations = ((x, y) for x in range(1, 7) for y in range(1, 3))
    for loc in all_locations:
        bot = setup_test_game(layout=layout, is_blue=True, bots=[loc])
        next_pos, _ = move(bot, None)
        # check that the position is valid
        assert next_pos in bot.legal_positions
コード例 #13
0
def test_stays_there_simple_layout():
    # Given a simple layout, verify that the bot does not move, independent
    # of its initial position.
    layout="""
    ########
    #     .#
    #.1  EE#
    ########
    """
    # generate all possible locations within the maze
    all_locations = ((x, y) for x in range(1,7) for y in range(1,3))
    for loc in all_locations:
        bot = setup_test_game(layout=layout, is_blue=True, bots=[loc])
        next_pos, _ = move(bot, None)
        # check that we did not move
        assert next_pos == bot.position
コード例 #14
0
def test_always_legal():
    # Given a random builtin layout, verify that the bot always returns a valid position
    bot = setup_test_game(layout=None, is_blue=True)
    next_pos, _ = move(bot, None)
    assert next_pos in bot.legal_positions
コード例 #15
0
def test_stays_there_builtin_random_layout():
    # Using a random builtin layout, verify that the bot stays on its initial position
    bot = setup_test_game(layout=None, is_blue=True)
    next_pos, _ = move(bot, None)
    # check that we did not move
    assert next_pos == bot.position