Ejemplo n.º 1
0
 def test_will_do_kamikaze(self):
     # check that we eat the last food when adjacent
     layout = """
     ########
     #x  a.##
     # .  b #
     ########
     """
     bot = setup_test_game(layout=layout, is_blue=True, bots={'y': (5, 1)})
     next_pos = food_eating_player(bot, {})
     assert next_pos == (5, 1)
Ejemplo n.º 2
0
 def test_move_towards_food(self):
     # check that we move closer to the food
     layout = """
     ########
     #y a .##
     #b.x   #
     ########
     """
     bot = setup_test_game(layout=layout, is_blue=True)
     next_pos = food_eating_player(bot, {})
     assert next_pos == (4, 1)
Ejemplo n.º 3
0
 def test_eat_food(self):
     # check that we eat the last food when adjacent
     layout = """
     ########
     #x  a.##
     # .  by#
     ########
     """
     bot = setup_test_game(layout=layout, is_blue=True)
     next_pos = food_eating_player(bot, {})
     assert next_pos == (5, 1)
Ejemplo n.º 4
0
 def test_legalmoves(self):
     # check that the only two valid moves are returned
     layout = """
     ########
     #a######
     #b. .xy#
     ########
     """
     bot = setup_test_game(layout=layout, is_blue=True)
     next_pos = food_eating_player(bot, {})
     assert next_pos in ((1, 2), (1, 1))
Ejemplo n.º 5
0
 def test_move_towards_next_food(self):
     # check that we move closer to the food in the next_food key,
     # even though another food is closer
     layout = """
     ########
     #y   .##
     #      #
     # .. a #
     #x   . #
     # .b   #
     ########
     """
     bot = setup_test_game(layout=layout, is_blue=True)
     next_pos = food_eating_player(bot, {0: {'next_food': (5, 1)}})
     assert next_pos == (5, 2)
Ejemplo n.º 6
0
def smart_eating_player(bot, state):
    # food eating player but won’t do kamikaze (although a sufficently smart
    # enemy will be able to kill the bot in its next turn as it doesn’t flee)
    next_pos = food_eating_player(bot, state)

    dangerous_enemy_pos = [
        enemy.position for enemy in bot.enemy
        if enemy.position in enemy.homezone
    ]

    # check, if the next_pos has an enemy on it
    if next_pos in dangerous_enemy_pos:
        # whoops, better wait this round and take another food next time
        state[bot.turn]['next_food'] = None
        return bot.position

    return next_pos