changeset 599:460b06ac7d99

Better chicken placement, now with fewer crashes.
author Jeremy Thurgood <firxen@gmail.com>
date Mon, 30 Nov 2009 17:39:07 +0000
parents 029e60f37743
children f9276a4f7bdf
files gamelib/gameboard.py
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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")