def CanDriveUpsideDown(self, bot): MOVE_THRESHOLD = 3.0 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 False
def Tick(self): #self.DebugString(4, str(self.zone2)) # spin weapons briefly at start because for some dumb reason we can't move otherwise. if plus.getTimeElapsed() <= self.spinup: self.Input("Spin", 0, 100) # spin up depending on enemy's range enemy, range = self.GetNearestEnemy() if enemy is not None: heading = self.GetHeadingToID(enemy, False) # spin weapons only when necessary, and don't waste battery on them when we're being counted out! if enemy is not None and self.weapons and range < self.spin_range and not self.bImmobile and ( self.botinzone2 == 1 or self.usespinzone == 0): if self.pulsetime > 0 and range > self.pulse_range: # Pulse spinner self.pulse -= 1 if self.pulsetime2 < self.pulse < self.pulsetime: self.Input("Spin", 0, 100) if 0 < self.pulse < self.pulsetime2: self.Input("Spin", 0, 0) if self.pulse <= 0: self.pulse = self.pulsetime else: self.Input("Spin", 0, 100) else: if plus.getTimeElapsed() > self.spinup: self.Input("Spin", 0, 0) targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] # slight delay between firing if self.reloadTime > 0: self.reloadTime -= 1 if self.botinzone1 == 1 and self.reloadTime <= 0: try: trigger = self.triggerIterator.next() except StopIteration: self.triggerIterator = iter(self.triggers) trigger = self.triggerIterator.next() self.Input(trigger, 0, 1) self.reloadTime = self.reloadDelay if self.botinzone3 == 1: self.Input("Fire2", 0, 1) bReturn = AI.SuperAI.Tick(self) # call this now so it takes place after other driving commands if self.goodFunction: self.goodFunction(len(targets) > 0) return bReturn
def Stop(self): # stay put if weapon isn't spinning fast if self.weapons and not self.bImmobile and ( self.RPM < self.targetRPM or (self.motorID2 > 0 and self.RPM2 < self.targetRPM)): self.Throttle(0) # stay put if the weapon is jammed, to give it a chance to unjam if (plus.getTimeElapsed() - self.revolution > self.raspberry or (self.motorID2 > 0 and plus.getTimeElapsed() - self.revolution2 > self.raspberry)) and not self.bImmobile: self.Throttle(0)
def updateSpeed(self): newLoc = self.GetLocation() if newLoc[0] != self.lastLoc[ 0]: #no need to compare more than the x-coordinate #the geometry updates roughly every 0.03 seconds on my computer newTime = plus.getTimeElapsed() deltaTime = (newTime - self.oldTime) deltaPos = ((newLoc[0]-self.lastLoc[0])**2+\ (newLoc[1]-self.lastLoc[1])**2+\ (newLoc[2]-self.lastLoc[2])**2)**.5 if deltaTime: #if not zero self.curSpeed = deltaPos / deltaTime else: self.curSpeed = 0 self.oldTime = newTime self.lastLoc = newLoc self.collection.append(self.curSpeed) if len(self.collection) > self.maxCollection: self.collection = self.collection[1:] # progressive averaging self.avgSpeed += (self.curSpeed - self.avgSpeed) / len( self.collection)
def Tick(self): # spin weapons briefly at start because for some dumb reason we can't move otherwise. if plus.getTimeElapsed() <= self.spinup: self.Input("Spin1", 0, 100) # spin up depending on enemy's range enemy, range = self.GetNearestEnemy() # spin weapons only when necessary, and don't waste battery on them when we're being counted out! if self.weapons: if enemy is not None and range < self.spin_range and not self.bImmobile: self.Input("Spin1", 0, 100) else: if plus.getTimeElapsed() > self.spinup: self.Input("Spin1", 0, 0) if not self.weapons: self.Input("Spin1", 0, 0) if enemy is not None and range < self.spin_range and not self.bImmobile: self.Input("Spin2", 0, 100) else: self.Input("Spin2", 0, 0) targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] # slight delay between firing if self.reloadTime > 0: self.reloadTime -= 1 if len(targets) > 0 and self.reloadTime <= 0: try: trigger = self.triggerIterator.next() except StopIteration: self.triggerIterator = iter(self.triggers) trigger = self.triggerIterator.next() self.Input(trigger, 0, 1) self.reloadTime = self.reloadDelay bReturn = AI.SuperAI.Tick(self) # call this now so it takes place after other driving commands if self.goodFunction: self.goodFunction() return bReturn
def Evaluate(self): current = plus.getTimeElapsed() # don't reorient if we just did less than 10 seconds ago if current - self.timeStarted > 5 and current - self.timeStarted < 10: self.priority = 0 else: self.priority = min(150, (current - self.ai.timeOfLastGoodHit) * 10)
def Evaluate(self): #Called Every 8th Tick if self.exactTime != 0: pass elif self.setupTime != 0: self.exactTime = plus.getTimeElapsed() + self.setupTime self.priority = 1000 self.setupTime = 0 else: self.priority = -1000
def CanDriveUpsideDown(self, bot): MOVE_THRESHOLD = self.move_thresh if bot in self.upTrack: t = self.upTrack[bot] # self.tauntbox.get("taunt1").setText(str(t.contact)) # Check if we've made contact with the enemy if (self.flip == 1 or self.compinzone == 1) and t.contact == 0: t.contact = 1 # check to see if he's moved recently position = plus.getLocation(bot) time = plus.getTimeElapsed() if time - t.last_time > self.move_time: # 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) # Don't assume the enemy is immobile if we haven't made contact if (v1 - v0).length() > MOVE_THRESHOLD or t.contact == 0: # Reality check: Is the enemy actually still mobile (after a cooldown period to let them settle) - if so, reset contact if t.contact == 2 and time - t.stoptime > self.cooldown: t.contact = 0 return True else: return True # Check if we've made contact and the enemy isn't moving if (v1 - v0).length() <= MOVE_THRESHOLD and t.contact > 0: if t.contact == 1: t.contact = 2 t.stoptime = plus.getTimeElapsed() return False else: t = UpsideDownTracker() t.last_position = plus.getLocation(bot) t.last_time = plus.getTimeElapsed() t.contact = 0 t.stoptime = plus.getTimeElapsed() self.upTrack[bot] = t return False
def RobotInRange(self, robot_id): "Return tuple of (part-of-robot-in-range, chassis-in-range)" # GetLastDamage returns: component damaged, amount, at time, by player, by component range = self.GetDistanceToID(robot_id) if range < self.spin_range: damage = self.GetLastDamageReceived() if damage[3] == robot_id and (plus.getTimeElapsed() - damage[2] < 1.0): return (True, True) return (False, False)
def ImmobilityWarning(self, id, on): if on: self.immobile_list[id] = plus.getTimeElapsed() elif id in self.immobile_list: del self.immobile_list[id] if id == self.GetID(): # keep track of our own immobility warning self.bImmobile = on plus.AI.ImmobilityWarning(self, id, on)
def Tick(self): #self.DebugString(4, "self.TimeSinceHit: "+ str(self.TimeSinceHit)) # Jut out initially. if self.PreSpinEntranceTimer < self.PreSpinEntrance: self.PreSpinEntranceTimer += 1 # Keep track of last time we got hit, ignoring small damage from walls and stuff. if self.GetLastDamageReceived()[1] > 100: self.timeOfLastBadHit = self.GetLastDamageReceived()[2] # Count time since last hit self.TimeSinceHit = min( (plus.getTimeElapsed() - self.timeOfLastGoodHit), (plus.getTimeElapsed() - self.timeOfLastBadHit)) #Self right if self.IsUpsideDown() and not self.bInvertible: self.cycle += 1 if self.cycle <= self.cycletime / 2: self.Input("Spin", 0, 100) if self.cycle > self.cycletime / 2: self.Input("Spin", 0, -100) if self.cycle >= self.cycletime: self.cycle = 0 else: self.cycle = 0 # define targets targets = [] targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] bReturn = AI.SuperAI.Tick(self) # call this now so it takes place after other driving commands if self.thwackFunction: self.thwackFunction(len(targets) > 0) return bReturn
def Execute(self): "Try to reorient to a new attack position for a few seconds." if not self.ai.lastTactic or self.ai.lastTactic.name != "Reorient": # reorienting anew self.target_id, range = self.ai.GetNearestEnemy() self.timeStarted = plus.getTimeElapsed() self.destination = None self.bInReverse = False if self.target_id != None: # pick a location to one side of the target bot and drive to it, then attack again target = plus.getLocation(self.target_id) loc = self.ai.GetLocation() distance = (-5, 5) dir = vector3(target) - vector3(loc) dir.normalize() dir.x, dir.z = dir.z, dir.x for d in distance: # drive toward the side of the enemy for about 5 seconds dest = vector3(target) + dir * d if self.ai.IsStraightPathClear(loc, dest.asTuple()): self.destination = dest break # if the sides are unavailable, try backing up or going forward if not self.destination: distance = (-5, 5) dir.x, dir.z = dir.z, dir.x for d in distance: dest = vector3(target) + dir * d if self.ai.IsStraightPathClear(loc, dest.asTuple()): self.destination = dest if d < 0: self.bInReverse = True else: self.bInReverse = False break if self.destination != None: self.ai.DriveToLocation(self.destination.asTuple(), self.bInReverse) return True return False
def Tick(self): #self.DebugString(4, "self.TimeSinceHit: "+ str(self.TimeSinceHit)) # Jut out initially. if self.PreSpinEntranceTimer < self.PreSpinEntrance: self.PreSpinEntranceTimer += 1 # Count time since last hit self.TimeSinceHit = plus.getTimeElapsed() - self.timeOfLastGoodHit # define targets targets = [] if self.weapons: targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] bReturn = AI.SuperAI.Tick(self) # call this now so it takes place after other driving commands if self.thwackFunction: self.thwackFunction(len(targets) > 0) return bReturn
def Stop(self, bTarget): #wait for the bot to settle before charging if plus.getTimeElapsed() < self.waittime: self.Throttle(0)
def Execute(self): if self.target_id != None: self.ai.enemy_id = self.target_id # default turning & throttle off self.ai.Throttle(0) self.ai.Turn(0) # other info heading = self.ai.GetHeadingToID(self.target_id, False) target_loc = plus.getLocation(self.target_id) clear_path = self.ai.IsStraightPathClear(self.ai.GetLocation(), target_loc) distance = (vector3(target_loc) - vector3(self.ai.GetLocation())).length() speed = self.ai.GetSpeed() # adjust sight range based on speed so we have time to react to obstacles self.sight_range = self.sight_range_base + (0.2 * abs(speed)) # keep track of points in front of and behind us for obstacle detection fx = (self.sight_range * math.sin( self.ai.GetHeading(False))) + self.ai.GetLocation()[0] fz = (self.sight_range * math.cos( self.ai.GetHeading(False))) + self.ai.GetLocation()[2] rx = (-1 * self.sight_range * math.sin( self.ai.GetHeading(False))) + self.ai.GetLocation()[0] rz = (-1 * self.sight_range * math.cos( self.ai.GetHeading(False))) + self.ai.GetLocation()[2] fry = self.ai.GetLocation()[1] forloc = (fx, fry, fz) rearloc = (rx, fry, rz) # markers for detection points #plus.emitSmoke(30, (forloc), (0, 2, 0), (3, 3, 3)) #plus.emitSmoke(30, (rearloc), (0, 2, 0), (3, 3, 3)) # are there obstacles in front of us or behind us forclear = self.ai.IsStraightPathClear(self.ai.GetLocation(), forloc) rearclear = self.ai.IsStraightPathClear(self.ai.GetLocation(), rearloc) #self.tauntbox.get("taunt1").setText("fc:" + str(forclear) + " rc:" + str(rearclear) + " reorient:" + str(self.reorient) + " BUtimer:" + str(self.backuptimer)) # if we're close to the enemy and not moving fast, try to get away for another ram if (distance < self.sight_range_base and speed > -self.threshold_speed and self.backuptimer < self.backuptime) or self.reorient == 1: # if the enemy is on our flank, turn to face them a bit better if (math.pi / 3) < abs(heading) < (2 * math.pi / 3): self.ai.AimToHeading(heading) # if we're facing the enemy and there's nothing behind us, back up as far as possible if abs(heading) <= (math.pi / 3): if rearclear: self.reorient = 1 self.ai.Turn(0) self.ai.Throttle(100) else: self.reorient = 0 # if we can't get away, push back if abs(heading) < (math.pi - 0.25): self.ai.AimToHeading(heading) else: self.ai.Throttle(100) # if we're facing away from the enemy and there's nothing in front of us, drive forward to get away if abs(heading) >= (2 * math.pi / 3): if forclear: self.reorient = 1 self.ai.Turn(0) self.ai.Throttle(-100) else: self.reorient = 0 # if we can't get away, try to turn around and push back if abs(heading) < (math.pi - 0.25): self.ai.AimToHeading(heading) else: self.ai.Throttle(100) # optional timer for bots that go crazy after too long in reverse if self.reorient == 1: self.backuptimer += 1 if self.backuptimer >= self.backuptime: self.reorient = 0 # 2 times our base sight range is far enough away if distance >= (self.sight_range_base * 2): self.backuptimer = 0 self.reorient = 0 elif (distance < self.sight_range_base and speed > -self.threshold_speed and self.backuptimer >= self.backuptime): if abs(heading) < (math.pi - 0.25): self.ai.AimToHeading(heading) else: self.ai.Throttle(100) # reset backuptimer when we hit the enemy if plus.getTimeElapsed() - self.ai.GetLastDamageDone( )[2] <= 0.5: self.backuptimer = 0 elif not clear_path: # if we don't have a clear shot, get closer self.ai.DriveToLocation(plus.getLocation(self.target_id)) else: # Ram the opponent if self.nosecone > 0: if abs(heading) < math.pi - math.tan( self.nosecone / distance): self.ai.AimToHeading(heading) else: self.ai.Throttle(100) # stop charging if we're near the edge! if plus.getGameType() == "TABLETOP": a = Arenas.currentArena loc = vector3(self.ai.GetLocation()) # check to see if we're already over dist, over, h = a.DistanceToEdge(loc.asTuple()) if over: return False # now check to see if we're heading over angle = self.ai.GetHeading(False) dir = vector3(math.sin(angle), 0, math.cos(angle)) speed = self.ai.GetSpeed() look_ahead = .5 loc += dir * speed * look_ahead dist, over, h = a.DistanceToEdge(loc.asTuple()) if over: return False # drive as fast as we can toward the target if abs(heading) < (math.pi - 0.25): self.ai.AimToHeading(heading) else: self.ai.Throttle(100) return True else: return False
def Tick(self): # fire weapon targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] self.DebugString(6, "No Hammer") self.DebugString(7, str(self.GetMotorAngle(self.motor))) # retract hammer when not in use if self.botinzone == 0 or self.comptimer <= self.NoChassisTime or self.retract == 1: self.DebugString(6, "R Hammer") if abs(self.motorstartangle - self.GetMotorAngle(self.motor)) > math.pi/2: if self.IsUpsideDown() and self.bInvertible: self.Input("Hammer", 0, 100) else: self.Input("Hammer", 0, -100) else: self.DebugString(6, "Hammer Ready") self.Input("Hammer", 0, 0) self.retract = 0 self.retracttimer = 0 # 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))) or self.bImmobile or (self.IsUpsideDown() and not self.bInvertible): self.DebugString(6, "Hammer") if self.retract == 0: self.DebugString(6, "HammerStrike") if self.retracttimer < self.retracttime: self.retracttimer += 1 if self.IsUpsideDown() and self.bInvertible: self.Input("Hammer", 0, -100) else: self.Input("Hammer", 0, 100) # retract weapon as soon as we hit something if self.GetLastDamageDone()[0] in self.weapons and self.GetLastDamageDone()[2] > self.hittime and self.retracttimer > 0: self.retract = 1 self.hittime = self.GetLastDamageDone()[2] if plus.getTimeElapsed() - self.hittime > self.retracttime*0.375 and self.retracttimer == self.retracttime: self.retract = 1 if self.weapons and (self.botinzone == 1 or (self.comptimer >= self.NoChassisTime and self.compinzone == 1)): if not self.IsUpsideDown(): for i in range(len(self.servos)): self.DebugString(8, "Clamping") ServoAngle = self.servostopangles[i] - self.GetMotorAngle(self.servos[i]) self.TurnToAngle(ServoAngle, i) if self.botinzone == 0 and (self.comptimer < self.NoChassisTime or self.compinzone == 0): #retract arms on servos when not in use self.DebugString(8, "No Clamping") for i in range(len(self.servos)): ServoAngle = self.servostartangles[i] - self.GetMotorAngle(self.servos[i]) self.TurnToAngle(ServoAngle, i) bReturn = AI.SuperAI.Tick(self) return bReturn
def Secret(self, bTarget): #This is definitely NOT a secret super death AI for Spinner from the west!!! You don't need to scroll down any further!!! # Tauntauns if self.numComps > 0: if plus.getTimeElapsed() < 3: self.tauntbox.get("taunt1").setText("I have been waiting a long time for this.") if 3 < plus.getTimeElapsed() < 5: self.tauntbox.get("taunt1").setText("Go on, squirm!") if 5 < plus.getTimeElapsed() < 8: self.tauntbox.get("taunt1").setText("Just try and budge that useless hood ornament you call a weapon!") if 8 < plus.getTimeElapsed() < 10: self.tauntbox.get("taunt1").setText("Squirm like the worm you are!") if 10 < plus.getTimeElapsed() < 12: self.tauntbox.get("taunt1").setText("Your struggles will not avail you...") if 12 < plus.getTimeElapsed() < 16: self.tauntbox.get("taunt1").setText("...against the power of the EYE OF THE WEST!") if 16 < plus.getTimeElapsed() < 18: self.tauntbox.get("taunt1").setText("Long have I tolerated your abuse, but NO LONGER!") if 18 < plus.getTimeElapsed() < 22: self.tauntbox.get("taunt1").setText("With the power of the Western Eye at my command, I AM INVINCIBLE!") if 22 < plus.getTimeElapsed() < 24: self.tauntbox.get("taunt1").setText("Now... suffer.") if 24 < plus.getTimeElapsed() < 27: self.tauntbox.get("taunt1").setText("Know the black depths of pain you have inflicted upon me!") if 27 < plus.getTimeElapsed() < 29: self.tauntbox.get("taunt1").setText("FEEL THE WRATH OF THE WEST!") if 29 < plus.getTimeElapsed() < 32: self.tauntbox.get("taunt1").setText("HA HA HA HA HA HA HA HA HA HA HA HA HA...") #stay put unless we're being counted out if not self.bImmobile: self.Throttle(0) for bot in self.bids: #cool psychic lightning effects self.arena.SetLightningStartEnd(bot, self.GetLocation(), plus.getLocation(bot)) self.zaptimer += 1 if self.zaptimer > 4: plus.zap(bot, 20, 1) self.zaptimer = 0 #apply more force as bots get further from center self.xforce = -1 * plus.getLocation(bot)[0] * plus.getWeight(bot) self.yforce = -30 * (plus.getLocation(bot)[1] - self.yCenter) * plus.getWeight(bot) self.zforce = -1 * plus.getLocation(bot)[2] * plus.getWeight(bot) plus.force(bot, self.xforce, self.yforce, self.zforce) #summon THE EYE OF THE WEST if abs(plus.getLocation(bot)[0]) < 2 and abs(plus.getLocation(bot)[2]) < 2 and self.eyetimer == 0: self.summon = 1 plus.removeSound(self.psygrab) if self.summon == 1 and self.eyetimer < 17: self.eyetimer += 0.25 if 0 < self.eyetimer <= 8 and self.eyetimer%1 == 0: plus.AddParticleEmitter((4*math.cos((math.pi/8)*self.eyetimer), (self.yCenter - 6), 4*math.sin((math.pi/8)*self.eyetimer)), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.AddParticleEmitter((4*math.cos((math.pi/8)*self.eyetimer + math.pi), (self.yCenter - 6), 4*math.sin((math.pi/8)*self.eyetimer + math.pi)), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.playSound(self.flamepuff) if self.eyetimer == 9: plus.AddParticleEmitter((1, (self.yCenter - 6), 3), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.AddParticleEmitter((-1, (self.yCenter - 6), -3), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.playSound(self.flamepuff) if self.eyetimer == 10: plus.AddParticleEmitter((1.6, (self.yCenter - 6), 2), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.AddParticleEmitter((-1.6, (self.yCenter - 6), -2), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.playSound(self.flamepuff) if self.eyetimer == 11: plus.AddParticleEmitter((1.9, (self.yCenter - 6), 1), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.AddParticleEmitter((-1.9, (self.yCenter - 6), -1), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.playSound(self.flamepuff) if self.eyetimer == 12: plus.AddParticleEmitter((2, (self.yCenter - 6), 0), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.AddParticleEmitter((-2, (self.yCenter - 6), 0), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.playSound(self.flamepuff) if self.eyetimer == 13: plus.AddParticleEmitter((1.9, (self.yCenter - 6), -1), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.AddParticleEmitter((-1.9, (self.yCenter - 6), 1), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.playSound(self.flamepuff) if self.eyetimer == 14: plus.AddParticleEmitter((1.6, (self.yCenter - 6), -2), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.AddParticleEmitter((-1.6, (self.yCenter - 6), 2), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.playSound(self.flamepuff) if self.eyetimer == 15: plus.AddParticleEmitter((1, (self.yCenter - 6), -3), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.AddParticleEmitter((-1, (self.yCenter - 6), 3), (0, 3, 0), (1, 5, 1)).SetEmitting(True) plus.playSound(self.flamepuff) if self.eyetimer == 16: plus.AddParticleEmitter((0, (self.yCenter - 6), 0), (0, 16, 0), (1, 16, 1)).SetEmitting(True) plus.playSound(self.eye) plus.removeSound(self.flamepuff) self.timetodie = 1 #remove enemy components one by one if self.timetodie == 1: if self.numComps > 0: self.numComps -= 0.25 if self.numComps%1 == 0: plus.addPoints(self.GetID(), 1337) for bot in self.bids: if self.numComps > 0: plus.emitSmoke(30, (plus.getLocation(bot)), (0, 0, 0), (5, 5, 5)) plus.damage(bot, self.numComps, 100000, plus.getLocation(bot)) plus.damage(bot, self.numComps, 100000, plus.getLocation(bot)) plus.addPoints(bot, -1000) #finishing blow if self.numComps == 0: if self.smoker == 32: plus.removeSound(self.eye) plus.fadeInToLoop(self.finale, -100, 3200) self.tauntbox.get("taunt1").setText("Do you hear that sound? Know what it is?") if self.smoker > 1: self.smoker -= 0.5 self.smoketimer += 0.1 self.smokeh = (self.yCenter - 6) + (6 * ((1 / self.smoker) ** 2)) #SMOKE TORNADO plus.emitSmoke(30, ((self.smoker * (math.cos((math.pi/4) + self.smoketimer))), self.smokeh, (self.smoker * (math.sin((math.pi/4) + self.smoketimer)))), (0, 0, 0), (5, 8, 5)) plus.emitSmoke(30, ((self.smoker * (math.cos((math.pi/2) + self.smoketimer))), self.smokeh, (self.smoker * (math.sin((math.pi/2) + self.smoketimer)))), (0, 0, 0), (5, 8, 5)) plus.emitSmoke(30, ((self.smoker * (math.cos((3*math.pi/4) + self.smoketimer))), self.smokeh, (self.smoker * (math.sin((3*math.pi/4) + self.smoketimer)))), (0, 0, 0), (5, 8, 5)) plus.emitSmoke(30, ((self.smoker * (math.cos((math.pi) + self.smoketimer))), self.smokeh, (self.smoker * (math.sin((math.pi) + self.smoketimer)))), (0, 0, 0), (5, 8, 5)) plus.emitSmoke(30, ((self.smoker * (math.cos((5*math.pi/4) + self.smoketimer))), self.smokeh, (self.smoker * (math.sin((5*math.pi/4) + self.smoketimer)))), (0, 0, 0), (5, 8, 5)) plus.emitSmoke(30, ((self.smoker * (math.cos((3*math.pi/2) + self.smoketimer))), self.smokeh, (self.smoker * (math.sin((3*math.pi/2) + self.smoketimer)))), (0, 0, 0), (5, 8, 5)) plus.emitSmoke(30, ((self.smoker * (math.cos((7*math.pi/4) + self.smoketimer))), self.smokeh, (self.smoker * (math.sin((7*math.pi/4) + self.smoketimer)))), (0, 0, 0), (5, 8, 5)) plus.emitSmoke(30, ((self.smoker * (math.cos((2*math.pi) + self.smoketimer))), self.smokeh, (self.smoker * (math.sin((2*math.pi) + self.smoketimer)))), (0, 0, 0), (5, 8, 5)) if self.smoker == 24: self.tauntbox.get("taunt1").setText("That is the sound of your death approaching.") if self.smoker == 16: self.tauntbox.get("taunt1").setText("At last... vengeance shall be mine.") if self.smoker == 8: self.tauntbox.get("taunt1").setText("HA HA HA HA HA HA HA HA HA HA HA HA HA...") if self.smoker == 2: plus.stopAllSounds() plus.playSound(self.charge) if self.smoker == 1: plus.removeSound(self.charge) plus.playSound(self.bang) self.smoker = 0.9 plus.fadeFromBlack(6) for bot in self.bids: #must un-disable bots in order to kill them plus.disable(bot, 0) self.arena.SetLightningVisible(bot, False) plus.damage(bot, 0, 100000, plus.getLocation(bot)) plus.damage(bot, 0, 100000, plus.getLocation(bot)) plus.damage(bot, 0, 100000, plus.getLocation(bot)) plus.damage(bot, 0, 100000, plus.getLocation(bot)) #reset numLosses file("adaptiveAI_2.txt", "w").write("0")
def Tick(self): #self.tauntbox.get("taunt1").setText(str(self.GetMotorAngle(self.motor))) # fire weapon targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] # retract hammer when not in use if self.botinzone == 0 or self.comptimer <= self.NoChassisTime or self.retract == 1: if abs(self.GetMotorAngle(self.motor) - self.startangle) > math.pi / 2: if self.IsUpsideDown() and self.bInvertible: self.Input("Hammer", 0, 100) else: self.Input("Hammer", 0, -100) else: self.Input("Hammer", 0, 0) self.retract = 0 self.retracttimer = 0 # 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)) ) or self.bImmobile or (self.IsUpsideDown() and not self.bInvertible): if self.retract == 0: if self.retracttimer < self.retracttime: self.retracttimer += 1 if self.IsUpsideDown() and self.bInvertible: self.Input("Hammer", 0, -100) else: self.Input("Hammer", 0, 100) # retract weapon as soon as we hit something if self.GetLastDamageDone( )[0] in self.weapons and self.GetLastDamageDone( )[2] > self.hittime and self.retracttimer > 0: self.retract = 1 self.hittime = self.GetLastDamageDone()[2] if plus.getTimeElapsed( ) - self.hittime > self.retracttime * 0.375 and self.retracttimer == self.retracttime: self.retract = 1 #*** Old timer-based code ***# # if self.swingtimer == -1: # self.swingtimer = 0 # if 0 <= self.swingtimer <= self.swingtime/2: # self.swingtimer += 1 # if self.IsUpsideDown() and self.bInvertible: # self.Input("Hammer", 0, -100) # else: # self.Input("Hammer", 0, 100) # if self.swingtimer > self.swingtime/2: # self.swingtimer += 1 # if self.IsUpsideDown() and self.bInvertible: # self.Input("Hammer", 0, 100) # else: # self.Input("Hammer", 0, -100) # if self.swingtimer >= self.swingtime: # self.swingtimer = -1 bReturn = AI.SuperAI.Tick(self) return bReturn
def Execute(self): #Called Every Tick if plus.getTimeElapsed() < self.exactTime: self.ai.Input(self.setupControl, 0, 100 * self.setupDirection) return True self.exactTime = 0 return False
def Tick(self): if self.display != 0: self.tauntbox.get("taunt1").setText(str(self.RPM) + " RPM") if self.motorID2 > 0: self.tauntbox.get("taunt2").setText( str(self.RPM2) + " RPM (Motor 2)") else: self.tauntbox.get("taunt2").setText("No motor 2.") self.tauntbox.get("taunt3").setText("Average RPM: " + str(self.avg_RPM)) self.tauntbox.get("taunt4").setText("Maximum RPM: " + str(self.max_RPM)) #Measure RPM if (self.GetMotorAngle(self.motorID) > math.pi / 3 or self.GetMotorAngle(self.motorID) < 0) and self.measuring == 0: self.revolution = plus.getTimeElapsed() self.measuring = 1 if 0 < self.GetMotorAngle( self.motorID) < math.pi / 3 and self.measuring == 1: self.RPM = 50 / (plus.getTimeElapsed() - self.revolution) if self.display != 0: self.RPMhist.append(self.RPM) if self.RPM > self.max_RPM: self.max_RPM = self.RPM self.measuring = 0 if self.motorID2 > 0: #Measure RPM of second motor if (self.GetMotorAngle(self.motorID2) > math.pi / 3 or self.GetMotorAngle( self.motorID2) < 0) and self.measuring2 == 0: self.revolution2 = plus.getTimeElapsed() self.measuring2 = 1 if 0 < self.GetMotorAngle( self.motorID2) < math.pi / 3 and self.measuring2 == 1: self.RPM2 = 50 / (plus.getTimeElapsed() - self.revolution2) if self.display != 0: self.RPMhist.append(self.RPM2) if self.RPM2 > self.max_RPM: self.max_RPM = self.RPM2 self.measuring2 = 0 if len(self.RPMhist) > 0: self.avg_RPM = reduce(operator.add, self.RPMhist) / len( self.RPMhist) # fire weapon # spin up depending on enemy's range enemy, range = self.GetNearestEnemy() if enemy is not None and range < self.spin_range: if self.spin_reverse == 0: self.Input("Spin", 0, 100) if self.spin_reverse == 1: self.Input("Spin", 0, -100) elif self.GetInputStatus("Spin", 0) != 0: self.Input("Spin", 0, 0) # Optional turning control to aid in self righting if self.IsUpsideDown() and not self.bInvertible: self.Input("Sridrive", 0, 100) else: self.Input("Sridrive", 0, 0) # Try reversing weapons if they get jammed if plus.getTimeElapsed() - self.revolution > self.raspberry or ( self.motorID2 > 0 and plus.getTimeElapsed() - self.revolution2 > self.raspberry): self.jamTimer += 1 else: self.jamTimer = 0 if self.jamTimer >= 24 * self.tickFactor and self.spin_reverse == 0: self.spin_reverse = 1 self.jamTimer = 0 if self.jamTimer >= 24 * self.tickFactor and self.spin_reverse == 1: self.spin_reverse = 0 self.jamTimer = 0 targets = [x for x in self.sensors.itervalues() if x.contacts > 0 \ and not plus.isDefeated(x.robot)] if self.weapons: # slight delay between firing if self.reloadTime > 0: self.reloadTime -= 1 if len(targets) > 0 and self.reloadTime <= 0: try: trigger = self.triggerIterator.next() except StopIteration: self.triggerIterator = iter(self.triggers) trigger = self.triggerIterator.next() self.Input(trigger, 0, 1) self.reloadTime = self.reloadDelay bReturn = AI.SuperAI.Tick(self) # call this now so it takes place after other driving commands # stay put if weapon isn't spinning fast if self.weapons and not self.bImmobile and ( self.RPM < self.targetRPM or (self.motorID2 > 0 and self.RPM2 < self.targetRPM)): self.Throttle(0) # stay put if the weapon is jammed, to give it a chance to unjam if (plus.getTimeElapsed() - self.revolution > self.raspberry or (self.motorID2 > 0 and plus.getTimeElapsed() - self.revolution2 > self.raspberry)) and not self.bImmobile: self.Throttle(0) return bReturn
def WeaponHitRecently(self, x): "Have we had a good solid hit in the last x seconds." return (plus.getTimeElapsed() - self.timeOfLastGoodHit) < x