comparison gamelib/gameboard.py @ 457:fc648da2334c

Fix position cache removal, slightly optimise chicken range check.
author Jeremy Thurgood <firxen@gmail.com>
date Mon, 23 Nov 2009 16:12:37 +0000
parents 96dbf2c8506e
children 7204c16ab64d
comparison
equal deleted inserted replaced
456:96dbf2c8506e 457:fc648da2334c
55 def add(self, animal, animal_type): 55 def add(self, animal, animal_type):
56 if animal and self._in_bounds(animal.pos): 56 if animal and self._in_bounds(animal.pos):
57 self._cache[animal_type][animal.pos] = animal 57 self._cache[animal_type][animal.pos] = animal
58 58
59 def remove(self, pos, animal_type): 59 def remove(self, pos, animal_type):
60 if pos in self._cache: 60 if pos in self._cache[animal_type]:
61 del self._cache[animal_type][pos] 61 del self._cache[animal_type][pos]
62 62
63 def update(self, old_pos, animal, animal_type): 63 def update(self, old_pos, animal, animal_type):
64 self.remove(old_pos, animal_type) 64 self.remove(old_pos, animal_type)
65 self.add(animal, animal_type) 65 self.add(animal, animal_type)