Refactor code structure for improved readability and maintainability
This commit is contained in:
+3
-3
@@ -44,7 +44,7 @@ class Rat(Unit):
|
||||
nx, ny = x + dx, y + dy
|
||||
if not self.game.map.in_bounds(nx, ny):
|
||||
continue
|
||||
if self.game.map.is_empty(nx, ny) and (nx, ny) != self.position_before:
|
||||
if self.game.map.is_traversable(nx, ny) and (nx, ny) != self.position_before:
|
||||
neighbors.append((nx, ny))
|
||||
|
||||
if not neighbors:
|
||||
@@ -52,11 +52,11 @@ class Rat(Unit):
|
||||
nx, ny = x + dx, y + dy
|
||||
if not self.game.map.in_bounds(nx, ny):
|
||||
continue
|
||||
if self.game.map.is_empty(nx, ny):
|
||||
if self.game.map.is_traversable(nx, ny):
|
||||
neighbors.append((nx, ny))
|
||||
|
||||
if not neighbors:
|
||||
print(f"[flow] rat fallback: no empty neighbors from position={self.position}", flush=True)
|
||||
print(f"[flow] rat fallback: no traversable neighbors from position={self.position}", flush=True)
|
||||
return self.position
|
||||
|
||||
self.position_before = self.position
|
||||
|
||||
Reference in New Issue
Block a user