return True
if tile == GATE:
print tile, pos, self._gates[pos]
- if self._gates[pos] != -1:
+ if self._gates[pos] > 0:
return True
return False
return abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1])
def is_gate(self, pos):
+ if not self._in_limits(pos):
+ return False
return self._data[pos[1]][pos[0]] == GATE
def is_button(self, pos):
+ if not self._in_limits(pos):
+ return False
return self._data[pos[1]][pos[0]] == BUTTON
+ def is_wall(self, pos):
+ if not self._in_limits(pos):
+ return True
+ return self._data[pos[1]][pos[0]] == WALL
+
def trigger_button(self, pos):
if not self.is_button(pos):
return False
gate_pos = cand
mindist = dist
if gate_pos:
- self._buttons[pos] == 'pressed'
+ self._buttons[pos] = 'pressed'
self._gates[gate_pos] = 3 # Raise gate
self._fix_tile(pos)
self._fix_tile(gate_pos)
def damage_gate(self, pos):
if not self.is_gate(pos):
- return False
+ return
if self._gates[pos] == -1 or self._gates[pos] == 0:
- return False
+ return
self._gates[pos] = self._gates[pos] - 1
- self._fix_gate_tile(pos)
- self._changed.append((pos, self.get_single_tile(pos)))
- return True
+ self._fix_tile(pos)
def get_changed_tiles(self):
ret = self._changed[:]
super(Nemesis, self).__init__()
self.sprite = load_image('sprites/nemesis.png')
self.reset_pos()
+ self.deadends = []
self.been = []
- def move(self, level):
+ def move(self, level, player_pos):
if not self.on_board():
# Advance towards the map a step at a time
self.pos = (self.pos[0] + 1, self.pos[1])
self.pos = level.enter_pos
return False
# AI goes here
+ # First, if we're standing next to a gate, we attack it
+ neighbours = [(self.pos[0] + 1, self.pos[1]),
+ (self.pos[0] - 1, self.pos[1]),
+ (self.pos[0], self.pos[1] + 1),
+ (self.pos[0], self.pos[1] - 1)]
+ for cand in neighbours:
+ if level.is_gate(cand) and level.blocked(cand):
+ level.damage_gate(cand)
+ return True
steps = 0
self.been.append(self.pos)
for direction in [(1, 0), (-1, 0), (0, -1), (0, 1)]: