def setup_3s_kickoff(agent: MyHivemind): x_pos = [round(drone.location.x) for drone in agent.drones] x_pos.extend([round(friend.location.x) for friend in agent.friends]) if sorted(x_pos) in [[-2048, -256, 2048], [-2048, 0, 2048], [-2048, 256, 2048]]: for drone in agent.drones: if round(drone.location.x) == -2048: drone.push(DiagonalKickoff()) drone.action = Action.Going elif round(drone.location.x) == 2048: drone.push(Shadow(agent.ball.location)) drone.action = Action.Shadowing else: drone.push( GotoBoost(closest_boost(agent, drone.location), agent.ball.location)) drone.action = Action.Boost elif sorted(x_pos) == [-256, 0, 256]: for drone in agent.drones: if round(drone.location.x) == -256: drone.push(OffCenterKickoff()) drone.action = Action.Going elif round(drone.location.x) == 256: drone.push(Shadow(agent.ball.location)) drone.action = Action.Shadowing else: drone.push( GotoBoost(closest_boost(agent, drone.location), agent.ball.location)) drone.action = Action.Boost elif -2048 in x_pos or 2048 in x_pos: for drone in agent.drones: if round(abs(drone.location.x)) == 2048: drone.push(DiagonalKickoff()) drone.action = Action.Going elif round(drone.location.x) == -256: drone.push(Shadow(agent.ball.location)) drone.action = Action.Shadowing elif round(drone.location.x) == 0: drone.push( GotoBoost(closest_boost(agent, drone.location), agent.ball.location)) drone.action = Action.Boost else: if 0 in x_pos: drone.push(Shadow(agent.ball.location)) drone.action = Action.Shadowing else: drone.push( GotoBoost(closest_boost(agent, drone.location), agent.ball.location)) drone.action = Action.Boost
def setup_3s_kickoff(agent: MyHivemind): x_pos = [round(drone.location.x) for drone in agent.drones] x_pos.extend([round(friend.location.x) for friend in agent.friends]) if sorted(x_pos) in [[-2048, -256, 2048], [-2048, 0, 2048], [-2048, 256, 2048]]: for drone in agent.drones: if round(drone.location.x) == agent.side() * -2048: drone.push(KickOff()) drone.action = Action.Going elif round(drone.location.x) == agent.side() * 2048: target = agent.friend_goal.location + 2 * ( agent.ball.location - agent.friend_goal.location) / 3 drone.push(Goto(target)) drone.action = Action.Cheating else: drone.push(GotoBoost(closest_boost(agent, drone.location))) drone.action = Action.Boost elif sorted(x_pos) == [-256, 0, 256]: for drone in agent.drones: if round(drone.location.x) == agent.side() * -256: drone.push(KickOff()) drone.action = Action.Going elif round(drone.location.x) == agent.side() * 256: target = agent.friend_goal.location + 2 * ( agent.ball.location - agent.friend_goal.location) / 3 drone.push(Goto(target)) drone.action = Action.Cheating else: drone.push(GotoBoost(closest_boost(agent, drone.location))) drone.action = Action.Boost elif -2048 in x_pos or 2048 in x_pos: for drone in agent.drones: if round(abs(drone.location.x)) == 2048: drone.push(KickOff()) drone.action = Action.Going elif round(drone.location.x) == agent.side() * -256: target = agent.friend_goal.location + 2 * ( agent.ball.location - agent.friend_goal.location) / 3 drone.push(Goto(target)) drone.action = Action.Cheating elif round(drone.location.x) == 0: drone.push(GotoBoost(closest_boost(agent, drone.location))) drone.action = Action.Boost else: if 0 in x_pos: target = agent.friend_goal.location + 2 * ( agent.ball.location - agent.friend_goal.location) / 3 drone.push(Goto(target)) drone.action = Action.Cheating else: drone.push(GotoBoost(closest_boost(agent, drone.location))) drone.action = Action.Boost
def run_hivemind(agent: MyHivemind): agent.debug_stack() if agent.kickoff_flag and all( len(drone.stack) < 1 for drone in agent.drones): if len(agent.friends + agent.drones) == 3: setup_3s_kickoff(agent) elif len(agent.friends + agent.drones) == 2: setup_2s_kickoff(agent) else: setup_other_kickoff(agent) elif not agent.kickoff_flag: for drone in agent.drones: drones = copy(agent.drones) drones.remove(drone) team = agent.friends + drones if len(drone.stack) < 1 or drone.action == Action.Shadowing: if drone.on_side and drone.closest or agent.conceding: push_shot(drone, agent) if len(drone.stack) < 1: if drone.action == Action.Going: if any(teammate.on_side for teammate in team): drone.push( GotoBoost(closest_boost(agent, drone.location))) drone.action = Action.Boost else: drone.push(Shadow(agent.ball.location)) drone.action = Action.Shadowing elif drone.action == Action.Shadowing: drone.push(Shadow(agent.ball.location)) drone.action = Action.Shadowing elif drone.action == Action.Boost: drone.push(Shadow(agent.ball.location)) drone.action = Action.Shadowing
def run_hivemind(agent: MyHivemind): agent.debug_stack() if agent.kickoff_flag and all(len(drone.stack) < 1 for drone in agent.drones): if len(agent.friends + agent.drones) == 3: setup_3s_kickoff(agent) elif len(agent.friends + agent.drones) == 2: setup_2s_kickoff(agent) else: setup_other_kickoff(agent) elif not agent.kickoff_flag: for drone in agent.drones: drones = copy(agent.drones) drones.remove(drone) team = agent.friends + drones empty_stack = len(drone.stack) < 1 and drone.on_side and drone.closest should_go = ( drone.action == Action.Shadowing) and drone.on_side and drone.closest conceding = (agent.conceding and not any(teammate.on_side for teammate in team)) or ( agent.conceding and drone.on_side and drone.closest) cheating = drone.action == Action.Cheating if empty_stack or should_go or conceding or cheating: if empty_stack or drone.stack[0].__class__.__name__ not in ["GroundShot", "JumpShot", "DoubleJump"]: shot = find_any_shot(drone) if shot is not None: drone.push(shot) drone.action = Action.Going if len(drone.stack) < 1: if drone.action == Action.Going: if any(teammate.on_side for teammate in team) and drone.boost < 66: drone.push(GotoBoost(closest_boost(agent, drone.location))) drone.action = Action.Boost else: drone.push(Shadow()) drone.action = Action.Shadowing elif drone.action == Action.Shadowing: if all(teammate.on_side for teammate in team) and drone.boost < 66: drone.push(GotoBoost(closest_boost(agent, drone.location))) drone.action = Action.Boost else: drone.push(Shadow()) drone.action = Action.Shadowing elif drone.action == Action.Boost: drone.push(Shadow()) drone.action = Action.Shadowing