Mercurial > rinkhals
comparison gamelib/animal.py @ 401:7405f7db469f
Tweak fox attack logic - we no longer ignore chickens we accidently step on
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 18 Nov 2009 15:54:31 +0000 |
parents | 3294929223bd |
children | 3a469d46b820 |
comparison
equal
deleted
inserted
replaced
400:d146b7bb9b99 | 401:7405f7db469f |
---|---|
386 return Position(self.pos.x, self.pos.y, new_z) | 386 return Position(self.pos.x, self.pos.y, new_z) |
387 return self._find_best_path_step(self.closest.pos, gameboard) | 387 return self._find_best_path_step(self.closest.pos, gameboard) |
388 | 388 |
389 def attack(self, gameboard): | 389 def attack(self, gameboard): |
390 """Attack a chicken""" | 390 """Attack a chicken""" |
391 if self.closest and self.closest.pos == self.pos: | 391 chicken = gameboard.get_animal_at_pos(self.pos, 'chicken') |
392 self._catch_chicken(self.closest, gameboard) | 392 if chicken: |
393 # Always attack a chicken we step on, even if not hunting | |
394 self._catch_chicken(chicken, gameboard) | |
393 | 395 |
394 def _catch_chicken(self, chicken, gameboard): | 396 def _catch_chicken(self, chicken, gameboard): |
395 """Catch a chicken""" | 397 """Catch a chicken""" |
396 chicken.damage(gameboard) | 398 chicken.damage(gameboard) |
397 self.closest = None | 399 self.closest = None |
401 def _update_pos(self, gameboard, new_pos): | 403 def _update_pos(self, gameboard, new_pos): |
402 """Update the position, making sure we don't step on other foxes""" | 404 """Update the position, making sure we don't step on other foxes""" |
403 if new_pos == self.pos: | 405 if new_pos == self.pos: |
404 # We're not moving, so we can skip all the checks | 406 # We're not moving, so we can skip all the checks |
405 return new_pos | 407 return new_pos |
406 blocked = gameboard.is_fox_at_pos(new_pos) | 408 blocked = gameboard.get_animal_at_pos(new_pos, 'fox') is not None |
407 if not blocked and new_pos.z == self.pos.z: | 409 if not blocked and new_pos.z == self.pos.z: |
408 # We're only worried about loops when not on a ladder | 410 # We're only worried about loops when not on a ladder |
409 blocked = new_pos in self.last_steps | 411 blocked = new_pos in self.last_steps |
410 final_pos = new_pos | 412 final_pos = new_pos |
411 if blocked: | 413 if blocked: |
421 self.pos.z == 0] | 423 self.pos.z == 0] |
422 # find the cheapest point in moves that's not blocked | 424 # find the cheapest point in moves that's not blocked |
423 final_pos = None | 425 final_pos = None |
424 min_cost = 1000 | 426 min_cost = 1000 |
425 for poss in moves: | 427 for poss in moves: |
426 if gameboard.is_fox_at_pos(poss): | 428 if gameboard.get_animal_at_pos(poss, 'fox'): |
427 continue # blocked | 429 continue # blocked |
428 cost = self._cost_tile(poss, gameboard) | 430 cost = self._cost_tile(poss, gameboard) |
429 if cost < min_cost: | 431 if cost < min_cost: |
430 min_cost = cost | 432 min_cost = cost |
431 final_pos = poss | 433 final_pos = poss |