예제 #1
0
파일: ai.py 프로젝트: untergrunt/untergrunt
 def ACT(self, circumstances, Time):
     self.stuck = False
     h = circumstances.get_hero()
     hx, hy = h.position
     x, y = self.who.position
     if not self.who.can('see'):
         MSG.pop(self.who.name+' cannot see!')
     if self.who.can('see') and circumstances.visible_by(self.who, hx, hy):
         self.memorize(0, (hx, hy))
         self.memorize(1,(hx - x, hy - y))
         self.memorize(2, 20)
         if self.who.light == 10000:
             self.who.light = 5
             MSG.pop('You hear someone whisper: "W-h-h-e s-s-see the hobbitses-s-s..."')
             log(self.who.name+'\'s seeker AI deactivates light')
     elif self.knows(0):
         hx, hy = self.recall(0)
         if (hx, hy) == (x, y):
             self.forget(0)
     elif self.knows(1) and self.recall(2) > 0:
         hx, hy = self.recall(1)
         self.decrease(2)
         hx += x
         hy += y
     else:
         hx, hy = x, y
         if self.who.light != 10000:
             self.who.light = 10000
             MSG.pop('You see a flash of light')
             log(self.who.name+'\'s seeker AI activates light')
     Time.after(self.who.get_stat('SPD'), lambda:self.act(circumstances, Time))
     l = circumstances.can_move_creature(self.who, -1, 0)
     r = circumstances.can_move_creature(self.who, 1, 0)
     u = circumstances.can_move_creature(self.who, 0, -1)
     d = circumstances.can_move_creature(self.who, 0, 1)
     dx, dy = hx - x, hy - y
     if abs(dx)>abs(dy):
         if dx > 0 and r:
             circumstances.move_creature(self.who, 1, 0)
             log(self.who.name+'\'s seeker AI decides to go right')
         elif dx < 0 and l:
             circumstances.move_creature(self.who, -1, 0)
             log(self.who.name+'\'s seeker AI decides to go left')
     else:
         if dy > 0 and d:
             circumstances.move_creature(self.who, 0, 1)
             log(self.who.name+'\'s seeker AI decides to go down')
         elif dy < 0 and u:
             circumstances.move_creature(self.who, 0, -1)
             log(self.who.name+'\'s seeker AI decides to go up')
예제 #2
0
 def die(self):
     self.AI = None
     if self.controlled_by_player:
         MSG.pop('You die')
     self.alive = False