# HG changeset patch # User Jeremy Thurgood # Date 1259602747 0 # Node ID 460b06ac7d9989af12ca196354e950cf1c470298 # Parent 029e60f37743e3ab1862693eecc74004d5984eb6 Better chicken placement, now with fewer crashes. diff -r 029e60f37743 -r 460b06ac7d99 gamelib/gameboard.py --- a/gamelib/gameboard.py Mon Nov 30 16:42:06 2009 +0000 +++ b/gamelib/gameboard.py Mon Nov 30 17:39:07 2009 +0000 @@ -571,16 +571,18 @@ if cur_chick: try_pos = None # find a free square nearby - poss = [(tile_pos[0] + x, tile_pos[1] + y) - for x in range(-1, 2) for y in range(-1, 2) + diff_pos = misc.Position(*tile_pos) + poss = [diff_pos + misc.Position(x, y) + for x in range(-2, 3) + for y in range(-2, 3) if (x, y) != (0, 0)] - poss.extend([(tile_pos[0] + x, tile_pos[1] + y) - for x in range(-2, 3, 2) for y in range(-2, 3) - if (x, y) != (0, 0)]) + poss.sort(key=lambda p: p.dist(diff_pos)) for cand in poss: - if self.tv.get(cand) == self.GRASSLAND and \ - not self.get_outside_chicken(cand): - try_pos = cand + if not self.in_bounds(cand): + continue + if self.tv.get(cand.to_tile_tuple()) == self.GRASSLAND and \ + not self.get_outside_chicken(cand.to_tile_tuple()): + try_pos = cand.to_tile_tuple() break if try_pos: chicken.unequip_by_name("Nest")