Skip to content

Instantly share code, notes, and snippets.

@Debilski
Created August 15, 2013 19:29
Show Gist options
  • Save Debilski/0f83566968acd4e900da to your computer and use it in GitHub Desktop.
Save Debilski/0f83566968acd4e900da to your computer and use it in GitHub Desktop.
class FoodEatingPlayer(AbstractPlayer):
def set_initial(self):
self.adjacency = AdjacencyList(self.current_uni.reachable([self.initial_pos]))
self.next_food = None
def goto_pos(self, pos):
return self.adjacency.a_star(self.current_pos, pos)[-1]
def get_move(self):
# check, if food is still present
if (self.next_food is None
or self.next_food not in self.enemy_food):
self.next_food = self.rnd.choice(self.enemy_food)
try:
next_pos = self.goto_pos(self.next_food)
move = diff_pos(self.current_pos, next_pos)
return move
except NoPathException:
return datamodel.stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment