def step(self, gamestate, smashbot_state, opponent_state): self._propagate = (gamestate, smashbot_state, opponent_state) # -1 means auto-adjust difficulty based on stocks remaining if self.set_difficulty == -1: self.difficulty = smashbot_state.stock else: self.difficulty = self.set_difficulty if SelfDestruct.shouldsd(gamestate, smashbot_state, opponent_state): self.picktactic(Tactics.SelfDestruct) return # Reset the approach state after 1 second # Or if opponent becomes invulnerable if self.approach and ((abs(self.approach_frame - gamestate.frame) > 60) or (opponent_state.invulnerability_left > 0)): self.approach_frame = -123 self.approach = False # Randomly approach sometimes rather than keeping distance # Should happen on average once per 2 seconds # The effect will last for about 1 second # On the first two difficulties, just always approach if (random.randint(0, 120) == 0 or (self.difficulty >= 4 and opponent_state.action != Action.CROUCHING )) and (opponent_state.invulnerability_left == 0): self.approach = True self.approach_frame = gamestate.frame if self.logger: self.logger.log("Notes", " approach: " + str(self.approach) + " ", concat=True) if Mitigate.needsmitigation(smashbot_state): self.picktactic(Tactics.Mitigate) return if self.tactic and not self.tactic.isinteruptible(): self.tactic.step(gamestate, smashbot_state, opponent_state) return # If we're stuck in a lag state, just do nothing. Trying an action might just # buffer an input we don't want if Wait.shouldwait(gamestate, smashbot_state, opponent_state, self.framedata): self.picktactic(Tactics.Wait) return if Recover.needsrecovery(smashbot_state, opponent_state, gamestate): self.picktactic(Tactics.Recover) return if Celebrate.deservescelebration(smashbot_state, opponent_state): self.picktactic(Tactics.Celebrate) return # Difficulty 5 is a debug / training mode # Don't do any attacks, and don't do any shielding # Take attacks, DI, and recover if self.difficulty == 5: self.picktactic(Tactics.KeepDistance) return if Defend.needsprojectiledefense(smashbot_state, opponent_state, gamestate, self.logger): self.picktactic(Tactics.Defend) return # If we can infinite our opponent, do that! if Infinite.caninfinite(smashbot_state, opponent_state, gamestate, self.framedata, self.difficulty): self.picktactic(Tactics.Infinite) return # If we can juggle opponent in the air, do that if Juggle.canjuggle(smashbot_state, opponent_state, gamestate, self.framedata, self.difficulty): self.picktactic(Tactics.Juggle) return # If we can punish our opponent for a laggy move, let's do that if Punish.canpunish(smashbot_state, opponent_state, gamestate, self.framedata): self.picktactic(Tactics.Punish) return # Do we need to defend an attack? if Defend.needsdefense(smashbot_state, opponent_state, gamestate, self.framedata): self.picktactic(Tactics.Defend) return # Can we edge guard them? if Edgeguard.canedgeguard(smashbot_state, opponent_state, gamestate): self.picktactic(Tactics.Edgeguard) return # Can we shield pressure them? if Pressure.canpressure(opponent_state, gamestate): self.picktactic(Tactics.Pressure) return if Retreat.shouldretreat(smashbot_state, opponent_state, gamestate, not self.approach): self.picktactic(Tactics.Retreat) return if Challenge.canchallenge(smashbot_state, opponent_state, gamestate, self.framedata, self.difficulty): self.picktactic(Tactics.Challenge) return if Approach.shouldapproach(smashbot_state, opponent_state, gamestate, self.framedata, self.logger) or \ (self.approach and not Approach.approach_too_dangerous(smashbot_state, opponent_state, gamestate, self.framedata)): self.picktactic(Tactics.Approach) return self.picktactic(Tactics.KeepDistance)
def step(self): # If we have stopped approaching, reset the state if type(self.tactic) != Tactics.Approach: self.approach = False if Mitigate.needsmitigation(self.smashbot_state): self.picktactic(Tactics.Mitigate) return if self.tactic and not self.tactic.isinteruptible(): self.tactic.step() return # If we're stuck in a lag state, just do nothing. Trying an action might just # buffer an input we don't want if Wait.shouldwait(self.smashbot_state, self.framedata): self.picktactic(Tactics.Wait) return if Recover.needsrecovery(self.smashbot_state, self.opponent_state, self.gamestate): self.picktactic(Tactics.Recover) return if Celebrate.deservescelebration(self.smashbot_state, self.opponent_state): self.picktactic(Tactics.Celebrate) return # Difficulty 5 is a debug / training mode # Don't do any attacks, and don't do any shielding # Take attacks, DI, and recover if self.difficulty == 5: self.picktactic(Tactics.KeepDistance) return if Defend.needsprojectiledefense(self.smashbot_state, self.opponent_state, self.gamestate): self.picktactic(Tactics.Defend) return # If we can infinite our opponent, do that! if Infinite.caninfinite(self.smashbot_state, self.opponent_state, self.gamestate, self.framedata, self.difficulty): self.picktactic(Tactics.Infinite) return # If we can punish our opponent for a laggy move, let's do that if Punish.canpunish(self.smashbot_state, self.opponent_state, self.gamestate, self.framedata): self.picktactic(Tactics.Punish) return # Do we need to defend an attack? if Defend.needsdefense(self.smashbot_state, self.opponent_state, self.gamestate, self.framedata): self.picktactic(Tactics.Defend) return # Can we edge guard them? if Edgeguard.canedgeguard(self.smashbot_state, self.opponent_state, self.gamestate): self.picktactic(Tactics.Edgeguard) return # Can we shield pressure them? if Pressure.canpressure(self.opponent_state, self.gamestate): self.picktactic(Tactics.Pressure) return if Retreat.shouldretreat(self.smashbot_state, self.opponent_state, self.gamestate): self.picktactic(Tactics.Retreat) return # Is opponent starting a jump? jumping = self.opponent_state.action == Action.KNEE_BEND if self.opponent_state.action in [Action.JUMPING_FORWARD, Action.JUMPING_BACKWARD] and \ self.opponent_state.speed_y_self > 0: jumping = True # Randomly approach some times rather than keeping distance if self.smashbot_state.action == Action.TURNING and random.randint( 0, 40) == 0: self.approach = True if (jumping and self.opponent_state.invulnerability_left <= 0 ) or self.approach: self.picktactic(Tactics.Approach) return self.picktactic(Tactics.KeepDistance)