import sys from creatures import Dragon import mpi from math import * import traceback from util import * import random class Scorch(Dragon): # self.Actions # GetBreath # GetFlyingDirection # GetFlyingPosition # ScanHorizon [Range] # SetFlyingDirection [self.Direction.East, self.Direction.NorthEast, etc.] # self.Direction.ToString(), self.Direction.FromString() # BreatheFire [Power] # Fly [distance] def action(self): bx, by = doMpi(self,self.Actions.GetBoard,[]) pos = doMpi(self,self.Actions.GetFlyingPosition,[]) x,y = (pos.x,pos.y) fdir = doMpi(self,self.Actions.GetFlyingDirection,[]) result = doMpi(self,self.Actions.ScanHorizon,[5]) tl = [] for en in result: (ex,ey) = en['coords'] # returns list of actions to take in order to hit the target tl = fireAt(self,fdir,x,y,ex,ey) break # if there's nothing to shoot, move to a random square if len(tl) == 0: fdir = doMpi(self,self.Actions.GetFlyingDirection,[]) rx = random.randint(0,bx-1) ry = random.randint(0,by-1) tl = moveTo(self,fdir,x,y,rx,ry) for turn in tl: doMpi(self,turn[0],turn[1]) doMpi(self,self.Actions.BreatheFire,[10])