Is there a possibility of a .py that uses the moving action of the FBS.py to just go to the center of the arena and spin there, instead of chasing the other bot?
Sorry to DP, but I want to show everyone what I did. I added this to popup.py after the bit about not firing until the enemy hits the body: if self.weapons: targets = [x.robot for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] fire = False for bot in targets: if not plus.isUpsideDown(bot) or self.CanDriveUpsideDown(bot): fire = True if fire: self.Input(self.trigger, 0, 1) bReturn = AI.SuperAI.Tick(self) return bReturn def CanDriveUpsideDown(self, bot): MOVE_THRESHOLD = 3.0 <- Tried increasing that to make it less sensitive to random movments? if bot in self.upTrack: t = self.upTrack[bot] if t.invertible: return True else: # check to see if he's moved recently position = plus.getLocation(bot) time = plus.getTimeElapsed() if time - t.last_time > 10: # this record is too old to be reliable t.last_time = time t.last_position = position return False v0 = vector3(t.last_position) v1 = vector3(position) if (v1-v0).length() > MOVE_THRESHOLD: t.invertible = True return t.invertible else: t = UpsideDownTracker() t.last_position = plus.getLocation(bot) t.last_time = plus.getTimeElapsed() self.upTrack[bot] = t return FalseThe bot still attacks upside down robots. What have I done wrong?
from __future__ import generatorsimport plusimport AIfrom AI import vector3import Arenasimport Gooeyimport mathimport Tacticsclass Popup(AI.SuperAI): "Like Plow, but waits for chassis contact before firing the weapon. If chassis is not found by a certain time, then fires anyway." # Use variable 'NoChassisTime' in Bindings.py to set the amount of time in seconds the AI will wait to find the chassis before giving up and firing, when there are components in the smart zone. name = "CheapPopup" def __init__(self, **args): AI.SuperAI.__init__(self, **args) self.zone1 = "weapon" self.triggers1 = ["Fire"] self.triggers2 = ["Srimech"] self.botinzone = 0 self.compinzone = 0 self.comptimer = 0 self.NoChassisTime = 8 if 'zone' in args: self.zone = args['zone'] if 'triggers' in args: self.triggers1 = args['triggers'] if 'triggers' in args: self.triggers2 = args['triggers'] if 'NoChassisTime' in args: self.NoChassisTime = args.get('NoChassisTime') * 4 self.tactics.append(Tactics.Engage(self)) self.tactics.append(Tactics.Charge(self)) self.tactics.append(Tactics.Shove(self)) def Activate(self, active): if active: if AI.SuperAI.debugging: self.debug = Gooey.Plain("watch", 0, 75, 100, 75) tbox = self.debug.addText("line0", 0, 0, 100, 15) tbox.setText("Throttle") tbox = self.debug.addText("line1", 0, 15, 100, 15) tbox.setText("Turning") tbox = self.debug.addText("line2", 0, 30, 100, 15) tbox.setText("") tbox = self.debug.addText("line3", 0, 45, 100, 15) tbox.setText("") self.RegisterSmartZone(self.zone1, 1) return AI.SuperAI.Activate(self, active) def Tick(self): # fire weapon targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] # if a component is in the smart zone but not the chassis, wait to find chassis before firing weapons if self.compinzone == 1 and self.botinzone == 0: self.comptimer += 1 if self.botinzone == 1: self.comptimer = 0 if self.weapons and (self.botinzone == 1 or (self.comptimer >= self.NoChassisTime and self.compinzone == 1)): for trigger in self.triggers1: self.Input(trigger, 0, 1) bReturn = AI.SuperAI.Tick(self) return bReturn def InvertHandler(self): # fire all weapons once per second (until we're upright!) while 1: for trigger in self.triggers2: self.Input(trigger, 0, 1) for i in range(0, 8): yield 0 def LostComponent(self, id): # if we lose all our weapons, stop using the Engage tactic and switch to Shove if id in self.weapons: self.weapons.remove(id) if not self.weapons: tactic = [x for x in self.tactics if x.name == "Engage"] if len(tactic) > 0: self.tactics.remove(tactic[0]) self.tactics.append(Tactics.Shove(self)) self.tactics.append(Tactics.Charge(self)) return AI.SuperAI.LostComponent(self, id) def Disable(self,btarget): # Disables opponent by charging it at an angle # we use a different angle (depending on the size of the opponent!) # if target is equal in size, the plow weapon charges are more direct if btarget > self: self.Turn(79) else: self.Turn(-79) if btarget < self: self.Turn(35) else: self.Turn(-35) if btarget == self: self.Turn(90) else: self.Turn(-90) if self.target: self.Turn(360) return AI.SuperAI.Disable(self, btarget) def DebugString(self, id, string): if self.debug: if id == 0: self.debug.get("line0").setText(string) elif id == 1: self.debug.get("line1").setText(string) elif id == 2: self.debug.get("line2").setText(string) elif id == 3: self.debug.get("line3").setText(string) def SmartZoneEvent(self, direction, id, robot, chassis): if id == 1 and self.weapons: if robot > 0: if direction == 1: self.compinzone = 1 if chassis: self.botinzone = 1 if direction == -1: self.compinzone = 0 if chassis: self.botinzone = 0 return True AI.register(CheapPopup)
Created a new AI: return AI.SuperAI.LostComponent(self, id) def Disable(self,btarget): <- Seems to be a space too little, try changing to def Disable(self, btarget): # Disables opponent by charging it at an angle Problem: Crashes RA2, and I don't know how. Help?
from __future__ import generatorsimport plusimport AIfrom AI import vector3import Arenasimport Gooeyimport mathimport Tacticsclass Cheap(AI.SuperAI): # "Like Omni, but waits for chassis contact before firing the weapon. If chassis is not found by a certain time, then fires anyway. it also attacks from the side, like the Plow AI." # Use variable 'NoChassisTime' in Bindings.py to set the amount of time in seconds the AI will wait to find the chassis before giving up and firing, when there are components in the smart zone. name = "Cheap" def __init__(self, **args): AI.SuperAI.__init__(self, **args) self.zone1 = "weapon" self.triggers1 = ["Fire"] self.triggers2 = ["Srimech"] self.botinzone = 0 self.compinzone = 0 self.comptimer = 0 self.NoChassisTime = 4 if 'zone' in args: self.zone = args['zone'] if 'triggers' in args: self.triggers1 = args['triggers'] if 'triggers' in args: self.triggers2 = args['triggers'] if 'NoChassisTime' in args: self.NoChassisTime = args.get('NoChassisTime') * 4 self.tactics.append(Tactics.Shove(self)) self.tactics.append(Tactics.Charge(self)) def Activate(self, active): if active: if AI.SuperAI.debugging: self.debug = Gooey.Plain("watch", 0, 75, 100, 75) tbox = self.debug.addText("line0", 0, 0, 100, 15) tbox.setText("Throttle") tbox = self.debug.addText("line1", 0, 15, 100, 15) tbox.setText("Turning") tbox = self.debug.addText("line2", 0, 30, 100, 15) tbox.setText("") tbox = self.debug.addText("line3", 0, 45, 100, 15) tbox.setText("") self.RegisterSmartZone(self.zone1, 1) return AI.SuperAI.Activate(self, active) def Tick(self): # fire weapon targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] # if a component is in the smart zone but not the chassis, wait to find chassis before firing weapons if self.compinzone == 1 and self.botinzone == 0: self.comptimer += 1 if self.botinzone == 1: self.comptimer = 0 if self.weapons and (self.botinzone == 1 or (self.comptimer >= self.NoChassisTime and self.compinzone == 1)): for trigger in self.triggers1: self.Input(trigger, 0, 1) bReturn = AI.SuperAI.Tick(self) return bReturn def InvertHandler(self): # fire all weapons once per second (until we're upright!) while 1: for trigger in self.triggers2: self.Input(trigger, 0, 1) for i in range(0, 8): yield 0 def LostComponent(self, id): # if we lose all our weapons, stop using the Engage tactic and switch to Shove if id in self.weapons: self.weapons.remove(id) if not self.weapons: tactic = [x for x in self.tactics if x.name == "Charge"] if len(tactic) > 0: self.tactics.remove(tactic[0]) self.tactics.append(Tactics.Shove(self)) return AI.SuperAI.LostComponent(self, id) def Disable(self, btarget): # Disables opponent by charging it at an angle # we use a different angle (depending on the size of the opponent!) # if target is equal in size, the plow weapon charges are more direct if btarget > self: self.Turn(79) else: self.Turn(-79) if btarget < self: self.Turn(35) else: self.Turn(-35) if btarget == self: self.Turn(90) else: self.Turn(-90) if self.target: self.Turn(360) return AI.SuperAI.Disable(self, btarget) def DebugString(self, id, string): if self.debug: if id == 0: self.debug.get("line0").setText(string) elif id == 1: self.debug.get("line1").setText(string) elif id == 2: self.debug.get("line2").setText(string) elif id == 3: self.debug.get("line3").setText(string) def SmartZoneEvent(self, direction, id, robot, chassis): if id == 1 and self.weapons: if robot > 0: if direction == 1: self.compinzone = 1 if chassis: self.botinzone = 1 if direction == -1: self.compinzone = 0 if chassis: self.botinzone = 0 return True AI.register(Cheap)