diff --git a/RLBotPack/Bubo/__init__.py b/RLBotPack/Bubo/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/RLBotPack/Bubo/agent.py b/RLBotPack/Bubo/agent.py deleted file mode 100644 index e7dffc1b..00000000 --- a/RLBotPack/Bubo/agent.py +++ /dev/null @@ -1,22 +0,0 @@ -import numpy as np -from stable_baselines3 import PPO -import os, sys -import pathlib - - -class Agent: - def __init__(self): - _path = pathlib.Path(__file__).parent.resolve() - custom_objects = { - "lr_schedule": 0.00001, - "clip_range": .02, - "n_envs": 1, - "device": "auto" - } - - sys.path.append(_path) - self.actor = PPO.load(str(_path) + '/bubo_net', custom_objects=custom_objects) - - def act(self, state): - action = self.actor.predict(state, deterministic=True) - return np.array([value-1 if count < 5 else value for count, value in enumerate(action[0])]), None diff --git a/RLBotPack/Bubo/appearance.cfg b/RLBotPack/Bubo/appearance.cfg deleted file mode 100644 index 3df32240..00000000 --- a/RLBotPack/Bubo/appearance.cfg +++ /dev/null @@ -1,100 +0,0 @@ -[Bot Loadout] -# Primary Color selection -team_color_id = 60 -# Secondary Color selection -custom_color_id = 49 -# Car type (Octane, Merc, etc) -car_id = 5713 -# Type of decal -decal_id = 0 -# Wheel selection -wheels_id = 0 -# Boost selection -boost_id = 35 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 0 -# Paint Type (for first color) -paint_finish_id = 1681 -# Paint Type (for secondary color) -custom_finish_id = 1681 -# Engine Audio Selection -engine_audio_id = 0 -# Car trail Selection -trails_id = 3220 -# Goal Explosion Selection -goal_explosion_id = 4118 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Loadout Orange] -# Primary Color selection -team_color_id = 30 -# Secondary Color selection -custom_color_id = 67 -# Car type (Octane, Merc, etc) -car_id = 5713 -# Type of decal -decal_id = 0 -# Wheel selection -wheels_id = 0 -# Boost selection -boost_id = 35 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 0 -# Paint Type (for first color) -paint_finish_id = 1681 -# Paint Type (for secondary color) -custom_finish_id = 1681 -# Engine Audio Selection -engine_audio_id = 0 -# Car trail Selection -trails_id = 3220 -# Goal Explosion Selection -goal_explosion_id = 4118 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Paint Blue] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 0 -# wheels_paint_id -wheels_paint_id = 0 -# boost_paint_id -boost_paint_id = 0 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 0 -# trails_paint_id -trails_paint_id = 0 -# goal_explosion_paint_id -goal_explosion_paint_id = 0 - -[Bot Paint Orange] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 0 -# wheels_paint_id -wheels_paint_id = 14 -# boost_paint_id -boost_paint_id = 14 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 0 -# trails_paint_id -trails_paint_id = 14 -# goal_explosion_paint_id -goal_explosion_paint_id = 0 - diff --git a/RLBotPack/Bubo/bot.cfg b/RLBotPack/Bubo/bot.cfg deleted file mode 100644 index fa0bfb0b..00000000 --- a/RLBotPack/Bubo/bot.cfg +++ /dev/null @@ -1,30 +0,0 @@ -[Locations] -# Path to loadout config. Can use relative path from here. -looks_config = ./appearance.cfg - -# Path to python file. Can use relative path from here. -python_file = ./bot.py -requirements_file = ./requirements.txt - -# Name of the bot in-game -name = Bubo - -# The maximum number of ticks per second that your bot wishes to receive. -maximum_tick_rate_preference = 120 - -[Details] -# These values are optional but useful metadata for helper programs -# Name of the bot's creator/developer -developer = Impossibum - -# Short description of the bot -description = A reinforcement learning bot made with rlgym and sb3 - -# Fun fact about the bot -fun_fact = Bubo was forged by Hephaestus and is a replica of Athena's owl. - -# Link to github repository -github = None - -# Programming language -language = Python diff --git a/RLBotPack/Bubo/bot.py b/RLBotPack/Bubo/bot.py deleted file mode 100644 index 622e2ace..00000000 --- a/RLBotPack/Bubo/bot.py +++ /dev/null @@ -1,66 +0,0 @@ -from rlbot.agents.base_agent import BaseAgent, SimpleControllerState -from rlbot.utils.structures.game_data_struct import GameTickPacket -import numpy as np -from agent import Agent -from obs.custom_obs import AdvancedObsRevised2 -from rlgym_compat import GameState - - -class Bubo(BaseAgent): - def __init__(self, name, team, index): - super().__init__(name, team, index) - self.obs_builder = AdvancedObsRevised2() - self.agent = Agent() - self.tick_skip = 8 - - self.game_state: GameState = None - self.controls = None - self.prev_action = None - self.ticks = 0 - self.prev_time = 0 - print(f"{name} loaded and ready!") - - def initialize_agent(self): - self.game_state = GameState(self.get_field_info()) - self.ticks = self.tick_skip - self.prev_time = 0 - self.controls = SimpleControllerState() - self.prev_action = np.zeros(8) - - def get_output(self, packet: GameTickPacket) -> SimpleControllerState: - cur_time = packet.game_info.seconds_elapsed - delta = cur_time - self.prev_time - self.prev_time = cur_time - - self.ticks += delta // 0.008 - - if self.ticks >= self.tick_skip: - self.ticks = 0 - - self.game_state.decode(packet) - player = self.game_state.players[self.index] - opponents = [p for p in self.game_state.players if p.team_num != self.team] - closest_op = min(opponents, key=lambda p: np.linalg.norm(self.game_state.ball.position - p.car_data.position)) - - self.game_state.players = [player, closest_op] - - obs = self.obs_builder.build_obs(player, self.game_state, self.prev_action) - action, discrete = self.agent.act(obs) - self.update_controls(action, discrete_action=discrete) - - return self.controls - - def update_controls(self, action, discrete_action=None): - if discrete_action == None: - self.prev_action[:] = action[:] - else: - self.prev_action = discrete_action - - self.controls.throttle = action[0] - self.controls.steer = action[1] - self.controls.pitch = action[2] - self.controls.yaw = action[3] - self.controls.roll = action[4] - self.controls.jump = action[5] > 0 - self.controls.boost = action[6] > 0 - self.controls.handbrake = action[7] > 0 diff --git a/RLBotPack/Bubo/bubo_net.zip b/RLBotPack/Bubo/bubo_net.zip deleted file mode 100644 index bcb9b3f7..00000000 Binary files a/RLBotPack/Bubo/bubo_net.zip and /dev/null differ diff --git a/RLBotPack/Bubo/obs/advanced_obs.py b/RLBotPack/Bubo/obs/advanced_obs.py deleted file mode 100644 index ad4dcf16..00000000 --- a/RLBotPack/Bubo/obs/advanced_obs.py +++ /dev/null @@ -1,87 +0,0 @@ -import math -import numpy as np -from typing import Any, List -from rlgym_compat import common_values -from rlgym_compat import PlayerData, GameState, PhysicsObject - - -class AdvancedObs: - POS_STD = 2300 - ANG_STD = math.pi - - def __init__(self): - super().__init__() - - def reset(self, initial_state: GameState): - pass - - def build_obs(self, player: PlayerData, state: GameState, previous_action: np.ndarray) -> Any: - - if player.team_num == common_values.ORANGE_TEAM: - inverted = True - ball = state.inverted_ball - pads = state.inverted_boost_pads - else: - inverted = False - ball = state.ball - pads = state.boost_pads - - # print(ball.position) - # print(ball.position / self.POS_STD) - # print("============") - - obs = [ball.position / self.POS_STD, - ball.linear_velocity / self.POS_STD, - ball.angular_velocity / self.ANG_STD, - previous_action, - pads] - - player_car = self._add_player_to_obs(obs, player, ball, inverted) - - allies = [] - enemies = [] - - for other in state.players: - if other.car_id == player.car_id: - continue - - if other.team_num == player.team_num: - team_obs = allies - else: - team_obs = enemies - - other_car = self._add_player_to_obs(team_obs, other, ball, inverted) - - # Extra info - team_obs.extend([ - (other_car.position - player_car.position) / self.POS_STD, - (other_car.linear_velocity - player_car.linear_velocity) / self.POS_STD - ]) - - obs.extend(allies) - obs.extend(enemies) - return np.concatenate(obs) - - def _add_player_to_obs(self, obs: List, player: PlayerData, ball: PhysicsObject, inverted: bool): - if inverted: - player_car = player.inverted_car_data - else: - player_car = player.car_data - - rel_pos = ball.position - player_car.position - rel_vel = ball.linear_velocity - player_car.linear_velocity - - obs.extend([ - rel_pos / self.POS_STD, - rel_vel / self.POS_STD, - player_car.position / self.POS_STD, - player_car.forward(), - player_car.up(), - player_car.linear_velocity / self.POS_STD, - player_car.angular_velocity / self.ANG_STD, - [player.boost_amount, - int(player.on_ground), - int(player.has_flip), - int(player.is_demoed)]]) - - return player_car diff --git a/RLBotPack/Bubo/obs/custom_obs.py b/RLBotPack/Bubo/obs/custom_obs.py deleted file mode 100644 index f2f3f808..00000000 --- a/RLBotPack/Bubo/obs/custom_obs.py +++ /dev/null @@ -1,159 +0,0 @@ -import math -import numpy as np -from typing import Any, List -from rlgym_compat import common_values, PlayerData, GameState, PhysicsObject - - -class AdvancedObsRevised: - POS_STD = 6000 - ANG_STD = math.pi - - def __init__(self): - super().__init__() - - def reset(self, initial_state: GameState): - pass - - def build_obs(self, player: PlayerData, state: GameState, previous_action: np.ndarray) -> Any: - - if player.team_num == common_values.ORANGE_TEAM: - inverted = True - ball = state.inverted_ball - pads = state.inverted_boost_pads - else: - inverted = False - ball = state.ball - pads = state.boost_pads - - obs = [ball.position / self.POS_STD, - ball.linear_velocity / self.POS_STD, - ball.angular_velocity / self.ANG_STD, - previous_action, - pads] - - player_car = self._add_player_to_obs(obs, player, ball, inverted) - - allies = [] - enemies = [] - - for other in state.players: - if other.car_id == player.car_id: - continue - - if other.team_num == player.team_num: - team_obs = allies - else: - team_obs = enemies - - other_car = self._add_player_to_obs(team_obs, other, ball, inverted) - - # Extra info - team_obs.extend([ - (other_car.position - player_car.position) / self.POS_STD, - (other_car.linear_velocity - player_car.linear_velocity) / self.POS_STD - ]) - - obs.extend(allies) - obs.extend(enemies) - return np.concatenate(obs) - - def _add_player_to_obs(self, obs: List, player: PlayerData, ball: PhysicsObject, inverted: bool): - if inverted: - player_car = player.inverted_car_data - else: - player_car = player.car_data - - rel_pos = ball.position - player_car.position - rel_vel = ball.linear_velocity - player_car.linear_velocity - - obs.extend([ - rel_pos / self.POS_STD, - rel_vel / self.POS_STD, - player_car.position / self.POS_STD, - player_car.forward(), - player_car.up(), - player_car.linear_velocity / self.POS_STD, - player_car.angular_velocity / self.ANG_STD, - [player.boost_amount, - int(player.on_ground), - int(player.has_flip), - int(player.is_demoed)]]) - - return player_car - -class AdvancedObsRevised2: - POS_STD = 6000 - ANG_STD = 5.5 - - def __init__(self): - super().__init__() - - def reset(self, initial_state: GameState): - pass - - def build_obs(self, player: PlayerData, state: GameState, previous_action: np.ndarray) -> Any: - - if player.team_num == common_values.ORANGE_TEAM: - inverted = True - ball = state.inverted_ball - pads = state.inverted_boost_pads - else: - inverted = False - ball = state.ball - pads = state.boost_pads - - obs = [ball.position / self.POS_STD, - ball.linear_velocity / self.POS_STD, - ball.angular_velocity / self.ANG_STD, - previous_action, - pads] - - player_car = self._add_player_to_obs(obs, player, ball, inverted) - - allies = [] - enemies = [] - - for other in state.players: - if other.car_id == player.car_id: - continue - - if other.team_num == player.team_num: - team_obs = allies - else: - team_obs = enemies - - other_car = self._add_player_to_obs(team_obs, other, ball, inverted) - - # Extra info - team_obs.extend([ - (other_car.position - player_car.position) / self.POS_STD, - (other_car.linear_velocity - player_car.linear_velocity) / self.POS_STD - ]) - - obs.extend(allies) - obs.extend(enemies) - return np.concatenate(obs) - - def _add_player_to_obs(self, obs: List, player: PlayerData, ball: PhysicsObject, inverted: bool): - if inverted: - player_car = player.inverted_car_data - else: - player_car = player.car_data - - rel_pos = ball.position - player_car.position - rel_vel = ball.linear_velocity - player_car.linear_velocity - - obs.extend([ - rel_pos / self.POS_STD, - rel_vel / self.POS_STD, - player_car.position / self.POS_STD, - player_car.forward(), - player_car.up(), - player_car.linear_velocity / self.POS_STD, - player_car.angular_velocity / self.ANG_STD, - [player.boost_amount, - int(player.on_ground), - int(player.has_flip), - int(player.is_demoed)]]) - - return player_car \ No newline at end of file diff --git a/RLBotPack/Bubo/obs/default_obs.py b/RLBotPack/Bubo/obs/default_obs.py deleted file mode 100644 index cb9ee982..00000000 --- a/RLBotPack/Bubo/obs/default_obs.py +++ /dev/null @@ -1,52 +0,0 @@ -import math -import numpy as np -from rlgym_compat import common_values -from rlgym_compat import PlayerData, GameState - - -class DefaultObs: - POS_STD = 2300 - ANG_STD = math.pi - - def __init__(self): - super().__init__() - - def reset(self, initial_state: GameState): - pass - - def build_obs(self, player: PlayerData, state: GameState, previous_action: np.ndarray) -> np.ndarray: - players = state.players - if player.team_num == common_values.ORANGE_TEAM: - player_car = player.inverted_car_data - ball = state.inverted_ball - else: - player_car = player.car_data - ball = state.ball - - ob = [] - - ob.append(ball.position / self.POS_STD) - ob.append(ball.linear_velocity / self.POS_STD) - ob.append(ball.angular_velocity / self.ANG_STD) - - ob.append(player_car.position / self.POS_STD) - ob.append(player_car.linear_velocity / self.POS_STD) - ob.append(player_car.angular_velocity / self.ANG_STD) - ob.append([player.boost_amount, - int(player.has_flip), - int(player.on_ground)]) - - for other in players: - if other.car_id == player.car_id: - continue - - if player.team_num == common_values.ORANGE_TEAM: - car_data = other.inverted_car_data - else: - car_data = other.car_data - - ob.append(car_data.position / self.POS_STD) - ob.append(car_data.linear_velocity / self.POS_STD) - ob.append(car_data.angular_velocity / self.ANG_STD) - - return np.concatenate(ob) diff --git a/RLBotPack/Bubo/requirements.txt b/RLBotPack/Bubo/requirements.txt deleted file mode 100644 index d2121bc2..00000000 --- a/RLBotPack/Bubo/requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Include everything the framework requires -# You will automatically get updates for all versions starting with "1.". -rlbot==1.* ---find-links https://download.pytorch.org/whl/torch_stable.html -torch==1.5.1+cpu -stable_baselines3 -rlgym-compat -numpy -pickle5 -cloudpickle - -# This will cause pip to auto-upgrade and stop scaring people with warning messages -pip diff --git a/RLBotPack/Diablo/States.py b/RLBotPack/Diablo/States.py deleted file mode 100644 index 55277b00..00000000 --- a/RLBotPack/Diablo/States.py +++ /dev/null @@ -1,783 +0,0 @@ -from Utilities import * -import time -import math -from rlbot.agents.base_agent import BaseAgent, SimpleControllerState -from rlbot.utils.structures.game_data_struct import GameTickPacket -from rlbot.utils.game_state_util import GameState, BallState, CarState, Physics, Vector3, Rotator - -from rlutilities.linear_algebra import * -from rlutilities.mechanics import Aerial, AerialTurn, Dodge, Wavedash, Boostdash, Drive -from rlutilities.simulation import Game, Ball, Car - - -class baseState: - def __init__(self, agent): - self.agent = agent - self.active = True - -class State: - RESET = 0 - WAIT = 1 - INITIALIZE = 2 - RUNNING = 3 - - - -class GetBoost(baseState): - def update(self): - return saferBoostGrabber(self.agent) - - - -class airLaunch(baseState): - def __init__(self,agent): - baseState.__init__(self,agent) - self.initiated = time.time() - self.jumpTimer = time.time() - self.firstJump = False - self.secondJump = False - self.firstJumpHold = 0.5 - self.secondJumpHold = 0.4 - self.active = True - - - def update(self): - stateController = SimpleControllerState() - - if not self.firstJump: - self.firstJump = True - stateController.jump = True - self.jumpTimer = time.time() - - elif self.firstJump and not self.secondJump: - if time.time() - self.jumpTimer < self.firstJumpHold: - stateController.jump = True - - elif time.time() - self.jumpTimer > self.firstJumpHold and time.time() - self.jumpTimer < self.firstJumpHold +.05: - stateController.boost = True - stateController.jump = False - - else: - self.secondJump = True - stateController.boost = True - self.jumpTimer = time.time() - - else: - if time.time() - self.jumpTimer < self.secondJumpHold: - stateController.jump = True - stateController.boost = True - - else: - self.active = False - self.jump = False - - if time.time() - self.jumpTimer > 0.15 and time.time() - self.jumpTimer < 0.35: - stateController.pitch = 1 - return stateController - - -class AerialHandler(): - def __init__(self,agent,struct): - self.agent = agent - self.active = True - self.threshold = 300 - self.struct = predictionStruct(convertStructLocationToVector(struct),struct.game_seconds) - self.currentPredStruct = None - - - def structViable(self): - updatedPredAtTime = find_pred_at_time(self.agent,self.struct.time) - self.currentPredStruct = updatedPredAtTime - if updatedPredAtTime.game_seconds <= self.agent.time: - return False - - if findDistance(convertStructLocationToVector(updatedPredAtTime),self.struct.location) > 10: - return False - return True - - - def update(self): - self.active = self.structViable() and not self.agent.aerial.finished - return aerialWorkHorse(self.agent,self.currentPredStruct) - -class WaveDashing(baseState): - def __init__(self,agent,targVec): - baseState.__init__(self,agent) - self.action = Wavedash(agent.game.my_car) - self.action.direction = vec2(targVec[0],targVec[1]) - - def update(self): - self.action.step(self.agent.deltaTime) - if self.action.finished: - self.active = False - return self.action.controls - - - - -class JumpingState(baseState): - def __init__(self,agent, targetCode): - self.agent = agent - self.active = True - self.targetCode = targetCode - self.flip_obj = FlipStatus(agent.time) - - def update(self): - controller_state = SimpleControllerState() - jump = flipHandler(self.agent, self.flip_obj) - if jump: - if self.targetCode == 1: - controller_state.pitch = -1 - controller_state.steer = 0 - controller_state.throttle = 1 - - elif self.targetCode == 0: - ball_local = toLocal(self.agent.ball.location, self.agent.me) - ball_angle = math.atan2(ball_local.data[1], ball_local.data[0]) - controller_state.jump = True - controller_state.yaw = math.sin(ball_angle) - pitch = -math.cos(ball_angle) - controller_state.pitch = pitch - if pitch > 0: - controller_state.throttle = -1 - else: - controller_state.throttle = 1 - - elif self.targetCode == 2: - controller_state.pitch = 0 - controller_state.steer = 0 - controller_state.yaw = 0 - elif self.targetCode == 3: - controller_state.pitch = 1 - controller_state.steer = 0 - controller_state.throttle = -1 - - elif self.targetCode == -1: - controller_state.pitch = 0 - controller_state.steer = 0 - controller_state.throttle = 0 - - controller_state.jump = jump - controller_state.boost = False - if self.flip_obj.flipDone: - self.active = False - - return controller_state - - -class gettingPhysical(baseState): - def update(self): - action = demoMagic(self.agent) - if action != None: - return action - else: - return saferBoostGrabber(self.agent) - - -class GroundShot(baseState): - def __init__(self, agent): - self.agent = agent - self.active = True - - def update(self): - return lineupShot(self.agent,3) - -class Dribble(baseState): - def __init__(self, agent): - self.agent = agent - self.active = True - - def update(self): - return lineupShot(self.agent,1) - -class GroundDefend(baseState): - def update(self): - return defendGoal(self.agent) - - -class AerialDefend(baseState): - pass - - - - -class Obstruct(baseState): - def update(self): - if not kickOffTest(self.agent): - return turtleTime(self.agent) - - else: - self.active = False - self.agent.activeState = Kickoff(self.agent) - return self.agent.activeState.update() - -# class Kickoff(baseState): -# def __init__(self,agent): -# self.agent = agent -# self.started = False -# self.firstFlip = False -# self.secondFlip = False -# self.finalFlipDistance = 650 -# self.active = True -# self.startTime = time.time() -# self.flipState = None -# -# def retire(self): -# self.active = False -# self.agent.activeState = None -# self.flipState = None -# -# def update(self): -# spd = self.agent.getCurrentSpd() -# if self.flipState != None: -# if self.flipState.active: -# controller = self.flipState.update() -# if time.time() - self.flipState.flip_obj.flipStartedTimer <= 0.15: -# if spd < 2200: -# controller.boost = True -# return controller -# if self.secondFlip: -# self.retire() -# -# jumping = False -# ballDistance = distance2D(self.agent.me.location, self.agent.ball.location) -# -# if not self.started: -# if not kickOffTest(self.agent): -# self.started = True -# self.startTime = time.time() -# -# if self.started and time.time() - self.startTime > 2.5: -# self.retire() -# -# if not self.firstFlip: -# if spd > 1100: -# self.flipState = JumpingState(self.agent,1) -# self.firstFlip = True -# return self.flipState.update() -# -# if ballDistance > self.finalFlipDistance: -# destination = self.agent.ball.location -# if not self.firstFlip: -# destination.data[1] += (sign(self.agent.team)*200) -# return greedyMover(self.agent, destination) -# -# else: -# self.flipState = JumpingState(self.agent,0) -# self.secondFlip = True -# return self.flipState.update() - -class Kickoff(baseState): - def __init__(self,agent): - self.agent = agent - self.started = False - self.firstFlip = False - self.secondFlip = False - self.finalFlipDistance = 750 - self.active = True - self.startTime = agent.time - self.flipState = None - - def fakeKickOffChecker(self): - closestToBall, bDist = findEnemyClosestToLocation(self.agent, self.agent.ball.location) - myDist = findDistance(self.agent.me.location,self.agent.ball.location) - - if bDist: - if bDist <= myDist*.75: - return True - else: - return False - return False - - def retire(self): - self.active = False - self.agent.activeState = None - self.flipState = None - - def update(self): - spd = self.agent.currentSpd - if self.flipState != None: - if self.flipState.active: - controller = self.flipState.update() - if self.agent.time - self.flipState.flip_obj.flipStartedTimer <= 0.15: - if spd < 2200: - controller.boost = True - return controller - if self.secondFlip: - self.retire() - - jumping = False - ballDistance = distance2D(self.agent.me.location, self.agent.ball.location) - - if not self.started: - if not kickOffTest(self.agent): - self.started = True - self.startTime = self.agent.time - - if self.started and self.agent.time - self.startTime > 2.5: - self.retire() - - if not self.firstFlip: - if spd > 1100: - self.flipState = JumpingState(self.agent,1) - self.firstFlip = True - return self.flipState.update() - - if ballDistance > self.finalFlipDistance: - destination = self.agent.ball.location - if not self.firstFlip: - destination.data[1] += (sign(self.agent.team)*100) - return greedyMover(self.agent, destination) - - else: - self.flipState = JumpingState(self.agent,0) - self.secondFlip = True - return self.flipState.update() - -class aerialRecovery(baseState): - def update(self): - if self.agent.me.location[2] < 600: - if self.agent.onSurface or self.agent.me.location[2] < 100: - self.active = False - controller_state = SimpleControllerState() - - if self.agent.me.rotation[2] > 0: - controller_state.roll = -1 - - elif self.agent.me.rotation[2] < 0: - controller_state.roll = 1 - - if self.agent.me.rotation[0] > self.agent.velAngle: - controller_state.yaw = -1 - - elif self.agent.me.rotation[0] < self.agent.velAngle: - controller_state.yaw = 1 - - if self.active: - controller_state.throttle = 1 - else: - controller_state.throttle = 0 - else: - controller_state = SimpleControllerState() - - return controller_state - - - -class halfFlip(baseState): - def __init__(self,agent): - self.agent = agent - self.active = True - self.firstJump= False - self.secondJump = False - self.jumpStart = 0 - self.timeCreated = time.time() - - - def update(self): - controller_state = SimpleControllerState() - if not self.firstJump: - controller_state.throttle = -1 - controller_state.jump = True - controller_state.pitch = 1 - self.firstJump = True - self.jumpStart = time.time() - return controller_state - - elif self.firstJump and not self.secondJump: - jumpTimer = time.time() - self.jumpStart - controller_state.throttle = -1 - controller_state.pitch = 1 - controller_state.jump = False - if jumpTimer < 0.12: - controller_state.jump = True - if jumpTimer > 0.15: - controller_state.jump = True - self.jumpStart = time.time() - self.secondJump = True - return controller_state - - elif self.firstJump and self.secondJump: - timer = time.time() - self.jumpStart - if timer < 0.15: - controller_state.throttle = -1 - controller_state.pitch = 1 - - else: - controller_state.pitch = -1 - controller_state.throttle = 1 - controller_state.roll = 1 - - if timer > .8: - controller_state.roll = 0 - if timer > 1.15: - self.active = False - return controller_state - - else: - print("halfFlip else conditional called in update. This should not be happening") - - - -class Chase(baseState): - def __init__(self, agent): - self.agent = agent - self.active = True - - def update(self): - if not kickOffTest(self.agent): - return efficientMover(self.agent,self.agent.ball,self.agent.maxSpd) - else: - self.active = False - self.agent.activeState = Kickoff(self.agent) - return self.agent.activeState.update() - -class backMan(baseState): - def update(self): - return backmanDefense(self.agent) - - -class secondMan(baseState): - def update(self): - return secondManSupport(self.agent) - - - - -def alteredStateManager(agent): - agentType = type(agent.activeState) - if agentType == JumpingState: - if agent.activeState.active != False: - return - if agentType != gettingPhysical: - agent.activeState = gettingPhysical(agent) - -def halfFlipStateManager(agent): - if agent.activeState.active == False: - agent.activeState = halfFlip(agent) - - else: - if type(agent.activeState) != halfFlip: - agent.activeState = halfFlip(agent) - - - - -class emergencyDefend(baseState): - def update(self): - penetrationPosition = convertStructLocationToVector(self.agent.goalPred) - penetrationPosition.data[1] = 5350 * sign(self.agent.team) - if self.agent.goalPred.game_seconds - self.agent.gameInfo.seconds_elapsed > .1: - if distance2D(self.agent.me.location,penetrationPosition) > 100: - return testMover(self.agent,penetrationPosition,2300) - else: - return testMover(self.agent, penetrationPosition, 100) - else: - if penetrationPosition[2] > 300: - self.activeState = JumpingState(self.agent,-1) - return self.activeState.update() - - else: - self.activeState = JumpingState(self.agent,0) - return self.activeState.update() - -def parseCarInfo(carList, index, _max = False): - val = 0 - best = None - for each in carList: - if _max: - if each[index] > val: - best = each - val = each[index] - else: - if each[index] < val: - best = each - val = each[index] - - return best - -def teamStateManager(agent): - if len(agent.allies) < 1: - soloStateManager(agent) - return - - agentType = type(agent.activeState) - if agentType != Kickoff: - if not kickOffTest(agent): - if agentType == AerialHandler: - if agent.activeState.active != False: - return - - myGoalLoc = center = Vector([0, 5150 * sign(agent.team), 200]) - ballDistanceFromGoal = distance2D(myGoalLoc, agent.ball) - carDistanceFromGoal = distance2D(myGoalLoc, agent.me) - carDistanceFromBall = distance2D(agent.me.location, agent.ball.location) - - carDistancesFromGoal = [] - cardistancesFromBall = [] - carInfo = [] - for c in agent.allies: - cdfg = distance2D(myGoalLoc, c.location) - cdfb = distance2D(agent.ball.location, c.location) - carDistancesFromGoal.append(cdfg) - cardistancesFromBall.append(cdfb) - carInfo.append([cdfg, cdfb, c]) - - _test = None - - timeTillBallReady = 9999 - agent.ballDelay = 6 - - ballStruct,aerialStruct = findSuitableBallPosition(agent, 120, agent.currentSpd, agent.me.location) - - agent.selectedBallPred = ballStruct - goalward = ballHeadedTowardsMyGoal(agent) - agent.openGoal = openNet = openGoalOpportunity(agent) - - if ballStruct != None: - if ballStruct == agent.ballPred.slices[0]: - timeTillBallReady = 0 - else: - timeTillBallReady = ballStruct.game_seconds - agent.gameInfo.seconds_elapsed - else: - timeTillBallReady = 0 - agent.ballDelay = timeTillBallReady - - if agent.ball.location[2] <= 120: - agent.ballGrounded = True - else: - agent.ballGrounded = False - - if agentType == JumpingState: - if agent.activeState.active != False: - return - if agentType == airLaunch: - if agent.activeState.active != False: - return - - if agentType == halfFlip: - if agent.activeState.active != False: - return - if agentType == WaveDashing: - if agent.activeState.active != False: - return - - if aerialStruct != None: - agent.activeState = AerialHandler(agent, aerialStruct) - return - - if agentType == aerialRecovery: - if agent.activeState.active != False: - return - - if not agent.onSurface: - if agent.me.location[2] > 150: - if agentType != aerialRecovery: - agent.activeState = aerialRecovery(agent) - return - - - if agent.goalPred != None: - if agentType != emergencyDefend: - agent.activeState = emergencyDefend(agent) - return - - - - - - if len(agent.allies) == 1: - if carDistanceFromBall< cardistancesFromBall[0]: - if carDistanceFromGoal < ballDistanceFromGoal: - if not goalward: - if agentType != Dribble: - agent.activeState = Dribble(agent) - return - else: - if agentType != GroundDefend: - agent.activeState = GroundDefend(agent) - return - else: - if ballDistanceFromGoal <= 3500: - if agent.activeState != backMan: - agent.activeState = backMan(agent) - return - else: - agent.activeState = secondMan(agent) - - else: - if ballDistanceFromGoal >=4500: - if agentType != secondMan: - agent.activeState = secondMan(agent) - return - else: - if agentType != backMan: - agent.activeState = backMan(agent) - return - - else: - if carDistanceFromBall < min(cardistancesFromBall): - if carDistanceFromGoal < ballDistanceFromGoal: - if agentType != Dribble: - agent.activeState = Dribble(agent) - return - else: - if agent.activeState != backMan: - agent.activeState = backMan(agent) - return - - elif carDistanceFromBall < max(cardistancesFromBall): - mostForward = parseCarInfo(carInfo, 0, _max=True) - moveForward = False - if agent.team == 0: - if mostForward[2].location[1] + 50 > agent.ball.location[1]: - moveForward = True - else: - if mostForward[2].location[1] - 50 < agent.ball.location[1]: - moveForward = True - - if moveForward: - if agentType != Dribble: - agent.activeState = Dribble(agent) - return - else: - if agentType != secondMan: - agent.activeState = secondMan(agent) - return - - else: - if agent.activeState != backMan: - agent.activeState = backMan(agent) - return - - else: - agent.activeState = Kickoff(agent) - -def launchStateManager(agent): - if agent.activeState: - if agent.activeState.active: - return - else: - if type(agent.activeState) == airLaunch: - agent.activeState = aerialRecovery(agent) - - else: - if agent.onSurface: - if agent.getCurrentSpd() < 50: - agent.activeState = airLaunch(agent) - - else: - agent.activeState = airLaunch(agent) - - - -def soloStateManager(agent): - agentType = type(agent.activeState) - - if agentType != Kickoff: - if not kickOffTest(agent): - if agentType == AerialHandler: - if agent.activeState.active != False: - return - myGoalLoc = center = Vector([0, 5150 * sign(agent.team), 200]) - - ballDistanceFromGoal = distance2D(myGoalLoc, agent.ball) - carDistanceFromGoal = distance2D(myGoalLoc, agent.me) - - timeTillBallReady = 9999 - agent.ballDelay = 6 - - - ballStruct,aerialStruct = findSuitableBallPosition(agent, 120, agent.currentSpd, agent.me.location) - - agent.selectedBallPred = ballStruct - goalward = ballHeadedTowardsMyGoal(agent) - agent.openGoal = openNet = openGoalOpportunity(agent) - - if ballStruct != None: - if ballStruct == agent.ballPred.slices[0]: - timeTillBallReady = 0 - else: - timeTillBallReady = ballStruct.game_seconds - agent.gameInfo.seconds_elapsed - else: - timeTillBallReady = 0 - agent.ballDelay = timeTillBallReady - - if agent.ball.location[2] <= 120: - agent.ballGrounded = True - else: - agent.ballGrounded = False - - if agentType == JumpingState: - if agent.activeState.active != False: - return - if agentType == airLaunch: - if agent.activeState.active != False: - return - - if agentType == halfFlip: - if agent.activeState.active != False: - return - if agentType == WaveDashing: - if agent.activeState.active != False: - return - - if aerialStruct != None: - agent.activeState = AerialHandler(agent, aerialStruct) - return - - - if agentType == aerialRecovery: - if agent.activeState.active != False: - return - - - if not agent.onSurface: - if agent.me.location[2] > 150: - if agentType != aerialRecovery: - agent.activeState = aerialRecovery(agent) - return - - if agent.goalPred != None: - if agentType != emergencyDefend: - agent.activeState = emergencyDefend(agent) - return - - if ballDistanceFromGoal < 2500: - if agentType != GroundDefend: - agent.activeState = GroundDefend(agent) - - - elif carDistanceFromGoal > ballDistanceFromGoal + 50: - if agentType != GroundDefend: - agent.activeState = GroundDefend(agent) - - elif goalward: - if agentType != GroundDefend: - agent.activeState = GroundDefend(agent) - - - else: - if openNet: - if agentType != Dribble: - agent.activeState = Dribble(agent) - return - - elif challengeDecider(agent): - if agentType != Dribble: - agent.activeState = Dribble(agent) - return - - - elif agent.me.boostLevel >= 25: - if agentType != Dribble: - agent.activeState = Dribble(agent) - - else: - if agentType != Dribble: - agent.activeState = Dribble(agent) - - else: - agent.activeState = Kickoff(agent) - - diff --git a/RLBotPack/Diablo/Utilities.py b/RLBotPack/Diablo/Utilities.py deleted file mode 100644 index 0ec71195..00000000 --- a/RLBotPack/Diablo/Utilities.py +++ /dev/null @@ -1,2500 +0,0 @@ -import math -import time -#import States -from rlbot.agents.base_agent import BaseAgent, SimpleControllerState -from rlutilities.linear_algebra import * -from rlutilities.mechanics import Aerial, AerialTurn, Dodge, Wavedash, Boostdash -from rlutilities.simulation import Game, Ball, Car -import cProfile, pstats, io - - - -def profile(fnc): - """A decorator that uses cProfile to profile a function""" - - def inner(*args, **kwargs): - pr = cProfile.Profile() - pr.enable() - retval = fnc(*args, **kwargs) - pr.disable() - s = io.StringIO() - sortby = 'cumulative' - ps = pstats.Stats(pr, stream=s).sort_stats(sortby) - ps.print_stats() - print(s.getvalue()) - return retval - - return inner - - - -GOAL_WIDTH = 1900 -FIELD_LENGTH = 10280 -FIELD_WIDTH = 8240 -maxPossibleSpeed = 2300 - -boosts = [ - [3584, 0,0], - [-3584, 0,0], - [3072, 4096,0], - [3072, -4096,0], - [-3072, 4096,0], - [-3072, -4096,0] - ] - -class predictionStruct: - def __init__(self,location,_time): - self.location = location - self.time = _time - - -class renderCall: - def __init__(self,_function,*args): - self.function = _function - self.args = args - - def run(self): - self.function(self.args[0],self.args[1],self.args[2]()) - - - -# class FlipStatus: -# def __init__(self): -# self.started = False -# self.flipStartedTimer = None -# self.flipDone = False - -class FlipStatus: - def __init__(self,_time): - self.started = False - self.flipStartedTimer = _time - self.flipDone = False - -class Boost_obj: - def __init__(self,location,bigBoost, spawned): - self.location = Vector(location) #list of 3 coordinates - self.bigBoost = bigBoost # bool indicating if it's a cannister or just a pad - self.spawned = spawned # bool indicating whether it's currently spawned - - -class physicsObject: - def __init__(self): - self.location = Vector([0, 0, 0]) - self.velocity = Vector([0, 0, 0]) - self.rotation = Vector([0, 0, 0]) - self.avelocity = Vector([0, 0, 0]) - self.local_location = Vector([0, 0, 0]) - self.boostLevel = 0 - self.team = -1 - self.matrix = [] - -class Vector: - def __init__(self, content): #accepts list of float/int values - self.data = content - - def __str__(self): - return str(self.data) - - def __repr__(self): - return str(self) - - def __len__(self): - return len(self.data) - - def __getitem__(self, item): - return self.data[item] - - def vec3Convert(self): - return vec3(self.data[0],self.data[1].self.data[2]) - - def raiseLengthError(self,other, operation): - raise ValueError(f"Tried to perform {operation} on 2 vectors of differing lengths") - - def raiseCrossError(self): - raise ValueError("Both vectors need 3 terms for cross product") - - def __mul__(self, other): - if len(self.data) == len(other.data): - return Vector([self.data[i] * other[i] for i in range(len(other))]) - else: - self.raiseLengthError(other,"multiplication") - - def __add__(self, other): - if len(self.data) == len(other.data): - return Vector([self.data[i] + other[i] for i in range(len(other))]) - else: - self.raiseLengthError(other, "addition") - - def __sub__(self, other): - if len(self.data) == len(other.data): - return Vector([self.data[i] - other[i] for i in range(len(other))]) - else: - self.raiseLengthError(other, "subtraction") - - def alignTo(self, rot): - v = Vector([self.data[0], self.data[1], self.data[2]]) - v = Vector([v[0],math.cos(rot[0]) * v[1] + math.sin(rot[0]) * v[2],math.cos(rot[0]) * v[2] - math.sin(rot[0]) * v[1]]) - v = Vector([math.cos(-rot[1]) * v[0] + math.sin(-rot[1]) * v[2], v[1], math.cos(-rot[1]) * v[2] - math.sin(-rot[1]) * v[0]]) - v = Vector([math.cos(-rot[2]) * v[0] + math.sin(-rot[2]) * v[1], math.cos(-rot[2]) * v[1] - math.sin(-rot[2]) * v[0], v[2]]) - - return v - - def crossProduct(self,other): - if len(self.data) == 3 and len(other.data) == 3: - newVec = [0,0,0] - newVec[0] = self[1]*other[2] - self[2]*other[1] - newVec[1] = self[2]*other[0] - self[0]*other[2] - newVec[2] = self[0] * other[1] - self[1] * other[0] - - return Vector(newVec) - - - else: - self.raiseCrossError() - - def flatten(self): - return Vector(self.data[:2]+[0]) - - - def magnitude(self): - return math.sqrt(sum([x*x for x in self])) - - def normalize(self): - mag = self.magnitude() - if mag != 0: - return Vector([x/mag for x in self]) - else: - return Vector([0 for _ in range(len(self.data))]) - - def dotProduct(self,other): - product = 0 - for i,j in zip(self,other): - product += i*j - return product - - def scale(self,scalar): - return Vector([x*scalar for x in self.data]) - - - def correction_to(self, ideal): - current_in_radians = math.atan2(self[1], -self[0]) - ideal_in_radians = math.atan2(ideal[1], -ideal[0]) - - correction = ideal_in_radians - current_in_radians - if abs(correction) > math.pi: - if correction < 0: - correction += 2 * math.pi - else: - correction -= 2 * math.pi - - return correction - - - def toList(self): - return self.data - - def lerp(self,otherVector,percent): #percentage indicated 0 - 1 - percent = clamp(1,0,percent) - originPercent = 1-percent - - scaledOriginal = self.scale(originPercent) - other = otherVector.scale(percent) - return scaledOriginal+other - -def convertStructLocationToVector(struct): - return Vector([struct.physics.location.x,struct.physics.location.y,struct.physics.location.z]) - -def Rotation_Vector(rot): - pitch = float(rot.pitch) - yaw = float(rot.yaw) - facing_x = math.cos(pitch) * math.cos(yaw) - facing_y = math.cos(pitch) * math.sin(yaw) - facing_z = math.sin(pitch) - return Vector([facing_x, facing_y, facing_z]) - - -def alternativeAngle(x): - if x > 0: - return x-360 - if x <= 0: - return x + 360 - - -def placeVecWithinArena(vec): - if vec[0] > 4096: - vec.data[0] = 4096 - - elif vec[0] < -4096: - vec.data[0] = -4096 - - if vec[1] > 5120: - if abs(vec[0]) > 850: - vec.data[1] = 5120 - - else: - if vec[1] > 5300: - vec.data[1] = 5300 - - elif vec[1] < -5120: - if abs(vec[0]) > 850: - vec.data[1] = -5120 - - else: - if vec[1] < -5300: - vec.data[1] = -5300 - - - - -def demoMagic(agent): - currentSpd = agent.getCurrentSpd() - if currentSpd <1900: - if agent.me.boostLevel <=0: - agent.activeState.active = False - e_goal = Vector([0, 5100 * -sign(agent.team), 200]) - best = None - distance = math.inf - for e in agent.enemies: - if e.location[2] <= 120: - _distance = distance2D(e_goal,e.location) - if _distance < distance: - distance = _distance - best = e - - if best != None: - if currentSpd <=100: - currentSpd = 100 - - currentTimeToTarget = distance / currentSpd - lead = clamp(agent.deltaTime*60,agent.deltaTime*5,agent.deltaTime*distance/500) - difference = best.velocity.scale(lead) - targetPos = e.location + difference - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, agent.me.location.data, targetPos.data, agent.renderer.purple)) - - if currentTimeToTarget <= agent.deltaTime*30: - targetLocal = toLocal(targetPos,agent.me) - angle = math.degrees(math.atan2(targetLocal[1],targetLocal[0])) - if abs(angle) <= 40: - agent.setJumping(0) - - return testMover(agent,targetPos,2300) - - - - else: - return None - - - -def kickOffTest(agent): - if agent.gameInfo.is_kickoff_pause: - if len(agent.allies) > 0: - myDist = distance2D(agent.me.location,agent.ball.location) - for ally in agent.allies: - if distance2D(ally.location,agent.ball.location) < myDist: - return False - return True - return False - -def flipHandler(agent,flip_status): - if flip_status.started: - jump = False - else: - jump = True - flip_status.started = True - flip_status.flipStartedTimer = time.time() - - if time.time() - flip_status.flipStartedTimer >= 0.15: - jump = True - flip_status.flipDone = True - - return jump - - -def quad(a,b,c): - inside = (b**2) - (4*a*c) - if inside < 0 or a == 0: - return 0.1 - else: - n = ((-b - math.sqrt(inside))/(2*a)) - p = ((-b + math.sqrt(inside))/(2*a)) - if p > n: - return p - return n - - - -def get_car_facing_vector(car): - pitch = float(car.rotation[0]) - yaw = float(car.rotation[1]) - facing_x = math.cos(pitch) * math.cos(yaw) - facing_y = math.cos(pitch) * math.sin(yaw) - - return Vector([facing_x, facing_y]) - - - - - - -def rotator_to_matrix(our_object): - r = our_object.rotation - CR = math.cos(r[2]) - SR = math.sin(r[2]) - CP = math.cos(r[0]) - SP = math.sin(r[0]) - CY = math.cos(r[1]) - SY = math.sin(r[1]) - - matrix = [] - matrix.append(Vector([CP*CY, CP*SY, SP])) - matrix.append(Vector([CY*SP*SR-CR*SY, SY*SP*SR+CR*CY, -CP * SR])) - matrix.append(Vector([-CR*CY*SP-SR*SY, -CR*SY*SP+SR*CY, CP*CR])) - return matrix - -def getLocation(_object): - if hasattr(_object, "data"): - return _object - if hasattr(_object, "location"): - return _object.location - raise ValueError( - f"{str(type(_object))} is not a valid input for 'getLocation' function " - ) - - - -def clamp(_max,_min,value): - if value > _max: - return _max - if value < _min: - return _min - return value - -def sign(x): - if x <= 0: - return -1 - else: - return 1 - -def steer(angle): - final = ((35 * angle) ** 3) / 20 - return clamp(1,-1,final) - -def newSteer(angle): - turn = Gsteer(angle) - slide = False - - if abs(math.degrees(angle)) >=85: - slide = True - - return (turn,slide) - -def slideSteer(angle,distance): - sliding = False - degrees = math.degrees(angle) - - if distance < 1000: - if abs(degrees) > 70 and abs(degrees) < 180: - sliding = True - """ - if abs(degrees) < 3: - return(0,False) - """ - - return (clamp(1, -1, (degrees/360)*8),sliding) - else: - if abs(degrees) < 3: - return(0,False) - - return (clamp(1, -1, (degrees/360)*8), sliding) - - -def saferBoostGrabber(agent): - minDistance = distance2D(Vector([0, 5100 * sign(agent.team), 200]),agent.ball.location) - closestBoost = physicsObject() - closestBoost.location = Vector([0, 5100 * sign(agent.team), 200]) - bestDistance = math.inf - bestAngle = 0 - - for boost in agent.boosts: - if boost.spawned: - goalDistance = distance2D(boost.location, Vector([0, 5100 * sign(agent.team), 200])) - if goalDistance < minDistance*.7: - distance = distance2D(agent.me.location,boost.location) - localCoords = toLocal(boost.location, agent.me) - angle = abs(math.degrees(math.atan2(localCoords[1], localCoords[0]))) - if boost.bigBoost: - distance = distance*.5 - distance += angle * 5 - if distance < bestDistance: - bestDistance = distance - closestBoost = boost - bestAngle = angle - - agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, closestBoost.location.data, - agent.renderer.yellow)) - - return efficientMover(agent, closestBoost.location, agent.maxSpd,boostHunt=False) - -def boostHungry(agent): - closestBoost = agent.me - bestDistance = math.inf - bestAngle = 0 - - for boost in agent.boosts: - if boost.spawned: - distance = distance2D(boost.location, agent.me) - localCoords = toLocal(closestBoost.location, agent.me) - angle = abs(math.degrees(math.atan2(localCoords[1], localCoords[0]))) - distance += angle*5 - distance += distance2D(agent.me.location,agent.ball.location) - if boost.bigBoost: - distance *= .5 - if distance < bestDistance: - bestDistance = distance - closestBoost = boost - bestAngle = angle - - agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, closestBoost.location.data, - agent.renderer.yellow)) - return efficientMover(agent, closestBoost.location, agent.maxSpd,boostHunt=False) - -def distance1D(origin,destination,index): - return abs(getLocation(origin)[index] - getLocation(destination)[index]) - - -def defendGoal(agent): - return ShellTime(agent) - - - -def findOppositeSideVector(agent,objVector,antiTarget, desiredBallDistance): - angle = math.degrees(angle2(objVector,antiTarget)) - targetDistance = distance2D(objVector, getLocation(antiTarget)) - oppositeVector = (getLocation(antiTarget) - objVector).normalize() - totalOffset = desiredBallDistance - return getLocation(antiTarget) - (oppositeVector.scale(targetDistance + desiredBallDistance)) - - -def findOppositeSide(agent,targetLoc,antiTarget, desiredBallDistance): - angle = correctAngle(math.degrees(angle2(targetLoc,antiTarget))) - targetDistance = distance2D(targetLoc, getLocation(antiTarget)) - oppositeVector = (getLocation(antiTarget) - targetLoc).normalize() - totalOffset = desiredBallDistance - return getLocation(antiTarget) - (oppositeVector.scale(targetDistance + desiredBallDistance)) - -def findGoalAngle(agent): - center = Vector([0, 5150 * -sign(agent.team), 200]) - return math.degrees(angle2(agent.ball, center)) * sign(agent.team) - -def determineVelocityToGoal(agent): - myGoal = Vector([0, 5150 * -sign(agent.team), 200]) - startingDistance = distance2D(myGoal,agent.ball.location) - if startingDistance < distance2D(myGoal,agent.ball.location + agent.ball.velocity): - return True - else: - return False - -def backmanDefense(agent): - center = Vector([0, 5120 * sign(agent.team), 200]) - rendevouz = Vector([0, 4900 * sign(agent.team), 200]) - ballToGoaldistance = distance2D(center,agent.ball.location) - distance = distance2D(agent.me.location,agent.ball.location) - - if distance < 5000: - if distance < 1500: - return ShellTime(agent) - - defenderFound = False - for ally in agent.allies: - a_dist= distance2D(ally.location,agent.ball.location) - if a_dist < distance: - if distance2D(center,ally.location) < ballToGoaldistance: - defenderFound = True - if not defenderFound: - return ShellTime(agent) - - else: - agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, center, - agent.renderer.blue)) - if distance2D(agent.me.location,rendevouz) > 500: - return efficientMover(agent, rendevouz, 2200,boostHunt=True) - else: - return efficientMover(agent,rendevouz,50,boostHunt=True) - - else: - return playBack(agent) - # - # centerField = Vector([0,agent.ball.location[1] + 3000*sign(agent.team),0]) - # if agent.me.boostLevel < 50: - # return saferBoostGrabber(agent) - # else: - # agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, centerField.data, - # agent.renderer.blue)) - # return efficientMover(agent, centerField, 2200,boostHunt=True) - - -def secondManSupport(agent): - return playBack(agent,distance = 1500) - # defendTarget = Vector([0, 5120 * sign(agent.team), 200]) - # if agent.me.boostLevel < 50: - # return saferBoostGrabber(agent) - # - # destination = findOppositeSide(agent,agent.ball.location,defendTarget,-100) - # destination.data[1] += sign(agent.team)*2200 - # destination.data[2] = 75 - # placeVecWithinArena(destination) - # destination.data[0] = clamp(3500,-3500,destination.data[0]) - # - # agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, destination.data, - # agent.renderer.green)) - # - # return efficientMover(agent,destination,2200,boostHunt=True) - -def ownGoalCheck(agent,targetVec): - leftPost = Vector([sign(agent.team) * 800, 5100 * sign(agent.team), 200]) - rightPost = Vector([-sign(agent.team) * 800, 5100 * sign(agent.team), 200]) - center = Vector([0, 5100 * sign(agent.team), 200]) - - if distance2D(agent.ball.location,center) < distance2D(agent.me.location,center): - localTarget = toLocal(targetVec,agent.me) - targetAngle = correctAngle(math.degrees(math.atan2(localTarget[1],localTarget[0]))) - - localRP = toLocal(rightPost, agent.me) - rightPostAngle = correctAngle(math.degrees(math.atan2(localRP[1], localRP[0]))) - - localLP = toLocal(leftPost, agent.me) - leftPostAngle = correctAngle(math.degrees(math.atan2(localLP[1], localLP[0]))) - - if leftPostAngle < targetAngle < rightPostAngle: - if leftPostAngle - targetAngle > rightPostAngle -targetAngle: - return True,leftPost - else: - return True,rightPost - - return False,None - -def noOwnGoalDefense(agent,targetVec): - leftCorner = Vector([-sign(agent.team) * 4096, 5200 * sign(agent.team), 50]) - rightCorner = Vector([sign(agent.team) * 4096, 5200 * sign(agent.team), 50]) - leftPost = Vector([-sign(agent.team) * 760, 4100 * sign(agent.team), 50]) - rightPost = Vector([sign(agent.team) * 760, 4100 * sign(agent.team), 50]) - center = Vector([0, 5400 * sign(agent.team), 200]) - - ballGoalDist = distance2D(targetVec, center) - carGoalDist = distance2D(agent.me.location, center) - - if ballGoalDist > 6000: - if (agent.me.location[1] * sign(agent.team)) + (sign(agent.team) * 120) < agent.ball.location[1] * sign(agent.team): - return (center, False) - - elif (agent.me.location[1] * sign(agent.team)) + (sign(agent.team) * 20) > agent.ball.location[1] * sign(agent.team): - return (center, False) - - if ballGoalDist < 1000: - return (center, False) - - ballToLeft = distance1D(leftCorner,targetVec,0) - ballToRight = distance1D(rightCorner,targetVec,0) - - carToLeft = distance1D(leftCorner,agent.me.location,0) - carToRight = distance1D(rightCorner,agent.me.location,0) - if carToLeft < ballToLeft: - return (rightPost, True) - - if carToRight < ballToRight: - return (leftPost, True) - - - return (rightPost, True) - - - -def turnTowardsPosition(agent,targetPosition,threshold): - localTarg = toLocal(targetPosition,agent.me) - localAngle = correctAngle(math.degrees(math.atan2(localTarg[1],localTarg[0]))) - controls = SimpleControllerState() - - if abs(localAngle) > threshold: - if agent.forward: - if localAngle > 0: - controls.steer = 1 - else: - controls.steer = -1 - - controls.handbrake = True - if agent.currentSpd <300: - controls.throttle = .5 - else: - if localAngle > 0: - controls.steer = -1 - else: - controls.steer = 1 - controls.handbrake = True - if agent.currentSpd <300: - controls.throttle = -.5 - - return controls - -def playDefensive(agent): - centerGoal = Vector([0, 5200 * sign(agent.team), 200]) - dist = distance2D(agent.me.location,centerGoal) - - if dist > 1000: - return testMover(agent, centerGoal, maxPossibleSpeed) - elif dist > 200: - return efficientMover(agent, centerGoal, maxPossibleSpeed, True) - else: - return turnTowardsPosition(agent, agent.ball.location, 2) - -def playBack(agent,distance = 4500): - centerField = Vector([agent.ball.location[0], agent.ball.location[1] + distance * sign(agent.team), 0]) - - - boostTarget,dist = boostSwipe(agent) - if boostTarget != None and dist < 2000: - #print("swiper no swiping!") - return testMover(agent,boostTarget,maxPossibleSpeed) - if agent.me.boostLevel < 50: - return backmanBoostGrabber(agent) - - else: - agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, centerField.data, - agent.renderer.blue)) - return efficientMover(agent, centerField, maxPossibleSpeed, boostHunt=True) - -def boostSwipe(agent): - enemyBackBoostLocations = [Vector([3072,-sign(agent.team)*4096,73]),Vector([-3072,-sign(agent.team)*4096,73])] - - backBoosts = [] - minDist = math.inf - bestBoost = None - for b in agent.boosts: - if b.bigBoost: - if b.spawned: - for eb in enemyBackBoostLocations: - if distance2D(eb,b.location) < 300: - backBoosts.append(eb) - dist = distance2D(eb,agent.me.location) - if dist < minDist: - bestBoost = eb - minDist = dist - #return b.location - - return bestBoost,minDist - -def findEnemyClosestToLocation2D(agent,location): - if len(agent.enemies) > 0: - closest = agent.enemies[0] - cDist = math.inf - for e in agent.enemies: - x = distance2D(e.location, location) - if x < cDist: - cDist = x - closest = e - return closest,cDist - else: - return None,None - - -def backmanBoostGrabber(agent): - #minDistance = distance2D(Vector([0, 5100 * sign(agent.team), 200]), agent.ball.location) - minY = (agent.ball.location[1] +3000*sign(agent.team))*sign(agent.team) - closestBoost = physicsObject() - closestBoost.location = Vector([0, 5100 * sign(agent.team), 200]) - bestDistance = math.inf - bestAngle = 0 - - for boost in agent.boosts: - if boost.spawned: - if boost.location[1] *sign(agent.team) >= minY: - #print(minY,boost.location[1] *sign(agent.team),sign(agent.team)) - #goalDistance = distance2D(boost.location, Vector([0, 5100 * sign(agent.team), 200])) - distance = distance2D(agent.me.location, boost.location) - localCoords = toLocal(boost.location, agent.me) - angle = abs(math.degrees(math.atan2(localCoords[1], localCoords[0]))) - distance += angle * 5 - if boost.bigBoost: - distance = distance * .75 - if distance < bestDistance: - bestDistance = distance - closestBoost = boost - bestAngle = angle - - agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, closestBoost.location.data, - agent.renderer.yellow)) - - return efficientMover(agent, closestBoost.location, agent.maxSpd, boostHunt=False) - - -# def ShellTime(agent): -# defendTarget = Vector([0, 5800 * sign(agent.team), 200]) -# rush = False -# heightCutoff = 120 -# if agent.selectedBallPred: -# targetVec = Vector([agent.selectedBallPred.physics.location.x, -# agent.selectedBallPred.physics.location.y, -# agent.selectedBallPred.physics.location.z]) -# else: -# targetVec = agent.ball.location -# -# defensiveRange = 50 -# -# goalDistance = distance2D(targetVec, defendTarget) -# carDistance = distance2D(agent.me.location, defendTarget) -# ballGoalDistance = distance2D(agent.ball.location,defendTarget) -# if ballGoalDistance+defensiveRange < carDistance: -# return playDefensive(agent) -# -# -# localPos = toLocal(targetVec, agent.me) -# angleDegrees = math.degrees(math.atan2(localPos[1], localPos[0])) -# -# if abs(angleDegrees) <= 45 or abs(angleDegrees) >= 135: -# carOffset = agent.carLength / 2 -# ballOffset = 75 -# else: -# carOffset = agent.carWidth/ 2 -# ballOffset = 45 -# -# totalOffset = carOffset + ballOffset -# -# if carDistance < goalDistance: -# destination = findOppositeSide(agent,targetVec,Vector([0, 5300 * -sign(agent.team), 0]),totalOffset) -# -# else: -# destination = findOppositeSide(agent, targetVec, defendTarget, -totalOffset) -# -# #placeVecWithinArena(destination) -# -# -# if agent.ballGrounded: -# modifiedDelay = clamp(6, 0, agent.ballDelay - (totalOffset / agent.currentSpd)) -# else: -# modifiedDelay = agent.ballDelay -# result = timeDelayedMovement(agent, destination, agent.ballDelay,True) -# -# flipDecider(agent, targetVec, True) -# destination.data[2] = 75 -# agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, -# agent.me.location.data, -# destination.data, -# agent.renderer.blue)) -# -# return result - -def ShellTime(agent): - defendTarget = Vector([0, 5800 * sign(agent.team), 200]) - rush = False - heightCutoff = 120 - if agent.selectedBallPred: - targetVec = Vector([agent.selectedBallPred.physics.location.x, - agent.selectedBallPred.physics.location.y, - agent.selectedBallPred.physics.location.z]) - else: - targetVec = agent.ball.location - - defensiveRange = 50 - # if agent.contested: - # defensiveRange = 10 - - goalDistance = distance2D(targetVec, defendTarget) - carDistance = distance2D(agent.me.location, defendTarget) - ballGoalDistance = distance2D(agent.ball.location,defendTarget) - if ballGoalDistance+defensiveRange < carDistance: - return playDefensive(agent) - - - localPos = toLocal(targetVec, agent.me) - angleDegrees = math.degrees(math.atan2(localPos[1], localPos[0])) - - if abs(angleDegrees) <= 45 or abs(angleDegrees) >= 135: - carOffset = agent.carLength / 2 - ballOffset = 75 - else: - carOffset = agent.carWidth/ 2 - ballOffset = 45 - - totalOffset = carOffset + ballOffset - - if carDistance < goalDistance: - destination = findOppositeSide(agent,targetVec,Vector([0, 5300 * -sign(agent.team), 0]),totalOffset) - - else: - # if agent.me.location[0] > targetVec[0]: - # xOff = 25 - # if agent.me.location[1] * -sign(agent.team) > -sign(agent.team) * targetVec[1]: - # xOff += clamp(30,1,abs(targetVec[1]-agent.me.location[1])/15) - # - # - # else: - # xOff = -25 - # if agent.me.location[1] * -sign(agent.team) > -sign(agent.team) * targetVec[1]: - # xOff -= clamp(30,1,abs(targetVec[1]-agent.me.location[1])/15) - # - # yOff = carOffset * .85 - # yOff += clamp(90,0,abs(targetVec[0] - agent.me.location[0])) - # #print("yoff matters?", agent.time) - - #destination = Vector([targetVec[0]+xOff,targetVec[1]+sign(agent.team)*yOff,targetVec[2]]) - destination = findOppositeSide(agent, targetVec, defendTarget, -totalOffset) - #print("here",agent.time) - - #placeVecWithinArena(destination) - - - if agent.ballGrounded: - modifiedDelay = clamp(6, 0, agent.ballDelay - (totalOffset / agent.currentSpd)) - else: - modifiedDelay = agent.ballDelay - result = timeDelayedMovement(agent, destination, agent.ballDelay,True) - - # if len(agent.allies) <1: - # flipDecider(agent,targetVec,True) - # else: - # flipDecider2(agent) - flipDecider(agent, targetVec, True) - destination.data[2] = 75 - agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, - agent.me.location.data, - destination.data, - agent.renderer.blue)) - - return result - - -def turtleTime(agent): - goalDistance = distance2D(agent.ball.location,Vector([0, 5100 * sign(agent.team), 200])) - defendTarget = Vector([0, 5250 * sign(agent.team), 200]) - - - if agent.selectedBallPred: - targetVec = Vector([agent.selectedBallPred.physics.location.x, agent.selectedBallPred.physics.location.y, - agent.selectedBallPred.physics.location.z]) - agent.ballDelay = agent.selectedBallPred.game_seconds - agent.gameInfo.seconds_elapsed - - else: - targetVec = agent.ball.location - agent.ballDelay = 0 - - _enemyInfluenced = True - if goalDistance < 1300: - _enemyInfluenced = False - - flipDecider(agent,targetVec,enemyInfluenced= _enemyInfluenced) - - if distance2D(targetVec,defendTarget) < 5000: - if ballHeadedTowardsMyGoal(agent): - defendTarget, reposition = noOwnGoalDefense(agent,targetVec) - if reposition: - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, agent.me.location.data, defendTarget.data, - agent.renderer.blue)) - placeVecWithinArena(defendTarget) - return testMover(agent, defendTarget, 2300) - targ_local = toLocal(targetVec,agent.me) - goal_local = toLocal(Vector([0, 5100 * sign(agent.team), 200]),agent.me) - targ_angle = math.degrees(math.atan2(targ_local[1],targ_local[0])) - goal_angle = math.degrees(math.atan2(goal_local[1],goal_local[0])) - - distance = distance2D(defendTarget,targetVec) - oppositeVector = (getLocation(defendTarget) - targetVec).normalize() - destination = getLocation(defendTarget) - (oppositeVector.scale(distance - clamp(110,50,50))) - placeVecWithinArena(destination) - result = timeDelayedMovement(agent, destination, agent.ballDelay,True) - - destination.data[2] = 95 - agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d,agent.me.location.data,destination.data,agent.renderer.blue)) - return result - -def prepareShot(agent): - leftPost = Vector([-sign(agent.team) * 700, 5100 * -sign(agent.team), 200]) - rightPost = Vector([sign(agent.team) * 700, 5100 * -sign(agent.team), 200]) - center = Vector([0, 5150 * -sign(agent.team), 200]) - -def goalWallFixer(agent): - myGoal = Vector([0, 5120 * sign(agent.team), 0]) - jump = False - if abs(agent.me.location[0]) < 893: - if abs(agent.me.location[1]) > 5120: - if agent.onWall: - jump = True - return jump - -def flipDecider2(agent): - if agent.selectedBallPred == None: - pred = agent.ballPred.slices[0] - else: - pred = agent.selectedBallPred - - targetVec = convertStructLocationToVector(pred) - dist = distance2D(agent.me.location,targetVec) - - jumpTimer = .5 - - if agent.contested: - timeUntilshot = pred.game_seconds - agent.gameInfo.seconds_elapsed - if pred.game_seconds - agent.gameInfo.seconds_elapsed< jumpTimer : - if dist <=50 or dist/agent.getCurrentSpd() <= jumpTimer : - if targetVec[2] >200: - agent.setJumping(-1) - elif targetVec[2] > 125: - agent.setJumping(0) - - else: - if pred.game_seconds - agent.gameInfo.seconds_elapsed< jumpTimer : - if dist <= 50 or dist/agent.getCurrentSpd() <= jumpTimer : - if targetVec[2] > 200: - agent.setJumping(-1) - elif targetVec[2] > 125: - agent.setJumping(0) - - -def flipDecider(agent,targetVec,enemyInfluenced=False): - if not enemyInfluenced: - targetVec = agent.ball.location - if distance2D(agent.me.location, agent.ball.location) <= 200: - if targetVec[2] <= 160: - agent.setJumping(0) - - else: - if distance2D(agent.me.location,targetVec) <= 200: - if targetVec[2] <= 160: - if len(agent.enemies) > 0: - closest = agent.enemies[0] - cDist = math.inf - for e in agent.enemies: - x = findDistance(e.location,agent.ball.location) - if x < cDist: - cDist = x - closest = e - if cDist < 350: - agent.setJumping(0) - -def findEnemyClosestToLocation(agent,location): - if len(agent.enemies) > 0: - closest = agent.enemies[0] - cDist = math.inf - for e in agent.enemies: - x = findDistance(e.location, location) - if x < cDist: - cDist = x - closest = e - return closest,cDist - else: - return None,None - -def ballContested(agent): - closestToMe,mDist = findEnemyClosestToLocation(agent,agent.me.location) - closestToBall, bDist = findEnemyClosestToLocation(agent,agent.ball.location) - - if mDist: - if mDist > 800 and bDist > 800: - agent.contested = False - else: - agent.contested = True - else: - agent.contested = False - -def lineupShot(agent,multi): - variance = 5 - - leftPost = Vector([-sign(agent.team) * 450, 5200 * -sign(agent.team), 200]) - rightPost = Vector([sign(agent.team) * 450, 5200 * -sign(agent.team), 200]) - center = Vector([0, 5500 * -sign(agent.team), 200]) - - myGoal = Vector([0, 5300 * sign(agent.team), 200]) - - - # if agent.me.location.data[1] *-sign(agent.team) > agent.ball.location.data[1] *-sign(agent.team): - # print("am I ahead of the ball?") - - if ballHeadedTowardsMyGoal(agent): - return ShellTime(agent) - - if agent.selectedBallPred: - targetVec = Vector([agent.selectedBallPred.physics.location.x, agent.selectedBallPred.physics.location.y, - agent.selectedBallPred.physics.location.z]) - agent.ballDelay = agent.selectedBallPred.game_seconds - agent.gameInfo.seconds_elapsed - - else: - targetVec = agent.ball.location - agent.ballDelay = 0 - - #ballCorner = cornerDetection(agent.ball.location) - - distance = distance2D(agent.me.location, targetVec) - dist2D = distance2D(agent.me.location, targetVec) - goalDist = distance2D(center, targetVec) - ballToGoalDist = distance2D(targetVec, center) - targetLocal = toLocal(targetVec,agent.me) - carToBallAngle = math.degrees(math.atan2(targetLocal[1],targetLocal[0])) - carToGoalDistance = distance2D(center,agent.me.location) - carToBallDistance = distance2D(targetVec,agent.me.location) - - carToBallAngle = correctAngle(carToBallAngle) - - - shotAngles = [math.degrees(angle2(targetVec, leftPost)), - math.degrees(angle2(targetVec, center)), - math.degrees(angle2(targetVec, rightPost))] - - correctedAngles=[correctAngle(x + 90 * -sign(agent.team)) for x in shotAngles] - - flipDecider(agent, targetVec, True) - - if distance2D(center,targetVec) < 2000: - goalAngle = correctedAngles[1] - goalSpot = center - - else: - if correctedAngles[1] < -variance: - goalAngle = correctedAngles[0] - goalSpot = leftPost - - elif correctedAngles[1] > variance: - goalAngle = correctedAngles[2] - goalSpot = rightPost - - else: - goalAngle = correctedAngles[1] - goalSpot = center - #goalSpot = center - - targetLoc = None - rush = False - ballOffset = 70 - - if abs(carToBallAngle) <=45 or abs(carToBallAngle) >= 135: - carOffset = agent.carLength/2 - else: - carOffset = agent.carWidth/2 - #carOffset = 5 - - positioningOffset = 0 - ballOffset = 70 - totalOffset = carOffset + ballOffset - - # if agent.contested and not agent.openGoal: - # _direction = direction(center, targetVec) - # targetLoc = targetVec - _direction.scale(carOffset+50) - # positioningOffset = carOffset+50 - - if abs(carToBallAngle) < 30: - if is_in_strike_zone(agent, targetVec): - targetLoc = targetVec - positioningOffset = totalOffset - targetLoc.data[1] += sign(agent.team)*10 - if abs(carToBallAngle) <=4: - if distance2D(agent.me.location, agent.ball.location) < 400: - if agent.ballGrounded: - if openGoalOpportunity(agent): - if agent.me.boostLevel < 1: - if (agent.me.location[1] * -sign(agent.team))+ -sign(agent.team)*100 < agent.ball.location[1] * -sign(agent.team): - agent.setJumping(0) - - - - if not targetLoc: - # if not agent.contested: - #if agent.closestEnemyToBallDistance >500: - if abs(targetVec[0]) < 2200: - if ballToGoalDist < 5800 and ballToGoalDist > 1300: - if agent.ballGrounded: - if abs(agent.me.location[1] - abs(targetVec[1]))> 600: - _direction = direction(goalSpot, targetVec) - - targetLoc = targetVec - _direction.scale(clamp(1000,totalOffset,120 + distance * 0.5)) - positioningOffset = clamp(1000,totalOffset,120 + distance * 0.5) - - - - if not targetLoc: - targetLoc = findOppositeSide(agent, targetVec, goalSpot, clamp(400, totalOffset, distance * .35)) - positioningOffset = clamp(400, totalOffset, distance * .35) - #targetLoc = findOppositeSide(agent,targetVec,goalSpot,clamp(125,20,(dist/1.5)-abs(carToBallAngle))) - - # if agent.contested: - # defensivePosition = findOppositeSide(agent, targetVec, myGoal, -120) - # y = targetLoc.data[1] - # percent = 1 - # if agent.team == 0: - # if y < 0: - # percent = clamp(1, 0, abs(y / 5120)) - # - # else: - # if y > 0: - # percent = clamp(1, 0, abs(y / 5120)) - # - # if percent < 0.75: - # targetLoc = targetLoc.lerp(defensivePosition, percent) - # # print(f"lerping {y} {percent}") - #placeVecWithinArena(targetLoc) - - - #modifiedDelay = clamp(6,0,agent.ballDelay-((positioningOffset+carOffset)/agent.currentSpd)) - if agent.ballGrounded: - modifiedDelay = clamp(6, 0, agent.ballDelay - ((positioningOffset) / clamp(maxPossibleSpeed,0.001,agent.currentSpd))) - else: - modifiedDelay = agent.ballDelay #clamp(6, 0, agent.ballDelay - (carOffset / agent.currentSpd)) - result = timeDelayedMovement(agent, targetLoc, modifiedDelay,True) - - targetLoc.data[2] = 95 - agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, targetLoc.data, - agent.renderer.purple)) - - agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.ball.location.data, goalSpot, - agent.renderer.red)) - return result - -# def lineupShot(agent,multi): -# variance = 5 -# -# leftPost = Vector([-sign(agent.team) * 450, 5200 * -sign(agent.team), 200]) -# rightPost = Vector([sign(agent.team) * 450, 5200 * -sign(agent.team), 200]) -# center = Vector([0, 5500 * -sign(agent.team), 200]) -# -# myGoal = Vector([0, 5300 * sign(agent.team), 200]) -# -# -# # if agent.me.location.data[1] *-sign(agent.team) > agent.ball.location.data[1] *-sign(agent.team): -# # print("am I ahead of the ball?") -# -# if ballHeadedTowardsMyGoal(agent): -# return ShellTime(agent) -# -# if agent.selectedBallPred: -# targetVec = Vector([agent.selectedBallPred.physics.location.x, agent.selectedBallPred.physics.location.y, -# agent.selectedBallPred.physics.location.z]) -# agent.ballDelay = agent.selectedBallPred.game_seconds - agent.gameInfo.seconds_elapsed -# -# else: -# targetVec = agent.ball.location -# agent.ballDelay = 0 -# -# #ballCorner = cornerDetection(agent.ball.location) -# -# distance = distance2D(agent.me.location, targetVec) -# dist2D = distance2D(agent.me.location, targetVec) -# goalDist = distance2D(center, targetVec) -# ballToGoalDist = distance2D(targetVec, center) -# targetLocal = toLocal(targetVec,agent.me) -# carToBallAngle = math.degrees(math.atan2(targetLocal[1],targetLocal[0])) -# carToGoalDistance = distance2D(center,agent.me.location) -# carToBallDistance = distance2D(targetVec,agent.me.location) -# -# carToBallAngle = correctAngle(carToBallAngle) -# -# -# shotAngles = [math.degrees(angle2(targetVec, leftPost)), -# math.degrees(angle2(targetVec, center)), -# math.degrees(angle2(targetVec, rightPost))] -# -# correctedAngles=[correctAngle(x + 90 * -sign(agent.team)) for x in shotAngles] -# -# -# # if len(agent.allies) < 2: -# # #flipDecider(agent,targetVec,True) -# # if abs(correctedAngles[1]) >= 60: -# # if agent.contested: -# # return playBack(agent) -# -# flipDecider(agent, targetVec, True) -# -# if distance2D(center,targetVec) < 2000: -# goalAngle = correctedAngles[1] -# goalSpot = center -# -# else: -# if correctedAngles[1] < -variance: -# goalAngle = correctedAngles[0] -# goalSpot = leftPost -# -# elif correctedAngles[1] > variance: -# goalAngle = correctedAngles[2] -# goalSpot = rightPost -# -# else: -# goalAngle = correctedAngles[1] -# goalSpot = center -# #goalSpot = center -# -# targetLoc = None -# rush = False -# ballOffset = 70 -# -# if abs(carToBallAngle) <=45 or abs(carToBallAngle) >= 135: -# carOffset = agent.carLength/2 -# else: -# carOffset = agent.carWidth/2 -# #carOffset = 5 -# -# positioningOffset = 0 -# ballOffset = 70 -# totalOffset = carOffset + ballOffset -# -# -# if abs(carToBallAngle) < 30: -# if is_in_strike_zone(agent, targetVec): -# targetLoc = targetVec -# positioningOffset = totalOffset -# targetLoc.data[1] += sign(agent.team)*10 -# if abs(carToBallAngle) <=4: -# if distance2D(agent.me.location, agent.ball.location) < 400: -# if agent.ballGrounded: -# if openGoalOpportunity(agent): -# if agent.me.boostLevel < 1: -# if (agent.me.location[1] * -sign(agent.team))+ -sign(agent.team)*100 < agent.ball.location[1] * -sign(agent.team): -# agent.setJumping(0) -# -# -# -# if not targetLoc: -# # if not agent.contested: -# #if agent.closestEnemyToBallDistance >500: -# if abs(targetVec[0]) < 2200: -# if ballToGoalDist < 5800 and ballToGoalDist > 1300: -# if agent.ballGrounded: -# if abs(agent.me.location[1] - abs(targetVec[1]))> 600: -# _direction = direction(goalSpot, targetVec) -# -# targetLoc = targetVec - _direction.scale(clamp(1000,totalOffset,120 + distance * 0.5)) -# positioningOffset = clamp(1000,totalOffset,120 + distance * 0.5) -# -# -# -# if not targetLoc: -# targetLoc = findOppositeSide(agent, targetVec, goalSpot, clamp(400, totalOffset, distance * .35)) -# positioningOffset = clamp(400, totalOffset, distance * .35) -# -# if agent.ballGrounded: -# modifiedDelay = clamp(6, 0, agent.ballDelay - ((positioningOffset) / clamp(maxPossibleSpeed,0.001,agent.currentSpd))) -# else: -# modifiedDelay = agent.ballDelay #clamp(6, 0, agent.ballDelay - (carOffset / agent.currentSpd)) -# result = timeDelayedMovement(agent, targetLoc, modifiedDelay,True) -# -# targetLoc.data[2] = 95 -# agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, targetLoc.data, -# agent.renderer.purple)) -# -# agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.ball.location.data, goalSpot, -# agent.renderer.red)) -# return result - - -# def lineupShot(agent,multi): -# variance = 5 -# -# leftPost = Vector([-sign(agent.team) * 700, 5200 * -sign(agent.team), 200]) -# rightPost = Vector([sign(agent.team) * 700, 5200 * -sign(agent.team), 200]) -# center = Vector([0, 5200 * -sign(agent.team), 200]) -# -# if ballHeadedTowardsMyGoal(agent): -# return ShellTime(agent) -# -# if agent.selectedBallPred: -# targetVec = Vector([agent.selectedBallPred.physics.location.x, agent.selectedBallPred.physics.location.y, -# agent.selectedBallPred.physics.location.z]) -# agent.ballDelay = agent.selectedBallPred.game_seconds - agent.gameInfo.seconds_elapsed -# -# else: -# targetVec = agent.ball.location -# agent.ballDelay = 0 -# -# dist = distance2D(agent.me.location, targetVec) -# goalDist = distance2D(center, targetVec) -# ballToGoalDist = distance2D(targetVec, center) -# targetLocal = toLocal(targetVec,agent.me) -# carToBallAngle = math.degrees(math.atan2(targetLocal[1],targetLocal[0])) -# carToGoalDistance = distance2D(center,agent.me.location) -# -# carToBallAngle = correctAngle(carToBallAngle) -# -# -# shotAngles = [math.degrees(angle2(targetVec, leftPost)), -# math.degrees(angle2(targetVec, center)), -# math.degrees(angle2(targetVec, rightPost))] -# -# correctedAngles=[x + 90 * -sign(agent.team) for x in shotAngles] -# -# if len(agent.allies) < 1: -# flipDecider(agent, targetVec,enemyInfluenced= True) -# else: -# flipDecider2(agent) -# -# if distance2D(center,targetVec) < 1500: -# goalAngle = correctedAngles[1] -# goalSpot = center -# -# else: -# if correctedAngles[1] < -variance: -# goalAngle = correctedAngles[0] -# goalSpot = leftPost -# -# elif correctedAngles[1] > variance: -# goalAngle = correctedAngles[2] -# goalSpot = rightPost -# -# else: -# goalAngle = correctedAngles[1] -# goalSpot = center -# -# -# targetLoc = None -# rush = False -# if agent.ball.location[2] <= 140: -# if dist > 40: -# rush = True -# -# if abs(carToBallAngle) < 30: -# if is_in_strike_zone(agent, targetVec): -# targetLoc = targetVec -# targetLoc.data[1] += sign(agent.team)*10 -# if abs(carToBallAngle) <=6: -# if distance2D(agent.me.location, agent.ball.location) < 400: -# if targetVec[2] <= 150: -# if openGoalOpportunity(agent): -# if (agent.me.location[1] * -sign(agent.team))+ -sign(agent.team)*100 < agent.ball.location[1] * -sign(agent.team): -# agent.setJumping(0) -# -# -# -# if not targetLoc: -# if abs(targetVec[0]) < 2200: -# if ballToGoalDist < 5800 and ballToGoalDist > 1300: -# if targetVec[2] < 120: -# if abs(agent.me.location[1] < abs(targetVec[1])): -# _direction = direction(center, targetVec) -# targetLoc = targetVec - _direction.scale(120 + dist * 0.5) -# if not targetLoc: -# targetLoc = findOppositeSide(agent,targetVec,goalSpot,clamp(125,60,(dist/1.5)-abs(carToBallAngle))) -# -# -# placeVecWithinArena(targetLoc) -# -# if rush: -# result = testMover(agent,targetLoc,maxPossibleSpeed) -# else: -# result = timeDelayedMovement(agent, targetLoc, agent.ballDelay,True) -# -# targetLoc.data[2] = 95 -# agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.me.location.data, targetLoc.data, -# agent.renderer.purple)) -# -# agent.renderCalls.append(renderCall(agent.renderer.draw_line_3d, agent.ball.location.data, goalSpot, -# agent.renderer.red)) -# return result - - - -def maxSpeedAdjustment(agent,target): - tar_local = toLocal(target,agent.me) - angle = abs(correctAngle(math.degrees(math.atan2(tar_local[1],tar_local[0])))) - dist = distance2D(agent.me.location,target) - distCorrection = dist/300 - - if dist >=2000: - return maxPossibleSpeed - - if abs(angle) <=3: - return maxPossibleSpeed - - - - cost_inc = maxPossibleSpeed/180 - if dist < 1000: - cost_inc*=2.5 - #angle = abs(angle) -10 - angle = abs(angle) - newSpeed = clamp(maxPossibleSpeed,400,maxPossibleSpeed - (angle*cost_inc)) - #print(f"adjusting speed to {newSpeed}") - - return newSpeed - - - -def is_in_strike_zone(agent, ball_vec): - leftPost = Vector([-sign(agent.team) * 700, 5100 * -sign(agent.team), 200]) - rightPost = Vector([sign(agent.team) * 700, 5100 * -sign(agent.team), 200]) - localLeft = toLocal(leftPost,agent.me) - localRight = toLocal(rightPost,agent.me) - localBall = toLocal(ball_vec,agent.me) - - angles = [math.degrees(math.atan2(localLeft[1],localLeft[0])), - math.degrees(math.atan2(localBall[1],localBall[0])), - math.degrees(math.atan2(localRight[1],localRight[0]))] - - if not agent.forward: - for i in range(len(angles)): - angles[i] = angles[i]-180 - - if angles[0]+2.5 < angles[1] < angles[2]-2.5: - return True - return False - -def calcTimeWithAcceleration(agent,distance): - estimatedSpd = agent.currentSpd - estimatedTime = 0 - distanceTally = 0 - boostAmount = agent.me.boostLevel - boostingCost = 33.3*agent.deltaTime - linearChunk = 1600/1410 - while distanceTally < distance and estimatedTime < 6: - if estimatedSpd < maxPossibleSpeed: - acceleration = 1600 - (estimatedSpd*linearChunk) - if boostAmount > 0: - acceleration+=991 - boostAmount -= boostingCost - if acceleration > 0: - estimatedSpd += acceleration * agent.deltaTime - distanceTally+= estimatedSpd*agent.deltaTime - estimatedTime += agent.deltaTime - else: - #estimatedSpd += acceleration * agent.deltaTime - distanceTally += estimatedSpd * agent.deltaTime - estimatedTime += agent.deltaTime - - #print("friendly ended") - return estimatedTime - -# def inaccurateArrivalEstimator(agent,destination): -# distance = clamp(math.inf,1,distance2D(agent.me.location,destination)) -# currentSpd = clamp(2300,1,agent.getCurrentSpd()) -# localTarg = toLocal(destination,agent.me) -# if agent.forward: -# angle = math.degrees(math.atan2(localTarg[1],localTarg[0])) -# else: -# angle = correctAngle(math.degrees(math.atan2(localTarg[1],localTarg[0]))-180) -# if distance < 2000: -# if abs(angle) > 40: -# distance+= abs(angle) -# -# if agent.me.boostLevel > 0: -# maxSpd = clamp(2300,currentSpd,currentSpd+ (distance*.3)) -# else: -# maxSpd = clamp(2200, currentSpd, currentSpd + (distance*.15)) -# -# return distance/maxSpd - -def inaccurateArrivalEstimator(agent,destination): - distance = clamp(math.inf,0.00001,distance2D(agent.me.location,destination)-(91+agent.carLength/2)) - moreAccurateEstimation = calcTimeWithAcceleration(agent,distance) - - #print(f"estimate for reaching distance {distance}: {moreAccurateEstimation}") - return moreAccurateEstimation - -def direction(source, target) -> Vector: - return (getLocation(source) - getLocation(target)).normalize() - -def angle2(target_location,object_location): - difference = getLocation(target_location) - getLocation(object_location) - return math.atan2(difference[1], difference[0]) - -def getVelocity(_obj): - return math.sqrt(sum([x*x for x in _obj])) - -def getVelocity2D(_obj): - return math.sqrt(sum[_obj.velocity[0]**2,_obj.velocity[0]**2]) - -def findDistance(origin,destination): - difference = getLocation(origin) - getLocation(destination) - return abs(math.sqrt(sum([x * x for x in difference]))) - -def distance2D(origin,destination): - _origin = getLocation(origin) - _destination = getLocation(destination) - _origin = Vector([_origin[0],_origin[1]]) - _destination = Vector([_destination[0],_destination[1]]) - difference = _origin - _destination - return abs(math.sqrt(sum([x * x for x in difference]))) - -def correctAngle(x): - - while x > 360: - x-=360 - while x < -360: - x+=360 - - if x > 180: - x-=360 - elif x < -180: - x+=360 - - return x - -def localizeVector(target_object,our_object): - x = (getLocation(target_object) - getLocation(our_object.location)).dotProduct(our_object.matrix[0]) - y = (getLocation(target_object) - getLocation(our_object.location)).dotProduct(our_object.matrix[1]) - z = (getLocation(target_object) - getLocation(our_object.location)).dotProduct(our_object.matrix[2]) - return Vector([x, y, z]) - -def toLocal(target,our_object): - # - return localizeVector(target,our_object) - -# def testMover(agent, target_object,targetSpd): -# if targetSpd > 2200: -# targetSpd = 2200 -# -# if agent.me.boostLevel <= 88: -# newTarget = convenientBoost(agent,getLocation(target_object)) -# if newTarget != None: -# target_object = newTarget -# targetSpd = 2200 -# agent.renderCalls.append( -# renderCall(agent.renderer.draw_line_3d, agent.me.location.data, target_object.data, -# agent.renderer.yellow)) -# return efficientMover(agent,target_object,targetSpd,boostHunt=False) -# currentSpd = agent.getCurrentSpd() -# _distance = distance2D(agent.me, target_object) -# -# if targetSpd < currentSpd+150 or agent.me.boostLevel <=0 or targetSpd < 900 or (getLocation(target_object)[2]>120 and _distance < 300): -# return efficientMover(agent,target_object,targetSpd,boostHunt=False) -# -# location = toLocal(target_object, agent.me) -# controller_state = SimpleControllerState() -# angle_to_target = math.atan2(location.data[1], location.data[0]) -# angle_degrees = correctAngle(math.degrees(angle_to_target)) -# if angle_degrees >=120: -# if currentSpd <= 500: -# agent.forward = False -# -# if not agent.forward: -# return efficientMover(agent, target_object, targetSpd,boostHunt=False) -# -# if len(agent.allies) >= 1: -# steering, slide = newSteer(angle_to_target) -# else: -# steering, slide = rockSteer(angle_to_target,_distance) -# -# if abs(steering) >=.95: -# optimalSpd = maxSpeedAdjustment(agent, target_object) -# -# if targetSpd > optimalSpd: -# targetSpd = optimalSpd -# -# controller_state.steer = steering -# controller_state.handbrake = slide -# if agent.forward: -# controller_state.throttle = 1.0 -# else: -# controller_state.throttle = -1.0 -# -# if targetSpd > currentSpd: -# if agent.onSurface and not slide: -# if targetSpd > 1400 and currentSpd < 2200: -# if agent.forward: -# controller_state.boost = True -# elif targetSpd < currentSpd: -# if agent.getActiveState() != 3: -# if agent.forward: -# controller_state.throttle = -1 -# else: -# controller_state.throttle = 1 -# else: -# if currentSpd - targetSpd < 25: -# controller_state.throttle = 0 -# else: -# if agent.forward: -# controller_state.throttle = -1 -# else: -# controller_state.throttle = 1 -# -# if currentSpd > 1400: -# if _distance > clamp(2300,1400,currentSpd+500)*1.6: -# if agent.onSurface: -# if not agent.onWall: -# if currentSpd < targetSpd: -# maxAngle = 3 + clamp(2,0,_distance/1000) -# if abs(angle_degrees) < maxAngle: -# agent.setJumping(1) -# -# return controller_state - -# def testMover(agent, target_object,targetSpd): -# if targetSpd > maxPossibleSpeed: -# targetSpd = maxPossibleSpeed -# placeVecWithinArena(target_object) -# currentSpd = agent.currentSpd -# _distance = distance2D(agent.me, target_object) -# -# # if targetSpd < currentSpd+150 or agent.me.boostLevel <=0 or targetSpd < 900 or (getLocation(target_object)[2]>120 and _distance < 300): -# # return efficientMover(agent,target_object,targetSpd,boostHunt=False) -# -# location = toLocal(target_object, agent.me) -# controller_state = SimpleControllerState() -# angle_to_target = math.atan2(location.data[1], location.data[0]) -# angle_degrees = correctAngle(math.degrees(angle_to_target)) -# if angle_degrees >=120: -# if currentSpd <= 500: -# agent.forward = False -# -# if not agent.forward: -# return efficientMover(agent, target_object, targetSpd,boostHunt=False) -# -# if agent.me.boostLevel <=0: -# return efficientMover(agent, target_object, targetSpd, boostHunt=False) -# -# if len(agent.allies) >= 1: -# steering, slide = newSteer(angle_to_target) -# else: -# steering, slide = rockSteer(angle_to_target,_distance) -# -# #steering, slide = newSteer(angle_to_target) -# -# if abs(steering) >=.95: -# optimalSpd = maxSpeedAdjustment(agent, target_object) -# -# if targetSpd > optimalSpd: -# targetSpd = optimalSpd -# -# controller_state.steer = steering -# controller_state.handbrake = slide -# if agent.forward: -# controller_state.throttle = 1.0 -# else: -# controller_state.throttle = -1.0 -# -# if targetSpd > currentSpd: -# if agent.onSurface and not slide: -# if targetSpd > 1400 and currentSpd < maxPossibleSpeed-100: -# if agent.forward: -# controller_state.boost = True -# elif targetSpd < currentSpd: -# if agent.getActiveState() != 3: -# if agent.forward: -# controller_state.throttle = -1 -# else: -# controller_state.throttle = 1 -# else: -# if currentSpd - targetSpd < 25: -# controller_state.throttle = 0 -# else: -# if agent.forward: -# controller_state.throttle = -1 -# else: -# controller_state.throttle = 1 -# -# if currentSpd > 1400: -# if _distance > clamp(2300,1400,currentSpd+500)*1.6: -# if agent.onSurface: -# if not agent.onWall: -# if currentSpd < targetSpd: -# maxAngle = 3 + clamp(2,0,_distance/1000) -# if abs(angle_degrees) < maxAngle: -# agent.setJumping(1) -# -# return controller_state - -def find_pred_at_time(agent, _time): - t_offset = 1.0 / 120.0 - for i in range(0, agent.ballPred.num_slices): - if _time < agent.ballPred.slices[i].game_seconds + t_offset: - pred = agent.ballPred.slices[i] - break - return pred - -def testMover(agent, target_object,targetSpd): - if targetSpd > maxPossibleSpeed: - targetSpd = maxPossibleSpeed - placeVecWithinArena(target_object) - currentSpd = agent.currentSpd - _distance = distance2D(agent.me, target_object) - - # if targetSpd < currentSpd+150 or agent.me.boostLevel <=0 or targetSpd < 900 or (getLocation(target_object)[2]>120 and _distance < 300): - # return efficientMover(agent,target_object,targetSpd,boostHunt=False) - - location = toLocal(target_object, agent.me) - controller_state = SimpleControllerState() - angle_to_target = math.atan2(location.data[1], location.data[0]) - angle_degrees = correctAngle(math.degrees(angle_to_target)) - if angle_degrees >=120: - if currentSpd <= 500: - agent.forward = False - - if not agent.forward: - return efficientMover(agent, target_object, targetSpd,boostHunt=False) - - if agent.me.boostLevel <=0: - return efficientMover(agent, target_object, targetSpd, boostHunt=False) - - # if len(agent.allies) >= 1: - # steering, slide = newSteer(angle_to_target) - # else: - # steering, slide = rockSteer(angle_to_target,_distance) - steering, slide = newSteer(angle_to_target) - if slide: - if abs(agent.me.avelocity[2]) < 1: - slide = False - - #steering, slide = newSteer(angle_to_target) - - if abs(steering) >=.95: - optimalSpd = maxSpeedAdjustment(agent, target_object) - - if targetSpd > optimalSpd: - targetSpd = optimalSpd - - controller_state.steer = steering - controller_state.handbrake = slide - if agent.forward: - controller_state.throttle = 1.0 - else: - controller_state.throttle = -1.0 - - if targetSpd > currentSpd: - if agent.onSurface and not slide: - if targetSpd > 1400 and currentSpd < maxPossibleSpeed-100: - if agent.forward: - controller_state.boost = True - elif targetSpd < currentSpd: - if agent.getActiveState() != 3: - if agent.forward: - controller_state.throttle = -1 - else: - controller_state.throttle = 1 - else: - if currentSpd - targetSpd < 25: - controller_state.throttle = 0 - else: - if agent.forward: - controller_state.throttle = -1 - else: - controller_state.throttle = 1 - - if currentSpd > 1400: - if _distance > clamp(2300,1400,currentSpd+500)*1.6: - if agent.onSurface: - if not agent.onWall: - if currentSpd < targetSpd: - maxAngle = 3 + clamp(2,0,_distance/1000) - if abs(angle_degrees) < maxAngle: - agent.setJumping(1) - - return controller_state - - -# def timeDelayedMovement(agent,targetVec,delay): -# arrivalEstimate = inaccurateArrivalEstimator(agent, targetVec) -# -# if arrivalEstimate >= delay: -# return testMover(agent, targetVec, 2200) -# -# else: -# dist = distance2D(agent.me.location, targetVec) -# adjustedSpd = 0 -# if dist > 150: -# adjustedSpd = dist/10 -# return efficientMover(agent, targetVec, (dist/delay)+adjustedSpd,boostHunt=True) - -def timeDelayedMovement(agent,targetVec,delay,boostHungry): - arrivalEstimate = inaccurateArrivalEstimator(agent, targetVec) - - if arrivalEstimate >= delay: - return testMover(agent, targetVec, maxPossibleSpeed) - - else: - distance = clamp(999999,0.00001,distance2D(agent.me.location,targetVec)) - speed = distance/delay - - return efficientMover(agent, targetVec, speed,boostHunt=boostHungry) - - - -# def efficientMover(agent,target_object,target_speed,boostHunt = False): -# controller_state = SimpleControllerState() -# originalTarget = target_object -# -# if boostHunt: -# if agent.me.boostLevel < 88: -# newTarget = convenientBoost(agent,getLocation(target_object)) -# if newTarget != None: -# target_speed = maxPossibleSpeed -# target_object = newTarget -# agent.renderCalls.append( -# renderCall(agent.renderer.draw_line_3d, agent.me.location.data, newTarget.data, -# agent.renderer.yellow)) -# placeVecWithinArena(originalTarget) -# placeVecWithinArena(target_object) -# location = toLocal(target_object, agent.me) -# angle_to_target = math.atan2(location.data[1], location.data[0]) -# _distance = distance2D(agent.me, target_object) -# current_speed = agent.currentSpd -# if not agent.forward: -# controller_state.throttle = -1 -# _angle = math.degrees(angle_to_target) -# _angle -= 180 -# if _angle < -180: -# _angle += 360 -# if _angle > 180: -# _angle -= 360 -# -# angle_to_target = math.radians(_angle) -# if agent.onSurface: -# if _distance > 1200: -# if abs(_angle) <= 50 : -# agent.setHalfFlip() -# -# if len(agent.allies) >= 1: -# steerDirection, slideBool = newSteer(angle_to_target) -# else: -# steerDirection, slideBool = rockSteer(angle_to_target,_distance) -# #steerDirection, slideBool = newSteer(angle_to_target) -# if not agent.forward: -# steerDirection = -steerDirection -# controller_state.steer = steerDirection -# controller_state.handbrake = slideBool -# -# if abs(steerDirection) >=.9: -# optimalSpd = maxSpeedAdjustment(agent, target_object) -# -# if target_speed > optimalSpd: -# target_speed = optimalSpd -# -# if current_speed < target_speed: -# if agent.forward: -# controller_state.throttle = 1 -# else: -# controller_state.throttle = -1 -# -# if agent.getActiveState() == 3 or agent.getActiveState() == 4 or agent.getActiveState() == 5: -# if abs(math.degrees(angle_to_target)) <= clamp(3,0,_distance/1000): -# if agent.onSurface: -# if current_speed >= 1050: -# o_dist = distance2D(agent.me.location,originalTarget) -# if o_dist >= 1000: -# if o_dist > clamp(2300,current_speed,current_speed+500)*1.7: -# if agent.forward: -# agent.setJumping(1) -# else: -# agent.setJumping(3) -# -# else: -# if current_speed > target_speed: -# if agent.getActiveState() != 3: -# if agent.forward: -# controller_state.throttle = -1 -# else: -# controller_state.throttle = 1 -# else: -# if current_speed - target_speed < 35: -# controller_state.throttle = 0 -# else: -# if agent.forward: -# controller_state.throttle = -1 -# else: -# controller_state.throttle = 1 -# -# if slideBool: -# if agent.currentSpd < 500: -# controller_state.handbrake = False -# -# return controller_state - -def efficientMover(agent,target_object,target_speed,boostHunt = False): - controller_state = SimpleControllerState() - originalTarget = target_object - - if boostHunt: - if agent.me.boostLevel < 88: - newTarget = convenientBoost(agent,getLocation(target_object)) - if newTarget != None: - target_speed = maxPossibleSpeed - target_object = newTarget - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, agent.me.location.data, newTarget.data, - agent.renderer.yellow)) - placeVecWithinArena(originalTarget) - placeVecWithinArena(target_object) - location = toLocal(target_object, agent.me) - angle_to_target = math.atan2(location.data[1], location.data[0]) - _distance = distance2D(agent.me, target_object) - current_speed = agent.currentSpd - if not agent.forward: - controller_state.throttle = -1 - _angle = math.degrees(angle_to_target) - _angle -= 180 - if _angle < -180: - _angle += 360 - if _angle > 180: - _angle -= 360 - - angle_to_target = math.radians(_angle) - if agent.onSurface: - if _distance > 1200: - if abs(_angle) <= 50 : - agent.setHalfFlip() - - # if len(agent.allies) >= 1: - # steerDirection, slideBool = newSteer(angle_to_target) - # else: - # steerDirection, slideBool = rockSteer(angle_to_target,_distance) - steerDirection, slideBool = newSteer(angle_to_target) - if slideBool: - if abs(agent.me.avelocity[2]) < 1: - slideBool = False - #steerDirection, slideBool = newSteer(angle_to_target) - if not agent.forward: - steerDirection = -steerDirection - controller_state.steer = steerDirection - controller_state.handbrake = slideBool - - if abs(steerDirection) >=.9: - optimalSpd = maxSpeedAdjustment(agent, target_object) - - if target_speed > optimalSpd: - target_speed = optimalSpd - - if current_speed < target_speed: - if agent.forward: - controller_state.throttle = 1 - else: - controller_state.throttle = -1 - - if agent.getActiveState() == 3 or agent.getActiveState() == 4 or agent.getActiveState() == 5: - if abs(math.degrees(angle_to_target)) <= clamp(3,0,_distance/1000): - if agent.onSurface: - if current_speed >= 1050: - o_dist = distance2D(agent.me.location,originalTarget) - if o_dist >= 1500: - if o_dist > clamp(2300,current_speed,current_speed+500)*1.9: - if agent.forward: - agent.setJumping(1) - else: - agent.setJumping(3) - - else: - if current_speed > target_speed: - if agent.getActiveState() != 3: - if agent.forward: - controller_state.throttle = -1 - else: - controller_state.throttle = 1 - else: - if current_speed - target_speed < 35: - controller_state.throttle = 0 - else: - if agent.forward: - controller_state.throttle = -1 - else: - controller_state.throttle = 1 - - if slideBool: - if agent.currentSpd < 500: - controller_state.handbrake = False - - return controller_state - - -def Gsteer(angle): - final = ((10 * angle+sign(angle))**3) / 20 - return clamp(1,-1,final) - - -def rockSteer(angle,distance): - turn = Gsteer(angle) - slide = False - distanceMod = clamp(10,.3,distance/500) - _angle = correctAngle(math.degrees(angle)) - - - adjustedAngle = _angle/distanceMod - if abs(turn) >=1: - if abs(adjustedAngle) > 100: - slide = True - - return turn,slide - -def isBallGrounded(agent,heightMax,frameMin): - if agent.ballPred is not None: - for i in range(0, frameMin): - if agent.ballPred.slices[i].physics.location.z > heightMax: - return False - return True - return False - -def greedyMover(agent,target_object): - controller_state = SimpleControllerState() - controller_state.handbrake = False - location = toLocal(target_object, agent.me) - angle = math.atan2(location.data[1], location.data[0]) - controller_state.throttle = 1 - if getVelocity(agent.me.velocity) < 2200: - if agent.onSurface: - controller_state.boost = True - controller_state.jump = False - - controller_state.steer = Gsteer(angle) - - return controller_state - - - - -def exampleController(agent, target_object,target_speed): - distance = distance2D(agent.me.location,target_object.location) - if distance > 400: - agent.state = efficientMover - return efficientMover(agent,target_object,target_speed,boostHunt=True) - - controller_state = SimpleControllerState() - controller_state.handbrake = False - - car_direction = get_car_facing_vector(agent.me) - car_to_ball = agent.me.location - target_object.location - - steer_correction_radians = steer(car_direction.correction_to(car_to_ball)) - - current_speed = getVelocity(agent.me.velocity) - controller_state.steer = steer(steer_correction_radians) - if target_speed > current_speed: - controller_state.throttle = 1.0 - if target_speed > 1400 and current_speed < 2250: - controller_state.boost = True - elif target_speed < current_speed: - controller_state.throttle = 0 - - return controller_state - -def isBallNearWall(ballstruct): - if ballstruct.physics.location.x > 4096 - 120: - return True - if ballstruct.physics.location.x < -4096 + 120: - return True - - if ballstruct.physics.location.y < -5120 + 120: - return True - - if ballstruct.physics.location.y > 5120 - 120: - return True - - - -def isBallHittable(ballStruct,agent,maxHeight): - multi = clamp(3, 1, len(agent.allies)+1) - if ballStruct.physics.location.z<= maxHeight: - return True - if ballStruct.physics.location.x > 4096 - 130: - if ballStruct.physics.location.z <= 200*multi: - return True - if ballStruct.physics.location.x < -4096 + 130: - if ballStruct.physics.location.z <= 200*multi: - return True - - if ballStruct.physics.location.y < -5120 + 130: - if ballStruct.physics.location.z <= 200*multi: - if abs(ballStruct.physics.location.x) > 893: - return True - if ballStruct.physics.location.y > 5120 - 130: - if ballStruct.physics.location.z <= 200*multi: - if abs(ballStruct.physics.location.x) > 900: - return True - return False - - -def findSoonestBallTouchable(agent): - if agent.ballPred != None: - bestStruct = agent.ballPred.slices[359] - quickest = 99999999 - spd = clamp(2200, 300, abs(agent.getCurrentSpd())) - - if agent.ballPred is not None: - for i in range(0, agent.ballPred.num_slices): - if agent.ballPred.slices[i].physics.location.z <= 155: - distance = distance2D(agent.me.location, Vector([agent.ballPred.slices[i].physics.location.x, - agent.ballPred.slices[i].physics.location.y, - agent.ballPred.slices[i].physics.location.z])) - adjustedSpd = clamp(2200,spd, spd+ distance * .5) - timeEstimate = distance / adjustedSpd - if timeEstimate < quickest: - bestStruct = agent.ballPred.slices[i] - quickest = timeEstimate - return bestStruct - - return None - - -def aerialWorkHorse(agent,struct): - myGoal = center = Vector([0, 5120 * sign(agent.team), 200]) - enemyGoal = center = Vector([0, 5120 * -sign(agent.team), 200]) - - - aerial = agent.aerial - a_turn = agent.a_turn - - targetVec = Vector([aerial.target[0],aerial.target[1],aerial.target[2]]) - #print(aerial.target.x) - - if agent.onSurface and not agent.onWall: - targetLocal = toLocal(targetVec, agent.me) - - carToBallAngle = correctAngle( - math.degrees(math.atan2(targetLocal[1], targetLocal[0]))) - targDist = distance2D(agent.me.location,targetVec) - maxAngle = clamp(10,2,targDist/200) - if abs(carToBallAngle) > maxAngle: - #print("driving to target") - agent.forward = True - return efficientMover(agent,targetVec,2200,boostHunt = False) - else: - if targDist > clamp(2800,1000,agent.getCurrentSpd()*1.5): - if targetVec[2] > 500: - #print("launching") - #agent.setLaunch() - jumpStatus = agent.setJumping(2) - if jumpStatus == 1: - return agent.activeState.update() - else: - return efficientMover(agent, targetVec, 2200, boostHunt=False) - - #print("returning aerial controls") - aerial.step(agent.deltaTime) - controls = aerial.controls - if agent.onSurface: - controls.jump = True - return controls - - - -#@profile -def aerialSelection(agent, struct): - - myGoal = Vector([0, 5120 * sign(agent.team), 200]) - enemyGoal = Vector([0, 5120 * -sign(agent.team), 200]) - - if agent.aerial == None: - agent.aerial = Aerial(agent.game.my_car) - if agent.a_turn == None: - agent.a_turn = AerialTurn(agent.game.my_car) - - aerial = agent.aerial - a_turn = agent.a_turn - - - targetVec = Vector([struct.physics.location.x,struct.physics.location.y,struct.physics.location.z]) - - - acceptable = False - if agent.team == 0: - if agent.me.location[1] < targetVec[1]: - acceptable = True - else: - if agent.me.location[1] > targetVec[1]: - acceptable = True - - if acceptable: - ballAngle = correctAngle(math.degrees(angle2(targetVec, enemyGoal) + 90 * -sign(agent.team))) - if agent.team == 0: - - targetLocal = toLocal(targetVec, agent.me) - - if targetVec[1] * sign(agent.team) > 3000 * sign(agent.team): - totalAngle = abs(math.degrees(math.atan2(targetLocal[1],targetLocal[0]))) - else: - totalAngle = correctAngle(abs(math.degrees(math.atan2(targetLocal[1],targetLocal[0])))+abs(ballAngle)) - - if abs(totalAngle) > 70: - return False - - elif agent.team == 1: - - targetLocal = toLocal(targetVec, agent.me) - totalAngle = math.degrees(math.atan2(targetLocal[1], targetLocal[0])) - - if abs(totalAngle) > 70: - return False - - - aerial.arrival_time = struct.game_seconds - direction = (enemyGoal.flatten() - targetVec.flatten()).normalize() - beneathAmount = 15 - if distance2D(targetVec, enemyGoal) <= 1500 or targetVec[2] > 1500: - beneathAmount = 0 - offset = direction.scale(85+beneathAmount) - #targetVec = targetVec - offset - - targetVec.data[2]-=beneathAmount - - aerial.target = vec3(targetVec[0], targetVec[1], targetVec[2]) - - simulation = aerial.simulate() - if norm(simulation.location - aerial.target) < 50: - return True - - return False - - -def findPredictionByTime(agent,_time): #agent and updated prediction.game_seconds - req_time = _time - agent.gameInfo.seconds_elapsed - index = int((1/60) * req_time) - if index <=0 or index >= 360: - return -1 - - return agent.ballPred[index] - - - -def findSuitableBallPosition(agent, heightMax, speed, origin): - applicableStructs = [] - spd = clamp(2300,300,speed) - ballInGoal = None - goalTimer = math.inf - - aerialStruct = None - aboveThreshold = False - valid = True - - for i in range(0, agent.ballPred.num_slices,3): - pred = agent.ballPred.slices[i] - if pred.game_seconds <= agent.time: - continue - - _distance = distance2D(Vector([pred.physics.location.x, pred.physics.location.y]), origin) - if isBallHittable(agent.ballPred.slices[i],agent,heightMax): - if agent.team == 0: - if pred.physics.location.y <= -5250: - ballInGoal = pred - goalTimer = pred.game_seconds - agent.gameInfo.seconds_elapsed - agent.goalPred = pred - agent.wallShot = isBallNearWall(pred) - return ballInGoal,aerialStruct - else: - if pred.physics.location.y >= 5250: - ballInGoal = pred - goalTimer = pred.game_seconds - agent.gameInfo.seconds_elapsed - agent.goalPred = pred - agent.wallShot = isBallNearWall(pred) - return ballInGoal, aerialStruct - - #ground ball selection here - - - timeToTarget = inaccurateArrivalEstimator(agent, Vector( - [pred.physics.location.x, pred.physics.location.y, pred.physics.location.z])) - if timeToTarget < (pred.game_seconds - agent.gameInfo.seconds_elapsed): - agent.wallShot = isBallNearWall(pred) - return pred, aerialStruct - - - - else: - if aerialStruct == None: - if pred.physics.location.z >= 400: - aboveThreshold = True - if valid: - if agent.me.boostLevel > 0: - if aerialSelection(agent, pred): - aerialStruct = pred - else: - if aboveThreshold: - valid = False - - - return agent.ballPred.slices[-1],aerialStruct - - - -def findSuitableBallPosition2(agent, heightMax, speed, origin): - applicableStructs = [] - spd = clamp(2300,300,speed) - ballInGoal = None - goalTimer = math.inf - if agent.ballPred is not None: - for i in range(0, agent.ballPred.num_slices): - if isBallHittable(agent.ballPred.slices[i],agent,heightMax): - applicableStructs.append(agent.ballPred.slices[i]) - if agent.team == 0: - if agent.ballPred.slices[i].physics.location.y <= -5050: - ballInGoal = agent.ballPred.slices[i] - goalTimer = agent.ballPred.slices[i].game_seconds - agent.gameInfo.seconds_elapsed - break - else: - if agent.ballPred.slices[i].physics.location.y >= 5050: - ballInGoal = agent.ballPred.slices[i] - goalTimer = agent.ballPred.slices[i].game_seconds - agent.gameInfo.seconds_elapsed - break - applicableStructs.append(agent.ballPred.slices[i]) - - for pred in applicableStructs: - distance = distance2D(Vector([pred.physics.location.x,pred.physics.location.y]),origin) - adjustSpd = clamp(2300,1000,speed+distance*.7) - if distance/adjustSpd < (pred.game_seconds - agent.gameInfo.seconds_elapsed): - if goalTimer < pred.game_seconds - agent.gameInfo.seconds_elapsed: - agent.goalPred = ballInGoal - return pred - - if goalTimer < math.inf: - agent.goalPred = ballInGoal - return agent.ballPred.slices[-1] - -def inaccurateArrivalEstimatorRemote(agent,start,destination): - distance = clamp(math.inf,1,distance2D(start,destination)) - currentSpd = clamp(2300,1,agent.getCurrentSpd()) - - if agent.me.boostLevel > 0: - maxSpd = clamp(2300,currentSpd,currentSpd+ (distance*.3)) - else: - maxSpd = clamp(2200, currentSpd, currentSpd + (distance*.15)) - - return distance/maxSpd - -def CB_Reworked(agent,targetVec): - dist = clamp(25000, 1, distance2D(agent.me.location, targetVec)) - ballDist = clamp(25000, 1, distance2D(agent.me.location, agent.ball.location)) - destinationEstimate = inaccurateArrivalEstimator(agent,targetVec) - locTarget = toLocal(targetVec, agent.me) - targetAngle = correctAngle(math.degrees(math.atan2(locTarget[1], locTarget[0]))) - - bestBoost = None - bestAngle = 0 - angleDisparity = 1000 - bestDist = math.inf - bestEstimate = math.inf - goodBoosts = [] - for b in agent.boosts: - _dist = distance2D(b.location, agent.me.location) - if _dist < dist*.6: - localCoords = toLocal(b.location, agent.me) - angle = correctAngle(math.degrees(math.atan2(localCoords[1], localCoords[0]))) - _angleDisparity = targetAngle - angle - - if _angleDisparity > targetAngle-30 and _angleDisparity < targetAngle+30: - goodBoosts.append(b) - - for b in goodBoosts: - pathEstimate = inaccurateArrivalEstimator(agent,b.location) + inaccurateArrivalEstimatorRemote(agent,b.location,targetVec) - if agent.me.boostLevel < 50: - if b.bigBoost: - pathEstimate*=.8 - if pathEstimate < bestEstimate: - bestBoost = b - bestEstimate = pathEstimate - - if bestEstimate < destinationEstimate*1.15 or bestEstimate < agent.ballDelay: - return bestBoost.location - else: - return None - -def convenientBoost(agent,targetVec): - dist = clamp(25000,1,distance2D(agent.me.location,targetVec)) - ballDist = clamp(25000,1,distance2D(agent.me.location,agent.ball.location)) - spd = agent.getCurrentSpd() - spd = clamp(2200,1500,spd + spd/(dist/1000)) - - locTarget = toLocal(targetVec,agent.me) - targetAngle = correctAngle(math.degrees(math.atan2(locTarget[1],locTarget[0]))) - - - bestBoost = None - bestAngle = 0 - angleDisparity = 1000 - bestDist = math.inf - goodBoosts = [] - for b in agent.boosts: - _dist = distance2D(b.location,agent.me.location) - if _dist < dist-500: - localCoords = toLocal(b.location,agent.me) - angle = correctAngle(math.degrees(math.atan2(localCoords[1],localCoords[0]))) - _angleDisparity = targetAngle - angle - _angleDisparity = (_angleDisparity + 180) % 360 - 180 - if b.bigBoost: - if _angleDisparity > 5: - _angleDisparity-=5 - elif _angleDisparity < -5: - _angleDisparity +=5 - - if abs(_angleDisparity) < clamp(35,0,30*_dist/2000): - goodBoosts.append(b) - - - for each in goodBoosts: - d = distance2D(each.location,agent.me.location) - if each.bigBoost: - d *=.7 - if d < bestDist: - bestBoost = each - bestDist = d - - - if bestBoost != None and abs(angleDisparity) and (bestDist/spd + distance2D(bestBoost.location,targetVec)/spd < agent.ballDelay): - if (bestDist/spd) + (distance2D(bestBoost.location,targetVec)/spd) <= agent.ballDelay or ballDist >= 3000: - return bestBoost.location - - return None - - -def ballHeadedTowardsMyGoal(agent): - myGoal = Vector([0, 5100 * sign(agent.team), 200]) - if (distance1D(myGoal, agent.ball.location, 1) - distance1D(myGoal, agent.ball.location + agent.ball.velocity, 1)) > 0: - if agent.ball.velocity.magnitude() > 5: - return True - - return False - -def openGoalOpportunity(agent): - enemyGoal = Vector([0, 5100 * -sign(agent.team), 200]) - ballDistance = distance2D(agent.ball.location,enemyGoal)+200 - - for e in agent.enemies: - if distance2D(e.location,enemyGoal,) < ballDistance: - return False - - return True - -def challengeDecider(agent): - myDistance = distance2D(agent.me.location,agent.ball.location) - for e in agent.enemies: - if distance2D(e.location,agent.ball.location) < myDistance-200: - return False - return True - - -def dpp(target_loc,target_vel,our_loc,our_vel): - target_loc = getLocation(target_loc) - our_loc = getLocation(our_loc) - our_vel = getLocation(our_vel) - d = distance2D(target_loc,our_loc) - if d != 0: - return (((target_loc.data[0] - our_loc.data[0]) * (target_vel.data[0] - our_vel.data[0])) + ((target_loc.data[1] - our_loc.data[1]) * (target_vel.data[1] - our_vel.data[1])))/d - else: - return 0 - -def timeZ(ball): - rate = 0.97 - return quad(-325, ball.velocity.data[2] * rate, ball.location.data[2]-92.75) - - -def radius(v): - return 139.059 + (0.1539 * v) + (0.0001267716565 * v * v) - -def ballLowEnough(agent): - if agent.ball.location[2] < 140: - return True - return False - -def ballReady(agent): - ball = agent.ball - if abs(ball.velocity.data[2]) < 140 and timeZ(agent.ball) < 1: - return True - return False - -def ballProject(agent): - goal = Vector([0,-sign(agent.team)*FIELD_LENGTH/2,100]) - goal_to_ball = (agent.ball.location - goal).normalize() - difference = agent.me.location - agent.ball.location - return difference * goal_to_ball - - - - - - - - - - - - - - diff --git a/RLBotPack/Diablo/appearance.cfg b/RLBotPack/Diablo/appearance.cfg deleted file mode 100644 index c834f988..00000000 --- a/RLBotPack/Diablo/appearance.cfg +++ /dev/null @@ -1,100 +0,0 @@ -[Bot Loadout] -# Primary Color selection -team_color_id = 57 -# Secondary Color selection -custom_color_id = 62 -# Car type (Octane, Merc, etc) -car_id = 25 -# Type of decal -decal_id = 318 -# Wheel selection -wheels_id = 3152 -# Boost selection -boost_id = 1327 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 229 -# Paint Type (for first color) -paint_finish_id = 275 -# Paint Type (for secondary color) -custom_finish_id = 541 -# Engine Audio Selection -engine_audio_id = 1817 -# Car trail Selection -trails_id = 2047 -# Goal Explosion Selection -goal_explosion_id = 1908 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Loadout Orange] -# Primary Color selection -team_color_id = 0 -# Secondary Color selection -custom_color_id = 74 -# Car type (Octane, Merc, etc) -car_id = 25 -# Type of decal -decal_id = 318 -# Wheel selection -wheels_id = 3152 -# Boost selection -boost_id = 1327 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 229 -# Paint Type (for first color) -paint_finish_id = 275 -# Paint Type (for secondary color) -custom_finish_id = 541 -# Engine Audio Selection -engine_audio_id = 1817 -# Car trail Selection -trails_id = 2047 -# Goal Explosion Selection -goal_explosion_id = 1908 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Paint Blue] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 0 -# wheels_paint_id -wheels_paint_id = 1 -# boost_paint_id -boost_paint_id = 1 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 1 -# trails_paint_id -trails_paint_id = 0 -# goal_explosion_paint_id -goal_explosion_paint_id = 0 - -[Bot Paint Orange] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 0 -# wheels_paint_id -wheels_paint_id = 1 -# boost_paint_id -boost_paint_id = 1 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 1 -# trails_paint_id -trails_paint_id = 0 -# goal_explosion_paint_id -goal_explosion_paint_id = 0 - diff --git a/RLBotPack/Diablo/diablo.cfg b/RLBotPack/Diablo/diablo.cfg deleted file mode 100644 index e385e953..00000000 --- a/RLBotPack/Diablo/diablo.cfg +++ /dev/null @@ -1,29 +0,0 @@ -[Locations] -# Path to loadout config. Can use relative path from here. -looks_config = ./appearance.cfg - -# Path to python file. Can use relative path from here. -python_file = ./diablo.py -maximum_tick_rate_preference = 60 - -# Name of the bot in-game -name = Diablo - -[Details] -# These values are optional but useful metadata for helper programs -# Name of the bot's creator/developer -developer = Impossibum (Kamael,Peter,Diablo) - -# Short description of the bot -description = Simple python bot that evolved from Gosling - -# Fun fact about the bot -fun_fact = Diablo is Kamael's Older Brother, but they hate each other for some reason. - -# Link to github repository -github = https://github.com/oxrock/Diablo - -# Programming language -language = python - -tags = 1v1, teamplay diff --git a/RLBotPack/Diablo/diablo.py b/RLBotPack/Diablo/diablo.py deleted file mode 100644 index c414db43..00000000 --- a/RLBotPack/Diablo/diablo.py +++ /dev/null @@ -1,266 +0,0 @@ -import os -import time -import math -from rlbot.agents.base_agent import BaseAgent, SimpleControllerState -from rlbot.utils.structures.game_data_struct import GameTickPacket -from rlbot.utils.game_state_util import GameState, BallState, CarState, Physics, Vector3 as vector3, Rotator -try: - from rlutilities.linear_algebra import * - from rlutilities.mechanics import Aerial, AerialTurn, Dodge, Wavedash, Boostdash - from rlutilities.simulation import Game, Ball, Car -except: - print("==========================================") - print("\nrlutilities import failed.") - print("Make sure rlutilities folder is local to Diablo bot's files. Running the setup.py file should download the module for you.") - path = str(os.path.realpath(__file__)) - print("setup.py should be located here: "+path[:path.rfind('\\')]) - - print("\n==========================================") - quit() - -from Utilities import * -from States import * -import cProfile, pstats, io - -def profile(fnc): - """A decorator that uses cProfile to profile a function""" - - def inner(*args, **kwargs): - pr = cProfile.Profile() - pr.enable() - retval = fnc(*args, **kwargs) - pr.disable() - s = io.StringIO() - sortby = 'cumulative' - ps = pstats.Stats(pr, stream=s).sort_stats(sortby) - ps.print_stats() - print(s.getvalue()) - return retval - - return inner - - -class diabloBot(BaseAgent): - def __init__(self, name, team, index): - Game.set_mode("soccar") - self.game = Game(index, team) - self.time = 0 - self.index = index - self.name = name - self.team = team - - def initialize_agent(self): - self.controller_state = SimpleControllerState() - self.me = physicsObject() - self.ball = physicsObject() - self.me.team = self.team - self.allies = [] - self.enemies = [] - self.start = 5 - self.flipStart = 0 - self.flipping = False - self.controller = None - self.flipTimer = time.time() - self.activeState = Kickoff(self) - self.gameInfo = None - self.onSurface = False - self.boosts = [] - self.fieldInfo = [] - self.positions = [] - self.deltaTime = 0 - self.maxSpd = 2200 - self.ballPred = [] - self.selectedBallPred = None - self.ballDelay = 0 - self.renderCalls = [] - self.ballPredObj = None - self.carHeight = 84 - self.forward = True - self.velAngle = 0 - self.onWall = False - self.stateTimer = time.time() - self.contested = True - self.flipTimer = 0 - self.goalPred = None - self.wallShot = False - self.carLength = 118.007 - self.carWidth = 84.2 - self.carHeight = 36.159 - self.openGoal = False - self.maxDT = 1/120 - self.aerial = None #Aerial(agent.game.my_car) - self.a_turn = None #AerialTurn(agent.game.my_car) - - def getActiveState(self): - if type(self.activeState) == JumpingState: - return 0 - if type(self.activeState) == Kickoff: - return 1 - if type(self.activeState) == GetBoost: - return 2 - if type(self.activeState) == Dribble: - return 3 - if type(self.activeState) == GroundShot: - return 4 - if type(self.activeState) == GroundDefend: - return 5 - if type(self.activeState) == halfFlip: - return 6 - - def setHalfFlip(self): - self.activeState = halfFlip(self) - - def setLaunch(self): - self.activeState = airLaunch(self) - - def determineFacing(self): - offset = self.me.location + self.me.velocity - loc = toLocal(offset,self.me) - angle = math.degrees(math.atan2(loc[1],loc[0])) - if angle < -180: - angle += 360 - if angle > 180: - angle -= 360 - - if abs(angle) >150 and self.getCurrentSpd() > 200: - self.forward = False - else: - self.forward = True - - self.velAngle = angle - - def setJumping(self,targetType): - _time = self.time - if _time - self.flipTimer >= 1.9: - if self.me.location[2] > 250: - self.activeState = JumpingState(self, -1) - else: - self.activeState = JumpingState(self, targetType) - self.flipTimer = _time - return 1 - else: - return 0 - - - def setDashing(self,target): - self.activeState = WaveDashing(self,target) - - - def getCurrentSpd(self): - return Vector(self.me.velocity[:2]).magnitude() - - def updateSelectedBallPrediction(self,ballStruct): - x = physicsObject() - x.location = Vector([ballStruct.physics.location.x, ballStruct.physics.location.y, ballStruct.physics.location.z]) - x.velocity = Vector([ballStruct.physics.velocity.x, ballStruct.physics.velocity.y, ballStruct.physics.velocity.z]) - x.rotation = Vector([ballStruct.physics.rotation.pitch, ballStruct.physics.rotation.yaw, ballStruct.physics.rotation.roll]) - x.avelocity = Vector([ballStruct.physics.angular_velocity.x, ballStruct.physics.angular_velocity.y, ballStruct.physics.angular_velocity.z]) - x.local_location = localizeVector(x.location, self.me) - self.ballPredObj = x - - - - - def preprocess(self, game): - self.ballPred = self.get_ball_prediction_struct() - self.players = [self.index] - self.game.read_game_information(game, - self.get_rigid_body_tick(), - self.get_field_info()) - car = game.game_cars[self.index] - self.me.location = Vector([car.physics.location.x, car.physics.location.y, car.physics.location.z]) - self.me.velocity = Vector([car.physics.velocity.x, car.physics.velocity.y, car.physics.velocity.z]) - self.me.rotation = Vector([car.physics.rotation.pitch, car.physics.rotation.yaw, car.physics.rotation.roll]) - self.me.avelocity = Vector([car.physics.angular_velocity.x, car.physics.angular_velocity.y, car.physics.angular_velocity.z]) - self.me.boostLevel = car.boost - self.onSurface = car.has_wheel_contact - self.deltaTime = clamp(1, self.maxDT, game.game_info.seconds_elapsed - self.time) - self.time = game.game_info.seconds_elapsed - - - ball = game.game_ball.physics - self.ball.location = Vector([ball.location.x, ball.location.y, ball.location.z]) - self.ball.velocity = Vector([ball.velocity.x, ball.velocity.y, ball.velocity.z]) - self.ball.rotation = Vector([ball.rotation.pitch, ball.rotation.yaw, ball.rotation.roll]) - self.ball.avelocity = Vector([ball.angular_velocity.x, ball.angular_velocity.y, ball.angular_velocity.z]) - self.me.matrix = rotator_to_matrix(self.me) - self.ball.local_location = localizeVector(self.ball.location,self.me) - self.determineFacing() - self.onWall = False - if self.onSurface: - if self.me.location[2] > 70: - self.onWall = True - - self.allies.clear() - self.enemies.clear() - for i in range(game.num_cars): - if i != self.index: - car = game.game_cars[i] - _obj = physicsObject() - _obj.index = i - _obj.team = car.team - _obj.location = Vector([car.physics.location.x, car.physics.location.y, car.physics.location.z]) - _obj.velocity = Vector([car.physics.velocity.x, car.physics.velocity.y, car.physics.velocity.z]) - _obj.rotation = Vector([car.physics.rotation.pitch, car.physics.rotation.yaw, car.physics.rotation.roll]) - _obj.avelocity = Vector([car.physics.angular_velocity.x, car.physics.angular_velocity.y, car.physics.angular_velocity.z]) - _obj.boostLevel = car.boost - _obj.local_location = localizeVector(_obj,self.me) - - if car.team == self.team: - self.allies.append(_obj) - else: - self.enemies.append(_obj) - - self.gameInfo = game.game_info - self.boosts.clear() - self.fieldInfo = self.get_field_info() - for index in range(self.fieldInfo.num_boosts): - packetBoost = game.game_boosts[index] - fieldInfoBoost = self.fieldInfo.boost_pads[index] - boostStatus = False - if packetBoost.timer <= 0: - boostStatus = True - boostLocation = [fieldInfoBoost.location.x, fieldInfoBoost.location.y, fieldInfoBoost.location.z] - # if boostLocation != self.badBoostLocation: - self.boosts.append( - Boost_obj([fieldInfoBoost.location.x, fieldInfoBoost.location.y, fieldInfoBoost.location.z], - fieldInfoBoost.is_full_boost, boostStatus)) - - ballContested(self) - self.goalPred = None - self.currentSpd = clamp(2300,0.001,self.getCurrentSpd()) - #self.ballGrounded = isBallGrounded(self, 125, 20) - self.ballGrounded = False - if len(self.enemies) > 0: - self.closestEnemyToBall, self.closestEnemyToBallDistance = findEnemyClosestToLocation2D(self,self.ball.location) - else: - self.closestEnemyToBall = self.me - self.closestEnemyToMe = self.me - self.closestEnemyToBallDistance = 0 - self.closestEnemyToMeDistance = 0 - self.contested = False - self.enemyAttacking = False - - #@profile - def get_output(self, packet: GameTickPacket) -> SimpleControllerState: - self.preprocess(packet) - if len(self.allies) >=1: - teamStateManager(self) - else: - soloStateManager(self) - action = self.activeState.update() - - self.renderer.begin_rendering() - #self.renderer.draw_string_2d(100, 100, 1, 1, str(type(self.activeState)), self.renderer.white()) - - for each in self.renderCalls: - each.run() - self.renderer.end_rendering() - self.renderCalls.clear() - if action == None: - print(f"{str(type(self.activeState))} failed to produce a controller. Whoops.") - action = SimpleControllerState() - - return action - - diff --git a/RLBotPack/Diablo/logo.png b/RLBotPack/Diablo/logo.png deleted file mode 100644 index 10440615..00000000 Binary files a/RLBotPack/Diablo/logo.png and /dev/null differ diff --git a/RLBotPack/Diablo/rlutilities/__init__.py b/RLBotPack/Diablo/rlutilities/__init__.py deleted file mode 100644 index 198b89e7..00000000 --- a/RLBotPack/Diablo/rlutilities/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -import sys -from .rlutilities import mechanics, simulation, linear_algebra - -sys.modules["rlutilities.mechanics"] = mechanics -sys.modules["rlutilities.simulation"] = simulation -sys.modules["rlutilities.linear_algebra"] = linear_algebra - -#from .skeleton_agent import SkeletonAgent diff --git a/RLBotPack/Diablo/rlutilities/__init__.pyi b/RLBotPack/Diablo/rlutilities/__init__.pyi deleted file mode 100644 index 288e09e5..00000000 --- a/RLBotPack/Diablo/rlutilities/__init__.pyi +++ /dev/null @@ -1,10 +0,0 @@ -from typing import * -from typing import Iterable as iterable -from typing import Iterator as iterator -from numpy import float64 -_Shape = Tuple[int, ...] -__all__ = [ -"linear_algebra", -"mechanics", -"simulation" -] \ No newline at end of file diff --git a/RLBotPack/Diablo/rlutilities/linear_algebra.pyi b/RLBotPack/Diablo/rlutilities/linear_algebra.pyi deleted file mode 100644 index 7c29d76f..00000000 --- a/RLBotPack/Diablo/rlutilities/linear_algebra.pyi +++ /dev/null @@ -1,195 +0,0 @@ -from typing import * -from typing import Iterable as iterable -from typing import Iterator as iterator -from numpy import float64 -_Shape = Tuple[int, ...] -__all__ = [ -"mat2", -"mat3", -"vec2", -"vec3", -"vec4", -"angle_between", -"axis_to_rotation", -"clip", -"cross", -"dot", -"euler_to_rotation", -"inv", -"look_at", -"norm", -"normalize", -"rotation", -"rotation_to_axis", -"sgn", -"transpose", -"xy" -] -class mat2(): - - def __getitem__(self, arg0: Tuple[int, int]) -> float: ... - def __init__(self, arg0: float, arg1: float, arg2: float, arg3: float) -> None: ... - def __setitem__(self, arg0: Tuple[int, int], arg1: float) -> None: ... - def __str__(self) -> str: ... - - pass -class mat3(): - - def __getitem__(self, arg0: Tuple[int, int]) -> float: ... - def __init__(self, arg0: float, arg1: float, arg2: float, arg3: float, arg4: float, arg5: float, arg6: float, arg7: float, arg8: float) -> None: ... - def __setitem__(self, arg0: Tuple[int, int], arg1: float) -> None: ... - def __str__(self) -> str: ... - - pass -class vec2(): - - def __add__(self, arg0: vec2) -> vec2: ... - def __getitem__(self, arg0: int) -> float: ... - def __iadd__(self, arg0: vec2) -> vec2: ... - def __imul__(self, arg0: float) -> vec2: ... - @overload - def __init__(self, arg0: vec3) -> None: - pass - @overload - def __init__(self, arg0: float, arg1: float) -> None: ... - @overload - def __init__(self, arg0: vec2) -> None: ... - def __isub__(self, arg0: vec2) -> vec2: ... - def __itruediv__(self, arg0: float) -> vec2: ... - def __mul__(self, arg0: float) -> vec2: ... - def __rmul__(self, arg0: float) -> vec2: ... - def __setitem__(self, arg0: int, arg1: float) -> None: ... - def __str__(self) -> str: ... - def __sub__(self, arg0: vec2) -> vec2: ... - def __truediv__(self, arg0: float) -> vec2: ... - - pass -class vec3(): - - def __add__(self, arg0: vec3) -> vec3: ... - def __getitem__(self, arg0: int) -> float: ... - def __iadd__(self, arg0: vec3) -> vec3: ... - def __imul__(self, arg0: float) -> vec3: ... - @overload - def __init__(self, arg0: vec2) -> None: - pass - @overload - def __init__(self, arg0: vec3) -> None: ... - @overload - def __init__(self, arg0: float, arg1: float, arg2: float) -> None: ... - def __isub__(self, arg0: vec3) -> vec3: ... - def __itruediv__(self, arg0: float) -> vec3: ... - def __mul__(self, arg0: float) -> vec3: ... - def __rmul__(self, arg0: float) -> vec3: ... - def __setitem__(self, arg0: int, arg1: float) -> None: ... - def __str__(self) -> str: ... - def __sub__(self, arg0: vec3) -> vec3: ... - def __truediv__(self, arg0: float) -> vec3: ... - - pass -class vec4(): - - def __add__(self, arg0: vec4) -> vec4: ... - def __getitem__(self, arg0: int) -> float: ... - def __iadd__(self, arg0: vec4) -> vec4: ... - def __imul__(self, arg0: float) -> vec4: ... - def __init__(self, arg0: float, arg1: float, arg2: float, arg3: float) -> None: ... - def __isub__(self, arg0: vec4) -> vec4: ... - def __itruediv__(self, arg0: float) -> vec4: ... - def __mul__(self, arg0: float) -> vec4: ... - def __rmul__(self, arg0: float) -> vec4: ... - def __setitem__(self, arg0: int, arg1: float) -> None: ... - def __str__(self) -> str: ... - def __sub__(self, arg0: vec4) -> vec4: ... - def __truediv__(self, arg0: float) -> vec4: ... - - pass -@overload -def angle_between(arg0: mat3, arg1: mat3) -> float: - pass -@overload -def angle_between(arg0: vec2, arg1: vec2) -> float: - pass -@overload -def angle_between(arg0: vec3, arg1: vec3) -> float: - pass -def axis_to_rotation(arg0: vec3) -> mat3: - pass -@overload -def clip(arg0: int, arg1: int, arg2: int) -> int: - pass -@overload -def clip(arg0: float, arg1: float, arg2: float) -> float: - pass -@overload -def cross(arg0: vec3) -> vec3: - pass -@overload -def cross(arg0: vec2) -> vec2: - pass -@overload -def cross(arg0: vec3, arg1: vec3) -> vec3: - pass -@overload -def dot(arg0: mat2, arg1: mat2) -> mat2: - pass -@overload -def dot(arg0: vec2, arg1: mat2) -> vec2: - pass -@overload -def dot(arg0: mat2, arg1: vec2) -> vec2: - pass -@overload -def dot(arg0: vec2, arg1: vec2) -> float: - pass -@overload -def dot(arg0: vec4, arg1: vec4) -> float: - pass -@overload -def dot(arg0: vec3, arg1: vec3) -> float: - pass -@overload -def dot(arg0: mat3, arg1: mat3) -> mat3: - pass -@overload -def dot(arg0: vec3, arg1: mat3) -> vec3: - pass -@overload -def dot(arg0: mat3, arg1: vec3) -> vec3: - pass -def euler_to_rotation(arg0: vec3) -> mat3: - pass -@overload -def inv(arg0: mat2) -> mat2: - pass -@overload -def inv(arg0: mat3) -> mat3: - pass -def look_at(arg0: vec3, arg1: vec3) -> mat3: - pass -@overload -def norm(arg0: vec2) -> float: - pass -@overload -def norm(arg0: vec3) -> float: - pass -@overload -def normalize(arg0: vec2) -> vec2: - pass -@overload -def normalize(arg0: vec3) -> vec3: - pass -def rotation(arg0: float) -> mat2: - pass -def rotation_to_axis(arg0: mat3) -> vec3: - pass -def sgn(arg0: float) -> float: - pass -@overload -def transpose(arg0: mat2) -> mat2: - pass -@overload -def transpose(arg0: mat3) -> mat3: - pass -def xy(arg0: vec3) -> vec3: - pass \ No newline at end of file diff --git a/RLBotPack/Diablo/rlutilities/mechanics.pyi b/RLBotPack/Diablo/rlutilities/mechanics.pyi deleted file mode 100644 index ddd93156..00000000 --- a/RLBotPack/Diablo/rlutilities/mechanics.pyi +++ /dev/null @@ -1,280 +0,0 @@ -from typing import * -from typing import Iterable as iterable -from typing import Iterator as iterator -from numpy import float64 -_Shape = Tuple[int, ...] -import rlutilities.simulation -__all__ = [ -"Aerial", -"AerialTurn", -"Boostdash", -"Dodge", -"Drive", -"FollowPath", -"Jump", -"Wavedash" -] -class Aerial(): - boost_accel = 1060.0 - boost_per_second = 30.0 - max_speed = 2300.0 - throttle_accel = 66.66667175292969 - - def __init__(self, arg0: rlutilities.simulation.Car) -> None: ... - def is_viable(self) -> bool: ... - def simulate(self) -> rlutilities.simulation.Car: ... - def step(self, arg0: float) -> None: ... - - @property - def angle_threshold(self) -> float: - pass - - @property - def arrival_time(self) -> float: - pass - - @property - def boost_estimate(self) -> float: - pass - - @property - def controls(self) -> rlutilities.simulation.Input: - pass - - @property - def finished(self) -> bool: - pass - - @property - def reorient_distance(self) -> float: - pass - - @property - def target(self) -> vec3: - pass - - @property - def target_orientation(self) -> Optional[mat3]: - pass - - @property - def throttle_distance(self) -> float: - pass - - @property - def up(self) -> vec3: - pass - - @property - def velocity_estimate(self) -> vec3: - pass - - pass -class AerialTurn(): - - def __init__(self, arg0: rlutilities.simulation.Car) -> None: ... - def simulate(self) -> rlutilities.simulation.Car: ... - def step(self, arg0: float) -> None: ... - - @property - def alpha(self) -> vec3: - pass - - @property - def controls(self) -> rlutilities.simulation.Input: - pass - - @property - def eps_omega(self) -> float: - pass - - @property - def eps_phi(self) -> float: - pass - - @property - def finished(self) -> bool: - pass - - @property - def horizon_time(self) -> float: - pass - - @property - def target(self) -> mat3: - pass - - pass -class Boostdash(): - - def __init__(self, arg0: rlutilities.simulation.Car) -> None: ... - def step(self, arg0: float) -> None: ... - - @property - def controls(self) -> rlutilities.simulation.Input: - pass - - @property - def finished(self) -> bool: - pass - - pass -class Dodge(): - forward_torque = 224.0 - input_threshold = 0.5 - side_torque = 260.0 - timeout = 1.5 - torque_time = 0.6499999761581421 - z_damping = 0.3499999940395355 - z_damping_end = 0.20999999344348907 - z_damping_start = 0.15000000596046448 - - def __init__(self, arg0: rlutilities.simulation.Car) -> None: ... - def simulate(self) -> rlutilities.simulation.Car: ... - def step(self, arg0: float) -> None: ... - - @property - def controls(self) -> rlutilities.simulation.Input: - pass - - @property - def delay(self) -> Optional[float]: - pass - - @property - def direction(self) -> Optional[vec2]: - pass - - @property - def duration(self) -> Optional[float]: - pass - - @property - def finished(self) -> bool: - pass - - @property - def preorientation(self) -> Optional[mat3]: - pass - - @property - def target(self) -> Optional[vec3]: - pass - - @property - def timer(self) -> float: - pass - - pass -class Drive(): - boost_accel = 991.6669921875 - brake_accel = 3500.0 - coasting_accel = 525.0 - max_speed = 2300.0 - max_throttle_speed = 1410.0 - - def __init__(self, arg0: rlutilities.simulation.Car) -> None: ... - @staticmethod - def max_turning_curvature(arg0: float) -> float: ... - @staticmethod - def max_turning_speed(arg0: float) -> float: ... - def step(self, arg0: float) -> None: ... - @staticmethod - def throttle_accel(arg0: float) -> float: ... - - @property - def controls(self) -> rlutilities.simulation.Input: - pass - - @property - def finished(self) -> bool: - pass - - @property - def reaction_time(self) -> float: - pass - - @property - def speed(self) -> float: - pass - - @property - def target(self) -> vec3: - pass - - pass -class FollowPath(): - - def __init__(self, arg0: rlutilities.simulation.Car) -> None: ... - def step(self, arg0: float) -> None: ... - - @property - def arrival_speed(self) -> float: - pass - - @property - def arrival_time(self) -> float: - pass - - @property - def controls(self) -> rlutilities.simulation.Input: - pass - - @property - def expected_error(self) -> float: - pass - - @property - def expected_speed(self) -> float: - pass - - @property - def finished(self) -> bool: - pass - - @property - def path(self) -> rlutilities.simulation.Curve: - pass - - pass -class Jump(): - acceleration = 1458.333251953125 - max_duration = 0.20000000298023224 - min_duration = 0.02500000037252903 - speed = 291.6669921875 - - def __init__(self, arg0: rlutilities.simulation.Car) -> None: ... - def simulate(self) -> rlutilities.simulation.Car: ... - def step(self, arg0: float) -> None: ... - - @property - def controls(self) -> rlutilities.simulation.Input: - pass - - @property - def duration(self) -> float: - pass - - @property - def finished(self) -> bool: - pass - - pass -class Wavedash(): - - def __init__(self, arg0: rlutilities.simulation.Car) -> None: ... - def step(self, arg0: float) -> None: ... - - @property - def controls(self) -> rlutilities.simulation.Input: - pass - - @property - def direction(self) -> Optional[vec2]: - pass - - @property - def finished(self) -> bool: - pass - - pass \ No newline at end of file diff --git a/RLBotPack/Diablo/rlutilities/rlutilities.cp37-win_amd64.pyd b/RLBotPack/Diablo/rlutilities/rlutilities.cp37-win_amd64.pyd deleted file mode 100644 index c8fd47aa..00000000 Binary files a/RLBotPack/Diablo/rlutilities/rlutilities.cp37-win_amd64.pyd and /dev/null differ diff --git a/RLBotPack/Diablo/rlutilities/simulation.pyi b/RLBotPack/Diablo/rlutilities/simulation.pyi deleted file mode 100644 index 19cbb910..00000000 --- a/RLBotPack/Diablo/rlutilities/simulation.pyi +++ /dev/null @@ -1,439 +0,0 @@ -from typing import * -from typing import Iterable as iterable -from typing import Iterator as iterator -from numpy import float64 -_Shape = Tuple[int, ...] -__all__ = [ -"Ball", -"Car", -"ControlPoint", -"Curve", -"Field", -"Game", -"Goal", -"Input", -"Navigator", -"Pad", -"obb", -"ray", -"sphere", -"tri", -"intersect" -] -class Ball(): - collision_radius = 93.1500015258789 - drag = -0.030500000342726707 - friction = 2.0 - mass = 30.0 - max_omega = 6.0 - max_speed = 4000.0 - moment_of_inertia = 99918.75 - radius = 91.25 - restitution = 0.6000000238418579 - - @overload - def __init__(self) -> None: - pass - @overload - def __init__(self, arg0: Ball) -> None: ... - def hitbox(self) -> sphere: ... - @overload - def step(self, arg0: float) -> None: - pass - @overload - def step(self, arg0: float, arg1: Car) -> None: ... - def to_json(self) -> str: ... - - @property - def angular_velocity(self) -> vec3: - pass - - @property - def location(self) -> vec3: - pass - - @property - def time(self) -> float: - pass - - @property - def velocity(self) -> vec3: - pass - - pass -class Car(): - - @overload - def __init__(self) -> None: - pass - @overload - def __init__(self, arg0: Car) -> None: ... - def extrapolate(self, arg0: float) -> None: ... - def forward(self) -> vec3: ... - def hitbox(self) -> obb: ... - def left(self) -> vec3: ... - def step(self, arg0: Input, arg1: float) -> None: ... - def to_json(self) -> str: ... - def up(self) -> vec3: ... - - @property - def angular_velocity(self) -> vec3: - pass - - @property - def boost(self) -> int: - pass - - @property - def controls(self) -> Input: - pass - - @property - def dodge_rotation(self) -> mat2: - pass - - @property - def dodge_timer(self) -> float: - pass - - @property - def double_jumped(self) -> bool: - pass - - @property - def id(self) -> int: - pass - - @property - def jump_timer(self) -> float: - pass - - @property - def jumped(self) -> bool: - pass - - @property - def location(self) -> vec3: - pass - - @property - def on_ground(self) -> bool: - pass - - @property - def quaternion(self) -> vec4: - pass - - @property - def rotation(self) -> mat3: - pass - - @property - def rotator(self) -> vec3: - pass - - @property - def supersonic(self) -> bool: - pass - - @property - def team(self) -> int: - pass - - @property - def time(self) -> float: - pass - - @property - def velocity(self) -> vec3: - pass - - pass -class ControlPoint(): - - @overload - def __init__(self, arg0: vec3, arg1: vec3, arg2: vec3) -> None: - pass - @overload - def __init__(self) -> None: ... - - @property - def n(self) -> vec3: - pass - - @property - def p(self) -> vec3: - pass - - @property - def t(self) -> vec3: - pass - - pass -class Curve(): - - @overload - def __init__(self, arg0: List[ControlPoint]) -> None: - pass - @overload - def __init__(self, arg0: List[vec3]) -> None: ... - def calculate_distances(self) -> None: ... - def calculate_max_speeds(self, arg0: float, arg1: float) -> float: ... - def calculate_tangents(self) -> None: ... - def curvature_at(self, arg0: float) -> float: ... - def find_nearest(self, arg0: vec3) -> float: ... - def max_speed_at(self, arg0: float) -> float: ... - def point_at(self, arg0: float) -> vec3: ... - def pop_front(self) -> None: ... - def tangent_at(self, arg0: float) -> vec3: ... - def write_to_file(self, arg0: str) -> None: ... - - @property - def length(self) -> float: - pass - - @property - def points(self) -> List[vec3]: - pass - - pass -class Field(): - mode = 'Uninitialized' - triangles = [] - walls = [] - - @staticmethod - @overload - def collide(arg0: obb) -> ray: - pass - @staticmethod - @overload - def collide(arg0: sphere) -> ray: ... - @staticmethod - def raycast_any(arg0: ray) -> ray: ... - @staticmethod - def snap(arg0: vec3) -> ray: ... - - pass -class Game(): - frametime = 0.008333333767950535 - gravity = -650.0 - map = 'map_not_set' - - def __init__(self, arg0: int, arg1: int) -> None: ... - def read_game_information(self, arg0: object, arg1: object, arg2: object) -> None: ... - @staticmethod - def set_mode(arg0: str) -> None: ... - - @property - def ball(self) -> Ball: - pass - - @property - def cars(self) -> List[Car[8]]: - pass - - @property - def frame(self) -> int: - pass - - @property - def frame_delta(self) -> int: - pass - - @property - def id(self) -> int: - pass - - @property - def kickoff_pause(self) -> bool: - pass - - @property - def match_ended(self) -> bool: - pass - - @property - def my_car(self) -> Car: - pass - - @property - def num_cars(self) -> int: - pass - - @property - def overtime(self) -> bool: - pass - - @property - def pads(self) -> List[Pad]: - pass - - @property - def round_active(self) -> bool: - pass - - @property - def team(self) -> int: - pass - - @property - def time(self) -> float: - pass - - @property - def time_delta(self) -> float: - pass - - @property - def time_remaining(self) -> float: - pass - - pass -class Goal(): - - def __init__(self) -> None: ... - - @property - def direction(self) -> vec3: - pass - - @property - def location(self) -> vec3: - pass - - @property - def team(self) -> int: - pass - - pass -class Input(): - - def __init__(self) -> None: ... - - @property - def boost(self) -> bool: - pass - - @property - def handbrake(self) -> bool: - pass - - @property - def jump(self) -> bool: - pass - - @property - def pitch(self) -> float: - pass - - @property - def roll(self) -> float: - pass - - @property - def steer(self) -> float: - pass - - @property - def throttle(self) -> float: - pass - - @property - def yaw(self) -> float: - pass - - pass -class Navigator(): - nodes = None # type: list # value = [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ] - - def __init__(self, arg0: Car) -> None: ... - def analyze_surroundings(self, arg0: float) -> None: ... - def path_to(self, arg0: vec3, arg1: vec3, arg2: float) -> Curve: ... - - pass -class Pad(): - - def __init__(self) -> None: ... - - @property - def is_active(self) -> bool: - pass - - @property - def is_full_boost(self) -> bool: - pass - - @property - def location(self) -> vec3: - pass - - @property - def timer(self) -> float: - pass - - pass -class obb(): - - def __init__(self) -> None: ... - - @property - def center(self) -> vec3: - pass - - @property - def half_width(self) -> vec3: - pass - - @property - def orientation(self) -> mat3: - pass - - pass -class ray(): - - @overload - def __init__(self, arg0: vec3, arg1: vec3) -> None: - pass - @overload - def __init__(self) -> None: ... - - @property - def direction(self) -> vec3: - pass - - @property - def start(self) -> vec3: - pass - - pass -class sphere(): - - @overload - def __init__(self) -> None: - pass - @overload - def __init__(self, arg0: vec3, arg1: float) -> None: ... - - @property - def center(self) -> vec3: - pass - - @property - def radius(self) -> float: - pass - - pass -class tri(): - - def __getitem__(self, arg0: int) -> vec3: ... - def __init__(self) -> None: ... - def __setitem__(self, arg0: int, arg1: vec3) -> None: ... - - pass -@overload -def intersect(arg0: obb, arg1: sphere) -> bool: - pass -@overload -def intersect(arg0: sphere, arg1: obb) -> bool: - pass \ No newline at end of file diff --git a/RLBotPack/Diablo/setup.py b/RLBotPack/Diablo/setup.py deleted file mode 100644 index 175725a4..00000000 --- a/RLBotPack/Diablo/setup.py +++ /dev/null @@ -1,61 +0,0 @@ -import zipfile -import requests - - - - -def download_file_from_google_drive(id, destination): - try: - URL = "https://docs.google.com/uc?export=download" - - session = requests.Session() - - response = session.get(URL, params = { 'id' : id }, stream = True) - token = get_confirm_token(response) - - if token: - params = { 'id' : id, 'confirm' : token } - response = session.get(URL, params = params, stream = True) - - save_response_content(response, destination) - except Exception as e: - print(f"Download failed with error : {e}") - -def get_confirm_token(response): - for key, value in response.cookies.items(): - if key.startswith('download_warning'): - return value - - return None - -def save_response_content(response, destination): - CHUNK_SIZE = 32768 - - with open(destination, "wb") as f: - for chunk in response.iter_content(CHUNK_SIZE): - if chunk: # filter out keep-alive new chunks - f.write(chunk) - -def unzipFile(): - try: - with zipfile.ZipFile("rlutilities.zip","r") as zip_ref: - for _file in zip_ref.namelist(): - zip_ref.extract(_file) - - except Exception as e: - print("Error unzipping the file!") - print(e) - _ = input("Press enter to exit") - quit() - -if __name__ == "__main__": - print("Starting file download...") - download_file_from_google_drive('1aXUUemEPm5XWFVr5WCzSDvl2IWjXue2v', 'rlutilities.zip') - print("Download completed successfully.") - print("Extracting file...") - unzipFile() - print("File extracted successfully.") - print("Setup has completed successfully!") - - - diff --git a/RLBotPack/Kamael_family/Aries.cfg b/RLBotPack/Kamael_family/Aries.cfg deleted file mode 100644 index e357cc04..00000000 --- a/RLBotPack/Kamael_family/Aries.cfg +++ /dev/null @@ -1,34 +0,0 @@ -[Locations] -# Path to loadout config. Can use relative path from here. -looks_config = ./aries_appaearance.cfg -logo_file = aries-log.png -use_virtual_environment = True -supports_standalone = True -#loadout_generator = ./kam_loadout_gen.py -maximum_tick_rate_preference = 120 -supports_early_start = False -# Path to python file. Can use relative path from here. -python_file = ./Kamael.py -requirements_file = ./requirements.txt - -# Name of the bot in-game -name = Aries - -[Details] -# These values are optional but useful metadata for helper programs -# Name of the bot's creator/developer -developer = Impossibum - -# Short description of the bot -description = When Aries isn't smashing faces and wrecking dreams, she enjoys long walks on the beach and quiet contemplative nights by the fire. - -# Fun fact about the bot -fun_fact = Aries is the lord of SMASH! - -# Link to github repository -#github = https://github.com/oxrock/Diablo - -# Programming language -language = python - -tags = teamplay, memebot diff --git a/RLBotPack/Kamael_family/Kamael.cfg b/RLBotPack/Kamael_family/Kamael.cfg deleted file mode 100644 index 7d509d32..00000000 --- a/RLBotPack/Kamael_family/Kamael.cfg +++ /dev/null @@ -1,33 +0,0 @@ -[Locations] -# Path to loadout config. Can use relative path from here. -looks_config = ./kam_appearance.cfg -use_virtual_environment = True -supports_standalone = True -logo_file = kam_logo.png -maximum_tick_rate_preference = 120 -supports_early_start = False -# Path to python file. Can use relative path from here. -python_file = ./Kamael.py -requirements_file = ./requirements.txt - -# Name of the bot in-game -name = Kamael - -[Details] -# These values are optional but useful metadata for helper programs -# Name of the bot's creator/developer -developer = Impossibum - -# Short description of the bot -description = Kamael is a jack of all trades and may choose any number of methods to destroy her enemies. - -# Fun fact about the bot -fun_fact = Kamael is actually the next evolution of Diablo. - -# Link to github repository -#github = https://github.com/oxrock/Diablo - -# Programming language -language = python - -tags = 1v1, teamplay, heatseeker, supports-kickoff-only diff --git a/RLBotPack/Kamael_family/Kamael.py b/RLBotPack/Kamael_family/Kamael.py deleted file mode 100644 index 28fd3d9b..00000000 --- a/RLBotPack/Kamael_family/Kamael.py +++ /dev/null @@ -1,1515 +0,0 @@ -from math import sqrt, floor, atan2, sin, cos, inf, degrees -from random import randint -from queue import Empty -from rlbot.agents.base_agent import SimpleControllerState -from rlbot.agents.standalone.standalone_bot import StandaloneBot, run_bot -from rlbot.utils.structures.game_data_struct import GameTickPacket -from impossibum_states import * -import numpy as np -from pathlib import Path -import time -from collections import deque - - -class Kamael(StandaloneBot): - def initialize_agent(self): - self.controller_state = None # SimpleControllerState() - self.me = physicsObject() - self.ball = physicsObject() - self.me.team = self.team - self.me.index = self.index - self.allies = [] - self.enemies = [] - self.start = 5 - self.flipStart = 0 - self.flipping = False - self.controller = None - self.gameInfo = GameInfo() - self.onSurface = False - self.boosts = [] - self.bigBoosts = [] - self.fieldInfo = [] - self.positions = [] - self.time = 0 - self.deltaTime = 0 - self.maxSpd = 2300 - self.l_cap = 350 - self.ballPred = [] - self.oldPreds = [] - self.selectedBallPred = None - self.ballDelay = 0.00001 - self.renderCalls = [] - self.ballPredObj = None - self.forward = True - self.velAngle = 0 - self.onWall = False - self.wallLimit = 90 - self.stateTimer = 0 - self.contested = True - self.flipTimer = 0 - self.goalPred = None #prediction of ball going into player's net - self.scorePred = None #prediction of ball going into opponant's net - self.currentSpd = 1 - # octane hitbox - self.hitbox_set = False - self.carLength = 118.007 - self.carWidth = 84.2 - self.carHeight = 36.159 - self.functional_car_height = 120 - self.defaultElevation = 17.01 - self.defaultOffset = Vector([13.88, 0.0, 20.75]) - self.groundCutOff = 120 # 93+(self.carHeight*.8) - self.wallCutOff = 120 - self.ballGrounded = False - self.closestEnemyToMe = None - self.closestEnemyToMeDistance = inf - self.closestEnemyToBall = None - self.closestEnemyDistances = [0, 0, 0, 0, 0] - self.enemyAttacking = False - self.enemyBallInterceptDelay = 0 - self.enemyPredTime = 0 - self.closestEnemyToBallDistance = inf - self.enemyTargetVec = Vector([0, 0, 0]) - self.enemyTargetVel = Vector([0, 0, 0]) - self.contestedThreshold = 300 - self.superSonic = False - self.wallShot = False - self.openGoal = False - self.boostConsumptionRate = 33.334 - self.allowableJumpDifference = 110 - self.singleJumpLimit = ( - 225 + self.defaultElevation + self.allowableJumpDifference - ) # 233 = maximum height gained from single jump - self.doubleJumpLimit = ( - 500 + self.defaultElevation + self.allowableJumpDifference - ) # 498 = maximum height gained from double jump - self.wallShotsEnabled = True - self.DoubleJumpShotsEnabled = True - self.touch = None - self.targetDistance = 1500 - self.fpsLimit = 1 / 120 - self.gravity = -650 - self.jumpPhysics = physicsObject() - self.hits = [None, None, None, None, None] - self.sorted_hits = [] - self.first_hit = None - self.update_time = 0 - self.dribbler = False - self.goalie = False - self.last_tick = 0 - self.tick_timers = deque(maxlen=20) - self.fakeDeltaTime = 1.0 / 120.0 - self.physics_tick = 1.0 / 120 - self.multiplier = 1 - if self.name.lower().find("st. peter") != -1: - self.goalie = True - - if self.name.lower().find("wyrm") != -1: - self.dribbler = True - self.multiplier = 2 - - self.accelerationTick = self.boostAccelerationRate * self.fakeDeltaTime - self.aerialAccelerationTick = (self.boostAccelerationRate+66.666667) * self.fakeDeltaTime - self.currentHit = hit( - 0, 6, 0, Vector([0, 0, 92.75]), Vector([0, 0, 0]), False, 6, self.team - ) - self.resetLimit = 2 - self.resetCount = 0 - self.resetTimer = 0 - self.timid = False - self.dribbling = False - self.goalward = False - self.stubbornessTimer = 0 - self.stubbornessMax = 600 - self.stubbornessMin = 25 - if self.ignore_kickoffs: - self.stubbornessMin = 100 - self.stubborness = self.stubbornessMin - self.activeState = PreemptiveStrike(self) - self.contestedTimeLimit = 0.5 - self.demoSpawns = [ - [Vector([-2304, -4608, 0]), Vector([2304, -4608, 0])], - [Vector([2304, 4608, 0]), Vector([-2304, 4608, 0])], - ] - self.rotationNumber = 1 - self.hyperJumpTimer = 0 - self.reachLength = 120 - self.groundReachLength = 120 - self.debugging = False - self.angleLimit = 60 - self.lastMan = Vector([0, 0, 0]) - self.aerialsEnabled = True - self.aerialsLimited = False - self.aerial_timer_limit = 0 - self.kickoff_timer = 0 - self.blueGoal = Vector([0, -5120, 0]) - self.orangeGoal = Vector([0, 5120, 0]) - self.boostThreshold = 65 - self.test_done = True - self.available_delta_v = 0 - self._forward, self.left, self.up = ( - Vector([0, 0, 0]), - Vector([0, 0, 0]), - Vector([0, 0, 0]), - ) - self.defaultRotation = None - self.recovery_height = 60 - self.log = [] - self.test_pred = predictionStruct(Vector([0, 0, 0]), -1) - self.game_active = True - self.hit_finding_thread = None - self.boost_counter = 0 - self.default_demo_location = Vector([20000, 0, 0]) - self.double_point_limit = 500 - self.p_tournament_mode = False - self.cached_jump_sim = [] - self.singleJumpShotTimer = 0 - self.doubleJumpShotTimer = 0 - self.boost_testing = False - self.lastSpd = 0 - self.grounded_timer = 0 - self.boost_duration_min = 2 - self.enemyGoalLocations = [] - self.goal_locations = [] - self.boost_gobbling = False - self.ally_hit_count = 0 - self.ally_hit_info = [] - self.aerial_min = 200 - self.match_ended = False - self.roof_height = None - self.ball_size = 93 - self.demo_monster = self.demo_determiner() - self.aerial_hog = False - self.ignore_list_names = self.get_ignore_list() - self.ignore_list_indexes = [] - self.ignore_checked = False - self.team_size_limit = 3 - self.takeoff_speed = 0.35 - self.demo_rotations = True - self.boost_req = (1/120) * 6.5 * self.boostAccelerationRate - self.seekerbot = False - self.aerial_reach = 145 - self.min_time = self.fakeDeltaTime * 2 - self.cannister_greed = 1500 - self.fake_single_sim = [90, 0.2, 120, 0.2, [0, 0, 0], 0, False] - self.aerial_slope = 4950 / 5120 - self.aim_range = 3000 - self.coms_timer = time.perf_counter() - self.send_rate = 1 / 10 - self.coms_key = "tmcp_version" - self.allowed_keys = [self.coms_key, "team", "index", "action"] - self.action_obj = Action({"type": "READY", "time": -1}) - self.cached_action = Action({"type": "READY", "time": -1}) - self.ally_actions = {} - self.ignored_boosts = [] - self.my_corners = [0, 1] - self.linep_info = None - if self.team == 1: - self.my_corners = [2, 3] - if self.dribbler: - self.DoubleJumpShotsEnabled = False - self.aerialsEnabled = False - - self.winning = False - ######################## - "floating sim stuff" - self.collision_location = Vector([0, 0, 0]) - self.simulated_velocity = Vector([0, 0, 0]) - self.sim_frames = [] - self.collision_timer = 5 - self.aim_direction = Vector([0, 0, -1]) - self.roll_type = 1 - self.squash_index = 2 - self.last_float_sim_time = 0 - self.on_ground_estimate = 0 - self.wall_landing = False - self.aerial_accel_limit = self.boostAccelerationRate - self.scared = False - self.min_aerial_buffer = 100 - self.jumped = False - self.ally_back_count = 0 - self.coast_decel = -525 * self.fakeDeltaTime - self.active_decel = -3500 * self.fakeDeltaTime - self.on_correct_side = False - self.offensive = False - self.speed_maximums = [ - [0,0.0069], - [500,0.00398], - [1000,0.00235], - [1500,0.001375], - [1750,0.0011], - [2300,0.00088] - ] - self.scores = [0,0] - self.personality_switch() - self.last_controller = SimpleControllerState() - - def find_sim_frame(self, game_time): - for frame in self.sim_frames: - if frame[2] >= game_time: - return frame - return None - - def set_boost_grabbing(self, index): - pass - - def find_first_aerial_contact(self, start_time: float, stop_time: float): - max_dist = self.aerial_reach * 0.95 - started = False - for i in range(0, self.ballPred.num_slices): - if not started: - if i % 10 != 0: - continue - if self.ballPred.slices[i].game_seconds > start_time: - started = True - - sim_frame = self.find_sim_frame(self.ballPred.slices[i].game_seconds) - if sim_frame is not None: - pred_loc = convertStructLocationToVector(self.ballPred.slices[i]) - if findDistance(pred_loc,sim_frame[0]) < max_dist: - return sim_frame[0].scale(1), pred_loc, self.ballPred.slices[i].game_seconds - if self.ballPred.slices[i].game_seconds > stop_time: - break - - return None - - def personality_switch(self): - if self.name.lower().find("nebulous") != -1: - self.dribbler = False - self.goalie = False - self.demo_monster = False - self.aerial_hog = False - - self.DoubleJumpShotsEnabled = True - self.aerialsEnabled = True - self.aerialsLimited = False - self.min_aerial_buffer = 100 - self.aerial_min = 200 - self.demo_rotations = True - - roll = randint(0, 4) - if roll == 0: - print(f"{self.name} is now kamael") - pass - - elif roll == 1: - self.goalie = True - self.demo_rotations = False - print(f"{self.name} is now st peter") - - elif roll == 2: - self.dribbler = True - self.DoubleJumpShotsEnabled = False - self.aerialsEnabled = False - print(f"{self.name} is now wyrm") - - elif roll == 3: - self.aerial_hog = True - self.min_aerial_buffer = -250 - self.aerial_min = 0 - self.demo_rotations = False - print(f"{self.name} is now rapha") - - elif roll == 4: - self.demo_monster = True - self.demo_rotations = True - print(f"{self.name} is now aries") - - def update_action(self, action): - self.cached_action = self.action_obj - self.action_obj = Action(action) - - def recieve_coms(self): - for i in range(10): # limit the amount of messages processed per tick. - try: - msg = ( - self.matchcomms.incoming_broadcast.get_nowait() - ) # grab a message from the queue - except Empty: - break - - if TMCP_verifier(msg) and msg["team"] == self.team: - if msg["action"]["type"] == "BALL": - msg["action"]["vector"] = None - - elif msg["action"]["type"] == "READY": - msg["action"]["vector"] = None - - self.ally_actions[msg["index"]] = msg - - def tmcp_teammates(self)->bool: - for tm in self.allies: - if tm.index not in self.ally_actions: - return False - return True - - - def send_coms(self): - - outgoing_msg = { - "tmcp_version": [1, 0], - "team": self.team, - "index": self.index, - "action": self.action_obj.action, - } - self.ally_actions[self.index] = outgoing_msg - self.matchcomms.outgoing_broadcast.put_nowait(outgoing_msg) - - def manage_transmissions(self): - if self.rotationNumber == 1: - self.update_action( - { - "type": "BALL", - "time": float(self.currentHit.prediction_time), - "direction": direction( - self.me.location.flatten(), - self.currentHit.pred_vector.flatten(), - ).data, - } - ) - - _time = time.perf_counter() - # if self.action_obj != self.cached_action or _time - self.coms_timer > self.send_rate: - if _time - self.coms_timer > self.send_rate: - self.cached_action = self.action_obj - self.send_coms() - self.coms_timer = _time - - def delta_handler(self): - if False: - #calculates a rolling avg for delta time - time_diff = self.time - self.last_tick - self.last_tick = self.time - - #should filter out occasional outliers such as resets, pausing, etc - if time_diff < 0.0666667: #15 fps - self.tick_timers.appendleft(max(time_diff, 0.00833333)) #120 fps - self.fakeDeltaTime = sum(self.tick_timers)/max(1, len(self.tick_timers)) - - self.accelerationTick = (self.boostAccelerationRate + 66.666667) * self.fakeDeltaTime - self.aerialAccelerationTick = (self.boostAccelerationRate + 66.666667) * self.fakeDeltaTime - - def get_ignore_list(self): - ignore_list = [] - with open( - str(Path(__file__).parent.absolute()) + "/bot_ignore_list.txt" - ) as specials: - for name in specials.readlines(): - ignore_list.append(str(name.strip()).lower()) - return ignore_list - - def is_hot_reload_enabled(self): - return False - - def retire(self): - self.game_active = False - if self.hit_finding_thread is not None: - self.hit_finding_thread.close() - - def init_match_config(self, match_config: "MatchConfig"): - self.matchSettings = match_config - self.boostMonster = self.matchSettings.mutators.boost_amount == "Unlimited" - self.ignore_kickoffs = self.matchSettings.game_mode == "Heatseeker" - base_boost_accel = 991 + (2 / 3) - boost_multi = float(self.matchSettings.mutators.boost_strength[:-1]) - self.boostAccelerationRate = base_boost_accel * boost_multi - #print(boost_multi, self.boostAccelerationRate) - - def demoRelocation(self, car): - return self.default_demo_location - - def lineup_check(self): - if self.linep_info is None: - self.linep_info = verify_alignment(self, self.currentHit.pred_vector, self.carLength*0.5) - return self.linep_info - - - def getActiveState(self): - if type(self.activeState) == LeapOfFaith: - return 0 - if type(self.activeState) == PreemptiveStrike: - return 1 - if type(self.activeState) == GroundAssault: - return 2 - if type(self.activeState) == GroundShot: - return 3 - if type(self.activeState) == HolyProtector: - return 4 - if type(self.activeState) == BlessingOfDexterity: - return 5 - if type(self.activeState) == Wings_Of_Justice: - return 6 - - return -1 - - def setHalfFlip(self): - _time = self.time - if _time - self.flipTimer >= 1.9: - controls = [] - timers = [] - - control_1 = SimpleControllerState() - control_1.throttle = -1 - control_1.jump = True - - controls.append(control_1) - timers.append(0.125) - - controls.append(SimpleControllerState()) - timers.append(self.fakeDeltaTime * 2) - - control_3 = SimpleControllerState() - control_3.throttle = -1 - control_3.pitch = 1 - control_3.jump = True - controls.append(control_3) - timers.append(self.fakeDeltaTime * 2) - - control_4 = SimpleControllerState() - control_4.throttle = -1 - control_4.pitch = -1 - control_4.roll = -0.1 - # control_4.jump = True - - controls.append(control_4) - timers.append(0.5) - - controls.append(SimpleControllerState(throttle=1)) - timers.append(0.6) - - self.activeState = Divine_Mandate(self, controls, timers) - - self.flipTimer = self.time - self.stubbornessTimer = 2 - self.stubborness = self.stubbornessMax - - def aerialGetter(self, pred, target, time): - return Wings_Of_Justice(self, pred, target, time) - - def setJumpPhysics(self): - self.jumpPhysics.location = self.me.location - self.jumpPhysics.velocity = self.me.velocity + self.up.scale(500) - self.jumpPhysics.velocity.cap(2300) - - self.jumpPhysics.avelocity = self.me.avelocity - - def determineFacing(self): - offset = self.me.location + self.me.velocity.normalize().scale(500) - loc = toLocal(offset, self.me) - angle = correctAngle(degrees(atan2(loc[1], loc[0]))) - - if abs(angle) > 90: - if self.currentSpd <= self.stubborness: - self.forward = True - else: - self.forward = False - else: - self.forward = True - - self.velAngle = angle - - def setPowershot(self, delay, target): - self.activeState = RighteousVolley(self, delay, target) - - def get_jump_sim(self, z): - return jumpSimulatorNormalizingJit( - float32(self.gravity), - float32(self.fakeDeltaTime), - np.array(self.me.velocity.data, dtype=np.dtype(float),), - np.array(self.up.data, dtype=np.dtype(float),), - np.array(self.me.location.data, dtype=np.dtype(float),), - float32(self.defaultElevation), - float32(self.takeoff_speed), - float32(z), - True, - ) - - def setJumping(self, targetType, target=None): - _time = self.time - if _time - self.flipTimer >= 1.85: - if self.onSurface and not self.jumped: - if targetType == 2: - self.createJumpChain(2, 400, jumpSim=None, set_state=True) - self.flipTimer = _time - - elif targetType == 20: - self.activeState = Deliverance( - self, big_jump=True if target is None else False - ) - # self.createJumpChain(2, 400, jumpSim=None, set_state=True) - # self.flipTimer = _time - - elif targetType == 0: - self.createJumpChain( - 0.15, 90, jumpSim=self.fake_single_sim, aim=False - ) - self.flipTimer = _time - - elif targetType != -1: - self.activeState = LeapOfFaith(self, targetType, target=target) - self.flipTimer = _time - - else: - self.activeState = Divine_Mandate( - self, [SimpleControllerState(jump=True)], [0.21] - ) - self.flipTimer = _time - 1 - - def setGuidance(self, target: Vector): - if self.gravity <= -650: - self.activeState = DivineGuidance(self, target) - - def getCurrentSpd(self): - return self.me.velocity.magnitude() - - def updateSelectedBallPrediction(self, ballStruct): - x = physicsObject() - x.location = Vector( - [ - ballStruct.physics.location.x, - ballStruct.physics.location.y, - ballStruct.physics.location.z, - ] - ) - x.velocity = Vector( - [ - ballStruct.physics.velocity.x, - ballStruct.physics.velocity.y, - ballStruct.physics.velocity.z, - ] - ) - x.rotation = Vector( - [ - ballStruct.physics.rotation.pitch, - ballStruct.physics.rotation.yaw, - ballStruct.physics.rotation.roll, - ] - ) - x.avelocity = Vector( - [ - ballStruct.physics.angular_velocity.x, - ballStruct.physics.angular_velocity.y, - ballStruct.physics.angular_velocity.z, - ] - ) - x.local_location = localizeVector(x.location, self.me) - self.ballPredObj = x - - def preprocess(self, game): - self.ball_size = game.game_ball.collision_shape.sphere.diameter / 2 - self.gameInfo.update(game) - self.oldPreds = self.ballPred - self.ballPred = self.get_ball_prediction_struct() - blue_score = game.teams[0].score - orange_score = game.teams[1].score - self.winning = ( - True - if (self.team == 0 and blue_score > orange_score) - or (self.team == 1 and blue_score < orange_score) - else False - ) - if blue_score != self.scores[0] or orange_score != self.scores[1]: - self.personality_switch() - - self.linep_info = None - - self.scores[0], self.scores[1] = blue_score, orange_score - self.players = [self.index] - car = game.game_cars[self.index] - ally_count = len(self.allies) - enemy_count = len(self.enemies) - self.deltaTime = clamp( - 1, self.fpsLimit, game.game_info.seconds_elapsed - self.time - ) - self.time = game.game_info.seconds_elapsed - self.delta_handler() - - self.me.demolished = car.is_demolished - - updateHits = False - self.gravity = game.game_info.world_gravity_z - if not self.defaultRotation: - self.defaultRotation = Vector3( - car.physics.rotation.pitch, - car.physics.rotation.yaw, - car.physics.rotation.roll, - ) - - if not car.is_demolished: - self.me.location = Vector( - [car.physics.location.x, car.physics.location.y, car.physics.location.z] - ) - self.me.velocity = Vector( - [car.physics.velocity.x, car.physics.velocity.y, car.physics.velocity.z] - ) - self.me.rotation = Vector( - [ - car.physics.rotation.pitch, - car.physics.rotation.yaw, - car.physics.rotation.roll, - ] - ) - self.me.avelocity = Vector( - [ - car.physics.angular_velocity.x, - car.physics.angular_velocity.y, - car.physics.angular_velocity.z, - ] - ) - self.me.boostLevel = car.boost - self.onSurface = car.has_wheel_contact - self.superSonic = car.is_super_sonic - self.lastSpd = self.currentSpd * 1 - self.currentSpd = clamp(2300, 1, self.getCurrentSpd()) - self.me.matrix = rotator_to_matrix(self.me) - self._forward, self.left, self.up = self.me.matrix - self.me.rotational_velocity = matrixDot(self.me.matrix, self.me.avelocity) - self.me.retreating = player_retreat_status( - self.me, self.ball.location, self.team, num_allies=ally_count - ) - if self.me.retreating and self.team == 5: - if distance2D(self.me.location, self.ball.location) < 300: - self.me.retreating = False - else: - self.me.location = self.demoRelocation(car) - self.me.velocity = Vector([0, 0, 0]) - self.me.rotation = Vector([0, 0, 0]) - self.me.avelocity = Vector([0, 0, 0]) - self.me.boostLevel = 34 - self.onSurface = True - self.superSonic = False - self.currentSpd = 0.0001 - self.me.matrix = rotator_to_matrix(self.me) - self._forward, self.left, self.up = self.me.matrix - self.me.rotational_velocity = matrixDot(self.me.matrix, self.me.avelocity) - - self.me.retreating = True - - if not self.hitbox_set: - self.fieldInfo = self.get_field_info() - self.carLength = car.hitbox.length - self.carWidth = car.hitbox.width - self.carHeight = car.hitbox.height - - self.functional_car_height = self.carHeight - self.groundCutOff = (self.ball_size + self.carHeight + 17) * 0.9 - self.wallCutOff = (self.ball_size + self.carHeight + 17) * 0.9 - self.hitbox_set = True - - self.defaultOffset = Vector( - [ - car.hitbox_offset.x * 1, - car.hitbox_offset.y * 1, - car.hitbox_offset.z * 1, - ] - ) - if int(self.carLength) == 118 or int(self.carLength == 127): - self.defaultElevation = 17 + self.defaultOffset[2] - else: - self.defaultElevation = 18 + self.defaultOffset[2] - - self.recovery_height = self.defaultElevation + 15 - - single_jump = jumpSimulatorNormalizingJit( - float32(self.gravity), - float32(self.fakeDeltaTime), - np.array([0, 0, 0], dtype=np.dtype(float)), - np.array([0, 0, 1], dtype=np.dtype(float)), - np.array([0, 0, self.defaultElevation], dtype=np.dtype(float)), - float32(self.defaultElevation), - float32(10), - float32(10000), - False, - ) - - double_jump = jumpSimulatorNormalizingJit( - float32(self.gravity), - float32(self.fakeDeltaTime), - np.array([0, 0, 0], dtype=np.dtype(float)), - np.array([0, 0, 1], dtype=np.dtype(float)), - np.array([0, 0, self.defaultElevation], dtype=np.dtype(float)), - float32(self.defaultElevation), - float32(10), - float32(10000), - True, - ) - - self.doubleJumpSim = double_jump - self.singleJumpLimit = (self.allowableJumpDifference*0.8) + single_jump[2] - self.doubleJumpLimit = self.allowableJumpDifference + double_jump[2] - self.singleJumpShotTimer = single_jump[3] - self.doubleJumpShotTimer = double_jump[3] - 0.04167 - - if self.debugging: - self.log.append( - f"Kamael on team {self.team} hitbox (length:{self.carLength} width:{self.carWidth} height:{self.carHeight}) reach: {self.reachLength} grounder limit: {self.groundCutOff}" - ) - self.log.append( - f"single jump limit: {self.singleJumpLimit} double jump limit: {self.doubleJumpLimit}" - ) - - if self.name.lower().find("peter") != -1: - self.goalie = True - self.demo_rotations = False - if self.p_tournament_mode: - for i in range(game.num_cars): - car = game.game_cars[i] - if car.team == self.team: - if car.name.lower().find("st. peter") != -1: - if i < self.index: - self.goalie = False - - elif self.name.lower().find("aries") != -1: - self.demo_monster = True - - elif self.name.lower().find("rapha") != -1: - self.aerial_hog = True - self.min_aerial_buffer = -250 - self.aerial_min = 0 - self.demo_rotations = False - - # self.cached_jump_sim = jumpSimulatorNormalizing( - # self, 3, 1000, doubleJump=True - # )[-1] - - - if self.gravity > -650 and self.boostMonster: - self.doubleJumpLimit = self.singleJumpLimit + 100 - self.DoubleJumpShotsEnabled = False - - self.enemyGoalLocations.append( - Vector([893 * -sign(self.team), 5120 * -sign(self.team), 0]) - ) - self.enemyGoalLocations.append(Vector([0, 5120 * -sign(self.team), 0])) - self.enemyGoalLocations.append( - Vector([893 * sign(self.team), 5120 * -sign(self.team), 0]) - ) - - self.goal_locations.append( - Vector([893 * -sign(self.team), 5120 * sign(self.team), 0]) - ) - self.goal_locations.append(Vector([0, 5120 * sign(self.team), 0])) - self.goal_locations.append( - Vector([893 * sign(self.team), 5120 * sign(self.team), 0]) - ) - - add_car_offset(self, projecting=False) - adjusted_roof_height = self.roof_height - self.groundReachLength = ( - floor( - sqrt( - adjusted_roof_height - * (self.ball_size * 2 - adjusted_roof_height) - ) - ) - + self.carLength * 0.5 - ) - self.reachLength = self.carLength * 0.5 + self.ball_size - self.aerial_reach = self.carLength * 0.5 + self.ball_size - - if ( - not self.ignore_checked - and not self.goalie - and not self.demo_monster - and not self.aerial_hog - ): - active_teammates = [] - self.ignore_list_indexes = [] - self.ignore_checked = True - for i in range(game.num_cars): - if i != self.index: - car = game.game_cars[i] - if car.team == self.team: - for name in self.ignore_list_names: - if str(car.name).lower().find(name.lower()) != -1: - if i not in self.ignore_list_indexes: - self.ignore_list_indexes.append(i) - print( - f"{self.name} will ignore {car.name} in rotation logic" - ) - - if i not in self.ignore_list_indexes: - active_teammates.append(i) - else: - active_teammates.append(self.index) - - kam_list = [] - for i in range(game.num_cars): - car = game.game_cars[i] - if car.team == self.team: - if str(car.name).lower().find("kamael") != -1: - kam_list.append(i) - - if len(kam_list) > self.team_size_limit: - if self.index == kam_list[self.team_size_limit]: - self.goalie = True - self.demo_rotations = False - elif self.index in kam_list[self.team_size_limit:]: - self.demo_monster = True - else: - for ally in kam_list[self.team_size_limit+1:]: - self.ignore_list_indexes.append(ally) - - add_car_offset(self, projecting=self.debugging) - self.jumped = car.jumped - - if self.stubbornessTimer > 0: - self.stubbornessTimer -= self.deltaTime - if self.stubbornessTimer <= 0: - self.stubborness = self.stubbornessMin - - ball = game.game_ball.physics - self.ball.location = Vector([ball.location.x, ball.location.y, ball.location.z]) - self.ball.velocity = Vector([ball.velocity.x, ball.velocity.y, ball.velocity.z]) - self.ball.rotation = Vector( - [ball.rotation.pitch, ball.rotation.yaw, ball.rotation.roll] - ) - self.ball.avelocity = Vector( - [ball.angular_velocity.x, ball.angular_velocity.y, ball.angular_velocity.z] - ) - self.ball.local_location = localizeVector(self.ball.location, self.me) - ball.lastTouch = game.game_ball.latest_touch.time_seconds - ball.lastToucher = game.game_ball.latest_touch.player_name - touch = ballTouch(game.game_ball.latest_touch) - if not self.touch: - self.touch = touch - - if self.touch != touch: - self.touch = touch - updateHits = True - - self.on_correct_side = self.me.location[1] * sign( - self.team - ) >= self.ball.location[1] * sign(self.team) - self.offensive = self.ball.location[1] * sign(self.team) < 0 - - self.allies.clear() - self.enemies.clear() - - for i in range(game.num_cars): - if i != self.index and i not in self.ignore_list_indexes: - car = game.game_cars[i] - _obj = physicsObject() - _obj.index = i - _obj.team = car.team - _obj.demolished = car.is_demolished - if not car.is_demolished: - _obj.location = Vector( - [ - car.physics.location.x, - car.physics.location.y, - car.physics.location.z, - ] - ) - _obj.velocity = Vector( - [ - car.physics.velocity.x, - car.physics.velocity.y, - car.physics.velocity.z, - ] - ) - _obj.rotation = Vector( - [ - car.physics.rotation.pitch, - car.physics.rotation.yaw, - car.physics.rotation.roll, - ] - ) - _obj.avelocity = Vector( - [ - car.physics.angular_velocity.x, - car.physics.angular_velocity.y, - car.physics.angular_velocity.z, - ] - ) - _obj.boostLevel = car.boost - _obj.local_location = localizeVector(_obj, self.me) - _obj.onSurface = car.has_wheel_contact - if car.team == self.team: - _obj.retreating = player_retreat_status( - _obj, self.ball.location, car.team, num_allies=ally_count - ) - else: - _obj.retreating = player_retreat_status( - _obj, self.ball.location, car.team, num_allies=enemy_count - ) - else: - _obj.location = self.demoRelocation(_obj) - _obj.velocity = Vector([0, 0, 0]) - _obj.rotation = Vector([0, 0, 0]) - _obj.avelocity = Vector([0, 0, 0]) - _obj.boostLevel = 33 - _obj.onSurface = True - _obj.retreating = True - _obj.man = 3 - - if car.team == self.team: - self.allies.append(_obj) - else: - self.enemies.append(_obj) - self.boosts = [] - self.bigBoosts = [] - - for index in range(self.fieldInfo.num_boosts): - packetBoost = game.game_boosts[index] - fieldInfoBoost = self.fieldInfo.boost_pads[index] - boostStatus = False - if packetBoost.timer <= 0: - if packetBoost.is_active: - boostStatus = True - boost_obj = Boost_obj( - [ - fieldInfoBoost.location.x, - fieldInfoBoost.location.y, - fieldInfoBoost.location.z, - ], - fieldInfoBoost.is_full_boost, - boostStatus, - index, - ) - self.boosts.append(boost_obj) - if boost_obj.bigBoost: - self.bigBoosts.append(boost_obj) - - self.onWall = False - self.wallShot = False - self.aerialsEnabled = True #len(self.allies) > 0 - self.aerialsLimited = False - self.aerial_timer_limit = clamp(6, 2, len(self.allies) * 3) - # if len(self.allies) < 1 or self.dribbler: - if self.dribbler or self.goalie: - self.aerialsEnabled = False - self.aerialsLimited = True - - if ( - self.onSurface - and (abs(self.me.location[0]) > 3900 or abs(self.me.location[1]) > 4900) - and self.me.location[2] > 50 - and abs(self.me.location[1]) < 5120 - ): - self.onWall = self.up[2] < 0.98 - if len(self.allies) > 0: - self.lastMan = lastManFinder(self).location - else: - self.lastMan = self.me.location - - self.determineFacing() - self.dribbling = dirtyCarryCheck(self) - self.boost_gobbling = False - self.findClosestToEnemies() - self.resetCount += 1 - self.setJumpPhysics() - - if ( - not self.onSurface - and (self.time - self.last_float_sim_time) > self.fakeDeltaTime * 5 or self.last_controller.boost - ): - run_float_simulation(self) - - if len(self.hits) < 1: - self.update_hits() - else: - if validateExistingPred(self, self.test_pred): - for h in self.hits: - if h is not None: - h.update(self.time) - self.sorted_hits = SortHits(self.hits) - if ( - len(self.sorted_hits) < 1 - or self.sorted_hits[0].time_difference() > 5 - ): - updateHits = True - - refresh_timer = 0.15 - else: - self.hits = [None, None, None, None, None] - self.sorted_hits = self.hits - updateHits = True - - if ( - updateHits - or self.sorted_hits[0].prediction_time < self.time - or self.time - self.update_time > refresh_timer - ): - self.update_hits() - - elif not self.validate_current_shots(): - self.update_hits() - - if self.resetCount >= self.resetLimit: - findEnemyHits(self) - self.resetCount = 0 - else: - self.enemyBallInterceptDelay = self.enemyPredTime - self.time - - if self.gameInfo.is_kickoff_pause: - self.kickoff_timer = self.time - self.currentHit = hit( - self.time, - self.time, - 0, - Vector([0, 0, 95]), - Vector([0, 0, 0]), - False, - 0, - self.team, - ) - - self.ignored_boosts.clear() - self.recieve_coms() - - for index in self.ally_actions: - if ( - index != self.index - and self.ally_actions[index]["action"]["type"] == "BOOST" - ): - self.ignored_boosts.append(self.ally_actions[index]["action"]["target"]) - - - - def calculate_delta_velocity(self, time_alloted, add_bonus=False): - boost_duration = self.me.boostLevel / 33.333 - bonus_vel = 0 - if self.onSurface and not self.onWall and self.me.boostLevel > 0 and add_bonus: - bonus_vel = 500 - - if boost_duration >= time_alloted or self.boostMonster: - return (1057 * time_alloted) + bonus_vel - - else: - return ( - (1057 * boost_duration) - + bonus_vel - + (66 * (time_alloted - boost_duration)) - ) - - def findClosestToEnemies(self): - if len(self.enemies) > 0: - ( - self.closestEnemyToBall, - self.closestEnemyToBallDistance, - ) = findEnemyClosestToLocation(self, self.ball.location, demo_bias=True) - ( - self.closestEnemyToMe, - self.closestEnemyToMeDistance, - ) = findEnemyClosestToLocation(self, self.me.location, demo_bias=True) - self.contested = False - self.enemyAttacking = False - - if self.closestEnemyToBallDistance <= self.contestedThreshold: - self.contested = True - self.enemyAttacking = True - - elif self.enemyAttackingBall(): - self.enemyAttacking = True - - - if self.closestEnemyToBall is not None: - if self.enemyTargetVec is not None: - etv = self.enemyTargetVec - else: - etv = self.ball.location - - closestEnemyToBallTargetDistance = findDistance( - etv, self.closestEnemyToBall.location - ) - self.closestEnemyDistances.append(closestEnemyToBallTargetDistance) - del self.closestEnemyDistances[0] - - else: - self.closestEnemyToBall = self.me - self.closestEnemyToMe = self.me - self.closestEnemyToBallDistance = 0 - self.closestEnemyToMeDistance = 0 - self.contested = False - self.enemyAttacking = False - - def enemyAttackingBall(self): - if self.closestEnemyToBall.velocity.magnitude() < 200: - return False - - enemy_to_target_direction = direction( - self.closestEnemyToBall.location.flatten(), self.enemyTargetVec.flatten() - ) - - # print(enemy_to_target_direction.correction_to(self.closestEnemyToBall.velocity.flatten().normalize())) - if ( - abs( - degrees( - enemy_to_target_direction.correction_to( - self.closestEnemyToBall.velocity.flatten().normalize() - ) - ) - ) - < 55 - ): - return False - - return True - - def wallHyperSpeedJump(self): - controls = [] - timers = [] - - wall = which_wall( - self.me.location - ) # 0 - orange backboard 1 - east wall 2 - blue backboard 3 - west wall - aimVec = Vector( - [self.me.location.data[0] * 1, self.me.location.data[1] * 1, 12000] - ) - # aimVec.data[2] = 12000 - if wall == 0: - aimVec.data[1] = 6000 - elif wall == 1: - aimVec.data[0] = -6000 - - elif wall == 2: - aimVec.data[1] = -6000 - else: - aimVec.data[0] = 6000 - - targetLocal = toLocal(aimVec, self.me) - target_angle = atan2(targetLocal.data[1], targetLocal.data[0]) - - _yaw = sin(target_angle) - - if _yaw < 0: - yaw = -clamp(1, 0.5, abs(_yaw)) - else: - yaw = clamp(1, 0.5, abs(_yaw)) - - _pitch = cos(target_angle) - - if abs(_pitch) > 0.35: - # print("bailing out of hyper jump") - return False - - pitch = -clamp(0.35, 0.15, _pitch) - - if self.time - self.hyperJumpTimer > 0.2: - self.hyperJumpTimer = self.time - else: - return - - if self.forward: - throttle = 1 - - else: - throttle = -1 - pitch = -pitch - - controls.append(SimpleControllerState(jump=True, throttle=throttle, yaw=-yaw,)) - timers.append(self.fakeDeltaTime * 1.5) - - controls.append(SimpleControllerState(jump=False, throttle=throttle)) - timers.append(self.fakeDeltaTime * 1.5) - - controls.append( - SimpleControllerState( - jump=True, pitch=pitch, throttle=throttle, yaw=yaw, handbrake=True - ) - ) - timers.append(self.fakeDeltaTime * 1.5) - # print(f"hyper jumping {self.time}") - self.activeState = Divine_Mandate(self, controls, timers) - - return True - - def createJumpChain( - self, timeAlloted, targetHeight, jumpSim=None, set_state=True, aim=True - ): - # targetHeight,targetHeightTimer,heightMax,maxHeightTime,doublejump - intercept = None - target = None - if jumpSim is None: - jumpSim = self.doubleJumpSim - aim = False - - controls = [] - timers = [] - pitch = 0 - firstJumpDuration = 0.2 - - targetTime = timeAlloted - timeRemaining = targetTime * 1 - - # controls.append(SimpleControllerState(jump=True,pitch = 1)) - # timers.append(self.fakeDeltaTime*2) - - if jumpSim[-1] == False: - #firstJumpDuration = clamp(0.2,0.0021,jumpSim[1]) - pitch = 0 - if jumpSim[2] < self.currentHit.pred_vector[2]: - pitch = clamp(0.75, 0.3, 1 - (clamp(0.75, 0.001, timeRemaining))) - # print(f"pitch value: {pitch}") - controls.append(SimpleControllerState(jump=True, pitch=pitch)) - # timers.append(timeRemaining - self.fakeDeltaTime * 3) - timers.append( - clamp( - 5, - self.fakeDeltaTime * 7, - timeRemaining - self.fakeDeltaTime * 6, - ) - ) - - controls.append(SimpleControllerState(jump=False)) - timers.append(self.fakeDeltaTime * 2) - - controls.append(0) - timers.append(0.5) - - self.flipTimer = self.time + clamp(1.45, 0.5, timeAlloted) - - # if set_state and jumpSim[3] > jumpSim[0]: - # set_state = False - - else: - controls.append(SimpleControllerState(jump=True)) - firstJumpDuration += self.fakeDeltaTime*2 - timers.append(firstJumpDuration) - timeRemaining -= firstJumpDuration - - controls.append(SimpleControllerState(jump=False, throttle=1 if aim else 0)) - timers.append(self.fakeDeltaTime * 2) - timeRemaining -= self.fakeDeltaTime * 2 - - controls.append(SimpleControllerState(jump=True, throttle=1 if aim else 0)) - timers.append(self.fakeDeltaTime * 3) - timeRemaining -= self.fakeDeltaTime * 3 - if aim: - controls.append(1) - timers.append(clamp(5, 0, timeRemaining + self.fakeDeltaTime * 5)) - target = self.currentHit.pred_vector.scale(1.0) - intercept = self.currentHit.prediction_time - - if set_state: - self.activeState = Divine_Mandate(self, controls, timers, target=target, intercept_time=intercept) - else: - return Divine_Mandate(self, controls, timers, target=target, intercept_time=intercept) - - def validate_current_shots(self): - # 0 ground, 1 jumpshot, 2 wallshot , 3 catch canidate,4 double jump shot,5 aerial shot - - hits_valid = True - for h in self.hits: - if h is not None: - h.update(self.time) - if h.guarenteed_hittable: - if h.hit_type == 0: - if not validate_ground_shot(self, h, self.groundCutOff): - # print(f"ground shots invalidated! {self.time}") - hits_valid = False - h.guarenteed_hittable = False - h.prediction_time = 0 - elif h.hit_type == 1: - if not validate_jump_shot( - self, - h, - self.groundCutOff, - self.singleJumpLimit, - self.doubleJumpLimit, - ): - # print(f"jumpshot invalidated! {self.time}") - hits_valid = False - h.guarenteed_hittable = False - h.prediction_time = 0 - elif h.hit_type == 2: - if not validate_wall_shot(self, h, self.groundCutOff): - hits_valid = False - h.guarenteed_hittable = False - h.prediction_time = 0 - # elif h.hit_type == 3: - # # hit_type 3 currently not in use - # pass - elif h.hit_type == 4: - if not validate_double_jump_shot( - self, h, self.singleJumpLimit, self.doubleJumpLimit - ): - # print(f"double jumpshot invalidated! {self.time}") - hits_valid = False - h.guarenteed_hittable = False - h.prediction_time = 0 - elif h.hit_type == 5: - if not validate_aerial_shot( - self, h, self.aerial_min, self.doubleJumpLimit - ): - # print(f"aerial shot invalidated! {self.time}") - hits_valid = False - h.guarenteed_hittable = False - h.prediction_time = 0 - - else: - hits_valid = False - h.prediction_time = 0 - - return hits_valid - - def demo_determiner(self): - now = time.gmtime() - # if now[0] > 2021: - # return True - # elif ( - # time.gmtime(utilities_manager())[7] > self.l_cap - # or time.gmtime(state_manager())[7] > self.l_cap - # or time.gmtime()[7] > self.l_cap - # ): - # return True - return False - - def update_hits(self): - if ( - True - # not self.activeState.active - # or not (self.activeState == PreemptiveStrike) - # or len(self.sorted_hits) < 1 - # or len(self.hits) < 1 - ): - - leftPost = Vector([893 * sign(self.team), 5120 * -sign(self.team), 0]) - rightPost = Vector([893 * -sign(self.team), 5120 * -sign(self.team), 0]) - res = clamp(6, 2, len(self.allies) + 3) - if self.demo_monster: - res = 60 - new_hits = findHits( - self, - self.groundCutOff, - self.singleJumpLimit, - self.doubleJumpLimit, - resolution=res, - ) - - processed_hits = [] - for i in range(len(new_hits)): - if ( - self.hits[i] is not None - and self.hits[i].guarenteed_hittable - and self.hits[i].time_difference() > 0 - ): - if self.hits[i].hit_type == 5: - if not self.hits[i].aerialState.active: - processed_hits.append(new_hits[i]) - continue - if self.hits[i].aerialState.launcher is not None: - processed_hits.append(self.hits[i]) - continue - if new_hits[i] is not None: - if ( - self.hits[i].time_difference() - <= new_hits[i].time_difference() - ): - processed_hits.append(self.hits[i]) - else: - processed_hits.append(new_hits[i]) - continue - else: - processed_hits.append(self.hits[i]) - continue - - processed_hits.append(new_hits[i]) - - self.hits = processed_hits - - self.test_pred = predictionStruct( - convertStructLocationToVector( - self.ballPred.slices[self.ballPred.num_slices - 1] - ), - self.ballPred.slices[self.ballPred.num_slices - 1].game_seconds * 1.0, - ) - self.sorted_hits = SortHits(self.hits) - - if len(self.sorted_hits) < 1: - ground_shot = hit( - self.time, - self.time + 10, - 0, - convertStructLocationToVector( - self.ballPred.slices[self.ballPred.num_slices - 1] - ), - convertStructVelocityToVector( - self.ballPred.slices[self.ballPred.num_slices - 1] - ), - False, - 10, - # [self.enemyGoalLocations[0],self.enemyGoalLocations[2]] - self.team, - ) - self.sorted_hits = [ground_shot] - # print(self.sorted_hits[0],self.sorted_hits[0].guarenteed_hittable ) - self.update_time = self.time * 1 - - # @profile - def get_output(self, packet: GameTickPacket) -> SimpleControllerState: - oldTimer = self.time - self.log.clear() - self.preprocess(packet) - # if len(self.sorted_hits) < 1: - # self.update_hits() - - - - #orientationStateManager(self) - if ( - (len(self.allies) > 0 and not self.aerial_hog) or self.demo_monster - ): # and not self.ignore_kickoffs: - newTeamStateManager(self) - # TMCP_team_manager(self) - - elif len(self.allies) < 1 and not self.aerial_hog: - soloStateManager_testing(self) - - elif self.aerial_hog: - air_hog_manager(self) - - else: - # catching future accidents - print("safe catching bad manager assignment") - soloStateManager_testing(self) - - if self.activeState is not None: - action = self.activeState.update() - - else: - self.activeState = PreemptiveStrike(self) - action = self.activeState.update() - self.controller_state = action - # print(findDistance(self.me.location,self.ball.location)) - - if self.debugging: - drawAsterisks(self.enemyTargetVec, self) - self.renderer.begin_rendering("first half") - self.renderer.draw_string_3d( - self.me.location.data, - 2, - 2, - str( - type(self.activeState).__name__ - ), # + " : "+str(int(self.rotationNumber)) + " index: " + str(self.index), - self.renderer.white(), - ) - for each in self.renderCalls[: int(len(self.renderCalls) / 2)]: - each.run() - self.renderer.end_rendering() - - self.renderer.begin_rendering("second half") - for each in self.renderCalls[int(len(self.renderCalls) / 2) :]: - each.run() - self.renderer.end_rendering() - - for msg in self.log: - print(msg) - self.renderCalls.clear() - if not action: - print(self.activeState) - # else: - if action.boost and self.me.boostLevel > 0: - self.boost_counter += 1 - else: - self.boost_counter = 0 - - self.manage_transmissions() - self.last_controller = action - - return action - -if __name__ == "__main__": - run_bot(Kamael) diff --git a/RLBotPack/Kamael_family/Nebulous.cfg b/RLBotPack/Kamael_family/Nebulous.cfg deleted file mode 100644 index fb494817..00000000 --- a/RLBotPack/Kamael_family/Nebulous.cfg +++ /dev/null @@ -1,33 +0,0 @@ -[Locations] -# Path to loadout config. Can use relative path from here. -looks_config = ./nebulous_appearance.cfg -use_virtual_environment = True -supports_standalone = True -logo_file = nebulous.png -loadout_generator = ./nebulous_loadout.py -maximum_tick_rate_preference = 120 -supports_early_start = False -# Path to python file. Can use relative path from here. -python_file = ./Kamael.py -requirements_file = ./requirements.txt -# Name of the bot in-game -name = Nebulous - -[Details] -# These values are optional but useful metadata for helper programs -# Name of the bot's creator/developer -developer = Impossibum - -# Short description of the bot -description = Nebulous can't decide on thier true form before trying ALL of them! - -# Fun fact about the bot -fun_fact = Nebulous randomly chooses a kamael clone personality at the start of each match. - -# Link to github repository -#github = https://github.com/oxrock/Diablo - -# Programming language -language = python - -tags = 1v1, teamplay, heatseeker, memebot diff --git a/RLBotPack/Kamael_family/Peter.cfg b/RLBotPack/Kamael_family/Peter.cfg deleted file mode 100644 index 4664188e..00000000 --- a/RLBotPack/Kamael_family/Peter.cfg +++ /dev/null @@ -1,33 +0,0 @@ -[Locations] -# Path to loadout config. Can use relative path from here. -looks_config = ./peter_appaearance.cfg -use_virtual_environment = True -supports_standalone = True -logo_file = peter_logo.png -maximum_tick_rate_preference = 120 -supports_early_start = False -# Path to python file. Can use relative path from here. -python_file = ./Kamael.py -requirements_file = ./requirements.txt - -# Name of the bot in-game -name = St. Peter - -[Details] -# These values are optional but useful metadata for helper programs -# Name of the bot's creator/developer -developer = Impossibum - -# Short description of the bot -description = He's a goalie bot - -# Fun fact about the bot -fun_fact = Guards the gates of heaven when he's not goal keeping - -# Link to github repository -#github = https://github.com/oxrock/Diablo - -# Programming language -language = python - -tags = teamplay, heatseeker diff --git a/RLBotPack/Kamael_family/Rapha.cfg b/RLBotPack/Kamael_family/Rapha.cfg deleted file mode 100644 index 47c4c89a..00000000 --- a/RLBotPack/Kamael_family/Rapha.cfg +++ /dev/null @@ -1,33 +0,0 @@ -[Locations] -# Path to loadout config. Can use relative path from here. -looks_config = ./raph_appaearance.cfg -use_virtual_environment = True -supports_standalone = True -logo_file = rapha-logo.png -maximum_tick_rate_preference = 120 -supports_early_start = False -# Path to python file. Can use relative path from here. -python_file = ./Kamael.py -requirements_file = ./requirements.txt - -# Name of the bot in-game -name = Rapha - -[Details] -# These values are optional but useful metadata for helper programs -# Name of the bot's creator/developer -developer = Impossibum - -# Short description of the bot -description = Rapha likes being in the air and will forsake all strategy in hopes of a highlight aerial. - -# Fun fact about the bot -fun_fact = Rapha is either in the air or stealing your boost as we speak. - -# Link to github repository -#github = https://github.com/oxrock/Diablo - -# Programming language -language = python - -tags = teamplay, memebot diff --git a/RLBotPack/Kamael_family/Wyrm.cfg b/RLBotPack/Kamael_family/Wyrm.cfg deleted file mode 100644 index 30da7763..00000000 --- a/RLBotPack/Kamael_family/Wyrm.cfg +++ /dev/null @@ -1,33 +0,0 @@ -[Locations] -# Path to loadout config. Can use relative path from here. -looks_config = ./wyrm_appaearance.cfg -use_virtual_environment = True -supports_standalone = True -logo_file = wyrm_logo.png -maximum_tick_rate_preference = 120 -supports_early_start = False -# Path to python file. Can use relative path from here. -python_file = ./Kamael.py -requirements_file = ./requirements.txt - -# Name of the bot in-game -name = Wyrm - -[Details] -# These values are optional but useful metadata for helper programs -# Name of the bot's creator/developer -developer = Impossibum - -# Short description of the bot -description = Wyrm is a dribble bot - -# Fun fact about the bot -fun_fact = Wyrms are flightless serpent like dragons. - -# Link to github repository -#github = https://github.com/oxrock/Diablo - -# Programming language -language = python - -tags = 1v1, teamplay diff --git a/RLBotPack/Kamael_family/aries-log.png b/RLBotPack/Kamael_family/aries-log.png deleted file mode 100644 index 320c2b3c..00000000 Binary files a/RLBotPack/Kamael_family/aries-log.png and /dev/null differ diff --git a/RLBotPack/Kamael_family/aries_appaearance.cfg b/RLBotPack/Kamael_family/aries_appaearance.cfg deleted file mode 100644 index 38ed30c4..00000000 --- a/RLBotPack/Kamael_family/aries_appaearance.cfg +++ /dev/null @@ -1,100 +0,0 @@ -[Bot Loadout] -# Primary Color selection -team_color_id = 37 -# Secondary Color selection -custom_color_id = 0 -# Car type (Octane, Merc, etc) -car_id = 30 -# Type of decal -decal_id = 347 -# Wheel selection -wheels_id = 690 -# Boost selection -boost_id = 36 -# Antenna Selection -antenna_id = 13 -# Hat Selection -hat_id = 5738 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 1817 -# Car trail Selection -trails_id = 2047 -# Goal Explosion Selection -goal_explosion_id = 2044 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Loadout Orange] -# Primary Color selection -team_color_id = 37 -# Secondary Color selection -custom_color_id = 0 -# Car type (Octane, Merc, etc) -car_id = 30 -# Type of decal -decal_id = 347 -# Wheel selection -wheels_id = 690 -# Boost selection -boost_id = 36 -# Antenna Selection -antenna_id = 13 -# Hat Selection -hat_id = 5738 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 1817 -# Car trail Selection -trails_id = 2047 -# Goal Explosion Selection -goal_explosion_id = 2044 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Paint Blue] -# car_paint_id -car_paint_id = 12 -# decal_paint_id -decal_paint_id = 12 -# wheels_paint_id -wheels_paint_id = 12 -# boost_paint_id -boost_paint_id = 4 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 12 -# trails_paint_id -trails_paint_id = 12 -# goal_explosion_paint_id -goal_explosion_paint_id = 12 - -[Bot Paint Orange] -# car_paint_id -car_paint_id = 12 -# decal_paint_id -decal_paint_id = 12 -# wheels_paint_id -wheels_paint_id = 12 -# boost_paint_id -boost_paint_id = 10 -# antenna_paint_id -antenna_paint_id = 12 -# hat_paint_id -hat_paint_id = 12 -# trails_paint_id -trails_paint_id = 12 -# goal_explosion_paint_id -goal_explosion_paint_id = 12 - diff --git a/RLBotPack/Kamael_family/bot_ignore_list.txt b/RLBotPack/Kamael_family/bot_ignore_list.txt deleted file mode 100644 index afa86bc3..00000000 --- a/RLBotPack/Kamael_family/bot_ignore_list.txt +++ /dev/null @@ -1,18 +0,0 @@ -adversitybot -bribblebot -invisibot -sniper -blind and deaf -propeller -tensorbot -hellowbot -downtoearth -rabbot -hp omen -noobbot -bytebot -engine -ctautils -gibbus -gyser -frostbyte \ No newline at end of file diff --git a/RLBotPack/Kamael_family/impossibum_states.py b/RLBotPack/Kamael_family/impossibum_states.py deleted file mode 100644 index 2880ee45..00000000 --- a/RLBotPack/Kamael_family/impossibum_states.py +++ /dev/null @@ -1,5975 +0,0 @@ -from impossibum_utilities import * -import math -from time import time -from rlbot.agents.base_agent import BaseAgent, SimpleControllerState -from rlbot.utils.structures.game_data_struct import GameTickPacket -from rlbot.utils.game_state_util import ( - GameState, - BallState, - CarState, - Physics, - Vector3, - Rotator, -) -import random - -""" -Right corner loc: (-2048, -2560), yaw: 0.25 pi loc: (2048, 2560), yaw: -0.75 pi -Left corner loc: (2048, -2560), yaw: 0.75 pi loc: (-2048, 2560), yaw: -0.25 pi -Back right loc: (-256.0, -3840), yaw: 0.5 pi loc: (256.0, 3840), yaw: -0.5 pi -Back left loc: (256.0, -3840), yaw: 0.5 pi loc: (-256.0, 3840), yaw: -0.5 pi -Far back center loc: (0.0, -4608), yaw: 0.5 pi loc: (0.0, 4608), yaw: -0.5 pi -""" - -class State: - RESET = 0 - WAIT = 1 - INITIALIZE = 2 - RUNNING = 3 - - -def locked_in(agent, agentType): - if agentType == LeapOfFaith: - return agent.activeState.active - if agentType == Divine_Mandate: - return agent.activeState.active - if agentType == airLaunch: - return agent.activeState.active - - if agentType == BlessingOfDexterity: - return agent.activeState.active - - if agentType == Wings_Of_Justice: - return agent.activeState.active - - if agentType == DivineGuidance: - return agent.activeState.active - - if agentType == RighteousVolley: - return agent.activeState.active - - if agentType == Deliverance: - return agent.activeState.active - - if agentType == Cannister_Grab: - return agent.activeState.active - - # if agentType == Kickoff_boosties: - # return agent.activeState.active - - return False - - -def getKickoffPosition(vec): - kickoff_locations = [[2048, 2560], [256, 3848], [0, 4608]] - # 0 == wide diagonal, 1 == short disgonal, 2 == middle - if abs(vec[0]) >= 350: - return 0 - elif abs(vec[0]) > 5: - return 1 - else: - return 2 - - -class baseState: - def __init__(self, agent): - self.agent = agent - self.active = True - - def __repr__(self): - return f"{type(self).__name__}" - - -class Player_reporter(baseState): - def update(self): - if len(self.agent.allies) > 0: - center = Vector([0, 5200 * -sign(self.agent.team), 200]) - dummy = self.agent.allies[0] - shotAngle = math.degrees(angle2(dummy.location, center)) - correctedAngle = correctAngle(shotAngle + 90 * -sign(self.agent.team)) - # agent.log.append( - # f"natural angle: {shotAngle} || corrected angle: {correctedAngle}" - # ) - print(distance2D(self.agent.allies[0].location, self.agent.ball.location)) - - else: - self.agent.log.append("waiting on player to join bot team") - - return SimpleControllerState() - - - -class Cannister_Grab(baseState): - def __init__(self, agent, boost_index): - super().__init__(agent) - self.boost_index = boost_index - self.last_position = self.agent.goal_locations[1] - - def find_boost_obj(self): - for b in self.agent.boosts: - if b.index == self.boost_index: - return b - return None - - - def update(self): - target = self.last_position - target_boost = self.find_boost_obj() - if target_boost is None: - self.active = False - elif not target_boost.spawned: - self.active = False - else: - target = target_boost.location - - if self.agent.goalPred is not None or not self.agent.onSurface or distance2D(self.agent.me.location, self.agent.goal_locations[1]) > distance2D(self.agent.ball.location, self.agent.goal_locations[1]): - self.active = False - - if self.agent.me.boostLevel > 90: - self.active = False - - self.last_position = target - - return driveController(self.agent, target, self.agent.time, expedite=True) - - - -class Kickoff_boosties(baseState): - def __init__(self, agent): - super().__init__(agent) - - def update(self): - self.active = ( - self.agent.gameInfo.is_kickoff_pause - or not self.agent.gameInfo.is_round_active - ) - return kickoff_boost_grabber(self.agent) - - -class airLaunch(baseState): - def __init__(self, agent): - super().__init__(agent) - self.initiated = agent.time - self.jumpTimer = agent.time - self.firstJump = False - self.secondJump = False - self.firstJumpHold = 0.5 - self.secondJumpHold = 0.4 - - def update(self): - stateController = SimpleControllerState() - - if not self.firstJump: - self.firstJump = True - stateController.jump = True - self.jumpTimer = self.agent.time - - elif self.firstJump and not self.secondJump: - if self.agent.time - self.jumpTimer < self.firstJumpHold: - stateController.jump = True - - elif ( - self.agent.time - self.jumpTimer > self.firstJumpHold - and self.agent.time - self.jumpTimer < self.firstJumpHold + 0.05 - ): - stateController.boost = True - stateController.jump = False - - else: - self.secondJump = True - stateController.boost = True - self.jumpTimer = self.agent.time - - else: - if self.agent.time - self.jumpTimer < self.secondJumpHold: - stateController.jump = True - stateController.boost = True - - else: - self.active = False - self.jump = False - self.agent.activeState = DivineGrace(self.agent) - - if ( - self.agent.time - self.jumpTimer > 0.15 - and self.agent.time - self.jumpTimer < 0.35 - ): - stateController.pitch = 1 - return stateController - - -class Aerial_Charge: - def __init__(self, agent, target: Vector): - self.target = target - self.agent = agent - self.active = True - self.anti_gravity_vec = Vector([0, 0, 1]) - self.timer = 0 - self.wallJump = self.agent.onWall - - def update(self): - controls = SimpleControllerState() - controls.throttle = 0 - self.timer += self.agent.deltaTime - # print(self.timer) - - delta_a = calculate_delta_acceleration( - self.target - self.agent.me.location, - self.agent.me.velocity, - 0.01, - self.agent.gravity, - ) - - if not self.agent.onSurface: - align_car_to(controls, self.agent.me.avelocity, delta_a, self.agent) - - aim_target = ( - (delta_a.normalize() + self.anti_gravity_vec).normalize().scale(2300) - ) - if self.wallJump: - if self.timer <= 0.2: - controls.boost = ( - self.agent._forward.dotProduct(delta_a.normalize()) > 0.6 - and delta_a.magnitude() > 100 - ) - controls.jump = True - return controls - - elif self.timer <= 0.2 + self.agent.fakeDeltaTime * 3: - controls.jump = False - controls.boost = ( - self.agent._forward.dotProduct(delta_a.normalize()) > 0.6 - and delta_a.magnitude() > 100 - ) - return controls - - elif self.timer > 0.2 + self.agent.fakeDeltaTime * 3: - controls.steer, controls.roll, controls.yaw, controls.pitch = 0, 0, 0, 0 - controls.jump = True - controls.boost = ( - self.agent._forward.dotProduct(delta_a.normalize()) > 0.6 - and delta_a.magnitude() > 100 - ) - if self.timer > 0.2 + self.agent.fakeDeltaTime * 6: - # print("Launch complete") - self.active = False - return controls - - else: - controls.boost = ( - self.agent._forward.dotProduct(delta_a.normalize()) > 0.6 - and delta_a.magnitude() > 100 - ) - - if self.timer < 0.2: - controls.jump = True - - elif self.timer < 0.2 + self.agent.fakeDeltaTime * 3: - controls.jump = False - - elif self.timer < 0.2 + self.agent.fakeDeltaTime * 5: - controls.steer, controls.roll, controls.yaw, controls.pitch = 0, 0, 0, 0 - controls.jump = True - - else: - controls.jump = True - self.active = False - - return controls - - print("error, launch condition out of range!") - self.active = False - return controls - - -class speed_takeoff: - def __init__(self, agent, target, time): - self.agent = agent - self.target = target - self.time = time - self.stage = 1 - self.start_time = agent.time * 1 - self.active = True - - def update(self): - controls = SimpleControllerState() - controls.throttle = 0 - dt = (self.start_time + 0.2 + self.agent.fakeDeltaTime * 6) - ( - self.agent.time - self.start_time - ) - timer = abs(self.start_time - self.agent.time) - - delta_a = calculate_delta_acceleration( - self.target - self.agent.me.location, - self.agent.me.velocity, - dt, - self.agent.gravity, - ) - total_req_delta_a = delta_a.magnitude() * ( - clamp(10, self.agent.fakeDeltaTime, dt) / self.agent.fakeDeltaTime - ) - current_alignment = self.agent._forward.dotProduct(delta_a.normalize()) - aligned = current_alignment > 0.6 - controls.boost = aligned and total_req_delta_a > 35 - controls.throttle = True - controls.jump = False - - if timer < 0.22: - align_car_to(controls, self.agent.me.avelocity, delta_a, self.agent) - controls.jump = True - - elif timer >= 0.22 + self.agent.fakeDeltaTime * 3: - if self.agent.up.dotProduct(delta_a.normalize()) > 0: - controls.jump = True - - if timer > 0.22 + self.agent.fakeDeltaTime * 6: - self.active = False - - return controls - - -class Wings_Of_Justice: - def __init__(self, agent, pred, target: Vector, time: float): - self.active = True - self.agent = agent - self.time = clamp(10, 0.0001, time) - self.airborne = False - self.launcher = None - self.pred = predictionStruct( - convertStructLocationToVector(pred), pred.game_seconds - ) - self.pred_vel = convertStructVelocityToVector(pred) - self.target = target - self.drive_controls = SimpleControllerState() - self.launch_projection = None - self.started = self.agent.time - self.offensive = self.target[1] * sign(self.agent.team) < 0 - self.point_time = 1 - self.accel_cap = self.agent.aerialAccelerationTick - self.boost_req = self.agent.boost_req - self.vel_reached = False - self.goal_down = target[1] * sign(agent.team) < 0 and butterZone(self.pred.location, x=1000) - self.col_info = None - self.col_timer = 0 - - def launch_window_check(self, time_into_future): - current_delta_req = calculate_delta_acceleration( - self.target - self.agent.me.location, - self.agent.me.velocity, - self.pred.time - self.agent.time, - self.agent.gravity, - ) - - projected_location = self.agent.me.location + ( - self.agent.me.velocity.scale(time_into_future) - ) - projected_delta_req = calculate_delta_acceleration( - self.target - projected_location, - self.agent.me.velocity, - self.pred.time - (self.agent.time + time_into_future), - self.agent.gravity, - ) - # print(projected_delta_req[2], current_delta_req[2]) - - return projected_delta_req[2] > current_delta_req[2] - - def setup(self): - launching = False - self.jumpSim = jumpSimulatorNormalizingJit( - float32(self.agent.gravity), - float32(self.agent.physics_tick), - np.array(self.agent.me.velocity.data, dtype=np.dtype(float)), - np.array(self.agent.up.data, dtype=np.dtype(float)), - np.array(self.agent.me.location.data, dtype=np.dtype(float)), - float32(self.agent.defaultElevation), - float32(self.agent.takeoff_speed), - float32(self.target[2]), - True, - ) - self.agent.currentHit.jumpSim = self.jumpSim - - destination = self.target - dt = self.pred.time - self.agent.time - delta_a = calculate_delta_acceleration( - self.target - Vector(self.jumpSim[4]), - Vector(self.jumpSim[5]), - dt - self.agent.takeoff_speed, - self.agent.gravity, - ) - - delta_mag = delta_a.magnitude() - takeoff_dt = dt - self.agent.takeoff_speed - total_req_delta_a = delta_mag * takeoff_dt - - if delta_mag > self.agent.aerial_accel_limit or takeoff_dt < 0: - self.active = False - - # print(delta_mag) - flips_enabled = ( - delta_a.flatten().magnitude() - - (clamp(2300, 0, self.agent.currentSpd + 500) * 2.1) - > self.target[2] - ) - - expedite = ( - self.agent.calculate_delta_velocity(takeoff_dt) - 10 > total_req_delta_a - or self.agent.boostMonster - or self.agent.aerial_hog - ) - - dist2D = distance2D(self.agent.me.location, self.target) - distance_multi = 4 if not self.agent.aerial_hog else 8 - if self.agent.onSurface: - if not self.agent.onWall: - if dist2D < self.target[2] * distance_multi: - accel_req_limit = self.agent.aerial_accel_limit - - if delta_mag < accel_req_limit: - if delta_a.flatten().magnitude() <= 300 or delta_mag <= 600: - launching = True - - else: - if ( - self.agent.me.velocity[2] > 0 - or self.target[2] < self.agent.me.location[2] - ): # and delta_mag < 950: - launching = True - - - - if launching: - #if self.agent.time - self.agent.flipTimer > 1.6: - if self.agent.onSurface and not self.agent.jumped: - if self.agent.onWall: - self.launcher = speed_takeoff( - self.agent, self.target, self.time - ) - else: - self.launcher = self.agent.createJumpChain( - 0.35, 400, jumpSim=None, set_state=False, aim=False - ) - - self.agent.flipTimer = self.agent.time - - self.drive_controls = driveController( - self.agent, - destination, - self.pred.time, - expedite=expedite, - flippant=False, - maintainSpeed=False, - flips_enabled=flips_enabled, - going_for_aerial=True, - ) - # else: - # self.active = True - - def update(self): - lazy = False - controls = SimpleControllerState() - controls.throttle = 0 - dt = self.pred.time - self.agent.time - target = self.target - createBox(self.agent, self.pred.location) - self.agent.update_action({"type": "BALL", "time": self.pred.time}) - - delta_a = calculate_delta_acceleration( - target - self.agent.me.location, - self.agent.me.velocity, - clamp(10, self.agent.fakeDeltaTime, dt), - self.agent.gravity, - ) - - if self.agent.time - self.started > 0.5: - if self.launch_projection is not None: - self.agent.log.append( - f"Projected delta_a after launcher: {str(self.launch_projection)[:6]}, in reality: {str(delta_a.magnitude())[:6]}" - ) - self.launch_projection = None - - pred_valid = validateExistingPred(self.agent, self.pred, max_variance=60) - if not pred_valid: - self.agent.update_action({"type": "READY", "time": -1}) - if self.launch_projection is not None: - self.agent.log.append( - f"Projected delta_a after launcher: {str(self.launch_projection)[:6]}, in reality: {str(delta_a.magnitude())[:6]}" - ) - self.launch_projection = None - if self.launcher is None: # and dt > self.point_time: - self.active = False - controls.jump = False - self.agent.log.append("canceling aerial because ball path changed") - - if self.agent.onSurface and self.launcher is None: - self.setup() - if self.launcher is None: - return self.drive_controls - - if self.launcher is not None: - #if pred_valid: - controls = self.launcher.update() - if not self.launcher.active: - self.launcher = None - else: - return controls - - aligned_threshold = 0.7 - current_alignment = self.agent._forward.dotProduct(delta_a.normalize()) - aligned = current_alignment >= aligned_threshold - delta_a_mag = delta_a.magnitude() - total_req_delta_a = delta_a_mag * (clamp(10, self.agent.fakeDeltaTime, dt)) - - # print(f"deltatime: {dt} delta magnitude: {delta_a_mag} required total accel change: {total_req_delta_a}") - boost_req = self.boost_req - body_pos = self.agent.find_sim_frame(self.pred.time) - - if body_pos is None: - body_pos = self.agent.me.location - else: - body_pos = body_pos[0] - - - if self.vel_reached: - boost_req = self.boost_req * 1.5 - - min_dist = 30 - - making_contact = findDistance(body_pos, self.pred.location) < self.agent.aerial_reach * 0.9 - if ( - not making_contact or (not self.vel_reached and self.goal_down) - ): - - if self.vel_reached: - boost_req = self.boost_req - self.vel_reached = False - align_car_to(controls, self.agent.me.avelocity, delta_a, self.agent) - - # controls.boost = aligned and (delta_a.magnitude() > boost_req or abs(delta_a.magnitude() - boost_req) < dt*delta_a.magnitude()) - if making_contact and total_req_delta_a < boost_req: - self.vel_reached = True - else: - - if aligned: - if not making_contact: - controls.boost = True - else: - if self.goal_down: - if total_req_delta_a >= boost_req: - controls.boost = True - else: - self.vel_reached = True - if total_req_delta_a > 66.6667 * self.agent.fakeDeltaTime: - controls.throttle = 1 - - else: - self.vel_reached = True - lazy = True - - if self.col_info is None or self.agent.time - self.col_timer > self.agent.fakeDeltaTime * 5: - self.col_info = self.agent.find_first_aerial_contact(clamp(self.pred.time, self.agent.time, self.pred.time -3), self.pred.time) - if self.col_info is not None and not self.goal_down: - self.pred = predictionStruct(self.col_info[1], self.col_info[2]) - self.target = self.col_info[1] - - if self.col_info is None: - target = self.pred.location - if not pred_valid: - target = self.agent.ball.location - - else: - target = self.col_info[1] - body_pos = self.col_info[0] - - - - - align_car_to( - controls, - self.agent.me.avelocity, - target - body_pos, - self.agent, - ) - - if aligned and total_req_delta_a > 66.6667 * self.agent.fakeDeltaTime: - controls.throttle = 1 - - if ( - self.agent.me.velocity[2] < -100 - and self.agent.me.location[2] < self.pred.location[2] - 200 - ): - self.active = False - self.agent.log.append("invalidating falling aerial") - controls.jump = False - - if dt < 0: - self.active = False - self.agent.log.append("Aerial timed out") - controls.jump = False - - if self.agent.onSurface: - self.agent.log.append("canceling aerial since we're on surface") - self.active = False - controls.jump = False - - # if dt > self.point_time and not lazy: - # req_vel = self.agent.me.velocity + delta_a - # if req_vel.magnitude() > 2300 and self.launcher and delta_a_mag > boost_req: - # self.active = False - - return controls - - -# class Wings_Of_Justice: -# def __init__(self, agent, pred, target: Vector, time: float): -# self.active = False -# self.agent = agent -# self.time = clamp(10, 0.0001, time) -# self.airborne = False -# self.launcher = None -# self.pred = predictionStruct( -# convertStructLocationToVector(pred), pred.game_seconds -# ) -# self.target = target -# self.drive_controls = SimpleControllerState() -# self.launch_projection = None -# self.started = self.agent.time -# self.powershot = ( -# distance2D(target, Vector([0, 5200 * -sign(agent.team), 0])) > 2000 -# ) -# self.point_time = 1.5 -# self.accel_cap = 1060 -# self.boost_req = self.agent.aerialAccelerationTick*3 -# -# def launch_window_check(self,time_into_future): -# current_delta_req = calculate_delta_acceleration( -# self.target - self.agent.me.location, -# self.agent.me.velocity, -# self.pred.time - self.agent.time, -# self.agent.gravity, -# ) -# -# projected_location = self.agent.me.location + (self.agent.me.velocity.scale(time_into_future)) -# projected_delta_req = calculate_delta_acceleration( -# self.target - projected_location, -# self.agent.me.velocity, -# self.pred.time - (self.agent.time+time_into_future), -# self.agent.gravity, -# ) -# print(projected_delta_req[2] , current_delta_req[2]) -# -# return projected_delta_req[2] > current_delta_req[2] -# -# -# def setup(self): -# # print(f"in setup {self.agent.time}") -# if self.agent.onSurface: -# if not self.agent.onWall:#self.agent.team == 0: -# launching = False -# dt = self.pred.time - self.agent.time -# accel_req_limit = 1060 -# -# delta_a = calculate_delta_acceleration( -# self.target - Vector(self.agent.currentHit.jumpSim[4]), -# Vector(self.agent.currentHit.jumpSim[5]), -# dt - self.agent.takeoff_speed, -# self.agent.gravity, -# ) -# takeoff_dt = dt - self.agent.takeoff_speed -# total_req_delta_a = delta_a.magnitude() * takeoff_dt -# -# expedite = ( -# self.agent.calculate_delta_velocity(takeoff_dt) - 10 > total_req_delta_a -# ) -# -# _direction = direction(self.agent.me.location, self.target) -# # _direction = delta_a.flatten().normalize().scale(-1) -# offset = clamp( -# math.inf, 20, distance2D(self.agent.me.location, self.target) -# ) -# # offset = delta_a.flatten().magnitude() -# -# destination = self.agent.me.location + _direction.scale(offset) -# -# self.drive_controls = driveController( -# self.agent, -# destination, -# self.pred.time, -# expedite=expedite, -# flippant=False, -# maintainSpeed=False, -# ) -# -# angle_difference = abs( -# angleBetweenVectors( -# self.agent.me.velocity.flatten().normalize(), -# delta_a.flatten().normalize(), -# ) -# ) -# -# if delta_a.magnitude() < 1050: -# if ( -# ( -# angle_difference < 10 -# and self.agent.currentSpd >= 1350 -# and not expedite -# ) -# or delta_a.flatten().magnitude() <= 600 -# or (not self.agent.forward and angle_difference < 20) -# or abs( -# angleBetweenVectors( -# self.agent.me.velocity.flatten().normalize(), -# delta_a.flatten().normalize(), -# ) -# ) -# <= 5 -# or ( -# self.agent.onWall -# and ( -# self.agent.me.velocity[2] > 0 -# or self.target[2] < self.agent.me.location[2] -# ) -# ) -# or (not self.agent.onWall and self.agent.currentSpd < 600) -# ): -# launching = True -# else: -# launching = False -# else: -# launching = True -# -# # if launching and self.agent.onSurface and not self.agent.onWall: -# # launching = self.launch_window_check(self.agent.fakeDeltaTime * 5) -# # if not launching: -# # print(f"Stalling take off! {self.agent.time}") -# -# if not launching: #and self.agent.team == 0: -# self.active = False -# -# else: -# if distance2D(self.target, self.agent.me.location) <= 5000: -# self.launcher = speed_takeoff(self.agent, self.target, self.time) -# self.active = True -# # print("launching!") -# else: -# self.active = False -# else: -# self.active = True -# -# def update(self): -# controls = SimpleControllerState() -# controls.throttle = 0 -# dt = self.pred.time - self.agent.time -# target = self.target -# createBox(self.agent, self.pred.location) -# -# delta_a = calculate_delta_acceleration( -# target - self.agent.me.location, -# self.agent.me.velocity, -# clamp(10, self.agent.fakeDeltaTime, dt), -# self.agent.gravity, -# ) -# -# if self.agent.time - self.started > 0.5: -# if self.launch_projection != None: -# self.agent.log.append( -# f"Projected delta_a after launcher: {str(self.launch_projection)[:6]}, in reality: {str(delta_a.magnitude())[:6]}" -# ) -# self.launch_projection = None -# -# pred_valid = validateExistingPred(self.agent, self.pred) -# -# if self.agent.onSurface and self.launcher == None: -# self.setup() -# if self.launcher == None: -# return self.drive_controls -# -# if self.launcher != None: -# controls = self.launcher.update() -# if not self.launcher.active: -# self.launcher = None -# return controls -# -# -# -# aligned_threshold = 0.7 -# current_alignment = self.agent._forward.dotProduct(delta_a.normalize()) -# delta_a_mag = delta_a.magnitude() -# total_req_delta_a = delta_a_mag * ( -# clamp(10, self.agent.fakeDeltaTime, dt) / self.agent.fakeDeltaTime -# ) -# -# #if total_req_delta_a >= self.boost_req and (self.agent.me.boostLevel > 0 or dt > self.point_time): -# if total_req_delta_a >= self.boost_req or (total_req_delta_a > 5 and dt > self.point_time): -# align_car_to(controls, self.agent.me.avelocity, delta_a, self.agent) -# aligned = current_alignment > aligned_threshold -# # controls.boost = aligned and (delta_a.magnitude() > boost_req or abs(delta_a.magnitude() - boost_req) < dt*delta_a.magnitude()) -# controls.boost = aligned and total_req_delta_a >= self.boost_req -# if aligned: -# controls.throttle = 1 -# else: -# target = self.pred.location # + offset -# if not pred_valid: -# target = self.agent.ball.location # + offset -# -# align_car_to( -# controls, -# self.agent.me.avelocity, -# self.pred.location - self.agent.me.location, -# self.agent, -# ) -# -# # if self.agent.me.location[2] > 500 and (self.agent.me.location[2] > self.pred.location[2] or self.target[2] > self.pred.location[2]) and abs(self.agent._forward[2]) < .4: -# # controls.roll = turnController(self.agent.me.rotation[2], self.agent.me.rotational_velocity[0] / 4) -# -# if not pred_valid: -# if self.launch_projection != None: -# self.agent.log.append( -# f"Projected delta_a after launcher: {str(self.launch_projection)[:6]}, in reality: {str(delta_a.magnitude())[:6]}" -# ) -# self.launch_projection = None -# if self.launcher == None and dt > self.point_time: -# self.active = False -# -# if dt < 0: -# self.active = False -# self.agent.log.append("Aerial timed out") -# -# if self.agent.onSurface: -# self.agent.log.append("canceling aerial since we're on surface") -# self.active = False -# -# if dt > self.point_time: -# req_vel = self.agent.me.velocity + delta_a -# if ( -# req_vel.magnitude() > 2300 -# #and self.launcher -# and (req_vel.magnitude() * dt) - (2300*dt) > 50 -# and self.agent.me.boostLevel > 1 -# ): -# self.active = False -# -# if delta_a_mag > self.accel_cap and (delta_a_mag*dt) - (1057*dt) > 50 and self.agent.me.boostLevel > 1: -# self.active = False -# -# return controls - - -class Deliverance(baseState): - def __init__(self, agent, big_jump=True): - super().__init__(agent) - if big_jump: - self.jump_action = LeapOfFaith(agent, 2) - # print("big carry!") - else: - self.jump_action = LeapOfFaith(agent, -1) - # print("little carry!") - self.start_time = self.agent.time - - def update(self): - if self.jump_action.active: - action = self.jump_action.update() - updated_time = self.agent.time - self.start_time - if not action.jump: - action.pitch = 1 - if not self.agent.onSurface: - self.throttle = -1 - return action - - controls = SimpleControllerState() - offset = Vector([0, 50 * sign(self.agent.team), 60]) - - ( - controls.steer, - controls.yaw, - controls.pitch, - _roll, - error, - ) = point_at_position(self.agent, self.agent.ball.location + offset) - - controls.boost = error < 0.6 and self.agent.ball.location[2] < 780 - - if ( - self.agent.me.boostLevel <= 0 - or self.agent.me.location[2] < 55 - or findDistance(self.agent.me.location, self.agent.ball.location) > 500 - or error > 5 - or self.agent.onSurface - ): - self.active = False - - # print(f"point error is: {error}") - - return controls - - -class LeapOfFaith(baseState): - def __init__(self, agent, targetCode, target=None): - super().__init__(agent) - self.targetCode = targetCode # 0 flip at ball , 1 flip forward, 2 double jump, 3 flip backwards, 4 flip left, 5 flip right, 6 flip at target ,7 left forward diagnal flip, 8 right forward diagnal flip , -1 hold single jump - self.flip_obj = FlipStatus(agent.time) - self.target = target - self.cancelTimerCap = 0.3 - self.cancelStartTime = None - self.jumped = False - self.followThrough = 0 - self.start_time = self.agent.time - self.last_controller = SimpleControllerState() - - def update(self): - if self.agent.onSurface: - if self.agent.time - self.start_time > 0.2: - self.active = False - controller_state = SimpleControllerState() - jump = flipHandler(self.agent, self.flip_obj) - # print(f"code: {self.targetCode}, height: {self.agent.me.location[2]} ") - if jump: - if self.targetCode == 1: - controller_state.pitch = -1 - controller_state.roll = 0 - controller_state.throttle = 1 - - elif self.targetCode == 0: - # ball_local = toLocal( - # self.agent.ball.location, self.agent.me - # ).normalize() - ball_local = self.agent.ball.local_location - ball_angle = math.atan2(ball_local.data[1], ball_local.data[0]) - controller_state.jump = True - yaw = math.sin(ball_angle) - pitch = -math.cos(ball_angle) - yp = Vector([abs(yaw), abs(pitch)]) - yp = yp.normalize() - if yaw > 0: - yaw = yp[0] - else: - yaw = -yp[0] - if pitch > 0: - pitch = yp[1] - else: - pitch = -yp[1] - - controller_state.yaw = yaw - controller_state.pitch = pitch - - if pitch > 0: - controller_state.throttle = -1 - else: - controller_state.throttle = 1 - - elif self.targetCode == 2: - controller_state.pitch = 0 - controller_state.steer = 0 - controller_state.yaw = 0 - - elif self.targetCode == 3: - controller_state.pitch = 1 - controller_state.steer = 0 - controller_state.throttle = -1 - - elif self.targetCode == -1: - controller_state.pitch = 0 - controller_state.steer = 0 - controller_state.throttle = 0 - - elif self.targetCode == 4: - controller_state.pitch = 0 - controller_state.yaw = -1 - controller_state.steer = -1 - controller_state.throttle = 1 - # print("in left side flip") - - elif self.targetCode == 5: - controller_state.pitch = 0 - controller_state.yaw = 1 - controller_state.steer = 1 - controller_state.throttle = 1 - # print("in right side flip") - - elif self.targetCode == 6: - target_local = toLocal(self.target, self.agent.me).normalize() - target_angle = math.atan2(target_local.data[1], target_local.data[0]) - controller_state.jump = True - controller_state.yaw = math.sin(target_angle) - pitch = -math.cos(target_angle) - controller_state.pitch = pitch - if pitch > 0: - controller_state.throttle = -1 - else: - controller_state.throttle = 1 - - elif self.targetCode == 7: - controller_state.pitch = -1 - controller_state.yaw = -1 - controller_state.steer = -1 - controller_state.throttle = 1 - - elif self.targetCode == 8: - controller_state.pitch = -1 - controller_state.yaw = 1 - controller_state.steer = 1 - controller_state.throttle = 1 - - elif self.targetCode == 9: - # diagnal flip cancel - controller_state.pitch = -0.2 - controller_state.yaw = -0.8 - # controller_state.steer = -1 - controller_state.throttle = 1 - - elif self.targetCode == 10: - # diagnal flip cancel - controller_state.pitch = -0.2 - controller_state.yaw = 0.8 - # controller_state.steer = -1 - controller_state.throttle = 1 - - controller_state.jump = jump - controller_state.boost = False - if self.targetCode == 7 or self.targetCode == 8: - controller_state.boost = True - if self.flip_obj.flipDone: - if self.targetCode != 9 or self.targetCode != 10: - controller_state = self.last_controller - if ( - self.followThrough < 0.33 - and self.targetCode != 2 - and self.targetCode != -1 - ): - self.followThrough += self.agent.deltaTime - else: - self.active = False - else: - if not self.cancelStartTime: - self.cancelStartTime = self.agent.time - return controller_state - if self.targetCode == 9: - controller_state.pitch = 1 - controller_state.roll = 1 - controller_state.throttle = 1 - else: - controller_state.pitch = 1 - controller_state.roll = -1 - controller_state.throttle = 1 - if self.agent.time - self.cancelStartTime >= self.cancelTimerCap: - self.active = False - - self.last_controller = controller_state - return controller_state - - -class Divine_Mandate: - # class for performing consecutive inputs over set periods of time. Example: Flipping forward - def __init__(self, agent, controls_list: list, durations_list: list, target=None, intercept_time=None): - self.controls = controls_list - self.durations = durations_list - self._controls = controls_list - self._durations = durations_list - self.complete = False - self.index = 0 - self.current_duration = 0 - self.agent = agent - self.touch = self.agent.ball.lastTouch - self.target = target - self.intercept_time = intercept_time - self.remote = None - self.remote_timer = 0 - # there should be a duration in the durations for every controller given in the list. This inserts 0 for any lacking - if len(durations_list) < len(controls_list): - self.durations += [0 * len(controls_list) - len(durations_list)] - self.active = True - - def create_custom_controls(self, actionCode): - # perform specialized actions if creating controlers at creation time wasn't feasible - controller_state = SimpleControllerState() - if actionCode == 0: - target = self.agent.ball.location - - if self.agent.ball.lastTouch == self.touch and self.target is not None: - target = self.target - - target_local = localizeVector(target, self.agent.me) - ball_angle = math.atan2(target_local.data[1], target_local.data[0]) - controller_state.jump = True - - yaw = math.sin(ball_angle) - pitch = -math.cos(ball_angle) - yp = Vector([abs(yaw), abs(pitch)]) - yp = yp.normalize() - if yaw > 0: - yaw = yp[0] - else: - yaw = -yp[0] - if pitch > 0: - pitch = yp[1] - else: - pitch = -yp[1] - - controller_state.pitch = pitch - controller_state.yaw = yaw - if pitch > 0: - controller_state.throttle = -1 - else: - controller_state.throttle = 1 - - self.controls[self.index] = controller_state - - if actionCode == 1: - remote_loc = None - target = self.agent.ball.location - - if self.agent.ball.lastTouch != self.touch or self.target is None: - self.intercept_time = None - else: - if self.intercept_time and self.agent.time < self.intercept_time: - if self.agent.time - self.remote_timer > self.agent.fakeDeltaTime * 5: - remote_loc = self.agent.find_sim_frame(self.intercept_time) - if remote_loc is not None: - remote_loc = remote_loc[0] - self.remote = remote_loc - self.remote_timer = self.agent.time - else: - remote_loc = self.remote - - target = self.target - - if target[1] * sign(self.agent.team) < 0 and butterZone(target, x=1200, y=4000): - target += Vector([0, 0, 40]) - - #target_local = localizeVector(target, self.agent.me, remote_location=remote_loc) - if remote_loc != None: - # just a hack so I don't have to update the point function to work remotely - target += (self.agent.me.location - remote_loc) - - ( - controller_state.steer, - controller_state.yaw, - controller_state.pitch, - controller_state.roll, - _, - ) = point_at_position(self.agent, target) - - controller_state.jump = False - controller_state.throttle = 1 - # print(f"agent height is : {self.agent.me.location[2]}") - - return controller_state - - def update( - self, - ): # call this once per frame with delta time to receive updated controls - self.current_duration += self.agent.deltaTime - if self.index >= len(self.controls): - self.active = False - return SimpleControllerState() - if self.current_duration > self.durations[self.index]: - self.index += 1 - self.current_duration = self.current_duration - self.agent.deltaTime - # self.current_duration = 0 - if self.index >= len(self.controls): - self.active = False - return SimpleControllerState() - - if type(self.controls[self.index]) == SimpleControllerState: - return self.controls[self.index] - - else: - return self.create_custom_controls(self.controls[self.index]) - - -class RighteousVolley(baseState): - def __init__(self, agent, delay, target): - super().__init__(agent) - self.smartAngle = False - self.target = target - height = target[2] - boomerDelay = 0.05 - delay = clamp(1.25, 0.3, delay + boomerDelay) - if delay >= 0.3: - if height <= 200: - # print("tiny powershot") - self.jumpTimerMax = 0.1 - self.angleTimer = clamp(0.15, 0.05, self.jumpTimerMax / 2) - else: - # print("normal powershot") - self.jumpTimerMax = delay - 0.2 - self.angleTimer = clamp(0.15, 0.1, self.jumpTimerMax / 2) - self.delay = delay - if self.delay >= 0.5: - self.smartAngle = True - self.jumped = False - self.jumpTimer = 0 - # print("setting action to powershot") - - def update(self): - controller_state = SimpleControllerState() - controller_state.throttle = 0 - controller_state.boost = False - ball_local = toLocal(self.agent.ball.location, self.agent.me).normalize() - # ball_local = toLocal(self.target, self.agent.me) - ball_angle = math.atan2(ball_local.data[1], ball_local.data[0]) - angle_degrees = correctAngle(math.degrees(ball_angle)) - if not self.jumped: - self.jumped = True - controller_state.jump = True - return controller_state - else: - self.jumpTimer += self.agent.deltaTime - - if self.jumpTimer < self.angleTimer: - controller_state.pitch = 1 - - if self.jumpTimer < self.jumpTimerMax: - controller_state.jump = True - - else: - controller_state.jump = False - - if self.jumpTimer > self.jumpTimerMax: - if ( - self.jumpTimer >= self.delay - 0.2 - and self.jumpTimer < self.delay - 0.15 - ): - controller_state.jump = False - elif ( - self.jumpTimer >= self.delay - 0.15 - and self.jumpTimer < self.delay - ): - controller_state.yaw = math.sin(ball_angle) - controller_state.pitch = -math.cos(ball_angle) - controller_state.jump = True - elif self.jumpTimer < self.delay + 0.1: - controller_state.jump = False - else: - self.active = False - controller_state.jump = False - return controller_state - - -class Divine_Retribution: - def __init__(self, agent, grab_boost=True): - self.agent = agent - self.active = True - self.grab_boost = grab_boost - - def update(self,): - best_target = unpicky_demo_picker(self.agent) - boostTarget, dist = boostSwipe(self.agent) - - if best_target is not None and ( - (self.agent.me.boostLevel > 12 or self.agent.currentSpd >= 2200) - or (boostTarget is None or dist > 3000 or not self.grab_boost) - ): - return demoTarget(self.agent, best_target) - - else: - if not self.grab_boost: - return driveController(self.agent, (self.agent.closestEnemyToBall.location + self.agent.closestEnemyToBall.velocity.scale(self.agent.fakeDeltaTime*20)).flatten(), self.agent.time, expedite=False) - #return playBack(self.agent) - - if boostTarget is not None and dist < 5000 and self.agent.me.boostLevel < 100: - return driveController( - self.agent, - boostTarget.location.flatten(), - self.agent.time, - expedite=True, - ) - - boost_suggestion = boost_suggester(self.agent, buffer=-20000, mode=0) - if boost_suggestion is not None and not self.agent.boostMonster: - target = boost_suggestion.location.scale(1) - return driveController(self.agent, target.flatten(), 0) - else: - return playBack(self.agent) - - -class DemolitionBot: - def __init__(self, agent): - self.agent = agent - self.active = True - - def update(self): - target = self.agent.closestEnemyToBall - valid = False - if target.location[2] <= 90: - if ( - target.location[1] > self.agent.ball.location[1] - and target.location[1] < self.agent.me.location[1] - ) or ( - target.location[1] < self.agent.ball.location[1] - and target.location[1] > self.agent.me.location[1] - ): - valid = True - - if valid: - return demoTarget(self.agent, target) - - else: - self.active = False - return ShellTime(self.agent) - - -class GroundShot(baseState): - def __init__(self, agent): - super().__init__(agent) - - def update(self): - return lineupShot(self.agent, 3) - - -class GroundAssault(baseState): - def __init__(self, agent): - super().__init__(agent) - - def update(self): - return lineupShot(self.agent, 1) - - -class DivineGuidance(baseState): - def __init__(self, agent, target): - super().__init__(agent) - self.controller = SimpleControllerState() - self.controller.jump = True - self.target = Vector([target[0], target[1], 30]) - self.start_time = agent.time - # self.agent.stubbornessTimer = 2 - # self.agent.stubborness = -50 - - def update(self): - temp_controller = SimpleControllerState(jump=True) - - if self.agent.time - self.start_time < self.agent.fakeDeltaTime * 5: - temp_controller.jump = True - - elif self.agent.time - self.start_time > 0.1: - temp_controller.jump = False - else: - temp_controller.jump = False - ( - temp_controller.steer, - temp_controller.yaw, - temp_controller.pitch, - temp_controller.roll, - _, - ) = point_at_position(self.agent, self.target.flatten()) - if self.agent.time - self.start_time > 1.2: - self.active = False - - if self.agent.onSurface: - if self.agent.time - self.start_time > 0.2: - self.active = False - - return temp_controller - - -class HolyGrenade(baseState): - def __init__(self, agent): - super().__init__(agent) - - def update(self): - return handleBounceShot(self.agent) - - -class HolyProtector(baseState): - def __init__(self, agent): - super().__init__(agent) - - def update(self): - return ShellTime(self.agent) - - -class Obstruct(baseState): - def update(self): - if not kickOffTest(self.agent): - return turtle_mode(self.agent) - - else: - self.active = False - self.agent.activeState = PreemptiveStrike(self.agent) - return self.agent.activeState.update() - - -class Kickoff_Boosties(baseState): - def __init__(self, agent): - super().__init__(agent) - self.setup() - - def setup(self): - closest_dist = math.inf - closest_loc = Vector([0, 0, 0]) - for bb in self.agent.bigBoosts: - dist = distance2D(self.agent.me.location, bb.location) - if dist < closest_dist: - closest_dist = dist - closest_loc = bb.location - self.boost_target = closest_loc - - def update(self): - if findDistance(self.agent.me.location, self.boost_target) < 100: - self.active = False - return driveController( - self.agent, - self.boost_target, - 0.0001, - expedite=True, - flippant=True, - kickoff=True, - ) - - -class HeavenlyReprieve(baseState): - def __init__(self, agent, boostloc): - super().__init__(agent) - self.boostLoc = boostloc - - def update(self): - result = inCornerWithBoost(self.agent) - if result != False: - self.agent.update_action({"type": "BOOST", "target": result[0].index}) - return refuel(self.agent, result[0].location) - else: - self.active = False - return ShellTime(self.agent) - - -# class PreemptiveStrike(baseState): -# def __init__(self, agent): -# super().__init__(agent) -# self.fakeDeltaTime = 1 / 120 -# self.started = False -# self.firstFlip = None -# self.secondFlip = None -# self.startTime = agent.time -# self.kickoff_type = getKickoffPosition(agent.me.location) -# # 0 == wide diagonal, 1 == short disgonal, 2 == middle -# agent.stubbornessTimer = 5 -# self.onRight = True -# self.short_offset = 75 -# self.setup() -# self.enemyGoal = Vector([0, 5200 * -sign(self.agent.team), 0]) -# self.phase = 1 -# self.KO_option = None -# self.maintaining_speed = False -# self.first_recovery = None -# self.random_offset = None -# -# def create_speed_flip_cancel(self, left=False): -# controls = [] -# timers = [] -# # first_controller = SimpleControllerState() -# # if left: -# # first_controller.steer = 1 -# # else: -# # first_controller.steer = -1 -# # -# # first_controller.handbrake = True -# # first_controller.throttle = 1 -# # first_controller.boost = True -# # first_controller.jump = False -# # controls.append(first_controller) -# # timers.append(self.agent.fakeDeltaTime * 1) -# -# second_controller = SimpleControllerState() -# -# # if left: -# # second_controller.steer = 1 -# # else: -# # second_controller.steer = -1 -# if not left: -# second_controller.steer = 1 -# else: -# second_controller.steer = -1 -# -# second_controller.throttle = 1 -# second_controller.boost = True -# second_controller.jump = True -# second_controller.pitch = 1 -# second_controller.handbrake = True -# controls.append(second_controller) -# timers.append(0.10) -# -# third_controller = SimpleControllerState() -# third_controller.jump = False -# third_controller.boost = True -# third_controller.throttle = 1 -# third_controller.pitch = 1 -# controls.append(third_controller) -# timers.append(self.fakeDeltaTime * 1.5) -# -# fourth_controller = SimpleControllerState() -# # yaw = 1 -# # if left: -# # yaw = -1 -# -# yaw = -1 -# if left: -# yaw = 1 -# -# fourth_controller.yaw = yaw -# # fourth_controller.roll = yaw -# fourth_controller.pitch = -1 -# fourth_controller.jump = True -# fourth_controller.boost = True -# fourth_controller.throttle = 1 -# controls.append(fourth_controller) -# timers.append(0.05) -# -# fifth_controller = SimpleControllerState() -# fifth_controller.yaw = -yaw -# # fifth_controller.roll = -yaw -# fifth_controller.pitch = 1 -# fifth_controller.throttle = 1 -# fifth_controller.boost = True -# fifth_controller.handbrake = False -# fifth_controller.jump = True -# controls.append(fifth_controller) -# timers.append(0.75) -# -# action = Divine_Mandate(self.agent, controls, timers) -# # print(type(action)) -# return action -# -# def create_diagonal_speed_flip(self, left=False): -# controls = [] -# timers = [] -# # jump start -# first_controller = SimpleControllerState() -# if self.kickoff_type == 0: -# if self.onRight: -# first_controller.yaw = -1 -# else: -# first_controller.yaw = 1 -# -# first_controller.jump = True -# first_controller.boost = True -# first_controller.throttle = 1 -# first_controller.pitch = -1 -# first_controller.jump = True -# controls.append(first_controller) -# timers.append(0.1) -# -# # jump delay -# second_controller = SimpleControllerState() -# second_controller.jump = False -# second_controller.boost = True -# second_controller.throttle = 1 -# if left: -# yaw = -0.75 -# else: -# yaw = 0.75 -# -# pitch = -0.25 -# -# second_controller.yaw = yaw -# second_controller.pitch = pitch -# second_controller.jump = False -# -# controls.append(second_controller) -# timers.append(self.fakeDeltaTime * 2) -# -# # jump flip -# third_controller = SimpleControllerState() -# third_controller.jump = True -# third_controller.boost = True -# third_controller.throttle = 1 -# -# if left: -# yaw = -0.75 -# else: -# yaw = 0.75 -# -# pitch = -0.25 -# -# third_controller.yaw = yaw -# third_controller.pitch = pitch -# controls.append(third_controller) -# timers.append(0.5) -# -# action = Divine_Mandate(self.agent, controls, timers) -# # print(type(action)) -# return action -# -# def setup(self): -# # setup randomness like offsets to either side of the ball. Make sure it's slightly offset from middle so we can flip center -# # setup flips -# ball_local = ( -# self.agent.ball.local_location -# ) # localizeVector(Vector([0, 0, 0]), self.agent.me) -# if self.kickoff_type == 0: -# if ball_local[1] > 0: -# # self.firstFlip = self.create_diagonal_speed_flip(left=True) -# # self.firstFlip = LeapOfFaith(self.agent,9) -# self.firstFlip = self.create_speed_flip_cancel(left=False) -# self.onRight = False -# # print("flipping left") -# else: -# # self.firstFlip = self.create_diagonal_speed_flip(left=False) -# # self.firstFlip = LeapOfFaith(self.agent, 10) -# self.firstFlip = self.create_speed_flip_cancel(left=True) -# self.onRight = True -# # print("flipping right") -# -# elif self.kickoff_type == 1: -# if ball_local[1] < 0: -# self.firstFlip = self.create_diagonal_speed_flip(left=False) -# self.onRight = True -# self.short_offset = -50 * sign(self.agent.team) -# else: -# self.firstFlip = self.create_diagonal_speed_flip(left=True) -# self.onRight = False -# self.short_offset = 50 * sign(self.agent.team) -# # print(f"on left and short offset == {self.short_offset}") -# -# else: -# # middle kickoff defaulting to right -# self.firstFlip = self.create_diagonal_speed_flip(left=True) -# # self.onRight shouldn't matter -# -# def wide_handler(self): -# # stage 1 - drive to boost pad -# if self.phase == 1: -# if distance2D(self.agent.me.location, self.agent.ball.location) > 3150: -# # return driveController(self.agent, self.enemyGoal+Vector([0,4000*sign(self.agent.team),0]), -# return driveController( -# self.agent, -# self.agent.ball.location -# + Vector([0, sign(self.agent.team) * -100, 0]), -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 3 -# -# # stage 3 - first flip -# if self.phase == 3: -# # if self.firstFlip == None: -# # self.firstFlip = self.create_speed_flip_cancel(left=not self.onRight) -# if self.firstFlip.active: -# # print(f"first flip active: {str(self.firstFlip)} {self.agent.time} {self.firstFlip.targetCode}") -# return self.firstFlip.update() -# -# if not self.agent.onSurface: -# _controller = SimpleControllerState() -# ( -# _controller.steer, -# _controller.yaw, -# _controller.pitch, -# _controller.roll, -# _err, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# _controller.boost = True -# _controller.handbrake = True -# return _controller -# -# else: -# self.phase = 4 -# # print(f"switched to stage 4! {self.agent.time}") -# -# # stage 4 - aim towards just offcenter of ball -# if self.phase == 4: -# if distance2D(self.agent.me.location, self.agent.ball.location) > 450: -# if self.agent.me.location[0] > self.agent.ball.location[0]: -# if self.random_offset == None: -# self.random_offset = random.randrange(2, 15) -# dummy_location = self.agent.ball.location + Vector( -# # [25, 120 * sign(self.agent.team), 0] -# [self.random_offset, 120 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal,self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale(distance2D(self.agent.me.location,dummy_location)*.5) -# else: -# if self.random_offset == None: -# self.random_offset = random.randrange(-15, -2) -# dummy_location = self.agent.ball.location + Vector( -# # [-25, 120 * sign(self.agent.team), 0] -# [self.random_offset, 120 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 5 -# # print(f"switched to stage 5! {self.agent.time}") -# -# # stage 5 - flip through center and end kickoff -# # 4 flip left, 5 flip right -# if self.phase == 5: -# if self.secondFlip == None: -# if ( -# self.agent.team == 0 -# and self.agent.me.location[0] < self.agent.ball.location[0] -# ) or ( -# self.agent.team == 1 -# and self.agent.me.location[0] > self.agent.ball.location[0] -# ): -# _code = 5 -# else: -# _code = 4 -# # _code = 4 -# # else: -# # _code = 5 -# -# self.secondFlip = LeapOfFaith(self.agent, _code, target=None) -# controls = self.secondFlip.update() -# if not self.secondFlip.active: -# self.retire() -# return controls -# -# def short_handler(self): -# # stage 1 - drive to boost pad -# if self.phase == 1: -# drive_target = Vector( -# [self.short_offset, sign(self.agent.team) * 2825.0, 0] -# ) -# if distance2D(self.agent.me.location, drive_target) > 575: -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 3 -# -# # stage 2 - angle towards outside of ball -# if self.phase == 2: -# controls = SimpleControllerState() -# if not self.agent.onSurface: -# ( -# controls.steer, -# controls.yaw, -# controls.pitch, -# controls.roll, -# alignment_error, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# return controls -# else: -# self.phase = 3 -# # stage 3 - first flip -# if self.phase == 3: -# if self.firstFlip.active: -# return self.firstFlip.update() -# if not self.agent.onSurface: -# _controller = SimpleControllerState() -# ( -# _controller.steer, -# _controller.yaw, -# _controller.pitch, -# _controller.roll, -# _err, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# _controller.boost = True -# _controller.handbrake = True -# return _controller -# else: -# self.phase = 4 -# -# # stage 4 - aim towards just offcenter of ball -# if self.phase == 4: -# if ( -# distance2D(self.agent.me.location, self.agent.ball.location) > 500 -# or not self.agent.onSurface -# ): -# if self.agent.me.location[0] > self.agent.ball.location[0]: -# if self.random_offset == None: -# self.random_offset = random.randrange(10, 25) -# dummy_location = self.agent.ball.location + Vector( -# [self.random_offset, 75 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# else: -# if self.random_offset == None: -# self.random_offset = random.randrange(-25, -10) -# dummy_location = self.agent.ball.location + Vector( -# [self.random_offset, 75 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 5 -# -# # stage 5 - flip through center and end kickoff -# # 4 flip left, 5 flip right -# if self.phase == 5: -# if self.secondFlip == None: -# if ( -# self.agent.team == 0 -# and self.agent.me.location[0] < self.agent.ball.location[0] -# ) or ( -# self.agent.team == 1 -# and self.agent.me.location[0] > self.agent.ball.location[0] -# ): -# _code = 4 -# else: -# _code = 5 -# # _code = 0 -# self.secondFlip = LeapOfFaith(self.agent, _code, target=None) -# controls = self.secondFlip.update() -# if not self.secondFlip.active: -# self.retire() -# return controls -# -# def middle_handler(self): -# # stage 1 - drive to boost pad -# if self.phase == 1: -# drive_target = Vector([0, sign(self.agent.team) * 4000, 0]) -# if distance2D(self.agent.me.location, drive_target) > 75: -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 2 -# -# # stage 2 - angle towards outside of ball -# if self.phase == 2: -# drive_target = Vector([4500 * sign(self.agent.team), 0, 0]) -# if ( -# distance2D(self.agent.me.location, self.agent.ball.location) > 3850 -# ): # 3875: -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 3 -# # stage 3 - first flip -# if self.phase == 3: -# if self.firstFlip.active: -# return self.firstFlip.update() -# else: -# if self.agent.onSurface: -# self.phase = 4 -# else: -# controls = SimpleControllerState() -# ( -# controls.steer, -# controls.yaw, -# controls.pitch, -# controls.roll, -# alignment_error, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# return controls -# -# # stage 4 - aim towards just offcenter of ball -# if self.phase == 4: -# -# if ( -# distance2D(self.agent.me.location, self.agent.ball.location) > 500 -# or not self.agent.onSurface -# ): -# if self.agent.me.location[0] > self.agent.ball.location[0]: -# if self.random_offset == None: -# self.random_offset = random.randrange(10, 25) -# dummy_location = self.agent.ball.location + Vector( -# [self.random_offset, 75 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# else: -# if self.random_offset == None: -# self.random_offset = random.randrange(-25, -10) -# dummy_location = self.agent.ball.location + Vector( -# [self.random_offset, 75 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 5 -# -# # stage 5 - flip through center and end kickoff -# # 4 flip left, 5 flip right -# if self.phase == 5: -# if self.secondFlip == None: -# if ( -# self.agent.team == 0 -# and self.agent.me.location[0] < self.agent.ball.location[0] -# ) or ( -# self.agent.team == 1 -# and self.agent.me.location[0] > self.agent.ball.location[0] -# ): -# _code = 4 -# else: -# _code = 5 -# # _code = 0 -# self.secondFlip = LeapOfFaith(self.agent, _code, target=None) -# controls = self.secondFlip.update() -# if not self.secondFlip.active: -# self.retire() -# return controls -# -# def retire(self): -# if self.phase != 5 or self.secondFlip == None or not self.secondFlip.active: -# self.active = False -# # self.agent.activeState = None -# # print(f"retiring on stage {self.phase} {self.agent.time}") -# -# def update(self): -# if not self.agent.gameInfo.is_round_active: -# self.setup() -# -# if not self.agent.gameInfo.is_kickoff_pause: -# # print(f"retiring due to kickoff pause") -# self.retire() -# -# if self.KO_option != None: -# if not self.KO_option.active: -# self.retire() -# return self.KO_option.update() -# -# # 0 == wide diagonal, 1 == short disgonal, 2 == middle -# if self.kickoff_type == 0: -# return self.wide_handler() -# elif self.kickoff_type == 1: -# return self.short_handler() -# else: -# return self.middle_handler() - -"" - - -# class PreemptiveStrike(baseState): -# def __init__(self, agent): -# super().__init__(agent) -# self.started = False -# self.firstFlip = None -# self.secondFlip = None -# self.startTime = agent.time -# self.kickoff_type = getKickoffPosition(agent.me.location) -# # 0 == wide diagonal, 1 == short disgonal, 2 == middle -# agent.stubbornessTimer = 5 -# self.onRight = True -# self.short_offset = 75 -# self.setup() -# self.enemyGoal = Vector([0, 5200 * -sign(self.agent.team), 0]) -# self.phase = 1 -# # if agent.team == 0: -# # self.KO_option = PreemptiveStrike_botpack(agent) -# # else: -# self.KO_option = None -# self.maintaining_speed = False -# self.first_recovery = None -# self.greedy = False -# self.greedy_req = 450 -# self.final_flip_dist = 575 -# -# def create_speed_flip_cancel(self, left=False): -# controls = [] -# timers = [] -# -# second_controller = SimpleControllerState() -# if not left: -# second_controller.steer = 1 -# else: -# second_controller.steer = -1 -# -# second_controller.throttle = 1 -# second_controller.boost = True -# second_controller.jump = True -# second_controller.pitch = 1 -# second_controller.handbrake = True -# controls.append(second_controller) -# timers.append(0.10) -# -# third_controller = SimpleControllerState() -# third_controller.jump = False -# third_controller.boost = True -# third_controller.throttle = 1 -# third_controller.pitch = 1 -# controls.append(third_controller) -# timers.append(self.agent.fakeDeltaTime * 2) -# -# fourth_controller = SimpleControllerState() -# # yaw = 1 -# # if left: -# # yaw = -1 -# -# yaw = -1 -# if left: -# yaw = 1 -# -# fourth_controller.yaw = yaw -# # fourth_controller.roll = yaw -# fourth_controller.pitch = -1 -# fourth_controller.jump = True -# fourth_controller.boost = True -# fourth_controller.throttle = 1 -# controls.append(fourth_controller) -# timers.append(0.05) -# -# fifth_controller = SimpleControllerState() -# fifth_controller.yaw = -yaw -# # fifth_controller.roll = -yaw -# fifth_controller.pitch = 1 -# fifth_controller.throttle = 1 -# fifth_controller.boost = True -# fifth_controller.handbrake = False -# fifth_controller.jump = True -# controls.append(fifth_controller) -# timers.append(0.75) -# -# action = Divine_Mandate(self.agent, controls, timers) -# # print(type(action)) -# return action -# -# def create_diagonal_speed_flip(self, left=False): -# controls = [] -# timers = [] -# # jump start -# first_controller = SimpleControllerState() -# if self.kickoff_type == 0: -# if self.onRight: -# first_controller.yaw = -1 -# else: -# first_controller.yaw = 1 -# -# first_controller.jump = True -# first_controller.boost = True -# first_controller.throttle = 1 -# first_controller.pitch = -1 -# first_controller.jump = True -# controls.append(first_controller) -# timers.append(0.1) -# -# # jump delay -# second_controller = SimpleControllerState() -# second_controller.jump = False -# second_controller.boost = True -# second_controller.throttle = 1 -# if left: -# yaw = -0.75 -# else: -# yaw = 0.75 -# -# pitch = -0.25 -# -# second_controller.yaw = yaw -# second_controller.pitch = pitch -# second_controller.jump = False -# -# controls.append(second_controller) -# timers.append(self.agent.fakeDeltaTime * 4) -# -# # jump flip -# third_controller = SimpleControllerState() -# third_controller.jump = True -# third_controller.boost = True -# third_controller.throttle = 1 -# -# if left: -# yaw = -0.75 -# else: -# yaw = 0.75 -# -# pitch = -0.25 -# -# third_controller.yaw = yaw -# third_controller.pitch = pitch -# controls.append(third_controller) -# timers.append(0.5) -# -# action = Divine_Mandate(self.agent, controls, timers) -# # print(type(action)) -# return action -# -# def setup(self): -# # setup randomness like offsets to either side of the ball. Make sure it's slightly offset from middle so we can flip center -# # setup flips -# ball_local = ( -# self.agent.ball.local_location -# ) # localizeVector(Vector([0, 0, 0]), self.agent.me) -# if self.kickoff_type == 0: -# if ball_local[1] > 0: -# # self.firstFlip = self.create_diagonal_speed_flip(left=True) -# # self.firstFlip = LeapOfFaith(self.agent,9) -# self.firstFlip = self.create_speed_flip_cancel(left=False) -# self.onRight = False -# # print("flipping left") -# else: -# # self.firstFlip = self.create_diagonal_speed_flip(left=False) -# # self.firstFlip = LeapOfFaith(self.agent, 10) -# self.firstFlip = self.create_speed_flip_cancel(left=True) -# self.onRight = True -# # print("flipping right") -# -# elif self.kickoff_type == 1: -# if ball_local[1] < 0: -# self.firstFlip = self.create_diagonal_speed_flip(left=False) -# self.onRight = True -# self.short_offset = -50 * sign(self.agent.team) -# else: -# self.firstFlip = self.create_diagonal_speed_flip(left=True) -# self.onRight = False -# self.short_offset = 50 * sign(self.agent.team) -# # print(f"on left and short offset == {self.short_offset}") -# -# else: -# # middle kickoff defaulting to right -# self.firstFlip = self.create_diagonal_speed_flip(left=True) -# # self.onRight shouldn't matter -# -# def wide_handler(self): -# # stage 1 - drive to boost pad -# if self.phase == 1: -# if distance2D(self.agent.me.location, self.agent.ball.location) > 3155: -# # return driveController(self.agent, self.enemyGoal+Vector([0,4000*sign(self.agent.team),0]), -# return driveController( -# self.agent, -# self.agent.ball.location, -# #+ Vector([0, sign(self.agent.team) * -50, 0]), -# #+ Vector([0, sign(self.agent.team) * -20, 0]), -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 3 -# -# # stage 3 - first flip -# if self.phase == 3: -# # if self.firstFlip == None: -# # self.firstFlip = self.create_speed_flip_cancel(left=not self.onRight) -# if self.firstFlip.active: -# # print(f"first flip active: {str(self.firstFlip)} {self.agent.time} {self.firstFlip.targetCode}") -# return self.firstFlip.update() -# -# if not self.agent.onSurface: -# _controller = SimpleControllerState() -# ( -# _controller.steer, -# _controller.yaw, -# _controller.pitch, -# _controller.roll, -# _err, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# _controller.boost = True -# _controller.handbrake = True -# return _controller -# -# else: -# self.phase = 4 -# # print(f"switched to stage 4! {self.agent.time}") -# -# # stage 4 - aim towards just offcenter of ball -# if self.phase == 4: -# if distance2D(self.agent.me.location, self.agent.ball.location) > self.final_flip_dist: -# drive_target = self.agent.ball.location -# # if self.agent.me.location[0] > self.agent.ball.location[0]: -# # dummy_location = self.agent.ball.location + Vector( -# # [25, 120 * sign(self.agent.team), 0] -# # ) -# # # _direction = direction(self.enemyGoal,self.agent.ball.location) -# # drive_target = dummy_location # + _direction.scale(distance2D(self.agent.me.location,dummy_location)*.5) -# # else: -# # dummy_location = self.agent.ball.location + Vector( -# # [-25, 120 * sign(self.agent.team), 0] -# # ) -# # # _direction = direction(self.enemyGoal, self.agent.ball.location) -# # drive_target = dummy_location # + _direction.scale( -# # # distance2D(self.agent.me.location, dummy_location) * .5) -# -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 5 -# # print(f"switched to stage 5! {self.agent.time}") -# -# # stage 5 - flip through center and end kickoff -# # 4 flip left, 5 flip right -# if self.phase == 5: -# if self.secondFlip is None and not self.greedy: -# self.greedy = distance2D(self.agent.me.location, self.agent.ball.location) + self.greedy_req <= distance2D(self.agent.closestEnemyToBall.location, self.agent.ball.location) -# if ( -# self.agent.team == 0 -# and self.agent.me.location[0] < self.agent.ball.location[0] -# or self.agent.team == 1 -# and self.agent.me.location[0] > self.agent.ball.location[0] -# ): -# _code = 5 -# else: -# _code = 4 -# # _code = 4 -# # else: -# # _code = 5 -# -# self.secondFlip = LeapOfFaith(self.agent, 0, target=None) #_code -# if not self.greedy: -# controls = self.secondFlip.update() -# if not self.secondFlip.active: -# self.retire() -# else: -# controls = driveController( -# self.agent, -# self.agent.ball.location, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# kickoff=True, -# ) -# controls.throttle = 0 -# if self.agent.ball.location[0] != 0 or self.agent.ball.location[1] != 0: -# self.retire() -# return controls -# -# def short_handler(self): -# # stage 1 - drive to boost pad -# if self.phase == 1: -# drive_target = Vector( -# [self.short_offset, sign(self.agent.team) * 2900.0, 0] -# ) -# if distance2D(self.agent.me.location, drive_target) > 525: -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 3 -# -# # stage 2 - angle towards outside of ball -# if self.phase == 2: -# controls = SimpleControllerState() -# if not self.agent.onSurface: -# ( -# controls.steer, -# controls.yaw, -# controls.pitch, -# controls.roll, -# alignment_error, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# return controls -# else: -# self.phase = 3 -# # stage 3 - first flip -# if self.phase == 3: -# if self.firstFlip.active: -# return self.firstFlip.update() -# if not self.agent.onSurface: -# _controller = SimpleControllerState() -# ( -# _controller.steer, -# _controller.yaw, -# _controller.pitch, -# _controller.roll, -# _err, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# _controller.boost = True -# _controller.handbrake = True -# return _controller -# else: -# self.phase = 4 -# -# # stage 4 - aim towards just offcenter of ball -# if self.phase == 4: -# if ( -# distance2D(self.agent.me.location, self.agent.ball.location) > self.final_flip_dist -# or not self.agent.onSurface -# ): -# drive_target = self.agent.ball.location -# # if self.agent.me.location[0] > self.agent.ball.location[0]: -# # dummy_location = self.agent.ball.location + Vector( -# # [65, 75 * sign(self.agent.team), 0] -# # ) -# # # _direction = direction(self.enemyGoal, self.agent.ball.location) -# # drive_target = dummy_location # + _direction.scale( -# # # distance2D(self.agent.me.location, dummy_location) * .5) -# # else: -# # dummy_location = self.agent.ball.location + Vector( -# # [-65, 75 * sign(self.agent.team), 0] -# # ) -# # # _direction = direction(self.enemyGoal, self.agent.ball.location) -# # drive_target = dummy_location # + _direction.scale( -# # # distance2D(self.agent.me.location, dummy_location) * .5) -# -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 5 -# -# # stage 5 - flip through center and end kickoff -# # 4 flip left, 5 flip right -# if self.phase == 5: -# if self.secondFlip is None and not self.greedy: -# self.greedy = distance2D(self.agent.me.location, self.agent.ball.location) + self.greedy_req <= distance2D( -# self.agent.closestEnemyToBall.location, self.agent.ball.location) -# if ( -# self.agent.team == 0 -# and self.agent.me.location[0] < self.agent.ball.location[0] -# or self.agent.team == 1 -# and self.agent.me.location[0] > self.agent.ball.location[0] -# ): -# _code = 4 -# else: -# _code = 5 -# # _code = 0 -# self.secondFlip = LeapOfFaith(self.agent, 0, target=None) -# -# if not self.greedy: -# controls = self.secondFlip.update() -# if not self.secondFlip.active: -# self.retire() -# else: -# controls = driveController( -# self.agent, -# self.agent.ball.location, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# kickoff=True, -# ) -# controls.throttle = 0 -# if self.agent.ball.location[0] != 0 or self.agent.ball.location[1] != 0: -# self.retire() -# return controls -# -# def middle_handler(self): -# # stage 1 - drive to boost pad -# if self.phase == 1: -# drive_target = Vector([0, sign(self.agent.team) * 4000, 0]) -# if distance2D(self.agent.me.location, drive_target) > 75: -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 2 -# -# # stage 2 - angle towards outside of ball -# if self.phase == 2: -# drive_target = Vector([4500 * sign(self.agent.team), 0, 0]) -# if ( -# distance2D(self.agent.me.location, self.agent.ball.location) > 3850 -# ): # 3875: -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 3 -# # stage 3 - first flip -# if self.phase == 3: -# if self.firstFlip.active: -# return self.firstFlip.update() -# else: -# if self.agent.onSurface: -# self.phase = 4 -# else: -# controls = SimpleControllerState() -# ( -# controls.steer, -# controls.yaw, -# controls.pitch, -# controls.roll, -# alignment_error, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# return controls -# -# # stage 4 - aim towards just offcenter of ball -# if self.phase == 4: -# -# if ( -# distance2D(self.agent.me.location, self.agent.ball.location) > self.final_flip_dist -# or not self.agent.onSurface -# ): -# drive_target = self.agent.ball.location -# # if self.agent.me.location[0] > self.agent.ball.location[0]: -# # dummy_location = self.agent.ball.location + Vector( -# # [55, 75 * sign(self.agent.team), 0] -# # ) -# # # _direction = direction(self.enemyGoal, self.agent.ball.location) -# # drive_target = dummy_location # + _direction.scale( -# # # distance2D(self.agent.me.location, dummy_location) * .5) -# # else: -# # dummy_location = self.agent.ball.location + Vector( -# # [-55, 75 * sign(self.agent.team), 0] -# # ) -# # # _direction = direction(self.enemyGoal, self.agent.ball.location) -# # drive_target = dummy_location # + _direction.scale( -# # # distance2D(self.agent.me.location, dummy_location) * .5) -# -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 5 -# -# # stage 5 - flip through center and end kickoff -# # 4 flip left, 5 flip right -# if self.phase == 5: -# if self.secondFlip is None and not self.greedy: -# self.greedy = distance2D(self.agent.me.location, self.agent.ball.location) + self.greedy_req <= distance2D( -# self.agent.closestEnemyToBall.location, self.agent.ball.location) -# if ( -# self.agent.team == 0 -# and self.agent.me.location[0] < self.agent.ball.location[0] -# or self.agent.team == 1 -# and self.agent.me.location[0] > self.agent.ball.location[0] -# ): -# _code = 4 -# else: -# _code = 5 -# # _code = 0 -# self.secondFlip = LeapOfFaith(self.agent, 0, target=None) -# if not self.greedy: -# controls = self.secondFlip.update() -# if not self.secondFlip.active: -# self.retire() -# else: -# controls = driveController( -# self.agent, -# self.agent.ball.location, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# kickoff=True, -# ) -# controls.throttle = 0 -# if self.agent.ball.location[0] != 0 or self.agent.ball.location[1] != 0: -# self.retire() -# return controls -# -# def retire(self): -# self.active = False -# if self.secondFlip and self.secondFlip.active: -# self.agent.activeState = self.secondFlip -# # self.agent.activeState = None -# # print(f"retiring on stage {self.phase} {self.agent.time}") -# -# def update(self): -# if not self.agent.gameInfo.is_round_active: -# self.setup() -# -# if not self.agent.gameInfo.is_kickoff_pause: -# # print(f"retiring due to kickoff pause") -# self.retire() -# -# if self.KO_option is not None: -# if not self.KO_option.active: -# self.retire() -# return self.KO_option.update() -# -# # 0 == wide diagonal, 1 == short disgonal, 2 == middle -# if self.kickoff_type == 0: -# return self.wide_handler() -# elif self.kickoff_type == 1: -# return self.short_handler() -# else: -# return self.middle_handler() - -class PreemptiveStrike(baseState): #testing 2/25/22 - def __init__(self, agent): - super().__init__(agent) - self.started = False - self.firstFlip = None - self.secondFlip = None - self.startTime = agent.time - self.kickoff_type = getKickoffPosition(agent.me.location) - # 0 == wide diagonal, 1 == short disgonal, 2 == middle - agent.stubbornessTimer = 5 - self.onRight = True - self.short_offset = 75 - self.setup() - self.enemyGoal = Vector([0, 5200 * -sign(self.agent.team), 0]) - self.phase = 1 - # if agent.team == 0: - # self.KO_option = PreemptiveStrike_botpack(agent) - # else: - self.KO_option = None - self.maintaining_speed = False - self.first_recovery = None - self.greedy = False - self.greedy_req = 450 - self.final_flip_dist = 500 - - def create_speed_flip_cancel(self, left=False): - controls = [] - timers = [] - - second_controller = SimpleControllerState() - if not left: - second_controller.steer = 1 - else: - second_controller.steer = -1 - - second_controller.throttle = 1 - second_controller.boost = True - second_controller.jump = True - second_controller.pitch = 1 - second_controller.handbrake = True - controls.append(second_controller) - timers.append(0.10) - - third_controller = SimpleControllerState() - third_controller.jump = False - third_controller.boost = True - third_controller.throttle = 1 - third_controller.pitch = 1 - controls.append(third_controller) - timers.append(self.agent.fakeDeltaTime * 2) - - fourth_controller = SimpleControllerState() - # yaw = 1 - # if left: - # yaw = -1 - - yaw = -1 - if left: - yaw = 1 - - fourth_controller.yaw = yaw - # fourth_controller.roll = yaw - fourth_controller.pitch = -1 - fourth_controller.jump = True - fourth_controller.boost = True - fourth_controller.throttle = 1 - controls.append(fourth_controller) - timers.append(0.05) - - fifth_controller = SimpleControllerState() - fifth_controller.yaw = -yaw - # fifth_controller.roll = -yaw - fifth_controller.pitch = 1 - fifth_controller.throttle = 1 - fifth_controller.boost = True - fifth_controller.handbrake = False - fifth_controller.jump = True - controls.append(fifth_controller) - timers.append(0.75) - - action = Divine_Mandate(self.agent, controls, timers) - # print(type(action)) - return action - - def create_diagonal_speed_flip(self, left=False): - controls = [] - timers = [] - # jump start - first_controller = SimpleControllerState() - if self.kickoff_type == 0: - if self.onRight: - first_controller.yaw = -1 - else: - first_controller.yaw = 1 - - first_controller.jump = True - first_controller.boost = True - first_controller.throttle = 1 - first_controller.pitch = -1 - first_controller.jump = True - controls.append(first_controller) - timers.append(0.1) - - # jump delay - second_controller = SimpleControllerState() - second_controller.jump = False - second_controller.boost = True - second_controller.throttle = 1 - if left: - yaw = -0.75 - else: - yaw = 0.75 - - pitch = -0.25 - - second_controller.yaw = yaw - second_controller.pitch = pitch - second_controller.jump = False - - controls.append(second_controller) - timers.append(self.agent.fakeDeltaTime * 4) - - # jump flip - third_controller = SimpleControllerState() - third_controller.jump = True - third_controller.boost = True - third_controller.throttle = 1 - - if left: - yaw = -0.75 - else: - yaw = 0.75 - - pitch = -0.25 - - third_controller.yaw = yaw - third_controller.pitch = pitch - controls.append(third_controller) - timers.append(0.5) - - action = Divine_Mandate(self.agent, controls, timers) - # print(type(action)) - return action - - def setup(self): - # setup randomness like offsets to either side of the ball. Make sure it's slightly offset from middle so we can flip center - # setup flips - ball_local = ( - self.agent.ball.local_location - ) # localizeVector(Vector([0, 0, 0]), self.agent.me) - if self.kickoff_type == 0: - if ball_local[1] > 0: - # self.firstFlip = self.create_diagonal_speed_flip(left=True) - # self.firstFlip = LeapOfFaith(self.agent,9) - self.firstFlip = self.create_speed_flip_cancel(left=False) - self.onRight = False - # print("flipping left") - else: - # self.firstFlip = self.create_diagonal_speed_flip(left=False) - # self.firstFlip = LeapOfFaith(self.agent, 10) - self.firstFlip = self.create_speed_flip_cancel(left=True) - self.onRight = True - # print("flipping right") - - elif self.kickoff_type == 1: - if ball_local[1] < 0: - self.firstFlip = self.create_diagonal_speed_flip(left=False) - self.onRight = True - self.short_offset = -75 * sign(self.agent.team) - else: - self.firstFlip = self.create_diagonal_speed_flip(left=True) - self.onRight = False - self.short_offset = 75 * sign(self.agent.team) - # print(f"on left and short offset == {self.short_offset}") - - else: - # middle kickoff defaulting to right - self.firstFlip = self.create_diagonal_speed_flip(left=True) - # self.onRight shouldn't matter - - def wide_handler(self): - # stage 1 - drive to boost pad - if self.phase == 1: - if distance2D(self.agent.me.location, self.agent.ball.location) > 3110: - # return driveController(self.agent, self.enemyGoal+Vector([0,4000*sign(self.agent.team),0]), - x_offset = 250 if self.agent.me.location[0] > self.agent.ball.location[0] else -250 - return driveController( - self.agent, - self.agent.ball.location + Vector([x_offset,0,0]), - #+ Vector([0, sign(self.agent.team) * -50, 0]), - #+ Vector([0, sign(self.agent.team) * -20, 0]), - 0, - expedite=True, - flippant=False, - maintainSpeed=self.maintaining_speed, - kickoff=True, - ) - else: - self.phase = 3 - - # stage 3 - first flip - if self.phase == 3: - # if self.firstFlip == None: - # self.firstFlip = self.create_speed_flip_cancel(left=not self.onRight) - if self.firstFlip.active: - # print(f"first flip active: {str(self.firstFlip)} {self.agent.time} {self.firstFlip.targetCode}") - return self.firstFlip.update() - - if not self.agent.onSurface: - _controller = SimpleControllerState() - ( - _controller.steer, - _controller.yaw, - _controller.pitch, - _controller.roll, - _err, - ) = point_at_position( - self.agent, - self.agent.me.location - + self.agent.me.velocity.normalize().flatten().scale(1000), - ) - _controller.boost = True - _controller.handbrake = True - return _controller - - else: - self.phase = 4 - # print(f"switched to stage 4! {self.agent.time}") - - # stage 4 - aim towards just offcenter of ball - if self.phase == 4: - if distance2D(self.agent.me.location, self.agent.ball.location) > self.final_flip_dist: - #drive_target = self.agent.ball.location - #if toLocal(self.agent.ball.location, self.agent.me)[0] > 0: - if (self.agent.me.location - self.agent.ball.location)[0] > 0: - dummy_location = [35, 0, 0] - else: - dummy_location = [-35, 0, 0] - - drive_target = self.agent.ball.location + Vector(dummy_location) - return driveController( - self.agent, - drive_target, - 0, - expedite=not self.agent.superSonic, - flippant=False, - maintainSpeed=self.maintaining_speed, - kickoff=True, - ) - else: - self.phase = 5 - # print(f"switched to stage 5! {self.agent.time}") - - # stage 5 - flip through center and end kickoff - # 4 flip left, 5 flip right - if self.phase == 5: - if self.secondFlip is None and not self.greedy: - self.greedy = distance2D(self.agent.me.location, self.agent.ball.location) + self.greedy_req <= distance2D(self.agent.closestEnemyToBall.location, self.agent.ball.location) - if (self.agent.me.location - self.agent.ball.location)[0] > 0: - _code = 5 - else: - _code = 4 - - self.secondFlip = LeapOfFaith(self.agent, 0, target=None) #_code - if not self.greedy: - controls = self.secondFlip.update() - if not self.secondFlip.active: - self.retire() - else: - controls = driveController( - self.agent, - self.agent.ball.location, - 0, - expedite=not self.agent.superSonic, - flippant=False, - kickoff=True, - ) - controls.throttle = 0 - if self.agent.ball.location[0] != 0 or self.agent.ball.location[1] != 0: - self.retire() - return controls - - def short_handler(self): - # stage 1 - drive to boost pad - if self.phase == 1: - drive_target = Vector( - [self.short_offset, sign(self.agent.team) * 2800.0, 0] - ) - if distance2D(self.agent.me.location, drive_target) > 555: - return driveController( - self.agent, - drive_target, - 0, - expedite=True, - flippant=False, - maintainSpeed=self.maintaining_speed, - kickoff=True, - ) - else: - self.phase = 3 - - # stage 2 - angle towards outside of ball - if self.phase == 2: - controls = SimpleControllerState() - if not self.agent.onSurface: - ( - controls.steer, - controls.yaw, - controls.pitch, - controls.roll, - alignment_error, - ) = point_at_position( - self.agent, - self.agent.me.location - + self.agent.me.velocity.normalize().flatten().scale(1000), - ) - return controls - else: - self.phase = 3 - # stage 3 - first flip - if self.phase == 3: - if self.firstFlip.active: - return self.firstFlip.update() - if not self.agent.onSurface: - _controller = SimpleControllerState() - ( - _controller.steer, - _controller.yaw, - _controller.pitch, - _controller.roll, - _err, - ) = point_at_position( - self.agent, - self.agent.me.location - + self.agent.me.velocity.normalize().flatten().scale(1000), - ) - _controller.boost = True - _controller.handbrake = True - return _controller - else: - self.phase = 4 - - # stage 4 - aim towards just offcenter of ball - if self.phase == 4: - if ( - distance2D(self.agent.me.location, self.agent.ball.location) > self.final_flip_dist - or not self.agent.onSurface - ): - drive_target = self.agent.ball.location - if (self.agent.me.location - self.agent.ball.location)[0] > 0: - dummy_location = [45, 0, 0] - else: - dummy_location = [-45, 0, 0] - - return driveController( - self.agent, - drive_target+Vector(dummy_location), - 0, - expedite=not self.agent.superSonic, - flippant=False, - maintainSpeed=self.maintaining_speed, - kickoff=True, - ) - else: - self.phase = 5 - - # stage 5 - flip through center and end kickoff - # 4 flip left, 5 flip right - if self.phase == 5: - if self.secondFlip is None and not self.greedy: - self.greedy = distance2D(self.agent.me.location, self.agent.ball.location) + self.greedy_req <= distance2D( - self.agent.closestEnemyToBall.location, self.agent.ball.location) - if (self.agent.me.location - self.agent.ball.location)[0] > 0: - _code = 5 - else: - _code = 4 - self.secondFlip = LeapOfFaith(self.agent, 0, target=None) - - if not self.greedy: - controls = self.secondFlip.update() - if not self.secondFlip.active: - self.retire() - else: - controls = driveController( - self.agent, - self.agent.ball.location, - 0, - expedite=not self.agent.superSonic, - flippant=False, - kickoff=True, - ) - controls.throttle = 0 - if self.agent.ball.location[0] != 0 or self.agent.ball.location[1] != 0: - self.retire() - return controls - - def middle_handler(self): - # stage 1 - drive to boost pad - if self.phase == 1: - drive_target = Vector([0, sign(self.agent.team) * 4015, 0]) - if distance2D(self.agent.me.location, drive_target) > 75: - return driveController( - self.agent, - drive_target, - 0, - expedite=True, - flippant=False, - maintainSpeed=self.maintaining_speed, - kickoff=True, - ) - else: - self.phase = 2 - - # stage 2 - angle towards outside of ball - if self.phase == 2: - drive_target = Vector([4500 * sign(self.agent.team), 0, 0]) - if ( - distance2D(self.agent.me.location, self.agent.ball.location) > 3875 - ): # 3875: - return driveController( - self.agent, - drive_target, - 0, - expedite=True, - flippant=False, - maintainSpeed=self.maintaining_speed, - kickoff=True, - ) - else: - self.phase = 3 - # stage 3 - first flip - if self.phase == 3: - if self.firstFlip.active: - return self.firstFlip.update() - else: - if self.agent.onSurface: - self.phase = 4 - else: - controls = SimpleControllerState() - ( - controls.steer, - controls.yaw, - controls.pitch, - controls.roll, - alignment_error, - ) = point_at_position( - self.agent, - self.agent.me.location - + self.agent.me.velocity.normalize().flatten().scale(1000), - ) - return controls - - # stage 4 - aim towards just offcenter of ball - if self.phase == 4: - - if ( - distance2D(self.agent.me.location, self.agent.ball.location) > self.final_flip_dist - or not self.agent.onSurface - ): - drive_target = self.agent.ball.location - if (self.agent.me.location - self.agent.ball.location)[0] > 0: - dummy_location = [25, 0, 0] - else: - dummy_location = [-25, 0, 0] - - return driveController( - self.agent, - drive_target + Vector(dummy_location), - 0, - expedite=not self.agent.superSonic, - flippant=False, - maintainSpeed=self.maintaining_speed, - kickoff=True, - ) - else: - self.phase = 5 - - # stage 5 - flip through center and end kickoff - # 4 flip left, 5 flip right - if self.phase == 5: - if self.secondFlip is None and not self.greedy: - self.greedy = distance2D(self.agent.me.location, self.agent.ball.location) + self.greedy_req <= distance2D( - self.agent.closestEnemyToBall.location, self.agent.ball.location) - if (self.agent.me.location - self.agent.ball.location)[0] > 0: - _code = 5 - else: - _code = 4 - # _code = 0 - self.secondFlip = LeapOfFaith(self.agent, 0, target=None) - if not self.greedy: - controls = self.secondFlip.update() - if not self.secondFlip.active: - self.retire() - else: - controls = driveController( - self.agent, - self.agent.ball.location, - 0, - expedite=not self.agent.superSonic, - flippant=False, - kickoff=True, - ) - controls.throttle = 0 - if self.agent.ball.location[0] != 0 or self.agent.ball.location[1] != 0: - self.retire() - return controls - - def retire(self): - self.active = False - if self.secondFlip and self.secondFlip.active: - self.agent.activeState = self.secondFlip - # self.agent.activeState = None - # print(f"retiring on stage {self.phase} {self.agent.time}") - - def update(self): - if not self.agent.gameInfo.is_round_active: - self.setup() - - if not self.agent.gameInfo.is_kickoff_pause: - # print(f"retiring due to kickoff pause") - self.retire() - - if self.KO_option is not None: - if not self.KO_option.active: - self.retire() - return self.KO_option.update() - - # 0 == wide diagonal, 1 == short disgonal, 2 == middle - if self.kickoff_type == 0: - return self.wide_handler() - elif self.kickoff_type == 1: - return self.short_handler() - else: - return self.middle_handler() - -"" - -# class PreemptiveStrike(baseState): # real kickoff -# def __init__(self, agent): -# self.agent = agent -# self.fakeDeltaTime = agent.fakeDeltaTime -# self.started = False -# self.firstFlip = None -# self.secondFlip = None -# self.active = True -# self.startTime = agent.time -# self.kickoff_type = getKickoffPosition(agent.me.location) -# agent.stubbornessTimer = 5 -# self.onRight = True -# self.short_offset = 75 -# self.setup() -# self.enemyGoal = Vector([0, 5200 * -sign(self.agent.team), 0]) -# self.phase = 1 -# self.KO_option = None -# self.maintaining_speed = False -# self.first_recovery = None -# self.queued_retire = False -# -# -# def create_speed_flip_cancel(self, left=False): -# controls = [] -# timers = [] -# -# second_controller = SimpleControllerState() -# if not left: -# second_controller.steer = 1 -# else: -# second_controller.steer = -1 -# -# second_controller.throttle = 1 -# second_controller.boost = True -# second_controller.jump = True -# second_controller.pitch = 1 -# second_controller.handbrake = True -# controls.append(second_controller) -# timers.append(0.10) -# -# third_controller = SimpleControllerState() -# third_controller.jump = False -# third_controller.boost = True -# third_controller.throttle = 1 -# third_controller.pitch = 1 -# controls.append(third_controller) -# timers.append(self.fakeDeltaTime * 1.5) -# -# fourth_controller = SimpleControllerState() -# -# yaw = -1 -# if left: -# yaw = 1 -# -# fourth_controller.yaw = yaw -# # fourth_controller.roll = yaw -# fourth_controller.pitch = -1 -# fourth_controller.jump = True -# fourth_controller.boost = True -# fourth_controller.throttle = 1 -# controls.append(fourth_controller) -# timers.append(0.05) -# -# fifth_controller = SimpleControllerState() -# fifth_controller.yaw = -yaw -# # fifth_controller.roll = -yaw -# fifth_controller.pitch = 1 -# fifth_controller.throttle = 1 -# fifth_controller.boost = True -# fifth_controller.handbrake = False -# fifth_controller.jump = True -# controls.append(fifth_controller) -# timers.append(0.75) -# -# action = Divine_Mandate(self.agent, controls, timers) -# # print(type(action)) -# return action -# -# def create_diagonal_speed_flip(self, left=False): -# controls = [] -# timers = [] -# # jump start -# first_controller = SimpleControllerState() -# if self.kickoff_type == 0: -# if self.onRight: -# first_controller.yaw = -1 -# else: -# first_controller.yaw = 1 -# -# first_controller.jump = True -# first_controller.boost = True -# first_controller.throttle = 1 -# first_controller.pitch = -1 -# first_controller.jump = True -# controls.append(first_controller) -# timers.append(0.1) -# -# # jump delay -# second_controller = SimpleControllerState() -# second_controller.jump = False -# second_controller.boost = True -# second_controller.throttle = 1 -# if left: -# yaw = -0.75 -# else: -# yaw = 0.75 -# -# pitch = -0.25 -# -# second_controller.yaw = yaw -# second_controller.pitch = pitch -# second_controller.jump = False -# -# controls.append(second_controller) -# timers.append(self.fakeDeltaTime * 2) -# -# # jump flip -# third_controller = SimpleControllerState() -# third_controller.jump = True -# third_controller.boost = True -# third_controller.throttle = 1 -# -# if left: -# yaw = -0.75 -# else: -# yaw = 0.75 -# -# pitch = -0.25 -# -# third_controller.yaw = yaw -# third_controller.pitch = pitch -# controls.append(third_controller) -# timers.append(0.5) -# -# action = Divine_Mandate(self.agent, controls, timers) -# # print(type(action)) -# return action -# -# def setup(self): -# # setup randomness like offsets to either side of the ball. Make sure it's slightly offset from middle so we can flip center -# # setup flips -# ball_local = ( -# self.agent.ball.local_location -# ) # localizeVector(Vector([0, 0, 0]), self.agent.me) -# if self.kickoff_type == 0: -# if ball_local[1] > 0: -# # self.firstFlip = self.create_diagonal_speed_flip(left=True) -# # self.firstFlip = LeapOfFaith(self.agent,9) -# self.firstFlip = self.create_speed_flip_cancel(left=False) -# self.onRight = False -# # print("flipping left") -# else: -# # self.firstFlip = self.create_diagonal_speed_flip(left=False) -# # self.firstFlip = LeapOfFaith(self.agent, 10) -# self.firstFlip = self.create_speed_flip_cancel(left=True) -# self.onRight = True -# # print("flipping right") -# -# elif self.kickoff_type == 1: -# if ball_local[1] < 0: -# self.firstFlip = self.create_diagonal_speed_flip(left=False) -# self.onRight = True -# self.short_offset = -50 * sign(self.agent.team) -# else: -# self.firstFlip = self.create_diagonal_speed_flip(left=True) -# self.onRight = False -# self.short_offset = 50 * sign(self.agent.team) -# # print(f"on left and short offset == {self.short_offset}") -# -# else: -# # middle kickoff defaulting to right -# self.firstFlip = self.create_diagonal_speed_flip(left=True) -# # self.onRight shouldn't matter -# -# def wide_handler(self): -# # stage 1 - drive to boost pad -# if self.phase == 1: -# if distance2D(self.agent.me.location, self.agent.ball.location) > 3150: -# if self.agent.me.location[1] < 0: -# y_off = -40 -# else: -# y_off = 40 -# -# return driveController( -# self.agent, -# self.agent.ball.location + Vector([0, y_off, 0]), -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 3 -# -# # stage 3 - first flip -# if self.phase == 3: -# if self.firstFlip.active: -# return self.firstFlip.update() -# # controls = self.firstFlip.update() -# # if self.agent.currentSpd > 2210: -# # controls.boost = False -# # return controls -# -# if not self.agent.onSurface: -# _controller = SimpleControllerState() -# ( -# _controller.steer, -# _controller.yaw, -# _controller.pitch, -# _controller.roll, -# _err, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# _controller.boost = True -# _controller.handbrake = True -# return _controller -# -# else: -# self.phase = 4 -# # print(f"switched to stage 4! {self.agent.time}") -# -# # stage 4 - aim towards just offcenter of ball -# if self.phase == 4: -# if distance2D(self.agent.me.location, self.agent.ball.location) > 550: -# if self.agent.me.location[0] > self.agent.ball.location[0]: -# dummy_location = self.agent.ball.location + Vector( -# [35, 120 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal,self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale(distance2D(self.agent.me.location,dummy_location)*.5) -# else: -# dummy_location = self.agent.ball.location + Vector( -# [-35, 120 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 5 -# # print(f"switched to stage 5! {self.agent.time}") -# -# # stage 5 - flip through center and end kickoff -# # 4 flip left, 5 flip right -# if self.phase == 5: -# # if distance2D(self.agent.closestEnemyToBall.location,self.agent.ball.location) < 600: -# if self.secondFlip == None: -# if ( -# self.agent.team == 0 -# and self.agent.me.location[0] < self.agent.ball.location[0] -# or self.agent.team == 1 -# and self.agent.me.location[0] > self.agent.ball.location[0] -# ): -# _code = 5 -# else: -# _code = 4 -# # _code = 4 -# # else: -# # _code = 5 -# -# self.secondFlip = LeapOfFaith(self.agent, _code, target=None) -# controls = self.secondFlip.update() -# if not self.secondFlip.active: -# self.retire() -# return controls -# -# def short_handler(self): -# # stage 1 - drive to boost pad -# if self.phase == 1: -# drive_target = Vector( -# [self.short_offset, sign(self.agent.team) * 2850.0, 0] -# ) -# if distance2D(self.agent.me.location, drive_target) > 575: -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 3 -# -# # stage 2 - angle towards outside of ball -# if self.phase == 2: -# controls = SimpleControllerState() -# if not self.agent.onSurface: -# ( -# controls.steer, -# controls.yaw, -# controls.pitch, -# controls.roll, -# alignment_error, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# return controls -# else: -# self.phase = 3 -# # stage 3 - first flip -# if self.phase == 3: -# if self.firstFlip.active: -# controls = self.firstFlip.update() -# if self.agent.currentSpd > 2210: -# controls.boost = False -# return controls -# # return self.firstFlip.update() -# if not self.agent.onSurface: -# _controller = SimpleControllerState() -# ( -# _controller.steer, -# _controller.yaw, -# _controller.pitch, -# _controller.roll, -# _err, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# _controller.boost = True -# _controller.handbrake = True -# return _controller -# else: -# self.phase = 4 -# -# # stage 4 - aim towards just offcenter of ball -# if self.phase == 4: -# if ( -# distance2D(self.agent.me.location, self.agent.ball.location) > 550 -# or not self.agent.onSurface -# ): -# if self.agent.me.location[0] > self.agent.ball.location[0]: -# dummy_location = self.agent.ball.location + Vector( -# [60, 120 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# else: -# dummy_location = self.agent.ball.location + Vector( -# [-60, 120 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 5 -# -# # stage 5 - flip through center and end kickoff -# # 4 flip left, 5 flip right -# if self.phase == 5: -# if self.secondFlip == None: -# if ( -# self.agent.team == 0 -# and self.agent.me.location[0] < self.agent.ball.location[0] -# or self.agent.team == 1 -# and self.agent.me.location[0] > self.agent.ball.location[0] -# ): -# _code = 4 -# else: -# _code = 5 -# # _code = 0 -# self.secondFlip = LeapOfFaith(self.agent, _code, target=None) -# controls = self.secondFlip.update() -# if not self.secondFlip.active: -# self.retire() -# return controls -# -# def middle_handler(self): -# # stage 1 - drive to boost pad -# if self.phase == 1: -# drive_target = Vector([0, sign(self.agent.team) * 4000, 0]) -# if distance2D(self.agent.me.location, drive_target) > 75: -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 2 -# -# # stage 2 - angle towards outside of ball -# if self.phase == 2: -# drive_target = Vector([4500 * sign(self.agent.team), 0, 0]) -# if ( -# distance2D(self.agent.me.location, self.agent.ball.location) > 3850 -# ): # 3875: -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=True, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 3 -# # stage 3 - first flip -# if self.phase == 3: -# if self.firstFlip.active: -# controls = self.firstFlip.update() -# if self.agent.currentSpd > 2210: -# controls.boost = False -# return controls -# # return self.firstFlip.update() -# else: -# if self.agent.onSurface: -# self.phase = 4 -# else: -# controls = SimpleControllerState() -# ( -# controls.steer, -# controls.yaw, -# controls.pitch, -# controls.roll, -# alignment_error, -# ) = point_at_position( -# self.agent, -# self.agent.me.location -# + self.agent.me.velocity.normalize().flatten().scale(1000), -# ) -# return controls -# -# # stage 4 - aim towards just offcenter of ball -# if self.phase == 4: -# -# if ( -# distance2D(self.agent.me.location, self.agent.ball.location) > 550 -# or not self.agent.onSurface -# ): -# if self.agent.me.location[0] > self.agent.ball.location[0]: -# dummy_location = self.agent.ball.location + Vector( -# [45, 120 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# else: -# dummy_location = self.agent.ball.location + Vector( -# [-45, 120 * sign(self.agent.team), 0] -# ) -# # _direction = direction(self.enemyGoal, self.agent.ball.location) -# drive_target = dummy_location # + _direction.scale( -# # distance2D(self.agent.me.location, dummy_location) * .5) -# -# return driveController( -# self.agent, -# drive_target, -# 0, -# expedite=not self.agent.superSonic, -# flippant=False, -# maintainSpeed=self.maintaining_speed, -# kickoff=True, -# ) -# else: -# self.phase = 5 -# -# # stage 5 - flip through center and end kickoff -# # 4 flip left, 5 flip right -# if self.phase == 5: -# if self.secondFlip == None: -# if ( -# self.agent.team == 0 -# and self.agent.me.location[0] < self.agent.ball.location[0] -# or self.agent.team == 1 -# and self.agent.me.location[0] > self.agent.ball.location[0] -# ): -# _code = 4 -# else: -# _code = 5 -# # _code = 0 -# self.secondFlip = LeapOfFaith(self.agent, _code, target=None) -# controls = self.secondFlip.update() -# if not self.secondFlip.active: -# self.retire() -# return controls -# -# def retire(self): -# if ( -# not self.secondFlip -# or not self.secondFlip.active -# or self.agent.time - self.startTime > 3 -# ): -# self.active = False -# else: -# self.queued_retire = True -# -# def update(self): -# if not self.agent.gameInfo.is_round_active: -# self.setup() -# -# if not self.agent.gameInfo.is_kickoff_pause or self.agent.ball.location.flatten() != Vector( -# [0, 0, 0] -# ): -# # print(f"retiring due to kickoff pause") -# self.retire() -# -# if self.queued_retire: -# self.retire() -# -# if self.KO_option != None: -# if not self.KO_option.active: -# self.retire() -# return self.KO_option.update() -# -# # 0 == wide diagonal, 1 == short disgonal, 2 == middle -# if self.kickoff_type == 0: -# return self.wide_handler() -# elif self.kickoff_type == 1: -# return self.short_handler() -# else: -# return self.middle_handler() - - -class DivineGrace(baseState): - def __init__(self, agent): - super().__init__(agent) - # self.run_simulation() - # print(f"default elevation is: {self.agent.defaultElevation}") - self.x_limit = 4096 - self.agent.defaultElevation - self.y_limit = 5120 - self.agent.defaultElevation - self.ground_limit = self.agent.defaultElevation - self.ceiling_limit = 2044 - self.agent.defaultElevation - self.ideal_orientation = Vector([0, 0, 0]) - # self.tick_length = 3 - # self.squash_index = 0 - # self.update_count = 0 - # self.collision_timer = 0 - # self.collision_location = Vector([0, 0, 0]) - # self.aim_direction = None - self.recovery_limit = 1.25 - - def get_roll_value(self): - if self.agent.roll_type == 1: - return turnController( - -self.agent.me.rotation[2], self.agent.me.rotational_velocity[0] / 4 - ) # will make bot roll top up - - elif self.agent.roll_type == 2: - return turnController( - self.agent.me.rotation[2], self.agent.me.rotational_velocity[0] / 4 - ) # will make bot roll top down - - elif self.agent.roll_type == 3: - return turnController( - -(3.1415 / 2) - self.agent.me.rotation[2], - self.agent.me.rotational_velocity[0] / 4, - ) # will make bot roll top left - - elif self.agent.roll_type == 4: - return turnController( - 3.1415 / 2 - self.agent.me.rotation[2], - self.agent.me.rotational_velocity[0] / 4, - ) # will make bot roll top right - - def get_controls(self): - controller_state = SimpleControllerState() - - aim_vector = self.agent.collision_location - self.agent.me.location - if self.agent.collision_timer <= self.recovery_limit: - aim_vector.data[self.agent.squash_index] = 0 - - if ( - self.agent.aim_direction is not None - and self.agent.collision_timer > self.recovery_limit - and self.agent.me.location[2] > 100 - ): - aim_vector = ( - self.agent.aim_direction - ) # (self.aim_direction + aim_vector.normalize()).normalize() - - aim_vector = aim_vector.normalize() - - align_car_to(controller_state, self.agent.me.avelocity, aim_vector, self.agent) - - # print(self.collision_timer) - if self.agent.collision_timer > self.recovery_limit: - if self.agent._forward.dotProduct(aim_vector) > 0.7: - if self.agent.me.velocity[2] > -1700 or self.agent.boostMonster: - if self.agent.me.boostLevel > 20: - controller_state.boost = True - - else: - controller_state.roll = self.get_roll_value() - - if self.agent.time - self.agent.flipTimer < 0.5: - controller_state.roll = 0 - controller_state.pitch = 0 - controller_state.yaw = 0 - - controller_state.throttle = 1 - - return controller_state - - # def run_simulation(self): - # self.update_count = 5 - # simulated_location = self.agent.me.location.scale(1) - # simulated_velocity = self.agent.me.velocity.scale(1) - # simulated_time = 0 - # self.aim_direction = None - # while ( - # simulated_time < 10 - # ): # 0 gravity could lead to infinite loop! may want to add hard limiters - # simulated_velocity = simulated_velocity + Vector( - # [0, 0, self.agent.gravity] - # ).scale((self.agent.fakeDeltaTime) * self.tick_length) - # if simulated_velocity.magnitude() > 2300: - # simulated_velocity = simulated_velocity.normalize().scale(2300) - # simulated_location = simulated_location + simulated_velocity.scale( - # (self.agent.fakeDeltaTime) * self.tick_length - # ) - # simulated_time += self.agent.fakeDeltaTime * self.tick_length - # if simulated_location[2] >= self.ceiling_limit: - # self.roll_type = 2 - # self.squash_index = 2 - # # print(f"ceiling recovery {self.agent.time}") - # self.aim_direction = Vector([0, 0, 1]) - # break - # if simulated_location[2] <= self.ground_limit: - # self.roll_type = 1 - # self.squash_index = 2 - # - # # print(f"ground recovery {self.agent.time}") - # break - # - # if simulated_location[0] <= -self.x_limit: - # # on blue's right wall - # # print(f"side wall recovery {self.agent.time}") - # self.squash_index = 0 - # if simulated_velocity[1] < 0: - # # need to keep top right - # self.roll_type = 4 - # - # else: - # # need to keep top left - # self.roll_type = 3 - # break - # - # if simulated_location[0] >= self.x_limit: - # # on blue's left wall - # self.squash_index = 0 - # # print(f"side wall recovery {self.agent.time}") - # if simulated_velocity[1] < 0: - # # need to keep top left - # self.roll_type = 3 - # - # else: - # # need to keep top right - # self.roll_type = 4 - # break - # - # if simulated_location[1] <= -self.y_limit: - # # on blue's backboard - # # print(f"back wall recovery {self.agent.time}") - # if abs(simulated_location[0]) < 893: - # if simulated_location[2] < 642: - # self.roll_type = 1 - # self.squash_index = 2 - # break - # self.squash_index = 1 - # if simulated_velocity[0] < 0: - # # need to keep top left - # self.roll_type = 3 - # - # else: - # # need to keep top right - # self.roll_type = 4 - # break - # - # if simulated_location[1] >= self.y_limit: - # # on orange's backboard - # # print(f"side wall recovery {self.agent.time}") - # if abs(simulated_location[0]) < 893: - # if simulated_location[2] < 642: - # self.roll_type = 1 - # self.squash_index = 2 - # break - # self.squash_index = 1 - # if simulated_velocity[0] < 0: - # # need to keep top right - # self.roll_type = 4 - # - # else: - # # need to keep top left - # self.roll_type = 3 - # break - # if simulated_time >= 10: - # self.roll_type = 1 - # self.squash_index = 2 - # - # if self.aim_direction == None: - # self.aim_direction = Vector([0, 0, -1]) - # - # self.collision_timer = simulated_time - # self.collision_location = simulated_location - - def update(self): - # self.update_count -= 1 - # if self.update_count < 0: - # self.run_simulation() - - controller_state = self.get_controls() - if ( - self.agent.onSurface - or self.agent.me.location[1] <= self.agent.recovery_height - ): - self.active = False - - # controller_state = SimpleControllerState() - controller_state.throttle = 1 - - return controller_state - - -# class DivineGrace(baseState): #mooonbots version -# def __init__(self, agent): -# self.agent = agent -# self.active = True -# # self.run_simulation() -# # print(f"default elevation is: {self.agent.defaultElevation}") -# self.x_limit = 4096 - self.agent.defaultElevation -# self.y_limit = 5120 - self.agent.defaultElevation -# self.ground_limit = self.agent.defaultElevation -# self.ceiling_limit = 2044 - self.agent.defaultElevation -# self.ideal_orientation = Vector([0, 0, 0]) -# self.tick_length = 5 -# self.squash_index = 0 -# self.update_count = 0 -# self.collision_timer = 0 -# self.collision_location = Vector([0, 0, 0]) -# self.aim_direction = None -# self.recovery_limit = 1 -# -# def get_roll_value(self): -# if self.roll_type == 1: -# return turnController( -# -self.agent.me.rotation[2], self.agent.me.rotational_velocity[0] / 4 -# ) # will make bot roll top up -# -# elif self.roll_type == 2: -# return turnController( -# self.agent.me.rotation[2], self.agent.me.rotational_velocity[0] / 4 -# ) # will make bot roll top down -# -# elif self.roll_type == 3: -# return turnController( -# -(3.1415 / 2) - self.agent.me.rotation[2], -# self.agent.me.rotational_velocity[0] / 4, -# ) # will make bot roll top left -# -# elif self.roll_type == 4: -# return turnController( -# 3.1415 / 2 - self.agent.me.rotation[2], -# self.agent.me.rotational_velocity[0] / 4, -# ) # will make bot roll top right -# -# def get_controls(self): -# controller_state = SimpleControllerState() -# -# aim_vector = self.collision_location - self.agent.me.location -# if self.collision_timer <= self.recovery_limit: -# aim_vector.data[self.squash_index] = 0 -# -# if self.aim_direction != None: -# if self.collision_timer > self.recovery_limit: -# aim_vector = (self.aim_direction + aim_vector.normalize()).normalize() -# -# aim_vector = aim_vector.normalize() -# -# align_car_to(controller_state, self.agent.me.avelocity, aim_vector, self.agent) -# -# # print(self.collision_timer) -# if self.collision_timer > self.recovery_limit: -# if self.agent._forward.dotProduct(aim_vector) > 0.7: -# if abs(self.agent.me.velocity[2]) < 1000 or self.agent.boostMonster: -# if self.agent.me.boostLevel > 20: -# controller_state.boost = True -# -# controller_state.throttle = 1 -# controller_state.roll = self.get_roll_value() -# return controller_state -# -# def run_simulation(self): -# self.update_count = 5 -# simulated_location = self.agent.me.location.scale(1) -# simulated_velocity = self.agent.me.velocity.scale(1) -# simulated_time = 0 -# self.aim_direction = None -# while ( -# simulated_time < 10 -# ): # 0 gravity could lead to infinite loop! may want to add hard limiters -# simulated_velocity = simulated_velocity + Vector( -# [0, 0, self.agent.gravity] -# ).scale((self.agent.fakeDeltaTime) * self.tick_length) -# if simulated_velocity.magnitude() > 2300: -# simulated_velocity = simulated_velocity.normalize().scale(2300) -# simulated_location = simulated_location + simulated_velocity.scale( -# (self.agent.fakeDeltaTime) * self.tick_length -# ) -# simulated_time += self.agent.fakeDeltaTime * self.tick_length -# if simulated_location[2] >= self.ceiling_limit: -# self.roll_type = 2 -# self.squash_index = 2 -# # print(f"ceiling recovery {self.agent.time}") -# self.aim_direction = Vector([0, 0, 1]) -# break -# if simulated_location[2] <= self.ground_limit: -# self.roll_type = 1 -# self.squash_index = 2 -# -# # print(f"ground recovery {self.agent.time}") -# break -# -# if simulated_location[0] <= -self.x_limit: -# # on blue's right wall -# # print(f"side wall recovery {self.agent.time}") -# self.squash_index = 0 -# if simulated_velocity[1] < 0: -# # need to keep top right -# self.roll_type = 4 -# -# else: -# # need to keep top left -# self.roll_type = 3 -# break -# -# if simulated_location[0] >= self.x_limit: -# # on blue's left wall -# self.squash_index = 0 -# # print(f"side wall recovery {self.agent.time}") -# if simulated_velocity[1] < 0: -# # need to keep top left -# self.roll_type = 3 -# -# else: -# # need to keep top right -# self.roll_type = 4 -# break -# -# if simulated_location[1] <= -self.y_limit: -# # on blue's backboard -# # print(f"back wall recovery {self.agent.time}") -# if abs(simulated_location[0]) < 893: -# if simulated_location[2] < 642: -# self.roll_type = 1 -# self.squash_index = 2 -# break -# self.squash_index = 1 -# if simulated_velocity[0] < 0: -# # need to keep top left -# self.roll_type = 3 -# -# else: -# # need to keep top right -# self.roll_type = 4 -# break -# -# if simulated_location[1] >= self.y_limit: -# # on orange's backboard -# # print(f"side wall recovery {self.agent.time}") -# if abs(simulated_location[0]) < 893: -# if simulated_location[2] < 642: -# self.roll_type = 1 -# self.squash_index = 2 -# break -# self.squash_index = 1 -# if simulated_velocity[0] < 0: -# # need to keep top right -# self.roll_type = 4 -# -# else: -# # need to keep top left -# self.roll_type = 3 -# break -# if simulated_time >= 10: -# self.roll_type = 1 -# self.squash_index = 2 -# -# if self.aim_direction == None: -# self.aim_direction = Vector([0, 0, -1]) -# -# self.collision_timer = simulated_time -# self.collision_location = simulated_location -# -# def update(self): -# self.update_count -= 1 -# if self.update_count < 0: -# self.run_simulation() -# controller_state = self.get_controls() -# if ( -# self.agent.onSurface -# or self.agent.me.location[1] <= self.agent.recovery_height -# ): -# self.active = False -# -# # controller_state = SimpleControllerState() -# -# return controller_state - - -# class WardAgainstEvil(baseState): -# def __init__(self, agent): -# self.agent = agent -# self.active = True -# self.timeCreated = self.agent.time -# -# def update(self): -# # print(f"We're too scared! {self.agent.time}") -# return scaredyCat(self.agent) - - -class WardAgainstEvil(baseState): - def __init__(self, agent): - super().__init__(agent) - - def update(self): - if goalie_shot(self.agent, self.agent.currentHit): - return ShellTime(self.agent) - - else: - return gate(self.agent) - - -class BlessingOfDexterity(baseState): - def __init__(self, agent): - super().__init__(agent) - self.firstJump = False - self.secondJump = False - self.jumpStart = 0 - self.timeCreated = self.agent.time - - def update(self): - controller_state = SimpleControllerState() - controller_state.throttle = -1 - if not self.firstJump: - controller_state.jump = True - controller_state.pitch = 1 - self.firstJump = True - self.jumpStart = self.agent.time - return controller_state - - elif self.firstJump and not self.secondJump: - jumpTimer = self.agent.time - self.jumpStart - controller_state.pitch = 1 - controller_state.jump = False - if jumpTimer < 0.12: - controller_state.jump = True - if jumpTimer > 0.15: - controller_state.jump = True - self.jumpStart = self.agent.time - self.secondJump = True - return controller_state - - elif self.firstJump and self.secondJump: - timer = self.agent.time - self.jumpStart - controller_state.throttle = 1 - if timer < 0.15: - controller_state.pitch = 1 - - else: - controller_state.pitch = -1 - controller_state.roll = 1 - - if timer > 0.8: - controller_state.roll = 0 - if timer > 1.25: - self.active = False - return controller_state - - else: - self.agent.log.append( - "halfFlip else conditional called in update. This should not be happening" - ) - - -class Do_No_Evil(baseState): - def __init__(self, agent): - super().__init__(agent) - - def update(self): - if self.agent.scorePred is None: - self.active = False - - elif ( - self.agent.scorePred.time - self.agent.time - ) + 0.5 > self.agent.enemyBallInterceptDelay: - self.active = False - # print("B)") - return arrest_movement(self.agent) - - -class Chase(baseState): - def __init__(self, agent): - super().__init__(agent) - - def update(self): - if not kickOffTest(self.agent): - return efficientMover(self.agent, self.agent.ball, self.agent.maxSpd) - else: - self.active = False - self.agent.activeState = PreemptiveStrike(self.agent) - return self.agent.activeState.update() - - -class HeetSeekerDefense(baseState): - def update(self): - return goFarPost(self.agent) - - -class Goalie(baseState): - def update(self): - distMin = 2000 - if self.agent.ignore_kickoffs: - distMin = 3000 - if ( - distance2D( - Vector([0, 5200 * sign(self.agent.team), 0]), self.agent.ball.location - ) - < distMin - or distance2D( - Vector([0, 5200 * sign(self.agent.team), 0]), - self.agent.currentHit.pred_vector, - ) - < distMin - ): - self.agent.rotationNumber = 1 - if self.agent.currentHit.hit_type == 5: - self.agent.activeState = self.agent.currentHit.aerialState - return self.agent.activeState.update() - return ShellTime(self.agent) - - offensive = ( - self.agent.offensive - ) # sign(self.agent.team) * self.agent.ball.location[1] < 0 - if offensive and self.agent.me.boostLevel < self.agent.boostThreshold: - target_boost = boost_suggester(self.agent, mode=0, buffer=3000) - if target_boost is not None: - target = target_boost.location.scale(1) - self.agent.update_action( - {"type": "BOOST", "target": target_boost.index} - ) - return driveController( - self.agent, target.flatten(), 0, flips_enabled=True - ) - self.agent.rotationNumber = 3 - self.agent.update_action({"type": "DEFEND"}) - return gate(self.agent, hurry=False) - - -class BlessingOfSafety(baseState): - def update(self): - distMin = 1500 - player_goal = Vector([0,5120 * sign(self.agent.team),0]) - dist = distance2D(self.agent.ball.location, player_goal) - offensive = self.agent.offensive - if (not offensive and butterZone(self.agent.ball.location)) or (self.agent.goalPred is not None and dist < 3000) or (dist < distMin): - self.agent.rotationNumber = 1 - createBox(self.agent, self.agent.currentHit.pred_vector) - if self.agent.currentHit.hit_type == 5: - self.agent.activeState = self.agent.currentHit.aerialState - return self.agent.activeState.update() - return ShellTime(self.agent) - - if self.agent.rotationNumber == 2: - # if len(self.agent.allies) == 1 and self.agent.team == 0: - # return playBack(self.agent, buffer=4500) - #if len(self.agent.allies) > 0: - if len(self.agent.allies) > 1: - # testing - if self.agent.lastMan != self.agent.me.location: - return secondManPositioning(self.agent) - else: - return thirdManPositioning(self.agent) - # print(f"we here {self.agent.time}") - return playBack(self.agent) - else: - #if len(self.agent.allies) > 0: - if len(self.agent.allies) > 1: - return thirdManPositioning(self.agent) - # return secondManPositioning(self.agent) - else: - return playBack(self.agent) - print(f"getting caught by playback {self.agent.time}") - return playBack(self.agent) - - -def halfFlipStateManager(agent): - if agent.activeState.active == False: - agent.activeState = BlessingOfDexterity(agent) - - else: - if type(agent.activeState) != BlessingOfDexterity: - agent.activeState = BlessingOfDexterity(agent) - - -class Holding_pattern(baseState): - def __init__(self, agent): - super().__init__(agent) - - def update(self): - if ( - self.agent.me.boostLevel < self.agent.boostThreshold - and self.agent.goalPred is None - ): - return linger(self.agent) - - if self.agent.me.location[1] * sign(self.agent.team) < self.agent.ball.location[ - 1 - ] * sign(self.agent.team): - if abs(self.agent.me.location[1]) < 4000: - return smart_retreat(self.agent) - - # if self.agent.goalPred != None or self.agent.ballDelay < 1.5: - action = ShellTime(self.agent) - # if self.agent.ballDelay > 1.5 and self.agent.me.location[1] * sign(self.agent.team) > \ - # self.agent.ball.location[1] * sign(self.agent.team): - if self.agent.goalPred is None: - action.boost = False - return action - - -class soloDefense(baseState): - def update(self): - if ( - distance2D( - Vector([0, 5200 * sign(self.agent.team), 200]), - convertStructLocationToVector(self.agent.selectedBallPred), - ) - < 1500 - ): - return ShellTime(self.agent) - else: - return playBack(self.agent) - - -class ScaleTheWalls(baseState): - def update(self): - return handleWallShot(self.agent) - - -class AngelicEmbrace(baseState): - def update(self): - return carry_flick_new(self.agent) - - -def parseCarInfo(carList, index, _max=False): - val = 0 - best = None - for each in carList: - if _max: - if each[index] > val: - best = each - val = each[index] - else: - if each[index] < val: - best = each - val = each[index] - - return best - - -def state_manager(): - return time() - - -def aerialStateManager(agent): - center = Vector([0, 5500 * -sign(agent.team), 200]) - - if agent.ball.location[2] < 110: - car_state = CarState( - physics=Physics( - velocity=Vector3(z=0, x=0, y=0), location=Vector3(0, 0, 17.1) - ) - ) - ball_state = BallState( - physics=Physics( - velocity=Vector3( - z=1550, - x=random.randrange(-1500, 1500), - y=random.randrange(-1500, 1500), - ), - location=Vector3(0, 0, 350), - ) - ) - game_state = GameState(cars={agent.index: car_state}, ball=ball_state) - agent.set_game_state(game_state) - agent.activeState = None - - if type(agent.activeState) != Wings_Of_Justice or not agent.activeState.active: - - pred = agent.ballPred.slices[0] - for i in range(0, agent.ballPred.num_slices): - if i > 60 and i % 3 != 0: - continue - - pred = agent.ballPred.slices[i] - tth = pred.game_seconds - agent.gameInfo.seconds_elapsed - if tth <= 0: - continue - - if agent.onSurface: - if pred.physics.location.z < 300: - continue - - pred_vec = convertStructLocationToVector(pred) - if findDistance(agent.me.location, pred_vec) < 2300 * tth: - _direction = direction(center, pred_vec).flatten() - positioningOffset = 90 - aim_loc = pred_vec - _direction.scale(90) - tempAerial = Wings_Of_Justice(agent, pred, aim_loc, tth) - if tempAerial.active: - break - if tempAerial.active: - agent.activeState = tempAerial - - -def demoTest(agent): - targ = findEnemyClosestToLocation(agent, agent.ball.location)[0] - return demoEnemyCar(agent, targ) - - -def air_hog_manager(agent): - agentType = type(agent.activeState) - if ( - agentType != PreemptiveStrike - or agentType == PreemptiveStrike - and not agent.activeState.active - ): - - if not kickOffTest(agent): - if locked_in(agent, agentType): - return - - if agent.goalPred is not None: - agent.contested = True - agent.enemyAttacking = True - fastesthit = agent.sorted_hits[0] # find_soonest_hit(agent) - hit = fastesthit - - if ( - hit.hit_type == 2 - and abs(agent.me.location[1]) > 5000 - and abs(agent.me.location[0]) < 900 - and len(agent.sorted_hits) > 1 - ): - fastesthit = agent.sorted_hits[1] - hit = fastesthit - - agent.currentHit = hit - agent.ballDelay = hit.prediction_time - agent.gameInfo.seconds_elapsed - - openNet = openGoalOpportunity(agent) - agent.openGoal = openNet - agent.timid = False - scared = False - tempDelay = hit.prediction_time - agent.gameInfo.seconds_elapsed - - if tempDelay >= agent.enemyBallInterceptDelay - agent.contestedTimeLimit: - agent.contested = True - - if agent.goalPred is not None: - agent.contested = True - agent.enemyAttacking = True - - if hit.hit_type == 5: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - return - - if agentType == DivineGrace: - if agent.activeState.active != False: - return - - if not agent.onSurface: - if agent.me.location[2] > agent.recovery_height: - if agentType != DivineGrace: - agent.activeState = DivineGrace(agent) - return - - if agent.dribbling: - if agentType != AngelicEmbrace: - agent.activeState = AngelicEmbrace(agent) - return - - boostOpportunity = inCornerWithBoost(agent) - if boostOpportunity != False: - if agent.me.boostLevel <= 50: - getBoost = False - if boostOpportunity[1] in agent.my_corners: - getBoost = True - if getBoost: - if agentType != HeavenlyReprieve: - agent.activeState = HeavenlyReprieve( - agent, boostOpportunity[0] - ) - return - - if agent.activeState != Holding_pattern: - agent.activeState = Holding_pattern(agent) - - else: - agent.activeState = PreemptiveStrike(agent) - - -def newTeamStateManager(agent): - agentType = type(agent.activeState) - if ( - agentType != PreemptiveStrike - or agentType == PreemptiveStrike - and not agent.activeState.active - ): - - if not kickOffTest(agent): - - myGoalLoc = Vector([0, 5200 * sign(agent.team), 200]) - enemyGoalLoc = Vector([0, 5200 * -sign(agent.team), 200]) - - ballDistanceFromGoal = distance2D(myGoalLoc, agent.ball.location) - carDistanceFromGoal = distance2D(myGoalLoc, agent.me.location) - - if locked_in(agent, agentType): - if agent.rotationNumber < 2 and agent.currentHit is not None: - createSphere(agent, agent.currentHit.pred_vector) - return - - fastesthit = agent.sorted_hits[0] # find_soonest_hit(agent) - hit = fastesthit - - if agent.dribbler: - if hit.hit_type != 0: - for h in agent.sorted_hits: - if h.hit_type == 0: - hit = h - break - - if ( - hit.hit_type == 2 - and abs(agent.me.location[1]) > 5000 - and abs(agent.me.location[0]) < 900 - and len(agent.sorted_hits) > 1 - ): - fastesthit = agent.sorted_hits[1] - hit = fastesthit - - openNet = openGoalOpportunity(agent) - agent.openGoal = openNet - agent.timid = False - scared = False - agent.scared = False - tempDelay = hit.prediction_time - agent.gameInfo.seconds_elapsed - - if tempDelay >= agent.enemyBallInterceptDelay - agent.contestedTimeLimit: - # if agent.enemyAttacking: - agent.contested = True - - if agent.goalPred is not None: - agent.contested = True - agent.enemyAttacking = True - - # if butterZone(hit.pred_vector): - # agent.contested = True - # agent.enemyAttacking = True - - if hit.hit_type == 5: - if ( - not agent.onSurface or hit.aerialState.launcher is not None - ) and hit.aerialState.active: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - return - - # if len(agent.sorted_hits) > 1 and not agent.boostMonster: - # if ( - # agent.sorted_hits[1].prediction_time - # - agent.sorted_hits[0].prediction_time - # < 0.5 - # ): - # fastesthit = agent.sorted_hits[1] - # hit = fastesthit - # tempDelay = hit.prediction_time - agent.gameInfo.seconds_elapsed - - if agentType == DivineGrace: - if agent.activeState.active != False: - return - - if not agent.onSurface: - if agent.me.location[2] > agent.recovery_height: - if agentType != DivineGrace: - agent.activeState = DivineGrace(agent) - return - - if agent.demo_monster: - agent.currentHit = hit - agent.ballDelay = tempDelay - if agent.activeState != Divine_Retribution: - agent.activeState = Divine_Retribution(agent) - return - - lastMan = agent.lastMan - catchViable = False - inclusive_team = [] - _inclusive_team = agent.allies[:] - # ignore_types = ["DEFEND","DEMO","BOOST"] - ignore_types = ["DEFEND"] - removals = [] - for i in range(len(inclusive_team)): - if _inclusive_team[i].index in agent.ally_actions: - if agent.ally_actions["action"]["type"] not in ignore_types: - inclusive_team.append(_inclusive_team[i]) - - inclusive_team.append(agent.me) - inclusive_team = sorted(inclusive_team, key=lambda x: x.index) - offensive = agent.offensive - - if not agent.gameInfo.is_round_active or agent.gameInfo.is_kickoff_pause: - man = 2 - if agent.me.location == agent.lastMan: - man = 3 - agent.rotationNumber = man - - agent.currentHit = fastesthit - agent.ballDelay = fastesthit.time_difference() - if man == 2: - if agentType != Kickoff_Boosties: - agent.activeState = Kickoff_Boosties(agent) - else: - if agentType != BlessingOfSafety: - agent.activeState = BlessingOfSafety(agent) - return - # if agentType != BlessingOfSafety: - # agent.activeState = BlessingOfSafety(agent) - # return - - else: - man = 1 - if ( - (agent.me.location[1] * sign(agent.team)) + 25 * sign(agent.team) - ) < hit.pred_vector[1] * sign(agent.team): - if agent.me.location != agent.lastMan: - if hit.pred_vector[1] * sign(agent.team) < 4600 and agent.ball.location[1] * sign(agent.team) < 3000: - man = len(agent.allies) + 1 - - if agent.me.demolished: - man = len(agent.allies) + 1 - - if man != len(agent.allies) + 1: - if offensive: - myDist = weighted_distance_2D( - agent.me.location, hit.pred_vector - ) - else: - myDist = distance2D(agent.me.location, hit.pred_vector) - - for ally in agent.allies: - if not ally.demolished and not ally.retreating: - ally_action = None - if ally.index in agent.ally_actions: - # testing - if agent.ally_actions[ally.index]["action"]["type"] in ["BALL", "READY"]: - if agent.ally_actions[ally.index]["action"]["time"] >= agent.time: - if agent.ally_actions[ally.index]["action"]["time"] < hit.prediction_time: - man+=1 - continue - elif agent.ally_actions[ally.index]["action"]["time"] == hit.prediction_time: - if ally.location[1] * sign(agent.team) < agent.me.location[1] * sign(agent.team): - man += 1 - continue - - if ( - agent.ally_actions[ally.index]["action"]["type"] - == "BALL" - ): - if ( - agent.ally_actions[ally.index]["action"]["time"] - > agent.time - ): - if ( - agent.ally_actions[ally.index]["action"][ - "vector" - ] - is None - ): - ally_pred = find_pred_at_time( - agent, - agent.ally_actions[ally.index][ - "action" - ]["time"], - ) - if ally_pred is not None: - agent.ally_actions[ally.index][ - "action" - ][ - "vector" - ] = convertStructLocationToVector( - ally_pred - ) - ally_targ = agent.ally_actions[ - ally.index - ]["action"]["vector"] - - if ( - agent.ally_actions[ally.index]["action"][ - "vector" - ] - is not None - ): - if ( - agent.ally_actions[ally.index][ - "action" - ]["vector"][2] - >= 700 - ): - if hit.hit_type == 5: - man += 1 - agent.log.append( - f"not double commiting {agent.time}" - ) - continue - man += 1 - continue - - - - if not ( - agent.ally_actions[ally.index]["action"]["type"] - == "BALL" - and agent.ally_actions[ally.index]["action"]["time"] - < agent.time - ): - ally_action = agent.ally_actions[ally.index][ - "action" - ] - key = "time" - if ally_action["type"] == "READY": - key = "time" - - ally_targ = agent.ball.location - - if ally_action is None or ( - ( - ally_action["type"] == "BALL" - or ally_action["type"] == "READY" - ) - #and ally_action[key] >= agent.time - ): - if ally_action is not None: - # ally_pred = find_pred_at_time(agent,ally_action[key]) - # if ally_pred != None: - if ( - agent.ally_actions[ally.index]["action"][ - "vector" - ] - is not None - ): - # ally_targ = convertStructLocationToVector(ally_pred) - ally_targ = ally_action["vector"] - else: - ally_pred = find_pred_at_time( - agent, ally_action[key] - ) - if ally_pred is not None: - agent.ally_actions[ally.index]["action"][ - "vector" - ] = convertStructLocationToVector(ally_pred) - ally_targ = agent.ally_actions[ally.index][ - "action" - ]["vector"] - - # else: - # continue - - if ally.location[1] * sign(agent.team) > ally_targ[ - 1 - ] * sign(agent.team): - if ( - ally_action is None - ): # or agent.ally_hit_info[ally.index][0].time < agent.time: - if offensive: - allyDist = weighted_distance_2D( - ally.location, ally_targ - ) - else: - allyDist = distance2D(ally.location, ally_targ) - if allyDist < myDist: - man += 1 - - else: - if agent.ally_actions[ally.index]["action"] == "BALL" or agent.ally_actions[ally.index]["action"] == "READY": - if ( - agent.ally_actions[ally.index]["action"][key] - < hit.prediction_time # +0.1 - ): - man += 1 - - elif ( - agent.ally_actions[ally.index]["action"][key] - == hit.prediction_time - ): - if distance2D( - agent.me.location, hit.pred_vector - ) > distance2D(ally.location, ally_targ): - man += 1 - - elif ( - agent.currentHit.hit_type == 5 - and agent.ally_actions[ally.index]["action"][ - "type" - ] - == "BALL" - and agent.ally_actions[ally.index]["action"][ - key - ] - < agent.currentHit.prediction_time # + 1 - ): - man += 1 - - man = clamp(3, 1, man) - # if offensive and man != 1: - if man != 1 and not offensive: - if agent.lastMan != agent.me.location: - man = 2 - else: - man = 3 - - # if man != 1: - # #disregard player furthest advanced - # - # y_dist = 2500 - # if agent.ball.location[0] > 0: - # x_target = -500 - # else: - # x_target = 500 - # - # y_target = agent.ball.location[1] + (sign(agent.team) * y_dist) - # two_spot = Vector([x_target, y_target, 0]) - # - # closest_ally = None - # closest_dist = math.inf - # - # most_advanced_position = -math.inf - # most_advanced_ally = None - # - # dists = [] - # - # for ally in inclusive_team: - # ally_dist = distance2D(ally.location, two_spot) - # dists.append([ally_dist,ally.index]) - # pos = ally.location[1] * -(sign(agent.team)) - # if pos > most_advanced_position: - # most_advanced_ally = [ally_dist,ally.index] - # - # #dists.remove(most_advanced_ally) - # #dists = sorted(dists, key=lambda x: x[0]) - # if len(dists) > 1: - # dists.remove(most_advanced_ally) - # dists = sorted(dists, key=lambda x: x[0]) - # if dists[0][1] == agent.index: - # man = 2 - # else: - # man = 3 - # else: - # man = 2 - - # if ( - # len(agent.enemies) < 4 - # and not agent.contested - # and hit.hit_type not in [5, 0] - # and not ( - # hit.hit_type == 2 - # and not ballHeadedTowardsMyGoal_testing(agent, hit) - # ) - # and agent.me.boostLevel > 0 - # and agent.forward - # and not ballHeadedTowardsMyGoal_testing(agent, hit) - # # and agent.team == 0 or not offensive - # and not offensive - # ): - # chrono_hits = agent.sorted_hits - # prev_hit = hit - # for h in chrono_hits[1:]: - # if ballHeadedTowardsMyGoal_testing(agent, h): - # break - # - # if distance2D(h.pred_vector, enemyGoalLoc) >= distance2D( - # agent.me.location, enemyGoalLoc - # ): - # break - # if h.pred_vel[1] * -sign(agent.team) >= 1 and h.hit_type != 5: - # if not butterZone(prev_hit.pred_vector): - # temptime = h.time_difference() - # if ( - # temptime - # < agent.enemyBallInterceptDelay - # - agent.contestedTimeLimit - # ): - # hit = h - # if ( - # agent.onWall - # and hit.hit_type == 2 - # or hit.hit_type == 0 - # or butterZone(hit.pred_vector) - # ): - # agent.ballDelay = hit.time_difference() - # break - # else: - # break - # else: - # break - # prev_hit = h - # - # hit = prev_hit - # agent.ballDelay = hit.time_difference() - - agent.rotationNumber = man - if man == 1: - createSphere(agent, hit.pred_vector) - - # if man > 1 and len(agent.sorted_hits) > 1: - # hit = agent.sorted_hits[1] - goalward = ballHeadedTowardsMyGoal_testing(agent, hit) - agent.goalward = goalward - agent.currentHit = hit - agent.ballDelay = hit.time_difference() - agent.ballGrounded = False - - if hit.hit_type == 2: - agent.wallShot = True - agent.ballGrounded = False - else: - agent.wallShot = False - if hit.hit_type == 1: - if hit.pred_vector[2] <= agent.groundCutOff: - agent.ballGrounded = True - else: - agent.ballGrounded = False - if man == 1: - createBox(agent, hit.pred_vector) - - if agent.dribbling: - if agentType != AngelicEmbrace: - agent.activeState = AngelicEmbrace(agent) - return - - if man !=1: - boostOpportunity = inCornerWithBoost(agent) - if boostOpportunity != False: - if agent.me.boostLevel <= 50: - getBoost = False - if boostOpportunity[1] in agent.my_corners: - getBoost = True - if getBoost: - if agentType != HeavenlyReprieve: - agent.activeState = HeavenlyReprieve( - agent, boostOpportunity[0] - ) - return - - if agent.ignore_kickoffs: - if distance2D(hit.pred_vector, myGoalLoc) > 3000: - if agent.activeState != HeetSeekerDefense: - agent.activeState = HeetSeekerDefense(agent) - return - - # if agent.goalie: - # if agent.activeState != Goalie: - # agent.activeState = Goalie(agent) - # return - if agent.goalie: - if hit.pred_vector[1] * sign(agent.team) < 0 or man != 1: - if agent.activeState != Goalie: - agent.activeState = Goalie(agent) - return - - if man == 1: - - # if catchViable: - # if not agent.dribbling: - # # if agent.hits[1].pred_vel[1] * -sign(agent.team) >= 1: - # agent.currentHit = agent.hits[1] - # agent.ballDelay = agent.currentHit.time_difference() - # if agent.activeState != Celestial_Arrest: - # agent.activeState = Celestial_Arrest(agent) - # return - - if carDistanceFromGoal > ballDistanceFromGoal and hit.hit_type != 5: - if agentType != HolyProtector: - agent.activeState = HolyProtector(agent) - return - - if goalward: - if hit.hit_type != 2 and hit.hit_type != 5: - if agentType != HolyProtector: - agent.activeState = HolyProtector(agent) - return - elif hit.hit_type == 2: - if agentType != ScaleTheWalls: - agent.activeState = ScaleTheWalls(agent) - return - else: - if hit.hit_type == 5: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - return - - else: - - if hit.hit_type == 0: # hit.pred_vector[2] <= agent.groundCutOff: - if agentType != GroundAssault: - agent.activeState = GroundAssault(agent) - return - - elif hit.hit_type == 1: - if agentType != HolyGrenade: - agent.activeState = HolyGrenade(agent) - return - - elif hit.hit_type == 4: - if agentType != HolyGrenade: - agent.activeState = HolyGrenade(agent) - # print("would have been wallshot before") - return - - elif hit.hit_type == 2: - if agentType != ScaleTheWalls: - agent.activeState = ScaleTheWalls(agent) - return - - elif hit.hit_type == 5: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - # agent.log.append(f"Going for aerial! {agent.time}") - return - - else: - agent.log.append(f"condition leaked through! {hit.hit_type}") - - else: - - if agentType != BlessingOfSafety: - agent.activeState = BlessingOfSafety(agent) - return - - else: - agent.activeState = PreemptiveStrike(agent) - - -"" - - -def TMCP_team_manager(agent): - agentType = type(agent.activeState) - if ( - agentType != PreemptiveStrike - or agentType == PreemptiveStrike - and not agent.activeState.active - ): - - if not kickOffTest(agent): - - myGoalLoc = Vector([0, 5200 * sign(agent.team), 200]) - enemyGoalLoc = Vector([0, 5200 * -sign(agent.team), 200]) - - ballDistanceFromGoal = distance2D(myGoalLoc, agent.ball.location) - carDistanceFromGoal = distance2D(myGoalLoc, agent.me.location) - - if locked_in(agent, agentType): - return - - fastesthit = agent.sorted_hits[0] # find_soonest_hit(agent) - hit = fastesthit - - if agent.dribbler: - if hit.hit_type != 0: - for h in agent.sorted_hits: - if h.hit_type == 0: - hit = h - break - - if ( - hit.hit_type == 2 - and abs(agent.me.location[1]) > 5000 - and abs(agent.me.location[0]) < 900 - and len(agent.sorted_hits) > 1 - ): - fastesthit = agent.sorted_hits[1] - hit = fastesthit - - openNet = openGoalOpportunity(agent) - agent.openGoal = openNet - agent.timid = False - scared = False - tempDelay = hit.prediction_time - agent.gameInfo.seconds_elapsed - - if tempDelay >= agent.enemyBallInterceptDelay - agent.contestedTimeLimit: - # if agent.enemyAttacking: - agent.contested = True - - if agent.goalPred is not None: - agent.contested = True - agent.enemyAttacking = True - - # if butterZone(hit.pred_vector): - # agent.contested = True - # agent.enemyAttacking = True - - if hit.hit_type == 5: - if not agent.onSurface: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - return - - if agentType == DivineGrace: - if agent.activeState.active != False: - return - - if not agent.onSurface: - if agent.me.location[2] > agent.recovery_height: - if agentType != DivineGrace: - agent.activeState = DivineGrace(agent) - return - - if agent.demo_monster: - agent.currentHit = hit - agent.ballDelay = tempDelay - if agent.activeState != Divine_Retribution: - agent.activeState = Divine_Retribution(agent) - return - - lastMan = agent.lastMan - catchViable = False - inclusive_team = [] - _inclusive_team = agent.allies[:] - # ignore_types = ["DEFEND","DEMO","BOOST"] - ignore_types = ["DEFEND"] - removals = [] - for i in range(len(inclusive_team)): - if _inclusive_team[i].index in agent.ally_actions: - if agent.ally_actions["action"]["type"] not in ignore_types: - inclusive_team.append(_inclusive_team[i]) - - inclusive_team.append(agent.me) - inclusive_team = sorted(inclusive_team, key=lambda x: x.index) - offensive = agent.offensive - - if not agent.gameInfo.is_round_active or agent.gameInfo.is_kickoff_pause: - man = 2 - if agent.me.location == agent.lastMan: - man = 3 - agent.rotationNumber = man - - agent.currentHit = fastesthit - agent.ballDelay = fastesthit.time_difference() - if agentType != BlessingOfSafety: - agent.activeState = BlessingOfSafety(agent) - return - - man = 3 - best_action = None - best_time = -1 - one_slot = None - closest_dist = 999999 - closest_ally = None - - for ally in inclusive_team: - ally_dist = findDistance(ally.location, agent.ball.location) - if ally_dist < closest_dist: - closest_dist = ally_dist - closest_ally = ally.index - if ally.index in agent.ally_actions: - if best_action is None: - if agent.ally_actions[ally.index]["action"]["type"] == "BALL": - if ( - agent.ally_actions[ally.index]["action"]["time"] - > agent.time - agent.fakeDeltaTime * 2 - ): - best_action = "BALL" - best_time = agent.ally_actions[ally.index]["action"][ - "time" - ] - one_slot = ally.index - - elif ( - agent.ally_actions[ally.index]["action"]["type"] == "READY" - ): - best_action = "READY" - best_time = agent.ally_actions[ally.index]["action"]["time"] - one_slot = ally.index - elif best_action == "READY": - if agent.ally_actions[ally.index]["action"]["type"] == "BALL": - if ( - agent.ally_actions[ally.index]["action"]["time"] - > agent.time - agent.fakeDeltaTime * 2 - ): - best_action = "BALL" - best_time = agent.ally_actions[ally.index]["action"][ - "time" - ] - one_slot = ally.index - - elif ( - agent.ally_actions[ally.index]["action"]["type"] == "READY" - ): - if ( - agent.ally_actions[ally.index]["action"]["time"] - > agent.time - agent.fakeDeltaTime * 2 - ): - if ( - agent.ally_actions[ally.index]["action"]["time"] - < best_time - ): - best_action = "READY" - best_time = agent.ally_actions[ally.index][ - "action" - ]["time"] - one_slot = ally.index - - elif best_action == "BALL": - if agent.ally_actions[ally.index]["action"]["type"] == "BALL": - if ( - agent.ally_actions[ally.index]["action"]["time"] - > agent.time - ): - if ( - agent.ally_actions[ally.index]["action"]["time"] - < best_time - ): - best_action = "BALL" - best_time = agent.ally_actions[ally.index][ - "action" - ]["time"] - one_slot = ally.index - - else: - print(f"{ally.index} not in ally_actions!") - - if one_slot is None: - one_slot = closest_ally - - # else: - # print(f"{best_action} {best_time}") - print(one_slot == agent.index) - if one_slot == agent.index: - man = 1 - - else: - y_dist = 2500 - if agent.ball.location[0] > 0: - x_target = -500 - else: - x_target = 500 - - y_target = agent.ball.location[1] + (sign(agent.team) * y_dist) - two_spot = Vector([x_target, y_target, 0]) - - closest_ally = None - closest_dist = math.inf - - for index, ally in enumerate(inclusive_team): - if index != one_slot.index: - ally_dist = distance2D(ally.location, agent.ball.location) - if ally_dist < closest_dist: - closest_ally = ally.index - closest_dist = ally_dist - - if closest_ally == agent.index: - man = 2 - else: - man = 3 - - # print(f"{agent.index}, {man}") - - if ( - len(agent.enemies) < 4 - and not agent.contested - and hit.hit_type not in [5, 0] - and not ( - hit.hit_type == 2 - and not ballHeadedTowardsMyGoal_testing(agent, hit) - ) - and agent.me.boostLevel > 0 - and agent.forward - and not ballHeadedTowardsMyGoal_testing(agent, hit) - # and agent.team == 0 or not offensive - and not offensive - and man == 1 - ): - chrono_hits = agent.sorted_hits - prev_hit = hit - for h in chrono_hits[1:]: - if ballHeadedTowardsMyGoal_testing(agent, h): - break - - if distance2D(h.pred_vector, enemyGoalLoc) >= distance2D( - agent.me.location, enemyGoalLoc - ): - break - if h.pred_vel[1] * -sign(agent.team) >= 1 and h.hit_type != 5: - if not butterZone(prev_hit.pred_vector): - temptime = h.time_difference() - if ( - temptime - < agent.enemyBallInterceptDelay - - agent.contestedTimeLimit - ): - hit = h - if ( - agent.onWall - and hit.hit_type == 2 - or hit.hit_type == 0 - or butterZone(hit.pred_vector) - ): - agent.ballDelay = hit.time_difference() - break - else: - break - else: - break - prev_hit = h - - hit = prev_hit - agent.ballDelay = hit.time_difference() - - agent.rotationNumber = man - - # if man > 1 and len(agent.sorted_hits) > 1: - # hit = agent.sorted_hits[1] - goalward = ballHeadedTowardsMyGoal_testing(agent, hit) - agent.goalward = goalward - agent.currentHit = hit - agent.ballDelay = hit.time_difference() - agent.ballGrounded = False - - if hit.hit_type == 2: - agent.wallShot = True - agent.ballGrounded = False - else: - agent.wallShot = False - if hit.hit_type == 1: - if hit.pred_vector[2] <= agent.groundCutOff: - agent.ballGrounded = True - else: - agent.ballGrounded = False - if man == 1: - createBox(agent, hit.pred_vector) - - if agent.dribbling: - if agentType != AngelicEmbrace: - agent.activeState = AngelicEmbrace(agent) - return - - boostOpportunity = inCornerWithBoost(agent) - if boostOpportunity != False: - if agent.me.boostLevel <= 50: - getBoost = False - if boostOpportunity[1] in agent.my_corners: - getBoost = True - if getBoost: - if agentType != HeavenlyReprieve: - agent.activeState = HeavenlyReprieve( - agent, boostOpportunity[0] - ) - return - - if agent.ignore_kickoffs: - if distance2D(hit.pred_vector, myGoalLoc) > 3000: - if agent.activeState != HeetSeekerDefense: - agent.activeState = HeetSeekerDefense(agent) - return - - if agent.goalie: - if agent.activeState != Goalie: - agent.activeState = Goalie(agent) - return - - if man == 1: - - if catchViable: - if not agent.dribbling: - # if agent.hits[1].pred_vel[1] * -sign(agent.team) >= 1: - agent.currentHit = agent.hits[1] - agent.ballDelay = agent.currentHit.time_difference() - if agent.activeState != Celestial_Arrest: - agent.activeState = Celestial_Arrest(agent) - return - - if carDistanceFromGoal > ballDistanceFromGoal and hit.hit_type != 5: - if agentType != HolyProtector: - agent.activeState = HolyProtector(agent) - return - - if goalward: - if hit.hit_type != 2 and hit.hit_type != 5: - if agentType != HolyProtector: - agent.activeState = HolyProtector(agent) - return - elif hit.hit_type == 2: - if agentType != ScaleTheWalls: - agent.activeState = ScaleTheWalls(agent) - return - else: - if hit.hit_type == 5: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - return - - else: - - if hit.hit_type == 0: # hit.pred_vector[2] <= agent.groundCutOff: - if agentType != GroundAssault: - agent.activeState = GroundAssault(agent) - return - - elif hit.hit_type == 1: - if agentType != HolyGrenade: - agent.activeState = HolyGrenade(agent) - return - - elif hit.hit_type == 4: - if agentType != HolyGrenade: - agent.activeState = HolyGrenade(agent) - # print("would have been wallshot before") - return - - elif hit.hit_type == 2: - if agentType != ScaleTheWalls: - agent.activeState = ScaleTheWalls(agent) - return - - elif hit.hit_type == 5: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - # agent.log.append(f"Going for aerial! {agent.time}") - return - - else: - agent.log.append(f"condition leaked through! {hit.hit_type}") - - else: - - if agentType != BlessingOfSafety: - agent.activeState = BlessingOfSafety(agent) - return - - else: - agent.activeState = PreemptiveStrike(agent) - - -def team_manager(agent): - agentType = type(agent.activeState) - if ( - agentType != PreemptiveStrike - or agentType == PreemptiveStrike - and not agent.activeState.active - ): - - if not kickOffTest(agent): - - myGoalLoc = Vector([0, 5200 * sign(agent.team), 200]) - enemyGoalLoc = Vector([0, 5200 * -sign(agent.team), 200]) - - ballDistanceFromGoal = distance2D(myGoalLoc, agent.ball.location) - carDistanceFromGoal = distance2D(myGoalLoc, agent.me.location) - - if locked_in(agent, agentType): - return - - fastesthit = agent.sorted_hits[0] - hit = fastesthit - if hit.hit_type == 5: - if agent.enemyBallInterceptDelay + 0.5 < hit.time_difference(): - if agent.onSurface: - if len(agent.sorted_hits) > 1: - hit = agent.sorted_hits[1] - - openNet = openGoalOpportunity(agent) - agent.openGoal = openNet - agent.timid = False - scared = False - tempDelay = hit.prediction_time - agent.gameInfo.seconds_elapsed - # if not agent.dribbling: - # agent.enemyAttacking = True - - if tempDelay >= agent.enemyBallInterceptDelay - agent.contestedTimeLimit: - # if agent.enemyAttacking or agent.team == 0: - agent.contested = True - # agent.enemyAttacking = True - - if agent.goalPred is not None: - agent.contested = True - agent.enemyAttacking = True - - if butterZone(hit.pred_vector): - agent.contested = True - agent.enemyAttacking = True - - if hit.hit_type == 5: - # print(f"going for aerial {agent.time}") - if not agent.onSurface: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - # agent.log.append(f"Going for aerial! {agent.time}") - return - - if agentType == DivineGrace: - if agent.activeState.active != False: - return - - if not agent.onSurface: - if agent.me.location[2] > agent.recovery_height: - if agentType != DivineGrace: - agent.activeState = DivineGrace(agent) - return - - lastMan = agent.lastMan - catchViable = False - inclusive_team = agent.allies[:] - inclusive_team.append(agent.me) - inclusive_team = sorted(inclusive_team, key=lambda x: x.index) - offensive = agent.offensive - - if not agent.gameInfo.is_round_active or agent.gameInfo.is_kickoff_pause: - man = 2 - else: - man = 1 - - hit_timers = [ - [ - fastesthit.prediction_time, - agent.me.retreating - or agent.me.location[1] * sign(agent.team) - < fastesthit.pred_vector[1] * sign(agent.team), - ] - ] - if agent.ally_hit_count == 0: - ally_hits = [] - for i in range(len(agent.allies)): - agent.allies[i].next_hit = find_ally_hit(agent, agent.allies[i]) - hit_timers.append( - [ - agent.allies[i].next_hit.time, - agent.allies[i].retreating - or agent.allies[i].location[1] * sign(agent.team) - < agent.allies[i].next_hit.location[1] - * sign(agent.team), - ] - ) - ally_hits.append( - [ - agent.allies[i].next_hit.time, - agent.allies[i].retreating - or agent.allies[i].location[1] * sign(agent.team) - < agent.allies[i].next_hit.location[1] - * sign(agent.team), - ] - ) - - agent.ally_hit_info = ally_hits - - else: - hit_timers = hit_timers + agent.ally_hit_info - - agent.ally_hit_count += 1 - if agent.ally_hit_count > 3: - agent.ally_hit_count = 0 - - sorted_team_hits = sorted(hit_timers, key=lambda x: x[0]) - - for index, th in enumerate(sorted_team_hits[:]): - if th[1]: - sorted_team_hits.append(th) - sorted_team_hits = sorted_team_hits[1:] - - for i in range(len(sorted_team_hits)): - if ( - sorted_team_hits[i][0] < fastesthit.prediction_time - or not sorted_team_hits[i][1] - and agent.me.retreating - ): - man += 1 - # print(sorted_team_hits[i][0],fastesthit.prediction_time) - - man = clamp(3, 1, man) - agent.boostThreshhold = man * 25 - - # if not agent.contested and agent.goalPred == None and len(agent.allies) < 2: - if False: # or (agent.team == 1 and not agent.contested): - # if not agent.contested and agent.lastMan != agent.me.location and man == 1 and hit.hit_type != 0 and agent.goalPred == None and not ballHeadedTowardsMyGoal_testing(agent, hit) and not agent.ignore_kickoffs:# and agent.team == 1: - chrono_hits = agent.sorted_hits - prev_hit = hit - for h in chrono_hits: - # if h.time_difference() < 1: - # break - - if h.hit_type == 5: - continue - - if distance2D(h.pred_vector, enemyGoalLoc) >= distance2D( - agent.me.location, enemyGoalLoc - ): - break - if h.pred_vel[1] * -sign(agent.team) >= 1: - if not butterZone(prev_hit.pred_vector): - temptime = h.time_difference() - if ( - temptime - < agent.enemyBallInterceptDelay - - agent.contestedTimeLimit - ): - hit = h - else: - break - else: - break - prev_hit = h - - hit = prev_hit - agent.ballDelay = hit.time_difference() - - if man == 2: - if agent.lastMan != agent.me.location: - if hit.pred_vector[1] * -sign(agent.team) > 4000 * -sign( - agent.team and len(agent.allies) > 1 - ): - if butterZone(hit.pred_vector): - if hit.time_difference() < agent.enemyBallInterceptDelay or ( - hit.time_difference() < 2 - and agent.lastMan[1] * sign(agent.team) > 0 - ): - man = 1 - agent.log.append( - f"risking it for the biscuit! {agent.time} {agent.team}" - ) - - agent.rotationNumber = man - - goalward = ballHeadedTowardsMyGoal_testing(agent, hit) - agent.goalward = goalward - agent.currentHit = hit - agent.ballDelay = hit.time_difference() - agent.ballGrounded = False - - if hit.hit_type == 2: - agent.wallShot = True - agent.ballGrounded = False - else: - agent.wallShot = False - if hit.hit_type == 1: - if hit.pred_vector[2] <= agent.groundCutOff: - agent.ballGrounded = True - else: - agent.ballGrounded = False - - createBox(agent, hit.pred_vector) - - if agent.dribbling: - if agentType != AngelicEmbrace: - agent.activeState = AngelicEmbrace(agent) - return - - boostOpportunity = inCornerWithBoost(agent) - if boostOpportunity != False: - if agent.me.boostLevel <= 50: - getBoost = False - if boostOpportunity[1] in agent.my_corners: - getBoost = True - if getBoost: - if agentType != HeavenlyReprieve: - agent.activeState = HeavenlyReprieve( - agent, boostOpportunity[0] - ) - return - - if agent.ignore_kickoffs: - if distance2D(hit.pred_vector, myGoalLoc) > 3000: - if agent.activeState != HeetSeekerDefense: - agent.activeState = HeetSeekerDefense(agent) - return - - if agent.goalie: - if agent.activeState != Goalie: - agent.activeState = Goalie(agent) - return - - if man == 1: - - if carDistanceFromGoal > ballDistanceFromGoal: - if agentType != HolyProtector: - agent.activeState = HolyProtector(agent) - return - - if goalward: - if hit.hit_type != 2: - if agentType != HolyProtector: - agent.activeState = HolyProtector(agent) - return - else: - if agentType != ScaleTheWalls: - agent.activeState = ScaleTheWalls(agent) - return - - else: - - if hit.hit_type == 0: # hit.pred_vector[2] <= agent.groundCutOff: - if agentType != GroundAssault: - agent.activeState = GroundAssault(agent) - return - - elif hit.hit_type == 1: - if agentType != HolyGrenade: - agent.activeState = HolyGrenade(agent) - return - - elif hit.hit_type == 4: - if agentType != HolyGrenade: - agent.activeState = HolyGrenade(agent) - # print("would have been wallshot before") - return - - elif hit.hit_type == 2: - if agentType != ScaleTheWalls: - agent.activeState = ScaleTheWalls(agent) - return - - elif hit.hit_type == 5: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - # agent.log.append(f"Going for aerial! {agent.time}") - return - - else: - agent.log.append(f"condition leaked through! {hit.hit_type}") - - else: - # if agent.team == 0: - # if agent.ball.location[1] * sign(agent.team) >= 0: - # if agent.lastMan == agent.me.location: - # if agentType != WardAgainstEvil: - # agent.activeState = WardAgainstEvil(agent) - # return - - if agentType != BlessingOfSafety: - agent.activeState = BlessingOfSafety(agent) - return - - else: - agent.activeState = PreemptiveStrike(agent) - - -def find_alternative_hit(agent, acceptable_hits): - for h in agent.sorted_hits: - if h.hit_type in acceptable_hits: - return h - - return agent.currentHit - -def soloStateManager_testing(agent): - agentType = type(agent.activeState) - - if ( - agentType != PreemptiveStrike - or (agentType == PreemptiveStrike and not agent.activeState.active) - ): - - if not kickOffTest(agent): - myGoalLoc = Vector([0, 5200 * sign(agent.team), 200]) - enemyGoalLoc = Vector([0, 5200 * -sign(agent.team), 200]) - - ballDistanceFromGoal = distance2D(myGoalLoc, agent.ball) - carDistanceFromGoal = distance2D(myGoalLoc, agent.me) - - # agent.resetTimer += agent.deltaTime - if locked_in(agent, agentType): - if agent.currentHit != None: - createSphere(agent, agent.currentHit.pred_vector) - return - - hit = agent.sorted_hits[0] - - openNet = openGoalOpportunity(agent) - agent.openGoal = openNet - agent.timid = False - scared = False - tempDelay = hit.time_difference() - offensive = agent.offensive - agent.rotationNumber = 1 - - # if tempDelay + agent.contestedTimeLimit > agent.enemyBallInterceptDelay: - # if agent.enemyAttacking: - # agent.contested = True - # if findDistance( - # agent.ball.location, agent.me.location - # ) > 400: - # scared = True - if not agent.contested and agent.closestEnemyToBall.location[1] * sign(agent.team) <= agent.enemyTargetVec[1] * sign(agent.team): - if tempDelay - agent.contestedTimeLimit > agent.enemyBallInterceptDelay: - if agent.enemyAttacking: - agent.contested = True - if ( - distance2D(agent.enemyTargetVec, agent.me.location) > 500 - ): # and agent.closestEnemyToBall.location[1] * sign(agent.team) < agent.enemyTargetVec[1] * sign(agent.team): - scared = True - - if ( - distance2D(hit.pred_vector, myGoalLoc) <= 2000 - or distance2D(agent.enemyTargetVec, myGoalLoc) <= 2000 - or ballDistanceFromGoal <= 2000 - ): - - if ( - agent.enemyAttacking - ): # or agent.me.velocity[1] * sign(agent.team) > 1: - agent.contested = True - agent.timid = False - scared = False - - if agent.goalPred is not None: - agent.contested = True - scared = False - - # testing - if agent.closestEnemyToBall.location[1] * sign( - agent.team - ) > agent.enemyTargetVec[1] * sign(agent.team): - scared = False - - if distance2D(agent.me.location, agent.ball.location) < 500: - scared = False - - # if agent.team == 1: - # scared = False - scared = False - agent.scared = scared - - if hit.hit_type == 5: - if hit.aerialState.active: - if not agent.onSurface: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState - return - else: - if agent.enemyBallInterceptDelay < hit.time_difference() and len(agent.sorted_hits) > 1: - agent.sorted_hits = agent.sorted_hits[1:] - - # if agent.scorePred is not None:# or (agent.goalPred is None and enemy_carry_check(agent)): - # test_state = DemolitionBot(agent) - # test_state.update() - # if test_state.active: - # #print(f"demoing {agent.time}") - # agent.activeState = test_state - # return - - - # testing to see if forcing quick shot with ballward shots is worth it - if ( - not agent.contested - and not butterZone(hit.pred_vector) - and hit.hit_type not in [0, 2] - and not ballHeadedTowardsMyGoal_testing(agent, hit) - ) or (hit.hit_type == 4 and agent.scorePred): - chrono_hits = agent.sorted_hits[1:] - for h in chrono_hits: - if ( - ballHeadedTowardsMyGoal_testing(agent, h) - and cornerDetection(h.pred_vector) not in agent.my_corners - ): - break - if h.hit_type == 5: - continue - temptime = h.time_difference() - if temptime + 0.334 < agent.enemyBallInterceptDelay or not agent.enemyAttacking: - # if not offensive or agent.team == 0 or extendToGoal(agent, h.pred_vector, agent.me.location, buffer=agent.ball_size * 3): - hit = h - if ( - (agent.onWall and hit.hit_type == 2) - or hit.hit_type == 0 - or butterZone(hit.pred_vector) - ): - agent.ballDelay = hit.time_difference() - break - - if agent.dribbler: - if hit.hit_type != 0: - for h in agent.sorted_hits: - if h.hit_type == 0: - hit = h - break - - goalward = ballHeadedTowardsMyGoal_testing(agent, hit) - agent.goalward = goalward - agent.currentHit = hit - agent.ballDelay = hit.prediction_time - agent.time - - catchViable = False # ballCatchViable(agent)# and agent.team == 1 - - if hit.hit_type == 2: - agent.wallShot = True - else: - agent.wallShot = False - - createSphere(agent, hit.pred_vector) - #createBox(agent, hit.pred_vector) - - if hit.hit_type == 5: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState - return - - if not agent.onSurface: - if agent.me.location[2] > agent.recovery_height: - if agentType != DivineGrace: - agent.activeState = DivineGrace(agent) - return - - if agent.dribbling: - # if not goalward: - if agentType != AngelicEmbrace: - agent.activeState = AngelicEmbrace(agent) - return - - if agent.scorePred is not None: - # if agent.me.location[1] * sign(agent.team) > agent.ball.location[1] * sign(agent.team): - # if agent.closestEnemyToBall.location[1] * sign(agent.team) > agent.ball.location[1] * sign(agent.team): - # if agent.activeState != Divine_Retribution: - # agent.activeState = Divine_Retribution(agent,grab_boost=False) - # print(f"going for demo! {agent.time}") - # return - - if agent.enemyBallInterceptDelay > agent.scorePred.time - agent.time: - if agent.activeState != BlessingOfSafety: - agent.activeState = BlessingOfSafety(agent) - return - - boostOpportunity = inCornerWithBoost(agent) - if boostOpportunity != False: - if agent.me.boostLevel <= 50: - getBoost = False - if boostOpportunity[1] in agent.my_corners: - getBoost = True - if getBoost: - if agentType != HeavenlyReprieve: - agent.activeState = HeavenlyReprieve( - agent, boostOpportunity[0] - ) - return - - if agent.goalie: - if agent.activeState != Goalie: - agent.activeState = Goalie(agent) - return - - - if agent.ignore_kickoffs: - if distance2D(hit.pred_vector, myGoalLoc) > 3000: - if agent.activeState != HeetSeekerDefense: - agent.activeState = HeetSeekerDefense(agent) - return - - if carDistanceFromGoal > ballDistanceFromGoal: - if agentType != HolyProtector: - agent.activeState = HolyProtector(agent) - return - #testing - if goalward or (agent.contested and (not agent.first_hit.scorable or not offensive)): - if hit.hit_type != 2 and hit.hit_type != 5: - if agentType != HolyProtector: - agent.activeState = HolyProtector(agent) - return - elif hit.hit_type == 2: - if agentType != ScaleTheWalls: - agent.activeState = ScaleTheWalls(agent) - return - else: - if hit.hit_type == 5: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - return - - else: - - if hit.hit_type == 0: # hit.pred_vector[2] <= agent.groundCutOff: - if agentType != GroundAssault: - agent.activeState = GroundAssault(agent) - return - - elif hit.hit_type == 1: - if agentType != HolyGrenade: - agent.activeState = HolyGrenade(agent) - return - - elif hit.hit_type == 4: - if agentType != HolyGrenade: - agent.activeState = HolyGrenade(agent) - # print("would have been wallshot before") - return - - elif hit.hit_type == 2: - if agentType != ScaleTheWalls: - agent.activeState = ScaleTheWalls(agent) - return - - elif hit.hit_type == 5: - if agentType != Wings_Of_Justice: - agent.activeState = hit.aerialState # .create_copy() - # agent.log.append(f"Going for aerial! {agent.time}") - return - - else: - agent.log.append(f"condition leaked through! {hit.hit_type}") - - else: - agent.activeState = PreemptiveStrike(agent) - - -def orientationStateManager(agent): - if agent.ball.location[2] < 100: - car_state = CarState( - physics=Physics(velocity=Vector3(z=-1, x=0, y=0), location=Vector3(0, 4000, 17)) - ) - ball_state = BallState(physics=Physics(velocity=Vector3(z=-1, x=0, y=15), location=Vector3(150, 3500, 500))) - game_state = GameState(cars={agent.index: car_state}, ball=ball_state) - agent.set_game_state(game_state) - - if type(agent.activeState) != AngelicEmbrace: - agent.activeState = AngelicEmbrace(agent) - - -def dummyState(agent): - if type(agent.activeState) != Player_reporter: - agent.activeState = Player_reporter(agent) diff --git a/RLBotPack/Kamael_family/impossibum_utilities.py b/RLBotPack/Kamael_family/impossibum_utilities.py deleted file mode 100644 index 3aa13734..00000000 --- a/RLBotPack/Kamael_family/impossibum_utilities.py +++ /dev/null @@ -1,7980 +0,0 @@ -import math -from rlbot.agents.base_agent import BaseAgent, SimpleControllerState -import numpy as np -import ctypes -from time import time -from numba import jit, float32, typeof, boolean - -# from functools import lru_cache - -GOAL_WIDTH = 1900 -FIELD_LENGTH = 10280 -FIELD_WIDTH = 8240 - -maxPossibleSpeed = 2300 - -boosts = [ - [3584, 0, 0], - [-3584, 0, 0], - [3072, 4096, 0], - [3072, -4096, 0], - [-3072, 4096, 0], - [-3072, -4096, 0], -] - - -class Action: - def __init__(self, action_dict): - self.action = action_dict - self.vector = None - - def __repr__(self): - return self.action - - def __eq__(self, other: dict) -> boolean: - if self.action["type"] != other.action["type"]: - return False - - if self.action["type"] == "BALL": - return self.action["time"] == other.action["time"] - - if self.action["type"] == "BOOST": - return self.action["target"] == other.action["target"] - - if self.action["type"] == "DEMO": - return ( - self.action["target"] == other.action["target"] - and self.action["time"] == other.action["time"] - ) - - if self.action["type"] == "READY": - return self.action["time"] == other.action["time"] - - if self.action["type"] == "DEFEND" and other.action["type"] == "DEFEND": - return True - - return False - - -def TMCP_verifier(msg: dict) -> boolean: - try: - assert ( - msg["tmcp_version"] in [[0, 7], [0, 8], [0, 9]] - or msg["tmcp_version"][0] == 1 - ) - msg["team"] = int(msg["team"]) - msg["index"] = int(msg["index"]) - assert type(msg["action"]) == dict - assert msg["action"]["type"] in [ - "READY", - "BALL", - "DEFEND", - "BOOST", - "DEMO", - "WAIT", - ] - assert msg["team"] in [0, 1] - assert msg["index"] >= 0 - if msg["action"]["type"] == "BALL": - msg["action"]["time"] = float(msg["action"]["time"]) - - elif msg["action"]["type"] == "BOOST": - assert type(msg["action"]["target"]) == int - - elif msg["action"]["type"] == "DEMO": - msg["action"]["time"] = float(msg["action"]["time"]) - assert type(msg["action"]["target"]) == int - - elif msg["action"]["type"] == "WAIT": - msg["action"]["type"] = "READY" - msg["action"]["time"] = float(msg["action"]["ready"]) - - elif msg["action"]["type"] == "READY": - msg["action"]["time"] = float(msg["action"]["time"]) - - # if msg['action']['type'] == 'DEFEND': - # pass - - return True - - except: - print("Recieved an invalid TMCP message!", msg) - return False - - -# def TMCP_verifier(msg): -# if msg['tmcp_version'] != [0,7]:return False -# #if type(msg['team']) != int:return False -# if not isinstance(msg['team'], int):return False -# #if type(msg['index']) != int:return False -# if not isinstance(msg['index'], int): return False -# #if type(msg['action']) != dict:return False -# if not isinstance(msg['action'], dict): return False -# if msg['action']['type'] not in ['WAIT','BALL','DEFEND','BOOST','DEMO']:return False -# if msg['team'] not in [0,1]: return False -# if msg['index'] < 0:return False -# if msg['action']['type'] == 'BALL': -# #if type(msg['action']['time']) != float:return False -# if not isinstance(msg['action']['time'], float): return False -# -# if msg['action']['type'] == 'BOOST': -# #if type(msg['action']['target']) != int:return False -# if not isinstance(msg['action']['target'], int): return False -# -# if msg['action']['type'] == 'DEMO': -# #if type(msg['action']['time']) != float:return False -# #if type(msg['action']['target']) != int:return False -# if not isinstance(msg['action']['time'], float): return False -# if not isinstance(msg['action']['target'], int): return False -# -# if msg['action']['type'] == 'WAIT': -# #if type(msg['action']['ready']) != float:return False -# if not isinstance(msg['action']['ready'], float): return False -# -# # if msg['action']['type'] == 'DEFEND': -# # pass -# -# return True - - -class predictionStruct: - def __init__(self, location, _time): - self.location = location - self.time = _time - - -class renderCall: - def __init__(self, _function, *args): - self.function = _function - self.args = args - - def run(self): - self.function(self.args[0], self.args[1], self.args[2]()) - - -class FlipStatus: - def __init__(self, _time): - self.started = False - self.flipStartedTimer = _time - self.flipDone = False - - -class Boost_obj: - def __init__(self, location, bigBoost, spawned, index): - self.location = Vector(location) # list of 3 coordinates - self.bigBoost = bigBoost # bool indicating if it's a cannister or just a pad - self.spawned = spawned # bool indicating whether it's currently - self.index = index - - -class GameInfo: - def __init__(self): - self.seconds_elapsed = 0 - self.game_time_remaining = 300 - self.is_overtime = False - self.is_unlimited_time = False - self.is_round_active = False - self.is_kickoff_pause = False - self.world_gravity_z = -1000 - self.game_speed = 1 - - def update(self, gamePacket): - self.seconds_elapsed = gamePacket.game_info.seconds_elapsed - self.game_time_remaining = gamePacket.game_info.game_time_remaining - self.is_overtime = gamePacket.game_info.is_overtime - self.is_unlimited_time = gamePacket.game_info.is_unlimited_time - self.is_round_active = gamePacket.game_info.is_round_active - self.is_kickoff_pause = gamePacket.game_info.is_kickoff_pause - self.world_gravity_z = gamePacket.game_info.world_gravity_z - self.game_speed = gamePacket.game_info.game_speed - - -class physicsObject: - def __init__(self): - self.location = Vector([0, 0, 0]) - self.velocity = Vector([0, 0, 0]) - self.rotation = Vector([0, 0, 0]) - self.avelocity = Vector([0, 0, 0]) - self.rotational_velocity = Vector([0, 0, 0]) - self.local_location = Vector([0, 0, 0]) - self.boostLevel = 0 - self.team = -1 - self.matrix = [] - self.lastTouch = 0 - self.lastToucher = 0 - self.rot_vector = None - self.onSurface = False - self.demolished = False - self.retreating = False - self.index = 0 - self.next_hit = None - - -def validateExistingPred(agent, pred_struct, max_variance=25): - if pred_struct.time <= agent.time: - return False - - updatedPredAtTime = find_pred_at_time(agent, pred_struct.time) - if updatedPredAtTime is None: - return False - - if ( - findDistance( - convertStructLocationToVector(updatedPredAtTime), pred_struct.location - ) - > max_variance - ): - return False - return True - - -def refuel(agent, boostLocation): - _direction = (boostLocation - agent.ball.location).flatten().normalize() - offset = 100 - _direction.scale(offset) - target = boostLocation + _direction - # print("going for corner boost") - return driveController(agent, target, agent.time, expedite=True) - - -def inCornerWithBoost(agent): - agentVal = cornerDetection(agent.me.location) - ballVal = cornerDetection(agent.ball.location) - cannister = getClosestBoostCannister(agent) - if cannister is not None: - cannVal = cornerDetection(cannister.location) - else: - return False - - if agentVal == ballVal and agentVal == cannVal: - if agentVal != -1: - return cannister, cannVal - return False - - -def getClosestBoostCannister(agent): - closest = None - bestDistance = math.inf - - for b in agent.bigBoosts: - if b.spawned: - d = distance2D(agent.me.location, b.location) - if d < bestDistance: - closest = b - bestDistance = d - return closest - - -class Vector: - def __init__(self, content): # accepts list of float/int values - if type(content) == np.array: - self.data = content.tolist() - else: - self.data = content - - def __str__(self): - return str(self.data) - - def __repr__(self): - return str(self) - - def __len__(self): - return len(self.data) - - def __getitem__(self, item): - return self.data[item] - - def vec3Convert(self): - return vec3(self.data[0], self.data[1].self.data[2]) - - def raiseLengthError(self, other, operation): - raise ValueError( - f"Tried to perform {operation} on 2 vectors of differing lengths" - ) - - def raiseCrossError(self): - raise ValueError("Both vectors need 3 terms for cross product") - - def __mul__(self, other): - if len(self.data) == len(other.data): - return Vector([self.data[i] * other[i] for i in range(len(other))]) - else: - self.raiseLengthError(other, "multiplication") - - __rmul__ = __mul__ - - def __eq__(self, other): - try: - return self.data == other.data - except: - return False - - def __add__(self, other): - if len(self.data) == len(other.data): - return Vector([self.data[i] + other[i] for i in range(len(other))]) - else: - self.raiseLengthError(other, "addition") - - def __sub__(self, other): - if len(self.data) == len(other.data): - return Vector([self.data[i] - other[i] for i in range(len(other))]) - else: - self.raiseLengthError(other, "subtraction") - - def align_to(self, rot): - v = Vector([self[0], self[1], self[2]]) - v.data = [ - v[0], - math.cos(rot[2]) * v[1] + math.sin(rot[2]) * v[2], - math.cos(rot[2]) * v[2] - math.sin(rot[2]) * v[1], - ] - v.data = [ - math.cos(-rot[1]) * v[0] + math.sin(-rot[1]) * v[2], - v[1], - math.cos(-rot[1]) * v[2] - math.sin(-rot[1]) * v[0], - ] - v.data = [ - math.cos(-rot[0]) * v[0] + math.sin(-rot[0]) * v[1], - math.cos(-rot[0]) * v[1] - math.sin(-rot[0]) * v[0], - v[2], - ] - - return v - - def align_from(self, rot): - v = Vector([self[0], self[1], self[2]]) - v.data = [ - math.cos(rot[0]) * v[0] + math.sin(rot[0]) * v[1], - math.cos(rot[0]) * v[1] - math.sin(rot[0]) * v[0], - v[2], - ] - v.data = [ - math.cos(rot[1]) * v[0] + math.sin(rot[1]) * v[2], - v[1], - math.cos(rot[1]) * v[2] - math.sin(rot[1]) * v[0], - ] - v.data = [ - v[0], - math.cos(-rot[2]) * v[1] + math.sin(-rot[2]) * v[2], - math.cos(-rot[2]) * v[2] - math.sin(-rot[2]) * v[1], - ] - - return v - - def crossProduct(self, other): - if len(self.data) == 3 and len(other.data) == 3: - newVec = [0, 0, 0] - newVec[0] = self[1] * other[2] - self[2] * other[1] - newVec[1] = self[2] * other[0] - self[0] * other[2] - newVec[2] = self[0] * other[1] - self[1] * other[0] - - return Vector(newVec) - - else: - self.raiseCrossError() - - def magnitude(self): - return abs(math.sqrt(sum([x * x for x in self]))) - - def normalize(self): - mag = self.magnitude() - if mag != 0: - return Vector([x / mag for x in self]) - else: - return Vector([0 for _ in range(len(self.data))]) - - def dotProduct(self, other): - product = 0 - for i, j in zip(self, other): - product += i * j - return product - - def scale(self, scalar): - return Vector([x * scalar for x in self.data]) - - def correction_to(self, ideal): - current_in_radians = math.atan2(self[1], -self[0]) - ideal_in_radians = math.atan2(ideal[1], -ideal[0]) - - correction = ideal_in_radians - current_in_radians - if abs(correction) > math.pi: - if correction < 0: - correction += 2 * math.pi - else: - correction -= 2 * math.pi - - return correction - - def flatten(self): - return Vector(self.data[:2] + [0]) - - def toList(self): - return self.data - - def lerp(self, otherVector, percent): # percentage indicated 0 - 1 - percent = clamp(1, 0, percent) - originPercent = 1 - percent - - scaledOriginal = self.scale(originPercent) - other = otherVector.scale(percent) - return scaledOriginal + other - - def cap(self, limit): - if self.magnitude() > limit: - self.data = self.normalize().scale(limit).data - - -def TMCP_rotations_sorter(agent): - timers = [] - for ally in agent.allies + [agent.me]: - if ally.index not in agent.ally_actions: - return False - t = agent.time + 6 - if agent.ally_actions[ally.index]["action"] == "READY" or agent.ally_actions[ally.index]["action"] == "BALL": - t = agent.ally_actions[ally.index]["action"]["time"] - if t < agent.time: - t = agent.time + 6 - timers.append([t, ally.index]) - - return True - - -def retreating_tally(teamPlayerList): - count = 0 - for player in teamPlayerList: - if player.retreating: - count += 1 - return count - - -def player_retreat_status(ally: physicsObject, ball: Vector, team: int, num_allies=2): - retreat_threshold = 500 # if team == 0 else 200 - retreat_distance = 2500 # if team == 0 else 3500 - dist = distance2D(ally.location, ball) - # if ball[1] * sign(team) > 0: - # return False - - if dist < retreat_distance and ally.location[1] * sign(team) < 3000: - # if ally.location[1] * sign(team) < 4500: - # retreat_threshold *=2 - if dist > retreat_threshold: - if team == 0: - if ally.velocity[1] < -retreat_threshold: - return True - - else: - if ally.velocity[1] > retreat_threshold: - return True - - return False - - -class hit: - def __init__( - self, - current_time: float, - prediction_time: float, - hit_type: int, - pred_vector: Vector, - pred_vel: Vector, - hittable: bool, - fastestTime: float, - agent_team: int, - jumpSim=None, - aerialState=None, - aim_target=None, - scorable=None, - ): - self.current_time = current_time - self.prediction_time = prediction_time - self.hit_type = hit_type # 0 ground, 1 jumpshot, 2 wallshot , 3 catch canidate,4 double jump shot,5 aerial shot - self.pred_vector = pred_vector - self.pred_vel = pred_vel - self.guarenteed_hittable = hittable - self.fastestArrival = fastestTime - self.agent_team = agent_team - self.jumpSim = jumpSim - self.aerialState = aerialState - self.aim_target = aim_target - self._scorable = scorable - self.shotlimit = None - - def __str__(self): - return f"hit type: {self.hit_type} delay: {self.time_difference()}" - - def update(self, current_time): - self.current_time = current_time - - def time_difference(self): - return self.prediction_time - self.current_time - - def scorable(self): - if self._scorable is not None: - return self._scorable - - # self._scorable = is_shot_scorable(self.pred_vector,self.goal_info[0],self.goal_info[0])[2] - self._scorable = is_shot_scorable(self.agent_team, self.pred_vector) - return self._scorable - - -def butterZone(vec: Vector, x: float = 800, y: float = 4400): - return abs(vec.data[0]) < x and abs(vec.data[1]) > y - - -def steer_handler(angle, rate): - final = ((35 * (angle + rate)) ** 3) / 20 - return clamp(1, -1, final) - - -def utilities_manager(): - return time() - - -def add_car_offset(agent, projecting=False): - up = agent.up.scale(agent.defaultOffset[2]) - forward = agent._forward.scale(agent.defaultOffset[0]) - left = agent.left.scale(agent.defaultOffset[1]) - agent.me.location = agent.me.location + up + forward + left - if not agent.roof_height: - agent.roof_height = math.floor( - (agent.me.location + agent.up.scale(agent.carHeight * 0.5))[2] - ) - # print(f"roof height is: {agent.roof_height}") - - if projecting: - projection = agent.me.location + agent.me.velocity.scale(agent.fakeDeltaTime) - # else: - # projection = agent.me.location - - forward_middle = projection + agent._forward.scale( - agent.carLength * 0.5 - ) # +Vector([0,0,50]) - backward_middle = projection - agent._forward.scale(agent.carLength * 0.5) - right_middle = projection - agent.left.scale(agent.carWidth * 0.5) - left_middle = projection + agent.left.scale(agent.carWidth * 0.5) - - forward_right = forward_middle + agent.left.scale(agent.carWidth * 0.5) - forward_left = forward_middle - agent.left.scale(agent.carWidth * 0.5) - - back_right = backward_middle + agent.left.scale(agent.carWidth * 0.5) - back_left = backward_middle - agent.left.scale(agent.carWidth * 0.5) - - up_offset = agent.up.scale(agent.carHeight * 0.5) - down_offset = agent.up.scale(-agent.carHeight * 0.5) - - FTL = forward_left + up_offset - FBL = forward_left + down_offset - # print(FTL[2]) - - FTR = forward_right + up_offset - FBR = forward_right + down_offset - - BTL = back_left + up_offset - BBL = back_left + down_offset - - BTR = back_right + up_offset - BBR = back_right + down_offset - - # vertical lines - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - FTL.toList(), - FBL.toList(), - agent.renderer.pink, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - FTR.toList(), - FBR.toList(), - agent.renderer.pink, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - BTL.toList(), - BBL.toList(), - agent.renderer.pink, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - BTR.toList(), - BBR.toList(), - agent.renderer.pink, - ) - ) - - # top square - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - FTL.toList(), - FTR.toList(), - agent.renderer.pink, - ) - ) - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - FTR.toList(), - BTR.toList(), - agent.renderer.pink, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - BTR.toList(), - BTL.toList(), - agent.renderer.pink, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - BTL.toList(), - FTL.toList(), - agent.renderer.pink, - ) - ) - - # bottom square - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - FBL.toList(), - FBR.toList(), - agent.renderer.pink, - ) - ) - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - FBR.toList(), - BBR.toList(), - agent.renderer.pink, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - BBR.toList(), - BBL.toList(), - agent.renderer.pink, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - BBL.toList(), - FBL.toList(), - agent.renderer.pink, - ) - ) - - -def is_shot_scorable(agent_team, target_location): - if abs(target_location[0]) < 800: - return True - shot_angle = math.degrees( - angle2(target_location, Vector([0, 5213 * -sign(agent_team), 0])) - ) - shot_angle = correctAngle(shot_angle + 90 * -sign(agent_team)) - # print(abs(shot_angle)) - return abs(shot_angle) <= 70 - - -class ballTouch: - def __init__(self, touchInfo): - self.player_name = touchInfo.player_name - self.hit_location = touchInfo.hit_location - self.team = touchInfo.team - self.player_index = touchInfo.player_index - self.time_seconds = touchInfo.time_seconds - - def __repr__(self): - valueString = f""" - player_name = {self.player_name} - hit_location = {self.hit_location} - team = {self.team} - player_index = {self.player_index} - time_seconds = {self.time_seconds} - """ - return valueString - - def __eq__(self, other): - if type(other) != ballTouch: - # raise ValueError( - # f"Can not do comparisan operations of balltouch and {type(other)} objects." - # ) - return False - - if self.player_name != other.player_name: - return False - - if self.hit_location != other.hit_location: - return False - - if self.team != other.team: - return False - - if self.player_index != other.player_index: - return False - - if self.time_seconds != other.time_seconds: - return False - - return True - - -def closest_enemy_to_goal(agent): - e_goal = Vector([0, 5600 * -sign(agent.team), 200]) - closest_distance = math.inf - closest = None - - for e in agent.enemies: - c_dist = distance2D(e.location, e_goal) - if c_dist < closest_distance: - closest_distance = c_dist - closest = e - - return closest, closest_distance - - -def boost_limping(agent): - return None, None - if agent.me.location[0] > 0: - targ_index = 18 - else: - targ_index = 15 - - target = None - go_ahead = False - if agent.boosts[targ_index].spawned: - target = agent.boosts[targ_index].location + Vector( - [0, -sign(agent.team) * 10, 0] - ) - if agent.currentHit.pred_vector[1] * sign(agent.team) < 0: - if abs(agent.ball.location[0]) >= 2000: - go_ahead = True - agent.boosts[targ_index].location - else: - target = None - - return target, go_ahead - - -def goal_selector_revised( - agent, mode=0 -): # 0 angles only, closest corner #1 enemy consideration, 2 center only - leftPost = Vector([500 * -sign(agent.team), 5320 * -sign(agent.team), 0]) - rightPost = Vector([500 * sign(agent.team), 5320 * -sign(agent.team), 0]) - center = Vector([0, 5600 * -sign(agent.team), 0]) - real_center = center = Vector([0, 5320 * -sign(agent.team), 0]) - maxAngle = 60 - - targetVec = agent.currentHit.pred_vector - - shotAngles = [ - math.degrees(angle2(targetVec, leftPost)), - math.degrees(angle2(targetVec, center)), - math.degrees(angle2(targetVec, rightPost)), - ] - - correctedAngles = [correctAngle(x + 90 * -sign(agent.team)) for x in shotAngles] - dist = distance2D(targetVec, center) - - if dist >= 6500 or (dist < 1500 and abs(targetVec[0]) < 820) or mode == 2: - aim = Vector([0, 5250 * -sign(agent.team), 0]) - #createBox(agent, aim) - return aim, correctedAngles[1] - - if correctedAngles[1] <= -maxAngle: - #createBox(agent, leftPost) - return leftPost, correctedAngles[1] - - if correctedAngles[1] >= maxAngle: - #createBox(agent, rightPost) - return rightPost, correctedAngles[1] - - if mode == 0 or agent.openGoal: - #createBox(agent, center) - return real_center, correctedAngles[1] - - goalie, dist = findEnemyClosestToLocation(agent, real_center) - - if goalie is not None and dist < 1000: - left_distance = distance2D(goalie.location, leftPost) - right_distance = distance2D(goalie.location, rightPost) - if left_distance >= right_distance: - return leftPost, correctedAngles[1] - else: - return rightPost, correctedAngles[1] - else: - return center, correctedAngles[1] - - -def convertStructLocationToVector(struct): - return Vector( - [ - struct.physics.location.x * 1.0, - struct.physics.location.y * 1.0, - struct.physics.location.z * 1.0, - ] - ) - - -def convertStructVelocityToVector(struct): - return Vector( - [ - struct.physics.velocity.x * 1.0, - struct.physics.velocity.y * 1.0, - struct.physics.velocity.z * 1.0, - ] - ) - - -def placeTargetVecWithinArena(vec, agent): - if vec[0] > 4096 - agent.defaultElevation: - vec.data[0] = 4096 - agent.defaultElevation - - elif vec[0] < -4096 + agent.defaultElevation: - vec.data[0] = -4096 + agent.defaultElevation - - if vec[1] > 5120 - agent.defaultElevation: - if abs(vec[0]) > 893: - vec.data[1] = 5120 - agent.defaultElevation - - else: - if vec[1] > 6000: - vec.data[1] = 6000 - - elif vec[1] < -5120 + agent.defaultElevation: - if abs(vec[0]) > 893: - vec.data[1] = -5120 + agent.defaultElevation - - else: - if vec[1] < -6000: - vec.data[1] = -6000 - - -def placeVecWithinArena(vec, offset=17.01): - if vec[0] > 4096 - offset: - vec.data[0] = 4096 - offset - - elif vec[0] < -4096 + offset: - vec.data[0] = -4096 + offset - - if vec[1] > 5120: - if abs(vec[0]) > 893: - vec.data[1] = 5120 - offset - - else: - if vec[1] > 6000: - vec.data[1] = 6000 - - elif vec[1] < -5120: - if abs(vec[0]) > 893: - vec.data[1] = -5120 + offset - - else: - if vec[1] < -6000: - vec.data[1] = -6000 - - -def get_min_boost_duration(agent): - return agent.boost_duration_min - clamp( - agent.boost_duration_min, 1, agent.boost_counter - ) - - -def directional_demo_picker( - agent, direction=0 -): # 0 = any, 1 = towards enemy goal, 2 = towards player goal - best_target = None - best_distance = math.inf - # print(f"function called {agent.time}") - - for enemy in agent.enemies: - if (enemy.onSurface or enemy.location[2] <= 145) and not enemy.demolished: - if ( - direction == 0 - or ( - direction == 1 - and (enemy.location[1] * sign(agent.team)) - < (agent.me.location[1] * sign(agent.team)) - ) - or ( - direction == 2 - and (enemy.location[1] * sign(agent.team)) - > (agent.me.location[1] * sign(agent.team)) - ) - ): - _distance = findDistance(agent.me.location, enemy.location) - # print(f"{_distance}") - if _distance < best_distance: - best_target = enemy - best_distance = _distance - - return best_target - - -def unpicky_demo_picker(agent): - best_target = None - best_distance = math.inf - - for enemy in agent.enemies: - if (enemy.onSurface or enemy.location[2] < 140) and not enemy.demolished: - _distance = findDistance(agent.me.location, enemy.location) - if _distance < best_distance: - best_target = enemy - best_distance = _distance - - return best_target - - -def demo_check(agent, target_car): - if target_car.demolished or target_car.team == agent.team: - return False - return True - - -def demoTarget(agent, targetCar): - currentSpd = clamp(maxPossibleSpeed, 100, agent.currentSpd) - distance = distance2D(agent.me.location, targetCar.location) - - currentTimeToTarget = inaccurateArrivalEstimator( - agent, targetCar.location, offset=105 - ) - lead = clamp(2, 0, currentTimeToTarget) - - enemyspd = targetCar.velocity.magnitude() - multi = clamp(1000, 0, enemyspd * currentTimeToTarget) - targPos = targetCar.location + (targetCar.velocity.normalize().scale(multi)) - - if not targetCar.onSurface or (agent.currentSpd < 2200 and agent.me.boostLevel < 1): - if currentTimeToTarget < 0.1: - local_target = localizeVector(targPos, agent.me) - angle = math.atan2(local_target[1], local_target[0]) - angle_degrees = correctAngle(math.degrees(angle)) - if abs(angle_degrees) < 30: - agent.setJumping(1) - - agent.update_action( - { - "type": "DEMO", - "time": float( - agent.time - + findDistance(agent.me.location, targPos) - / clamp(2300, 0.001, agent.currentSpd) - ), - "target": targetCar.index, - } - ) - - return driveController( - agent, targPos, agent.time, expedite=True, demos=True - ) - - -def kickOffTest(agent): - if agent.ignore_kickoffs or agent.ball.location.flatten() != Vector([0, 0, 0]): - return False - - if ( - agent.gameInfo.is_kickoff_pause or not agent.gameInfo.is_round_active - ) or agent.ball.location.flatten() != Vector([0, 0, 0]): - if len(agent.allies) > 0: - myDist = distance2D(agent.me.location, agent.ball.location) - equalAlly = None - for ally in agent.allies: - ally_dist = distance2D(ally.location, agent.ball.location) - if abs(ally_dist - myDist) < 50: - equalAlly = ally - elif ally_dist < myDist: - return False - if equalAlly is not None: - if agent.team == 0: - if agent.me.location[0] > 0: - return True - else: - return False - else: - if agent.me.location[0] < 0: - return True - else: - return False - - return True - return False - - -def flipHandler(agent, flip_status): - if flip_status.started: - if agent.time - flip_status.flipStartedTimer <= 0.10: - jump = True - else: - jump = False - else: - jump = True - flip_status.started = True - flip_status.flipStartedTimer = agent.time - - if agent.time - flip_status.flipStartedTimer >= 0.15: - jump = True - - if agent.time - flip_status.flipStartedTimer >= 0.45: - flip_status.flipDone = True - - return jump - - -def rotator_to_matrix(our_object): - r = our_object.rotation - CR = math.cos(r[2]) - SR = math.sin(r[2]) - CP = math.cos(r[0]) - SP = math.sin(r[0]) - CY = math.cos(r[1]) - SY = math.sin(r[1]) - - matrix = [ - Vector([CP * CY, CP * SY, SP]), - Vector([CY * SP * SR - CR * SY, SY * SP * SR + CR * CY, -CP * SR]), - Vector([-CR * CY * SP - SR * SY, -CR * SY * SP + SR * CY, CP * CR]), - ] - - return matrix - - -def getLocation(_object): - if hasattr(_object, "data"): - return _object - if hasattr(_object, "location"): - return _object.location - raise ValueError( - f"{str(type(_object))} is not a valid input for 'getLocation' function " - ) - - -@jit(float32(float32, float32, float32), nopython=True) -def clamp(_max, _min, value): - if value > _max: - return _max - if value < _min: - return _min - return value - - -def sign(x): - if x <= 0: - return -1 - else: - return 1 - - -def newSteer(angle): - turn = Gsteer(angle) - slide = False - - if abs(math.degrees(angle)) >= 85: - slide = True - - return (turn, slide) - - -def slideSteer(angle, distance): - sliding = False - degrees = math.degrees(angle) - - if distance < 1000: - if 70 < abs(degrees) < 180: - sliding = True - """ - if abs(degrees) < 3: - return(0,False) - """ - - return (clamp(1, -1, (degrees / 360) * 8), sliding) - else: - if abs(degrees) < 3: - return (0, False) - - return (clamp(1, -1, (degrees / 360) * 8), sliding) - - -def find_closest_cannister(agent): - big_cans = [x for x in agent.boosts if x.spawned and x.bigBoost] - if len(big_cans) > 0: - closest_cannister = min( - big_cans, key=lambda k: distance2D(k.location, agent.me.location) - ) - return ( - closest_cannister, - distance2D(agent.me.location, closest_cannister.location), - ) - return None, math.inf - - -def boost_suggester( - agent, mode=1, buffer=3000, strict=False -): # mode 0: any side, mode:1 stay on side, mode:2 stay on opposite side - if agent.aerial_hog or agent.demo_monster: - mode = 0 - minY = agent.ball.location[1] + (buffer * sign(agent.team)) - closestBoost = None - bestDistance = math.inf - bestAngle = 0 - multiplier = 1 - if mode == 1: - if agent.ball.location[0] < 0: - multiplier = -1 - - elif mode == 2: - if agent.ball.location[0] > 0: - multiplier = -1 - - for boost in agent.boosts: - if boost.spawned and boost.index not in agent.ignored_boosts: - if ( - (boost.location[1] <= minY and agent.team == 0) - or (boost.location[1] >= minY and agent.team == 1) - or ( - not strict - and boost.bigBoost - and boost.location[1] * sign(agent.team) - > agent.me.location[1] * sign(agent.team) - ) - ): - if mode == 0 or boost.location[0] * multiplier >= 0: - distance = distance2D(agent.me.location, boost.location) - localCoords = toLocal(boost.location, agent.me) - angle = abs( - math.degrees(math.atan2(localCoords[1], localCoords[0])) - ) - if not agent.forward: - angle -= 180 - angle = correctAngle(angle) - - distance += angle * 5 - if boost.bigBoost and agent.me.boostLevel < 50: - distance = distance * 0.333 - if distance < bestDistance: - bestDistance = distance - closestBoost = boost - bestAngle = angle - - if closestBoost is not None: - agent.boost_gobbling = True - - return closestBoost - - -def distance1D(origin, destination, index): - return abs(getLocation(origin)[index] - getLocation(destination)[index]) - - -def findOppositeSideVector(agent, objVector, antiTarget, desiredBallDistance): - # angle = math.degrees(angle2(objVector,antiTarget)) - targetDistance = distance2D(objVector, getLocation(antiTarget)) - oppositeVector = (getLocation(antiTarget) - objVector).normalize() - return getLocation(antiTarget) - ( - oppositeVector.scale(targetDistance + desiredBallDistance) - ) - - -def findOppositeSide(agent, targetLoc, antiTarget, desiredBallDistance): - # angle = correctAngle(math.degrees(angle2(targetLoc,antiTarget))) - targetDistance = distance2D(targetLoc, getLocation(antiTarget)) - oppositeVector = (getLocation(antiTarget) - targetLoc).normalize() - return getLocation(antiTarget) - ( - oppositeVector.scale(targetDistance + desiredBallDistance) - ) - - -def find_L_distance(groundVector, wallVector): - groundedWallSpot = Vector([wallVector.data[0], wallVector.data[1], 0]) - return distance2D(groundVector, groundedWallSpot) + findDistance( - groundedWallSpot, wallVector - ) - - -def goFarPost(agent, hurry=True): - rightPost = Vector([800, 4800 * sign(agent.team), 0]) - leftPost = Vector([-800, 4800 * sign(agent.team), 0]) - rightDist = distance2D(agent.ball.location, rightPost) - leftDist = distance2D(agent.ball.location, leftPost) - selectedDist = 99999 - if rightDist > leftDist: - post = rightPost - selectedDist = rightDist - pointDir = leftPost + Vector([0, -sign(agent.team) * 400, 0]) - - else: - post = leftPost - selectedDist = leftDist - pointDir = rightPost + Vector([0, -sign(agent.team) * 400, 0]) - - area_info = teammate_nearby(agent, post, 300) - - if distance2D(post, agent.me.location) < 250 and not agent.onWall: - if agent.currentSpd < 100: - localTarget = toLocal(pointDir, agent.me) - angle = math.degrees(math.atan2(localTarget[1], localTarget[0])) - if abs(angle) > 45: - agent.setGuidance(pointDir) - return arrest_movement(agent) - - return driveController( - # agent, post, agent.time + 0.25, expedite=True - agent, - post, - agent.time, - expedite=hurry, - ) - - -def gate(agent, hurry=True): - # print(f"{agent.index} in gate") - rightPost = Vector([840, 4600 * sign(agent.team), 0]) - leftPost = Vector([-840, 4600 * sign(agent.team), 0]) - center = Vector([0, 5350 * sign(agent.team), 0]) - enemy_goal = Vector([0, 5000 * -sign(agent.team), 0]) - rightDist = distance2D(agent.me.location, rightPost) - leftDist = distance2D(agent.me.location, leftPost) - selectedDist = 99999 - # own_goal_info = own_goal_check(agent, agent.ball.location.flatten(), agent.me.location.flatten(), send_back=True) - - if ( - agent.goalie - and agent.lastMan != agent.me.location - and abs(agent.me.location[0]) < 800 - ): - center = Vector([0, 6500 * sign(agent.team), 200]) - - if rightDist < leftDist: - post = rightPost - selectedDist = rightDist - else: - post = leftPost - selectedDist = leftDist - inPlace = False - centerDist = distance2D(agent.me.location, center) - if centerDist <= 450: - inPlace = True - - if teammate_nearby(agent, post, 500)[0]: - post = center - - if not inPlace: - if selectedDist >= 1200: - return driveController( - agent, - post, - agent.time + (selectedDist / 2300), - expedite=hurry, - flippant=(not agent.forward or not agent.on_correct_side), - ) - - elif centerDist > 350: - return driveController(agent, center, agent.time + 0.2, expedite=False) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - agent.me.location.toList(), - agent.enemyTargetVec.toList(), - agent.renderer.red, - ) - ) - if inPlace: - if agent.currentSpd < 50: - localTarget = toLocal(enemy_goal, agent.me) - angle = math.degrees(math.atan2(localTarget[1], localTarget[0])) - if ( - abs(angle) > 35 - and distance2D(agent.me.location, agent.ball.location) > 3000 - and agent.goalPred is None - ): - agent.setGuidance(enemy_goal) - # return SimpleControllerState() - return arrest_movement(agent) - - return driveController(agent, center, agent.time + 0.6, expedite=False) - - -def arrest_movement(agent): - controls = SimpleControllerState() - if agent.currentSpd > 20: - if agent.forward: - controls.throttle = -1 - - else: - controls.throttle = 1 - - return controls - - -def get_ball_offset_simple(agent, ball_location): - if ball_location[2] > agent.groundCutOff: - return 60 - adjusted_roof_height = agent.roof_height - (ball_location[2] - agent.ball_size) - return math.floor( - math.sqrt(clamp(200, 0.0001, adjusted_roof_height * (agent.ball_size * 2 - adjusted_roof_height))) - ) - - -def get_ball_offset(agent, hit): - if hit.pred_vector[2] > agent.groundCutOff: - return 65 - adjusted_roof_height = agent.roof_height - (hit.pred_vector[2] - agent.ball_size) - # if adjusted_roof_height < 1: - # print("roof height too low!") - return math.floor( - math.sqrt(clamp(200, 0.0001, adjusted_roof_height * (agent.ball_size * 2 - adjusted_roof_height))) - ) - - -def find_defensive_target(agent): - start = agent.ball.location - if agent.enemyTargetVec is not None: - start = agent.enemyTargetVec - - if abs(start[0]) < 500: - return agent.goal_locations[1] - - if distance2D(start, agent.goal_locations[0]) < distance2D(start, agent.goal_locations[2]): - return agent.goal_locations[0] - else: - return agent.goal_locations[2] - - -def ShellTime(agent, retreat_enabled=True, aim_target=None): - defendTarget = Vector([0, 5500 * sign(agent.team), 200]) - attackTarget = Vector([0, 5200 * -sign(agent.team), 200]) - - targetVec = agent.currentHit.pred_vector - carDistance = distance2D(agent.me.location, defendTarget) - ballGoalDistance = distance2D(agent.ball.location, defendTarget) - targDistance = distance2D(agent.me.location, targetVec) - targToGoalDistance = distance2D(attackTarget, targetVec) - expedite = True - flippant = False - offensive = agent.offensive - defensiveRange = 200 - require_lineup = False - flipping = True - force_close = False - fudging = False - if agent.currentHit.hit_type == 5: - agent.activeState = agent.currentHit.aerialState - return agent.activeState.update() - is_mirror_shot = False - - mode = 0 - - goalSpot = aim_target - ballGoalAngle = 0 - - if not offensive and agent.me.velocity[1] * sign(agent.team) > 0: - is_mirror_shot = True - force_close = True - - if not goalSpot: - goalSpot, ballGoalAngle = goal_selector_revised(agent, mode=mode) - - localPos = toLocal(targetVec, agent.me) - angleDegrees = correctAngle(math.degrees(math.atan2(localPos[1], localPos[0]))) - - if abs(angleDegrees) <= 40 or abs(angleDegrees) >= 140: - carOffset = agent.carLength * 0.5 - else: - carOffset = agent.carWidth * 0.5 - - ballOffset = get_ball_offset(agent, agent.currentHit) - totalOffset = (carOffset + ballOffset) * 0.9 - offset_min = totalOffset * 0.8 - - positioningOffset = offset_min - - - destination = None - moddedOffset = False - if len(agent.allies) > 0: - retreat_enabled = False - - - if carDistance - defensiveRange > ballGoalDistance and retreat_enabled: - if True: - cornerShot = cornerDetection(targetVec) != -1 - if not agent.goalPred: # and agent.lastMan != agent.me.location): - if retreat_enabled or cornerShot: - rightPost = Vector([900, 5000 * sign(agent.team), 200]) - leftPost = Vector([-900, 5000 * sign(agent.team), 200]) - if distance2D(agent.me.location, rightPost) < distance2D( - agent.me.location, leftPost - ): - post = rightPost - else: - post = leftPost - - if distance2D(targetVec, post) + defensiveRange < distance2D( - agent.me.location, post - ): - return driveController( - agent, post.flatten(), agent.time, expedite=True - ) - # return corner_retreat(agent) - else: - return smart_retreat(agent) - else: - if not agent.currentHit.guarenteed_hittable and agent.me.boostLevel <= 0: - flippant = True - - if len(agent.allies) < 2: - if abs(ballGoalAngle) >= agent.angleLimit and abs(targetVec[0]) > 800: - expedite = False - if retreat_enabled: - if ( - agent.enemyBallInterceptDelay < agent.currentHit.time_difference() - and agent.enemyBallInterceptDelay < 2.5 - and agent.enemyAttacking - ) or agent.me.boostLevel < agent.boostThreshold: - return playBack(agent) - - # if (agent.superSonic or agent.me.boostLevel > 0) and enemy_carry_check(agent) and \ - # demo_check(agent, agent.closestEnemyToBall) and ( - # agent.me.location != agent.lastMan or agent.goalPred is None): - # return demoTarget(agent, agent.closestEnemyToBall) - - if defensive_check(agent) and retreat_enabled: - return defensive_positioning(agent) - - if agent.currentHit.hit_type == 1 or agent.currentHit.hit_type == 4: - return handleBounceShot(agent, waitForShot=False) - - if agent.currentHit.hit_type == 2: - agent.wallShot = True - agent.ballGrounded = False - return handleWallShot(agent) - - # testing - if not is_mirror_shot and not agent.ignore_kickoffs: - mirror_info = mirrorshot_qualifier(agent) - is_mirror_shot = ( - mirror_info[0] - and len(mirror_info[1]) < 1 - and (agent.lastMan == agent.me.location) - and agent.contested - and not offensive - ) - - if not offensive and not agent.forward: - is_mirror_shot = True - - # relative_speed = relativeSpeed( - # agent.currentHit.pred_vel.flatten(), agent.me.velocity - # ) - # if agent.currentHit.time_difference() < 1: - # if ( - # (relative_speed * 1.75 >= targToGoalDistance or (butterZone(targetVec) and agent.contested)) - # and offensive - # and agent.team == 0 - # ): - # # print(f"forcing jumpshot {agent.time}") - # return handleBounceShot(agent, waitForShot=False) - # - # if agent.team == 0 and agent.me.location[1] * sign(agent.team) > targetVec[1] * sign(agent.team) and targetVec[2] > agent.groundCutOff * 0.85 and relative_speed > 1800: - # return handleBounceShot(agent, waitForShot=False) - - if targetVec[1] * sign(agent.team) < agent.me.location[1] * sign(agent.team) and agent.contested and agent.currentHit.time_difference() < 1: - return handleBounceShot(agent, waitForShot=False) - - - max_swoop = 900 if agent.contested else 1800 - lined_up = agent.lineup_check() - - if ( - not lined_up - and targetVec[1] * sign(agent.team) < -3500 - and abs(targetVec[0]) < 3000 - and not is_mirror_shot - and agent.goalPred is None - ): - require_lineup = True - - _direction = direction(targetVec.flatten(), goalSpot.flatten()) - simple_pos = targetVec.flatten() + _direction.scale(positioningOffset) - simple_pos.data[2] = agent.defaultElevation - - if len(agent.allies) < 2: - shot_scorable = agent.currentHit.scorable() - - if not shot_scorable: - require_lineup = True - max_swoop = 900 - if ( - agent.enemyBallInterceptDelay < agent.currentHit.time_difference() - and agent.enemyBallInterceptDelay < 2.5 - and agent.enemyAttacking - ) or agent.me.boostLevel < agent.boostThreshold: - return playBack(agent) - - if not destination and (agent.goalPred is not None or agent.scared or lined_up): - destination = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - offset_min, - )[0] - - if not destination: - if ( - agent.contested - and not require_lineup - and ( - distance2D(agent.closestEnemyToBall.location, attackTarget) - < distance2D(agent.me.location, attackTarget) - ) - ): - if not is_mirror_shot: - destination = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - offset_min, - )[0] - else: - destination = aim_wallshot_naive( - agent, agent.currentHit, offset_min, force_close=force_close - ) - - if not destination and require_lineup: - offset = clamp(max_swoop, offset_min, targDistance * 0.5) - positioningOffset = offset - if not is_mirror_shot: - destination = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - )[0] - moddedOffset = positioningOffset > offset_min - else: - destination = aim_wallshot_naive( - agent, agent.currentHit, positioningOffset, force_close=force_close - ) - moddedOffset = positioningOffset > offset_min - - if not destination and abs(targetVec[0]) < 3500: - # if not agent.contested: - if ( - targDistance > totalOffset - and targDistance > (agent.currentSpd * agent.currentHit.time_difference()) - and abs(targetVec[1]) <= 4000 - ): - # print(f"in here {agent.time}") - offset = clamp(max_swoop, offset_min, targDistance * 0.25) - # _direction = direction(attackTarget, targetVec) - positioningOffset = offset - destination = targetVec + _direction.scale(positioningOffset) - if agent.team != 3: - if not is_mirror_shot: - destination = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - )[0] - else: - destination = aim_wallshot_naive( - agent, - agent.currentHit, - positioningOffset, - force_close=force_close, - ) - moddedOffset = positioningOffset > offset_min - - if not destination: - # _direction = direction(targetVec, attackTarget) - positioningOffset = offset_min - destination = targetVec + _direction.scale(positioningOffset) - if agent.team != 3: - if not is_mirror_shot: - destination = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - )[0] - else: - destination = aim_wallshot_naive( - agent, agent.currentHit, positioningOffset, force_close=force_close - ) - moddedOffset = False - - if moddedOffset: - modifiedDelay = clamp( - 6, - 0, - agent.currentHit.time_difference() - - ( - # (positioningOffset - offset_min) - positioningOffset - / clamp(maxPossibleSpeed, 0.001, agent.currentSpd) - ), - ) - fudging = True - - else: - modifiedDelay = agent.currentHit.time_difference() - - if agent.team == 3: - modifiedDelay -= agent.fakeDeltaTime - - destination.data[2] = agent.defaultElevation - if agent.ball.location[1] * sign(agent.team) > agent.me.location[1] * sign( - agent.team - ) or targetVec[1] * sign(agent.team) > agent.me.location[1] * sign(agent.team): - expedite = True - - - - result = driveController( - agent, - destination, - agent.time + modifiedDelay, - expedite=expedite, - flippant=flippant, - flips_enabled=flipping, - fudging=fudging, - offset_dist=0 if not fudging else findDistance(destination, simple_pos) - ) - - # destination.data[2] = 75 - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - agent.me.location.toList(), - destination.toList(), - agent.renderer.blue, - ) - ) - - agent.update_action({"type": "BALL", "time": agent.currentHit.prediction_time}) - - return result - - -def findEnemyClosestToLocation(agent, location, demo_bias=False): - if len(agent.enemies) > 0: - closest = agent.enemies[0] - cDist = math.inf - for e in agent.enemies: - x = math.inf if (demo_bias and e.demolished) else findDistance(e.location, location) - if x < cDist: - cDist = x - closest = e - return closest, cDist - else: - return None, None - - -def cornerDetection(_vec): - # a simple function for determining if a vector is located within the corner of the field - # if the vector is, will return the corner number, otherwise will return -1 - # 0 = blue right, 1 = blue left, 2 = orange left, 3 = orange right #perspective from blue goal - y_value = 3840 - x_value = 2500 - - if abs(_vec.data[0]) > x_value and abs(_vec.data[1]) > y_value: - x = _vec.data[0] - y = _vec.data[1] - - if x > 0: - if y > 0: - return 2 - else: - return 1 - else: - if y > 0: - return 3 - else: - return 0 - - else: - return -1 - - -def teammate_nearby(agent, location, distanceLimit): - for a in agent.allies: - e_dist = distance2D(agent.me.location, a.location) - if e_dist <= distanceLimit: - return True, e_dist - - return False, 0 - - -def naive_flip_relocator(agent): - flip_window = 0.5 - contact_time = agent.currentHit.time_difference() - flip_time = 0 - if contact_time > flip_window: - flip_time = contact_time - flip_window - -def handleBounceShot(agent, waitForShot=True, forceDefense=False, aim_target=None): - myGoal = Vector([0, 5300 * sign(agent.team), 200]) - - targetVec = agent.currentHit.pred_vector - mirrorShot = False - force_close = False - offensive = agent.offensive - in_zone = butterZone(targetVec) - - if len(agent.allies) < 1 and agent.offensive and agent.contested and agent.me.boostLevel < 50 and agent.enemyBallInterceptDelay < agent.ballDelay: - return playBack(agent) - - if forceDefense: - defensiveTouch = True - else: - defensiveTouch = ( - # inTheMiddle( - # targetVec[1], [2000 * sign(agent.team), 5500 * sign(agent.team)] - # ) - targetVec[1] * sign(agent.team) > 2000 - and not agent.openGoal - # and len(agent.enemies) > 1 - ) - if defensiveTouch: - if agent.currentHit.hit_type != 4: - if abs(targetVec[0]) > 1500: - defensiveTouch = False - - is_mirror_shot = False - flipping = True - - if agent.me.location[1] * sign(agent.team) < targetVec[1] * sign(agent.team): - is_mirror_shot = True - - # testing - if not is_mirror_shot and not agent.ignore_kickoffs: - mirror_info = mirrorshot_qualifier(agent) - is_mirror_shot = ( - mirror_info[0] - and len(mirror_info[1]) < 1 - and not offensive - and (agent.lastMan == agent.me.location) - and agent.contested - ) - - if is_mirror_shot and offensive and in_zone: - is_mirror_shot = False - targDistance = distance2D(agent.me.location, targetVec) - - targetLocal = toLocal(targetVec, agent.me) - carToTargAngle = math.degrees(math.atan2(targetLocal[1], targetLocal[0])) - - if abs(carToTargAngle) <= 40 or abs(carToTargAngle) >= 140: - carOffset = agent.carLength * 0.5 - else: - carOffset = agent.carWidth * 0.5 - - lined_up = agent.lineup_check() - - require_lineup = False - annoyingShot = False - - ballOffset = agent.ball_size # 91.25 - modifier = 0.99999 - totalOffset = (carOffset + ballOffset) * modifier - # if agent.currentHit.hit_type == 4: - # offset_min = totalOffset * 0.8 - # else: - offset_min = (carOffset + ballOffset) * 0.65 - safety_margin = 0 - - if agent.currentHit.pred_vector[2] <= agent.groundCutOff: - #ballOffset = get_ball_offset(agent, agent.currentHit) - totalOffset = (ballOffset + carOffset)+30 - offset_min = totalOffset * 0.5 - annoyingShot = True - safety_margin = -50 - #print(f"annoying shot {agent.time}") - - - shotViable = False - hurry = True - - is_shooting = True - if len(agent.allies) < 2: - shot_scorable = agent.currentHit.scorable() - if not shot_scorable: # and len(agent.allies) < 1: - hurry = False - is_shooting = False - - mode = 0 - - goalSpot = aim_target - ballGoalAngle = 0 - - if agent.me.velocity[1] * sign(agent.team) > 0: - is_mirror_shot = True - force_close = True - - if not goalSpot: - goalSpot, ballGoalAngle = goal_selector_revised(agent, mode=mode) - if len(agent.allies) < 1: - if abs(ballGoalAngle) >= agent.angleLimit and abs(targetVec[0]) > 800: - if ( - agent.enemyBallInterceptDelay < agent.currentHit.time_difference() - and agent.enemyBallInterceptDelay < 2.5 - and agent.enemyAttacking - # and agent.team == 0 - ) or agent.me.boostLevel < agent.boostThreshold: - # return secondManPositioning(agent) - return playBack(agent) - - if agent.scared: - return turtle_mode(agent) - - if agent.currentHit.hit_type != 2: - repos_action = reposition_handler(agent, targetVec) - if repos_action is not None: - return repos_action - - - if not annoyingShot: - if defensive_check(agent): - return defensive_positioning(agent) - - - if agent.currentHit.jumpSim is None or agent.currentHit.current_time < agent.time: - if agent.currentHit.hit_type != 4: - agent.currentHit.jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array(agent.me.velocity.data, dtype=np.dtype(float)), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array(agent.me.location.data, dtype=np.dtype(float)), - float32(agent.defaultElevation), - float32(agent.currentHit.time_difference()), - float32(targetVec[2]), - False, - ) - else: - agent.currentHit.jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array(agent.me.velocity.data, dtype=np.dtype(float)), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array(agent.me.location.data, dtype=np.dtype(float)), - float32(agent.defaultElevation), - float32(agent.currentHit.time_difference()), - float32(targetVec[2]), - False, - ) - agent.currentHit.current_time = agent.time - - test_offset = clamp( - 1500, offset_min, agent.currentSpd * agent.currentHit.time_difference() - ) - # safety_margin = 10 if targetVec[2] > agent.singleJumpLimit else 0 - - if ( - #distance2D(Vector(agent.currentHit.jumpSim[4]), targetVec) - findDistance(Vector(agent.currentHit.jumpSim[4]), targetVec) - < totalOffset - safety_margin - ): - shotViable = True - - waiting = False - - - positioningOffset = offset_min - launching = False - targetLoc = None - boostHog = True - variance = agent.fakeDeltaTime - if annoyingShot: - variance *= 6 - if agent.currentHit.jumpSim[1] != 0: - shotlimit = clamp(1, 0.07, agent.currentHit.jumpSim[1] + variance) - else: - shotlimit = clamp(1, 0.07, agent.currentHit.jumpSim[3] + variance) - - else: - maxValue = agent.doubleJumpShotTimer - if agent.currentHit.hit_type == 1: - maxValue = agent.singleJumpShotTimer - - if agent.currentHit.jumpSim[1] != 0: - shotlimit = clamp( - maxValue, - agent.currentHit.jumpSim[1], - agent.currentHit.jumpSim[1] + variance, - ) - else: - shotlimit = clamp( - maxValue, - agent.currentHit.jumpSim[3], - agent.currentHit.jumpSim[3] + variance, - ) - - agent.currentHit.shotlimit = shotlimit - modifiedDelay = agent.currentHit.time_difference() - waitingShotPosition = None - _direction = (goalSpot.flatten() - targetVec.flatten()).normalize() - bad_direction = _direction.scale(-1) - if not agent.offensive: - bad_direction= (myGoal.flatten() - targetVec.flatten()).normalize() - badPosition = targetVec.flatten() + bad_direction.scale(offset_min) - fudging = False - - lineup_grace = 0.33334 - - if defensiveTouch or is_mirror_shot: - waitingShotPosition = aim_wallshot_naive( - agent, agent.currentHit, offset_min, force_close=force_close - ) - - else: - if ( - not lined_up - and offensive - and agent.forward - and agent.currentHit.time_difference() > shotlimit + lineup_grace - and agent.me.velocity[1] * sign(agent.team) < 0 - and not annoyingShot - and (agent.me.boostLevel > 0 or in_zone) - and targDistance > 500 - and agent.currentSpd * agent.currentHit.time_difference() - shotlimit - < targDistance - and agent.goalPred is None - and agent.currentHit.hit_type != 4 - ): - require_lineup = True - - #_direction = direction(goalSpot.flatten(), targetVec.flatten()) - simple_pos = targetVec.flatten() + _direction.scale(positioningOffset) - simple_pos.data[2] = agent.defaultElevation - - if waitingShotPosition is None: - if not require_lineup: - waitingShotPosition = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - offset_min, - # test_offset - )[0] - else: - positioningOffset = clamp(2100, offset_min, targDistance * lineup_grace) - - if positioningOffset > offset_min: - modifiedDelay = clamp( - 6, - 0.0001, - agent.ballDelay - - ( - # (positioningOffset - offset_min) - positioningOffset - / clamp(maxPossibleSpeed, 0.001, agent.currentSpd) - ), - ) - fudging = True - - waitingShotPosition = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - # test_offset - )[0] - - if agent.currentHit.time_difference() <= shotlimit: - - # if targetLoc == None: - if annoyingShot or agent.goalPred is not None or distance2D( - Vector(agent.currentHit.jumpSim[4]), waitingShotPosition - ) < distance2D(Vector(agent.currentHit.jumpSim[4]), badPosition): - if not agent.onWall and agent.onSurface and is_shooting: - if shotViable: - agent.createJumpChain( - agent.currentHit.time_difference(), - targetVec[2], - agent.currentHit.jumpSim, - ) - targetLoc = targetVec - launching = True - if annoyingShot: - agent.log.append(f"taking annoying shot! {agent.time}") - - if not targetLoc: - targetLoc = waitingShotPosition - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - agent.me.location.toList(), - waitingShotPosition.flatten().toList(), - agent.renderer.green, - ) - ) - - if agent.ball.location[1] * sign(agent.team) > agent.me.location[1] * sign( - agent.team - ) or targetVec[1] * sign(agent.team) > agent.me.location[1] * sign(agent.team): - hurry = True - if waiting and distance2D(agent.me.location, myGoal) < distance2D(targetVec, myGoal): - hurry = False - - agent.update_action({"type": "BALL", "time": agent.currentHit.prediction_time}) - - return driveController( - agent, - targetLoc.flatten(), - agent.time + modifiedDelay, - expedite=hurry, - flips_enabled=flipping, - fudging=fudging, - offset_dist=0 if not fudging else findDistance(targetLoc, simple_pos) - ) - - -def SortHits(hit_list): - no_nones = list(filter(None, hit_list)) - return sorted(no_nones, key=lambda x: x.prediction_time) - - -def intercept_handler(agent): - if agent.goalPred is None and agent.me.location == agent.lastMan: - if agent.enemyBallInterceptDelay + 1 < agent.ballDelay: - # print(f"Falling back cause I scared {agent.time}") - return thirdManPositioning(agent) - - return None - - -def secondManPositioning(agent): - # print("in second man",agent.time) - playerGoal = Vector([0, 5200 * sign(agent.team), 0]) - enemyGoal = playerGoal.scale(-1) - stealing_range = 2000 - boostTarget, dist = boostSwipe(agent) - maintain_speed = True - if ( - boostTarget is not None - and dist < stealing_range - # and agent.me.boostLevel < 100 - and not agent.boostMonster - and ( - agent.me.location[1] * sign(agent.team) - < agent.ball.location[1] * sign(agent.team) - ) - ) or ( - boostTarget is not None and dist < 900 and not agent.boostMonster - ): # and agent.me.boostLevel < 100): - agent.update_action({"type": "BOOST", "target": boostTarget.index}) - controller = driveController( - agent, boostTarget.location.flatten(), agent.time, expedite=True - ) - if agent.me.boostLevel == 100: - controller.boost = True - return controller - - offensive = agent.offensive - cannister_info = None - - if agent.me.boostLevel < agent.boostThreshold and ( - agent.me.location != agent.lastMan or offensive - ): - cannister_info = find_closest_cannister(agent) - if cannister_info[1] <= agent.cannister_greed: - boost_suggestion = cannister_info[0] - target = boost_suggestion.location.scale(1) - target.data[2] = 0 - agent.update_action({"type": "BOOST", "target": boost_suggestion.index}) - return driveController(agent, target.flatten(), 0, flips_enabled=True) - - # agent.update_action({"type": "READY", "time": agent.currentHit.prediction_time}) - - # test demo code - if ( - agent.me.location != agent.lastMan - and agent.demo_rotations - and (agent.me.boostLevel > 0 or agent.currentSpd > 2200) - ): - # 0 = any, 1 = towards enemy goal, 2 = towards player goal - _dir = -1 - if agent.me.location[1] * sign(agent.team) < agent.ball.location[1] * sign( - agent.team - ): - if ( - agent.me.retreating - or agent.currentSpd < 500 - or agent.me.velocity[1] * sign(agent.team) > 500 * sign(agent.team) - ): - _dir = 2 - else: - if ( - False - and offensive - and agent.me.location[1] * sign(agent.team) - < agent.ball.location[1] * sign(agent.team) - and agent.me.location != agent.lastMan - and agent.lastMan[1] * sign(agent.team) - > agent.ball.location[1] * sign(agent.team) - and agent.me.velocity[1] * sign(agent.team) < -400 - and (agent.me.boostLevel >= 0 or agent.me.currentSpd >= 2200) - ): - _dir = 1 - - if _dir != -1: - demo_target = directional_demo_picker(agent, direction=_dir) - if demo_target is not None and demo_check(agent, demo_target): - difference = agent.me.location - demo_target.location - if abs(difference[0]) < abs(difference[1]) + 350: - if _dir != 2 or demo_target.location[1] * sign( - agent.team - ) < agent.ball.location[1] * sign(agent.team): - return demoTarget(agent, demo_target) - - if agent.me.location[1] * sign(agent.team) < agent.ball.location[1] * sign( - agent.team - ): - return smart_retreat(agent) - - scaler = 2500 - if not agent.offensive: - scaler = 1500 - _direction = (agent.ball.location.flatten() - enemyGoal).normalize() - destination = agent.ball.location.flatten() + _direction.scale(scaler) - x_target = clamp(3000, -3000, destination[0]) - destination.data[1] += abs(destination[0] - x_target) * sign(agent.team) - destination.data[0] = x_target - y_target = destination[1] - - - - # y_dist = 1500 - # - # if agent.ball.location[0] > 0: - # x_target = agent.ball.location[0]-1500 - # else: - # x_target = agent.ball.location[0]+1500 - # - # y_target = agent.ball.location[1] + (sign(agent.team) * y_dist) - - if not offensive: - #_direction = (playerGoal - agent.ball.location.flatten()).normalize() - #destination = agent.ball.location.flatten() + _direction.scale(1000) - # x_target = clamp(2000, -2000, destination[0]) - # y_target = destination[1] - maintain_speed = False - - if y_target * sign(agent.team) > 4700: - if agent.me.location[1] * sign(agent.team) < agent.ball.location[1] * sign( - agent.team - ): - return rotate_back(agent) - # mode 0: any side, mode:1 stay on side, mode:2 stay on opposite side - boost_suggestion = None - if agent.me.boostLevel < agent.boostThreshold: - if cannister_info is None: - cannister_info = find_closest_cannister(agent) - if cannister_info[1] <= 1000 and cannister_info[0].location[1] * sign( - agent.team - ) > agent.ball.location[1] * sign(agent.team): - boost_suggestion = cannister_info[0] - else: - mode = 2 - # if offensive: - # if agent.me.boostLevel >= 35: - # mode = 2 - # else: - # mode = 0 - - if boost_suggestion is None and agent.me.boostLevel <= 35: - boost_suggestion = boost_suggester(agent, buffer=1500, mode=mode) - if boost_suggestion is not None: - target = boost_suggestion.location.scale(1) - agent.update_action({"type": "BOOST", "target": boost_suggestion.index}) - return driveController(agent, target.flatten(), 0, flips_enabled=True) - - if y_target * sign(agent.team) < 4700: - timer = agent.currentHit.prediction_time - # if ( - # agent.me.location[1] * sign(agent.team) - # < agent.currentHit.pred_vector[1] * sign(agent.team) - # and agent.me.location != agent.lastMan - # ): - # timer = float(-1) - # - # elif agent.me.retreating and agent.me.location != agent.lastMan: - # timer = float(-1) - agent.update_action({"type": "READY", "time": timer}) - - return driveController( - agent, - Vector([x_target, y_target, 0]), - 0, - expedite=False, - maintainSpeed=maintain_speed, - flips_enabled=False, - ) - - return smart_retreat(agent) - - -def linger(agent): - stealing_range = 2000 - boostTarget, dist = boostSwipe(agent) - if ( - boostTarget is not None - and dist < stealing_range - # and agent.me.boostLevel < 100 - and not agent.boostMonster - and ( - agent.me.location[1] * sign(agent.team) - < agent.ball.location[1] * sign(agent.team) - ) - ) or ( - boostTarget is not None and dist < 900 and not agent.boostMonster - ): # and agent.me.boostLevel < 100): - agent.update_action({"type": "BOOST", "target": boostTarget.index}) - controller = driveController( - agent, boostTarget.location.flatten(), agent.time, expedite=True - ) - if agent.me.boostLevel == 100: - controller.boost = True - return controller - - cannister_info = None - - if agent.me.boostLevel < agent.boostThreshold: - cannister_info = find_closest_cannister(agent) - if cannister_info[1] <= agent.cannister_greed: - boost_suggestion = cannister_info[0] - target = boost_suggestion.location.scale(1) - target.data[2] = 0 - agent.update_action({"type": "BOOST", "target": boost_suggestion.index}) - return driveController( - agent, target.flatten(), agent.time, flips_enabled=True - ) - - if cannister_info is None: - cannister_info = find_closest_cannister(agent) - if cannister_info[1] <= 1000 and cannister_info[0].location[1] * sign( - agent.team - ) > agent.ball.location[1] * sign(agent.team): - boost_suggestion = cannister_info[0] - else: - mode = 0 - boost_suggestion = boost_suggester(agent, mode=mode, buffer=500) - if boost_suggestion is not None: - target = boost_suggestion.location.scale(1) - target.data[2] = 0 - agent.update_action({"type": "BOOST", "target": boost_suggestion.index}) - return driveController(agent, target.flatten(), agent.time, flips_enabled=True) - - offset_amount = 500 - y_target = agent.ball.location[1] # + (sign(agent.team) * offset_amount) - x_target = clamp(3500, -3500, agent.ball.location[0]) - - if y_target * sign(agent.team) > 4800: - if agent.me.location[1] * sign(agent.team) < agent.ball.location[1] * sign( - agent.team - ): - return smart_retreat(agent) - - return driveController( - agent, - Vector([x_target, y_target, 9]), - agent.time, - expedite=False, - maintainSpeed=True, - ) - - -def thirdManPositioning(agent, buffer=None): - # print("in third man", agent.time) - playerGoal = Vector([0, 5200 * sign(agent.team), 0]) - stealing_range = 2000 - boostTarget, dist = boostSwipe(agent) - if ( - boostTarget is not None - and dist < stealing_range - # and agent.me.boostLevel < 100 - and not agent.boostMonster - and ( - agent.me.location[1] * sign(agent.team) - < agent.ball.location[1] * sign(agent.team) - ) - ) or ( - boostTarget is not None and dist < 900 and not agent.boostMonster - ): # and agent.me.boostLevel < 100): - agent.update_action({"type": "BOOST", "target": boostTarget.index}) - controller = driveController( - agent, boostTarget.location.flatten(), agent.time, expedite=True - ) - if agent.me.boostLevel == 100: - controller.boost = True - return controller - - offensive = agent.offensive - - cannister_info = None - - if agent.me.boostLevel < agent.boostThreshold and ( - agent.me.location != agent.lastMan or offensive - ): - cannister_info = find_closest_cannister(agent) - if cannister_info[1] <= agent.cannister_greed: - boost_suggestion = cannister_info[0] - target = boost_suggestion.location.scale(1) - target.data[2] = 0 - agent.update_action({"type": "BOOST", "target": boost_suggestion.index}) - return driveController(agent, target.flatten(), 0, flips_enabled=True) - - # test demo code - if ( - agent.me.location != agent.lastMan - and agent.demo_rotations - and (agent.me.boostLevel > 0 or agent.currentSpd > 2200) - ): - # 0 = any, 1 = towards enemy goal, 2 = towards player goal - _dir = -1 - if agent.me.location[1] * sign(agent.team) < agent.ball.location[1] * sign( - agent.team - ): - if ( - agent.me.retreating - or agent.currentSpd < 500 - or agent.me.velocity[1] * sign(agent.team) > 500 * sign(agent.team) - ): - _dir = 2 - else: - if ( - False - and offensive - and agent.me.location[1] * sign(agent.team) - < agent.ball.location[1] * sign(agent.team) - and agent.me.location != agent.lastMan - and agent.lastMan[1] * sign(agent.team) - > agent.ball.location[1] * sign(agent.team) - and agent.me.velocity[1] * sign(agent.team) < -400 - and (agent.me.boostLevel >= 0 or agent.me.currentSpd >= 2200) - ): - _dir = 1 - - if _dir != -1: - demo_target = directional_demo_picker(agent, direction=_dir) - if demo_target is not None and demo_check(agent, demo_target): - difference = agent.me.location - demo_target.location - if abs(difference[0]) < abs(difference[1]) + 350: - if _dir != 2 or demo_target.location[1] * sign( - agent.team - ) < agent.ball.location[1] * sign(agent.team): - return demoTarget(agent, demo_target) - - if agent.me.location[1] * sign(agent.team) < agent.ball.location[1] * sign( - agent.team - ): - return smart_retreat(agent) - - - - _direction = ( - agent.ball.location.flatten() - Vector([0, 5200 * -sign(agent.team), 0]) - ).normalize() - target_loc = agent.ball.location.flatten() + _direction.scale(5000) - x_target = clamp(1500, -1500, target_loc[0]) - y_target = target_loc[1] - if abs(agent.ball.location[1] - target_loc[1]) < 5500: - y_target = agent.ball.location[1] + 5500 * sign(agent.team) - - if abs(y_target) * sign(agent.team) - agent.me.location[1] * sign(agent.team) > 1000: - return smart_retreat(agent) - - boost_suggestion = None - if abs(y_target) < 4500: - if agent.me.location[1] * sign(agent.team) < agent.ball.location[1] * sign( - agent.team - ): - return smart_retreat(agent) - - if ( - agent.me.boostLevel < agent.boostThreshold - and agent.ball.location[1] * -sign(agent.team) > 0 - ): - if cannister_info is None: - cannister_info = find_closest_cannister(agent) - if cannister_info[1] <= 1000 and cannister_info[0].location[1] * sign( - agent.team - ) > agent.ball.location[1] * sign(agent.team): - boost_suggestion = cannister_info[0] - else: - if agent.me.boostLevel >= 35: - mode = 1 - else: - mode = 0 - - if boost_suggestion is None and agent.me.boostLevel <= 35: - boost_suggestion = boost_suggester(agent, mode=mode, buffer=4500) - if boost_suggestion is not None: - target = boost_suggestion.location.scale(1) - target.data[2] = 0 - # agent.update_action({"type": "BOOST", "target": boost_suggestion.index}) - return driveController(agent, target.flatten(), 0, flips_enabled=True) - - # if abs(y_target) < 4500: - agent.update_action({"type": "READY", "time": agent.currentHit.prediction_time}) - # agent.forward = True - return driveController( - agent, - Vector([x_target, y_target, 0]), - 0, - expedite=False, - maintainSpeed=False, - flips_enabled=False, - ) - - return smart_retreat(agent) - - -def goalie_shot(agent, goal_violator: hit): - vec = goal_violator.pred_vector - if abs(vec[0]) < 1000: - if abs(vec[1]) * sign(agent.team) > 4300: - if abs(vec[2]) < 1000: - return True - - if agent.goalPred is not None: - if agent.goalPred.time - agent.time < 2.5: - return True - - return False - - -def smart_retreat(agent): - timer = float(agent.currentHit.prediction_time) - if ( - agent.me.location[1] * sign(agent.team) - < agent.currentHit.pred_vector[1] * sign(agent.team) - and abs(agent.me.location[1]) < 4000 - ) and agent.me.location != agent.lastMan: - timer = float(-1) - - elif ( - agent.me.retreating - and agent.me.location != agent.lastMan - and abs(agent.me.location[1]) < 4000 - ): - timer = float(-1) - - agent.update_action({"type": "READY", "time": timer}) - #playerGoal = Vector([0, sign(agent.team) * 5200, 0]) - hurry = agent.me.location[1] * sign(agent.team) < agent.ball.location[1] * sign(agent.team) - if agent.lastMan == agent.me.location: # and len(agent.allies) < 1: - return gate(agent, hurry=hurry) - else: - return goFarPost(agent, hurry=hurry) - - -def rotate_back(agent, onside=False): - rightBoost = Vector([-3584.0, sign(agent.team) * 10, 73.0]) - leftBoost = Vector([3584.0, sign(agent.team) * 10, 73.0]) - - backRightBoost = Vector([-3072, 4096 * sign(agent.team), 73.0]) - backLeftBoost = Vector([3072, 4096 * sign(agent.team), 73.0]) - - if agent.ball.location[0] > 0 and not onside: - difference = agent.me.location - rightBoost - else: - difference = agent.me.location - leftBoost - - timer = agent.currentHit.prediction_time - if ( - agent.me.location[1] * sign(agent.team) - < agent.currentHit.pred_vector[1] * sign(agent.team) - and agent.me.location != agent.lastMan - ): - timer = float(-1) - - elif agent.me.retreating and agent.me.location != agent.lastMan: - timer = float(-1) - agent.update_action({"type": "READY", "time": timer}) - - if ( - agent.me.location[1] * sign(agent.team) < 0 - and agent.me.location != agent.lastMan - and agent.ball.location[1] * sign(agent.team) < 0 < len(agent.allies) - and abs(difference[0]) < abs(difference[1]) - ): - if agent.ball.location[0] > 0 and not onside: - return driveController( - agent, rightBoost, agent.time, expedite=False, maintainSpeed=True - ) - else: - return driveController( - agent, leftBoost, agent.time, expedite=False, maintainSpeed=True - ) - else: - if agent.ball.location[0] > 0 and not onside: - return driveController( - agent, backRightBoost, agent.time, expedite=False, maintainSpeed=True - ) - else: - return driveController( - agent, backLeftBoost, agent.time, expedite=False, maintainSpeed=True - ) - - -def boost_steal(agent): - boostTarget, dist = boostSwipe(agent) - if boostTarget is not None and dist < 2000 and agent.me.boostLevel < 100: - agent.update_action({"type": "BOOST", "target": boostTarget.index}) - return driveController(agent, boostTarget.location, agent.time, expedite=True) - return None - - -def corner_retreat(agent): - # print(f"corner retreating! {agent.time}") - threatening_shot = is_shot_scorable(1 if agent.team == 0 else 0, agent.enemyTargetVec) - if (not threatening_shot or (agent.enemyBallInterceptDelay > 2 and not agent.enemyAttacking) and agent.goalPred is None): - if agent.me.boostLevel < 50: - boost_target = boost_suggester(agent, buffer=0, mode=1) - if boost_target is not None: - return driveController(agent, boost_target.location, agent.time, expedite=boost_target.bigBoost) - else: - return smart_retreat(agent) - - if not agent.enemyAttacking: - return smart_retreat(agent) - - corner_1 = Vector([4096, 5120 * sign(agent.team), 0]) - corner_2 = Vector([-4096, 5120 * sign(agent.team), 0]) - - target_vec = agent.currentHit.pred_vector - target = corner_1 if distance2D(corner_1, target_vec) < distance2D(corner_2, target_vec) else corner_2 - return ShellTime(agent, retreat_enabled=False, aim_target=target) - - -def playBack(agent, buffer=4000, get_boost=True): - playerGoal = Vector([0, sign(agent.team) * 5200, 0]) - enemyGoal = Vector([0, 5500 * -sign(agent.team), 200]) - - # _direction = direction(playerGoal.flatten(), agent.ball.location.flatten()) - # fo_target = agent.ball.location + _direction.normalize().scale(buffer) - # if agent.team == 0: - #_direction = (agent.ball.location.flatten() - enemyGoal.flatten()).normalize() - _direction = (agent.currentHit.pred_vector.flatten()- enemyGoal.flatten()).normalize() - fo_target = agent.ball.location.flatten() + _direction.normalize().scale(buffer) - - centerField = Vector( - [ - clamp(3500, -3500, fo_target[0]), - agent.ball.location[1] + sign(agent.team) * buffer, - agent.defaultElevation, - ] - ) - boostTarget, dist = boostSwipe(agent) - if ( - boostTarget is not None - and dist < 2000 - # and agent.me.boostLevel < 100 - and not agent.boostMonster - and agent.me.boostLevel < 100 - ) or ( - boostTarget is not None and dist < 900 and not agent.boostMonster - ): # and agent.me.boostLevel < 100): - agent.update_action({"type": "BOOST", "target": boostTarget.index}) - controller = driveController( - agent, boostTarget.location.flatten(), agent.time, expedite=True - ) - if agent.me.boostLevel == 100: - controller.boost = True - - agent.set_boost_grabbing(boostTarget.index) - return controller - - offensive = agent.offensive - - if agent.team == 0: - if centerField[1] < -4500: - return smart_retreat(agent) - else: - if centerField[1] > 4500: - return smart_retreat(agent) - - if agent.ball.location[1] * sign(agent.team) > 0: - if agent.ball.velocity[1] * sign(agent.team) > 5: - if not teammate_nearby(agent, playerGoal, 700)[0]: - return smart_retreat(agent) - - if len(agent.allies) > 1: - if agent.me.location[1] * sign(agent.team) < agent.ball.location[1] * sign( - agent.team - ): - rightBoost = Vector([-3584.0, sign(agent.team) * 10, 73.0]) - leftBoost = Vector([3584.0, sign(agent.team) * 10, 73.0]) - - backRightBoost = Vector([-3072, 4096 * sign(agent.team), 73.0]) - backLeftBoost = Vector([3072, 4096 * sign(agent.team), 73.0]) - - right_index, left_index = 15, 18 - bri, bli = 3, 4 - if agent.team != 0: - bri, bli = 29, 30 - - if agent.me.location[1] * sign(agent.team) < 0: - if agent.ball.location[0] > 0: - agent.update_action({"type": "BOOST", "target": right_index}) - return driveController( - agent, rightBoost, agent.time, expedite=False - ) - else: - agent.update_action({"type": "BOOST", "target": left_index}) - return driveController(agent, leftBoost, agent.time, expedite=False) - else: - if agent.ball.location[0] > 0: - agent.update_action({"type": "BOOST", "target": bri}) - return driveController( - agent, backRightBoost, agent.time, expedite=False - ) - else: - agent.update_action({"type": "BOOST", "target": bli}) - return driveController( - agent, backLeftBoost, agent.time, expedite=False - ) - - # mode 0: any side, mode:1 stay on side, mode:2 stay on opposite side - if agent.me.boostLevel < agent.boostThreshold: - cannister_info = find_closest_cannister(agent) - if cannister_info[1] <= 1000 and cannister_info[0].location[1] * sign( - agent.team - ) > agent.ball.location[1] * sign(agent.team): - boost_suggestion = cannister_info[0] - else: - mode = 1 - boost_suggestion = boost_suggester(agent, buffer=3000, mode=mode) - if boost_suggestion is not None: - target = boost_suggestion.location.scale(1) - agent.update_action({"type": "BOOST", "target": boost_suggestion.index}) - if boost_suggestion.bigBoost: - agent.set_boost_grabbing(boost_suggestion.index) - return driveController(agent, target.flatten(), 0, flips_enabled=True) - - # maintainspeed = False - # if agent.team == 0: - agent.forward = True - maintainspeed = True - # testing maintainspeed - return driveController( - agent, centerField, agent.time, expedite=False, floppies=False, maintainSpeed=maintainspeed - ) - # return turtle_mode(agent) - - -def boostSwipe(agent): - backBoosts = [] - minDist = math.inf - bestBoost = None - for b in agent.boosts: - if b.bigBoost and b.spawned and b.index not in agent.ignored_boosts: - if b.location[1] * -sign(agent.team) > 4000: - dist = distance2D(b, agent.me.location) - if dist < minDist: - bestBoost = b - minDist = dist - - if bestBoost is not None and minDist < 2000: - agent.boost_gobbling = True - - return bestBoost, minDist - - -def naive_boostless_push(agent): - return None - # targetVec = agent.ball.location - dist_2d = distance2D(agent.me.location, agent.ball.location) - if ( - dist_2d < (agent.reachLength + agent.ball_size) * 1.2 - and agent.onSurface - and not agent.onWall - and agent.ball.location[2] <= 120 - ): - targetLocal = toLocal(agent.ball.location, agent.me) - carToBallAngle = math.degrees(math.atan2(targetLocal[1], targetLocal[0])) - carToBallAngle = correctAngle(carToBallAngle) - if abs(carToBallAngle) <= 35 or abs(carToBallAngle) >= 135: - carOffset = agent.carLength * 0.5 - else: - carOffset = agent.carWidth * 0.5 - - ballOffset = get_ball_offset_simple(agent, agent.ball.location) - totalOffset = carOffset + ballOffset - - lined_up = extendToGoal( - agent, agent.ball.location, agent.me.location, buffer=agent.ball_size * 3 - ) - - if lined_up or agent.contested: #and relativeSpeed(agent.me.velocity.flatten(), agent.ball.velocity.flatten()) < 400: - if not agent.forward and abs(carToBallAngle) >= 145: - agent.setHalfFlip() - print(f"Naively pushing! {agent.time}") - else: - if abs(carToBallAngle) < 35: - agent.setJumping(0) - print(f"Naively pushing! {agent.time}") - # print(f"Naively pushing! {agent.time}") - - -def turtle_mode(agent): - myGoal = Vector([0, 5120 * sign(agent.team), 0]) - targetVec = agent.enemyTargetVec - ball_delay = agent.enemyBallInterceptDelay - if distance2D(agent.closestEnemyToBall.location, targetVec) > 2500: - targetVec = agent.ball.location - ball_delay = 0 - # expedite = False - - target_dist = distance2D(targetVec, myGoal) - agent_dist = distance2D(agent.me.location, myGoal) - - expedite = target_dist < agent_dist - if agent.me.boostLevel <= 0 and expedite: - return smart_retreat(agent) - - multi = 1 - min_offset = clamp(3000, 250, (targetVec[2]) + agent.ball_size) - # dist_diff = distance2D(agent.me.location, targetVec) - # speed_offset = agent.closestEnemyToBall.velocity.magnitude() - speed_offset = max( - [ - relativeSpeed( - agent.closestEnemyToBall.velocity.flatten(), - agent.enemyTargetVel.flatten(), - ), - agent.closestEnemyToBall.velocity.magnitude(), - ] - ) - # dist_offset = distance2D(agent.me.location, targetVec) * 0.5 - # offset = clamp(4000, min_offset, min_offset + dist_offset) - offset = clamp(5000, min_offset, (min_offset + speed_offset) * multi) - _direction = (myGoal - targetVec.flatten()).normalize() - destination = targetVec + _direction.scale(offset) - - pre_clamp = destination.data[0] - destination.data[0] = clamp(3500, -3500, destination[0]) - clamp_diff = abs(pre_clamp - destination.data[0]) - destination.data[1] += clamp_diff * sign(agent.team) - destination.data[2] = 0 - - if distance2D(destination, myGoal) < agent_dist - 100: - # print(f"Retreating where we weren't before {agent.time}") - return smart_retreat(agent) - - if (agent.team == 0 and destination.data[1] * sign(agent.team) < -4900) or ( - agent.team == 1 and destination.data[1] * sign(agent.team) > 4900 - ): - # print(f"target location: {targetVec.data} destination: {destination} calculated offset: {offset}") - return smart_retreat(agent) - - return driveController( - agent, destination, agent.time + ball_delay, expedite=expedite, floppies=False - ) - - -def verify_alignment(agent, target_vector, car_offset): - if ( - distance2D(agent.me.location.flatten(), target_vector.flatten()) - <= car_offset + agent.ball_size - ): - return extendToGoal( - agent, target_vector, agent.me.location, buffer=agent.ball_size * 3 - ) - - car_to_ball_dir = (agent.me.location - target_vector).flatten().normalize() - ball_to_car_dir = car_to_ball_dir.scale(-1) - - car_contact_point = agent.me.location + (car_to_ball_dir.scale(car_offset)) - ball_contact_point = target_vector + (ball_to_car_dir.scale(agent.ball_size)) - - return extendToGoal( - agent, ball_contact_point, car_contact_point, buffer=agent.ball_size * 3 - ) - - -def defensive_check(agent): - return False - if len(agent.allies) > 0: - return False - if agent.lastMan == agent.me.location and agent.me.location[1] * sign(agent.team) < 4000 and agent.enemyTargetVec[1] * sign(agent.team) < 4000: - myGoal = Vector([0, 5300 * sign(agent.team), 100]) - - if not agent.goalPred and not(agent.offensive and butterZone(agent.currentHit.pred_vector)) and agent.enemyBallInterceptDelay - agent.time < 3 and agent.contested and \ - agent.currentHit.time_difference() > 0.5 and agent.enemyBallInterceptDelay < agent.currentHit.time_difference() \ - and distance2D(myGoal, agent.enemyTargetVec) < distance2D(myGoal, agent.closestEnemyToBall.location) and \ - agent.me.location[1] * sign(agent.team) > agent.ball.location[1] * sign(agent.team) and not butterZone( - agent.enemyTargetVec): - return True - - if (agent.offensive and butterZone(agent.currentHit.pred_vector) and agent.currentHit.time_difference() < 1) or agent.closestEnemyToBall.velocity[1] * -(sign(agent.team)) > 0: - return False - - - - return False - - -def defensive_positioning(agent): - # myGoal = Vector([0, 5300 * sign(agent.team), 100]) - myGoal = find_defensive_target(agent) - defensive_target = agent.enemyTargetVec - if defensive_target[1] * sign(agent.team) > agent.me.location[1] * sign(agent.team): - return smart_retreat(agent) - protect_direction = (myGoal.flatten() - defensive_target.flatten()).normalize() - hit_direction = (defensive_target.flatten() - agent.closestEnemyToBall.location.flatten()).normalize() - # if agent.contested: - # blended_direction = (hit_direction+protect_direction).normalize() - # else: - blended_direction = protect_direction - - - - min_distance = 100 - max_distance = clamp(3500, min_distance + 1, distance2D(agent.me.location, defensive_target)) - defensive_offset = max(agent.closestEnemyToBall.velocity.magnitude(), - relativeSpeed(agent.closestEnemyToBall.velocity, agent.enemyTargetVel)) - defensive_offset = clamp(max_distance, min_distance, defensive_offset) - - protect_projection = defensive_target + blended_direction.scale(defensive_offset) - - # simple_slope - find target within 90 degrees of agent velocity if target would cause reversal - - protect_projection.data[0] += -agent.me.velocity[0] * 0.1 - protect_projection.data[1] += -agent.me.velocity[1] * 0.1 - - - - if protect_projection[0] > 4040: - protect_projection.data[0] -= abs(protect_projection[0] - 4040) - - elif protect_projection[0] < -4040: - protect_projection.data[0] += abs(protect_projection[0] + 4040) - - if abs(protect_projection[1]) > 5000: - protect_projection.data[1] = 5000 * sign(protect_projection[1]) - - # angle = angleBetweenVectors(agent.me.velocity.flatten().normalize(), protect_projection.flatten().normalize()) - # if abs(angle) > 90: - # print(angle) - - discrepancy = distance2D(protect_projection, myGoal) - distance2D(agent.me.location, myGoal) - if discrepancy < -500: - return smart_retreat(agent) - - expedite = discrepancy < -100 - - result = driveController( - agent, - protect_projection, - # agent.enemyPredTime + 0.1, - agent.time, - expedite=expedite, - floppies=False - ) - - protect_projection.data[2] = 20 - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - agent.me.location.toList(), - protect_projection.toList(), - agent.renderer.purple, - ) - ) - agent.update_action({"type": "BALL", "time": agent.currentHit.prediction_time}) - return result - -def reposition_handler(agent, target): - return None - if len(agent.allies) > 0: - return None - - elif agent.contested: - return None - - elif not agent.offensive: - return None - - if wrong_side_check(agent, target): - return go_wide(agent,target) - - return None - - -def wrong_side_check(agent, target): - return None - if abs(target[0]) < 650: #just shove in balls down the middle - return False - - if target[0] > agent.me.location[0] and target[0] > 0: - return True - elif target[0] < agent.me.location[0] and target[0] < 0: - return True - - return False - -def go_wide(agent, target): - dir = (target - agent.me.location).normalize() - x_dist = abs((target-agent.me.location)[0]) - y_dist = clamp(2000, 500, x_dist) - y_off = y_dist*sign(agent.team) - x_off = x_dist * sign(dir[0]) - offset = Vector([x_off, y_off, 0]) - return driveController(agent, target+offset, agent.time, expedite=True) - - - - -def lineupShot(agent, multi, aim_target=None): - variance = 5 - leftPost = Vector([-500, 5500 * -sign(agent.team), 200]) - rightPost = Vector([500, 5500 * -sign(agent.team), 200]) - center = Vector([0, 5500 * -sign(agent.team), 200]) - - myGoal = Vector([0, 5300 * sign(agent.team), 200]) - - targetVec = agent.currentHit.pred_vector - if agent.me.location[1] * sign(agent.team) < targetVec[1] * sign(agent.team): - return ShellTime(agent, aim_target) - - if len(agent.allies) < 1 and agent.offensive and agent.contested and agent.me.boostLevel < 50: - return playBack(agent) - - hurry = True - distance = distance2D(agent.me.location, targetVec) - targToGoalDistance = distance2D(targetVec, center) - targetLocal = toLocal(targetVec, agent.me) - carToBallAngle = math.degrees(math.atan2(targetLocal[1], targetLocal[0])) - offensive = agent.offensive - require_lineup = False - flipping = True - - carToBallAngle = correctAngle(carToBallAngle) - - mode = 0 - if targToGoalDistance < agent.aim_range: - mode = 1 - goalSpot = aim_target - correctedAngle = 0 - - if not goalSpot: - goalSpot, correctedAngle = goal_selector_revised(agent, mode=mode) - - shot_scorable = agent.currentHit.scorable() - - # if agent.scorePred is not None and agent.closestEnemyToBall.onSurface and demo_check(agent, agent.closestEnemyToBall) and agent.me.location != agent.lastMan: - # return demoTarget(agent, agent.closestEnemyToBall) - - if not shot_scorable and len(agent.allies) < 2: - hurry = False - # flipping = False - # goalSpot.data[2] = 5000 * (-sign(agent.team)) - if ( - agent.enemyBallInterceptDelay < agent.currentHit.time_difference() - and agent.enemyBallInterceptDelay < 2.5 - and agent.enemyAttacking - # and agent.team == 0 - ) or agent.me.boostLevel < agent.boostThreshold: - # return secondManPositioning(agent) - return playBack(agent) - - # if ( - # agent.goalPred is None - # and len(agent.allies) < 1 - # and agent.currentHit.time_difference() - agent.enemyBallInterceptDelay >= 1 - # and agent.on_correct_side - # ): - # hurry = False - - if len(agent.allies) < 2: - if abs(correctedAngle) >= agent.angleLimit and abs(targetVec[0]) > 800: - hurry = False - # flipping = False - if ( - agent.enemyBallInterceptDelay < agent.currentHit.time_difference() - and agent.enemyBallInterceptDelay < 2.5 - and agent.enemyAttacking - # and agent.team == 0 - ) or agent.me.boostLevel < agent.boostThreshold: - # return secondManPositioning(agent) - return playBack(agent) - - # if not agent.openGoal and agent.me.boostLevel < agent.boostThreshold and offensive and agent.me.location[1] * sign(agent.team) > 0: - # return playBack(agent) - - if agent.scared: - return turtle_mode(agent) - - if defensive_check(agent): - return defensive_positioning(agent) - - corner = cornerDetection(targetVec) - - mirror_info = mirrorshot_qualifier(agent) - - # testing - fudging = False - - is_mirror_shot = ( - mirror_info[0] - and len(mirror_info[1]) < 1 - and distance < 3500 - #and not offensive - #and (agent.lastMan == agent.me.location) - #and agent.contested - ) - maxRange = 1800 if not agent.contested else 900 - - if len(agent.allies) < 2: - if not shot_scorable: # and len(agent.allies) < 1: - # return playBack(agent) - # hurry = False - require_lineup = True - # testing - goalSpot.data[1] = 5000 * -sign(agent.team) - maxRange = 900 - - targetLoc = None - - if abs(carToBallAngle) <= 40 or abs(carToBallAngle) >= 140: - carOffset = agent.carLength * 0.5 - else: - carOffset = agent.carWidth * 0.5 - - ballOffset = get_ball_offset(agent, agent.currentHit) - - totalOffset = (carOffset + ballOffset) * 0.9 - offset_min = totalOffset * 0.75 - - positioningOffset = totalOffset - - - - _direction = direction(targetVec.flatten(), goalSpot.flatten()) - lined_up = agent.lineup_check() - - scooching = False - max_dist_multi = 0.5 - if not agent.offensive: - max_dist_multi = 0.4 - if agent.scorePred is None and ( - # (not is_mirror_shot and distance < offset_min * 0.85) - not is_mirror_shot - and targetVec[2] >= agent.ball_size + 20 - and not butterZone(targetVec) - and distance2D(agent.closestEnemyToBall.location, center) < distance2D(targetVec, center) - and not agent.contested - and (agent.currentHit.pred_vel.flatten().magnitude() < 1500) - ): - offset_min = totalOffset * 0.5 - positioningOffset = offset_min - max_dist_multi = 0.2 - scooching = True - - if agent.currentHit.time_difference() < 0.5 and hurry and not scooching: - if agent.me.location[1] * sign(agent.team) > targetVec[1] * sign(agent.team): - if ((not agent.forward or agent.me.boostLevel < 1) or lined_up) and agent.contested: - return handleBounceShot(agent, waitForShot=False) - - repos_action = reposition_handler(agent, targetVec) - if repos_action is not None: - return repos_action - - # testing - if is_mirror_shot and offensive: - is_mirror_shot = False - - if ( - targetVec[1] * sign(agent.team) < -3500 - # and not lined_up - and abs(targetVec[0]) < 3000 - # and len(agent.allies) < 2 - and not is_mirror_shot - ): - require_lineup = True - # maxRange = 1800 if not lined_up else maxRange - - # if agent.team == 0 and not is_mirror_shot and offensive and not agent.contested: - # require_lineup = True - - flipHappy = False - # challenge_flip(agent, targetVec) - - # if agent.contested and agent.me.boostLevel < 1: - # if not is_mirror_shot: - # targetLoc = get_aim_vector( - # agent, - # goalSpot.flatten(), - # targetVec.flatten(), - # agent.currentHit.pred_vel, - # positioningOffset, - # )[0] - # - # else: - # targetLoc = aim_wallshot_naive(agent, agent.currentHit, positioningOffset) - # modifiedDelay = agent.ballDelay - - #_direction = direction(targetVec.flatten(), goalSpot.flatten()) - simple_pos = targetVec.flatten() + _direction.scale(positioningOffset) - simple_pos.data[2] = agent.defaultElevation - - if not targetLoc and agent.scared: - # if agent.scorePred == None and agent.team != 0: - # positioningOffset = clamp( - # maxRange, offset_min, distance * 0.1 - # ) - # targetLoc = get_aim_vector( - # agent, - # goalSpot.flatten(), - # targetVec.flatten(), - # agent.currentHit.pred_vel, - # positioningOffset, - # )[0] - # else: - targetLoc = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - #vel_adjust=False, - )[0] - - modifiedDelay = agent.ballDelay - - if ( - not targetLoc - and agent.contested - and not agent.openGoal - #and (not require_lineup or lined_up or agent.me.boostLevel < 1) - and (not require_lineup or agent.me.boostLevel < 1) - and ( - distance2D(agent.closestEnemyToBall.location, center) - < distance2D(agent.me.location, center) - or agent.me.boostLevel < 1 - ) - ): - if not is_mirror_shot: - targetLoc = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - #vel_adjust=False, - )[0] - - else: - targetLoc = aim_wallshot_naive(agent, agent.currentHit, positioningOffset) - modifiedDelay = agent.ballDelay - - if not targetLoc: - if not agent.contested or require_lineup: - # if ballToGoalDist < 5000: - if abs(targetVec[0]) < 3000: - if agent.forward: - # if offensive: - positioningOffset = clamp( - maxRange, offset_min, distance * max_dist_multi - ) - if not is_mirror_shot: - targetLoc = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - #vel_adjust=False, - )[0] - - else: - targetLoc = aim_wallshot_naive( - agent, agent.currentHit, positioningOffset - ) - - modifiedDelay = agent.currentHit.time_difference() - if positioningOffset > offset_min: - modifiedDelay = clamp( - 6, - 0.0001, - agent.ballDelay - - ( - # (positioningOffset - offset_min) - positioningOffset - / clamp(maxPossibleSpeed, 0.001, agent.currentSpd) - ), - ) - fudging = True - - if not targetLoc: - if agent.forward and not agent.contested and agent.me.boostLevel > 0: - if sign(agent.team) * targetVec[1] <= 0: - # multiCap = clamp(max_dist_multi, 0.3, distance / 10000) - # testing - multiCap = max_dist_multi - # print("in second shot") - multi = clamp( - multiCap, 0.25, (5000 - abs(agent.me.location[0])) / 10000 - ) - positioningOffset = clamp(maxRange, offset_min, (distance * multi)) - # if agent.contested: - # positioningOffset = clamp(800,totalOffset*.5,positioningOffset) - - targetLoc = targetVec + _direction.scale(positioningOffset) - - if not is_mirror_shot: - targetLoc = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - #vel_adjust=False, - )[0] - - else: - targetLoc = aim_wallshot_naive( - agent, agent.currentHit, positioningOffset - ) - - modifiedDelay = agent.currentHit.time_difference() - if positioningOffset > offset_min: - modifiedDelay = clamp( - 6, - 0.0001, - agent.ballDelay - - ( - # (positioningOffset - offset_min) - positioningOffset - / clamp(maxPossibleSpeed, 0.001, agent.currentSpd) - ), - ) - fudging = True - - if ( - targetLoc - and len(agent.allies) > 0 - and targetLoc[1] * sign(agent.team) > agent.me.location[1] * sign(agent.team) - ): - targetLoc = None - - if not targetLoc: - positioningOffset = clamp(maxRange, offset_min, (distance * 0.2)) - if not is_mirror_shot: - targetLoc = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - #vel_adjust=False, - )[0] - - else: - targetLoc = aim_wallshot_naive(agent, agent.currentHit, positioningOffset) - - modifiedDelay = agent.currentHit.time_difference() - if positioningOffset > offset_min: - modifiedDelay = clamp( - 6, - 0.0001, - agent.ballDelay - - ( - # (positioningOffset - offset_min) - positioningOffset - / clamp(maxPossibleSpeed, 0.001, agent.currentSpd) - ), - ) - fudging = True - - if not targetLoc: - if not is_mirror_shot: - targetLoc = get_aim_vector( - agent, - goalSpot.flatten(), - targetVec.flatten(), - agent.currentHit.pred_vel, - positioningOffset, - #vel_adjust=False, - )[0] - - else: - targetLoc = aim_wallshot_naive(agent, agent.currentHit, positioningOffset) - modifiedDelay = agent.currentHit.time_difference() - - if ( - not agent.forward - #or butterZone(targetVec) - or (agent.me.boostLevel < 12 and distance2D(agent.me.location, agent.enemyGoalLocations[1]) < distance2D(agent.closestEnemyToBall.location, agent.enemyGoalLocations[1])) - ): - naive_boostless_push(agent) - - targetLoc.data[2] = agent.defaultElevation - - result = driveController( - agent, - targetLoc, - agent.time + modifiedDelay, - expedite=hurry, - flippant=flipHappy, - flips_enabled=flipping, - fudging=fudging, - offset_dist=0 if not fudging else findDistance(targetLoc, simple_pos) - ) - - # targetLoc.data[2] = 95 - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - agent.me.location.toList(), - targetLoc.toList(), - agent.renderer.purple, - ) - ) - agent.update_action({"type": "BALL", "time": agent.currentHit.prediction_time}) - return result - - -def turn_radius(v: float) -> float: - if v == 0: - return 0 - return 1.0 / curvature(v) - - -def curvature(v: float) -> float: - # v is the magnitude of the velocity in the car's forward direction - if 0.0 <= v < 500.0: - return 0.006900 - 5.84e-6 * v - if 500.0 <= v < 1000.0: - return 0.005610 - 3.26e-6 * v - if 1000.0 <= v < 1500.0: - return 0.004300 - 1.95e-6 * v - if 1500.0 <= v < 1750.0: - return 0.003025 - 1.1e-6 * v - if 1750.0 <= v < 2500.0: - return 0.001800 - 4e-7 * v - - return 0.0 - - -def max_speed_of_curvature(c: float) -> float: - if c >= 0.0069: - return 0 - if c > 0.00398: - return (0.0069 - c) / 0.00000584 - if c > 0.00235: - return 500 + (0.00398 - c) / 0.00000584 - if c > 0.001375: - return 1000 + (0.00235 - c) / 0.00000584 - if c > 0.0011: - return 1500 + (0.001375 - c) / 0.0000011 - if c > 0.00088: - return 1750 + (0.0011 - c) / 0.0000004 - - return 2400 - - -# def find_arc_length(local_target:Vector,radius:float,curve:float): -# circumference = math.pi * 2 * radius -# _dir = local_target.flatten().normalize() -# #dist = local_target.flatten().magnitude() -# midpoint = local_target.scale(0.5) -# x2 = (math.cos(90)*_dir[0])-(math.sin(90)*_dir[1]) -# y2 = (math.sin(90)*_dir[0]) + (math.cos(90)*_dir[1]) -# c1 = midpoint + Vector([x2,y2,0]).scale(radius) -# c2 = midpoint + Vector([x2,y2,0]).scale(-radius) -# #print(c1,c2,local_target.flatten()) -# -# # dist1 = abs(distance2D(c1,local_target)-distance2D(c1,Vector([0,0,0]))) -# # dist2= abs(distance2D(c2, local_target)-distance2D(c2, Vector([0,0,0]))) -# -# -# ang1 = abs(angleBetweenVectors(c1-local_target.flatten(),c1)) -# ang2 = abs(angleBetweenVectors(c2-local_target.flatten(),c2)) -# ang = min(ang1,ang2) -# -# # print(radius) -# # print(distance2D(c1,local_target),distance2D(c1,Vector([0,0]))) -# # print(distance2D(c2, local_target), distance2D(c2, Vector([0, 0]))) -# #print(dist1,dist2) -# # print(ang,circumference) -# # print(abs(circumference*(ang/360))) -# return abs(circumference*(ang/360)) -# -# def find_max_speed(curvature:float,speed_maximums): -# curvature = abs(curvature) -# index = -1 -# for i in range(len(speed_maximums)): -# if curvature > speed_maximums[i][1]: -# index = i -# break -# -# if index == -1: -# return 2300 -# -# elif index == 0: -# return 0 -# -# else: -# start = index-1 -# speed_diff = speed_maximums[index][0] - speed_maximums[start][0] -# normalized_vals = [] -# _max = speed_maximums[start][1] -# _min = speed_maximums[index][1] -# curve_norm = 1 - ((curvature-_min)/(_max-_min)) -# # print(start,index) -# # print(curve_norm) -# return speed_maximums[start][0] + (speed_diff*curve_norm) -# -# def find_curve(local_target:Vector): -# _radius = max(local_target.data[:2]) -# return 1/_radius,_radius - -def radius_from_local_point(a): - try: - a = a.flatten() - return 1 / (2 * a[1] / a.dotProduct(a)) - except ZeroDivisionError: - return 0.000000001 - - -def find_arc_distance(angle_degrees, radius): - circumference = math.pi * 2 * radius - return circumference * abs(angle_degrees) / 180 - - -def find_curve(agent, global_target): - x = agent._forward.dotProduct(global_target - agent.me.position) - y = agent.left.dotProduct(global_target - agent.me.position) - return (2 * y) / (x * x + y * y) - - -def get_path_info(local_target, angle): - radius = radius_from_local_point(local_target) - c = 1 / radius - distance = find_arc_distance(angle, radius) - return abs(radius), abs(c), abs(distance) - - -# def horrible_curve_finder(agent, target, angle): -# speed = agent.currentSpd -# speed_inc = 10 -# if target[0] < 0: -# target = target.scale(-1) -# -# _rad = turn_radius(speed) -# center = agent.me.location + agent.left.scale(-_rad) -# center_dist = distance2D(center, agent.me.location+target) -# -# -# if center_dist > _rad: -# while speed < maxPossibleSpeed: -# _rad = turn_radius(speed) -# center = agent.me.location + agent.left.scale(-_rad) -# center_dist = distance2D(center, agent.me.location + target) -# if center_dist < _rad: -# break -# speed += speed_inc -# else: -# while speed > 350: -# _rad = turn_radius(speed) -# center = agent.me.location + agent.left.scale(-_rad) -# center_dist = distance2D(center, agent.me.location + target) -# if center_dist > _rad: -# break -# speed -= speed_inc -# -# _rad = turn_radius(speed) -# c = curvature(clamp(maxPossibleSpeed, 350, speed)) -# circumference = math.pi * 2 * radius -# arc_distance = circumference * abs(angle)/180 -# -# return c, turn_radius(speed), arc_distance - - -def maxSpeedAdjustment(agent, target, angle, _distance, curve, fudging): - if agent.onWall or fudging: - return maxSpeedAdjustmentWall(agent, target, angle, _distance) - _angle = abs(angle) - if _angle > 180: - _angle -= 180 - - if (_angle <= 60 or _angle >= 120) and _distance <= agent.ball_size + 30: - return maxPossibleSpeed - - return max_speed_of_curvature(curve) - - -def maxSpeedAdjustmentWall(agent, local_target, angle, dist): - if abs(angle) <= 3: - return maxPossibleSpeed - - if not agent.forward: - return maxPossibleSpeed - - if (abs(angle) <= 45 or abs(angle) >= 135) and dist <= agent.groundReachLength: - return maxPossibleSpeed - - cost_inc = maxPossibleSpeed / 180 - if dist < 1200: - cost_inc *= 2 - new_speed = clamp(maxPossibleSpeed, 350, maxPossibleSpeed - (abs(angle) * cost_inc)) - # print(f"adjusting speed to {newSpeed}") - - return new_speed - - -def extend_to_sidewall(agent, targ_vec, startPos): - _slope = simple_slope(startPos, targ_vec) - slope = _slope[0] / _slope[1] - if startPos[0] >= targ_vec[0]: - x_diff = -(4096 - 93) - (targ_vec[0] - startPos[0]) - x_tar = -(4096 - 93) - else: - x_diff = (4096 - 93) - (targ_vec[0] - startPos[0]) - x_tar = 4096 - 93 - - y_inter = targ_vec[1] + slope * x_diff - - return Vector([x_tar, y_inter, 0]) - - -def extendToGoal(agent, ball_vec, startPos, buffer=120, send_back=False): - acceptable = True - - if ball_vec[0] >= 893 and startPos[0] <= ball_vec[0]: - acceptable = False - - elif ball_vec[0] <= 893 and startPos[0] >= ball_vec[0]: - acceptable = False - - elif startPos[1] * sign(agent.team) < ball_vec[1] * sign(agent.team): - acceptable = False - - _slope = simple_slope(startPos, ball_vec) - if _slope[0] == 0: - _slope.data[0] = 0.0001 - slope = _slope[1] / _slope[0] - y_diff = ((5120 + 93) * -sign(agent.team)) - ball_vec[1] - x_inter = ball_vec[0] + slope * y_diff - if not send_back: - return abs(x_inter) < 893 - buffer and acceptable - else: - return [abs(x_inter) < 893 - buffer and acceptable, x_inter] - - -def own_goal_check(agent, ball_vec, startPos, buffer=90, send_back=False): - _slope = simple_slope(startPos, ball_vec) - if _slope[0] == 0: - _slope.data[0] = 0.0001 - slope = _slope[1] / _slope[0] - y_diff = (5120 * sign(agent.team)) - ball_vec[1] - x_inter = ball_vec[0] + slope * y_diff - if not send_back: - return abs(x_inter) < 893 - buffer - else: - return abs(x_inter) < 893 - buffer, x_inter - - -def direction(source, target) -> Vector: - return (getLocation(source) - getLocation(target)).normalize() - - -def angle2(target_location, object_location): - difference = getLocation(target_location) - getLocation(object_location) - return math.atan2(difference[1], difference[0]) - - -@jit -def getVelocity(_obj): - return math.sqrt(sum([x * x for x in _obj])) - - -def getVelocity2D(_obj): - return math.sqrt(sum[_obj.velocity[0] ** 2, _obj.velocity[0] ** 2]) - - -def findDistance(origin, destination): - difference = getLocation(origin) - getLocation(destination) - return abs(math.sqrt(sum([x * x for x in difference]))) - - -def distance2D(origin, destination): - _origin = getLocation(origin) - _destination = getLocation(destination) - _origin = Vector([_origin[0], _origin[1]]) - _destination = Vector([_destination[0], _destination[1]]) - difference = _origin - _destination - return abs(math.sqrt(sum([x * x for x in difference]))) - - -def weighted_distance_2D(player_location: Vector, ball_location: Vector): - _origin = getLocation(player_location).flatten() - _destination = getLocation(ball_location).flatten() - difference = _origin - _destination - if abs(ball_location[0]) > 500: - if (ball_location[0] > 0 and player_location[0] < ball_location[0]) or ( - ball_location[0] < 0 and player_location[0] > ball_location[0] - ): - difference.data[0] = difference[0] * 1.5 - return difference.magnitude() - - -@jit -def correctAngle(x): - y = x * 1 - if y > 360: - y -= 360 - if y < -360: - y += 360 - - if y > 180: - y = 360 - elif y < -180: - y += 360 - - return y - - -def localizeVector(target_object, our_object, remote_location=None): - if remote_location is None: - x = (getLocation(target_object) - getLocation(our_object.location)).dotProduct( - our_object.matrix[0] - ) - y = (getLocation(target_object) - getLocation(our_object.location)).dotProduct( - our_object.matrix[1] - ) - z = (getLocation(target_object) - getLocation(our_object.location)).dotProduct( - our_object.matrix[2] - ) - - else: - x = (getLocation(target_object) - remote_location).dotProduct(our_object.matrix[0]) - y = (getLocation(target_object) - remote_location).dotProduct(our_object.matrix[1]) - z = (getLocation(target_object) - remote_location).dotProduct(our_object.matrix[2]) - - return Vector([x, y, z]) - - -def localizeRotation(target_rotation, agent): - return Vector( - [ - target_rotation.dotProduct(agent._forward), - target_rotation.dotProduct(agent.left), - target_rotation.dotProduct(agent.up), - ] - ) - - -def toLocal(target, our_object): - return localizeVector(target, our_object) - - -def ruleOneCheck(agent): - if agent.closestEnemyToMeDistance < 250: - if agent.currentSpd < 200: - if relativeSpeed(agent.me.velocity, agent.closestEnemyToMe.velocity) < 100: - return True - if len(agent.allies) > 0: - for ally in agent.allies: - if distance2D(agent.me.location, ally.location) < 200: - if relativeSpeed(agent.me.velocity, ally.velocity) < 100: - return True - - return False - - -def aim_adjustment(velocity, team): - vel = velocity.flatten() - mag = vel.magnitude() - return vel.normalize().scale(clamp(50, 0, mag / 40)) - - - -# def get_aim_vector( -# agent, end_target_vec, target_ball_vec, target_ball_velocity, offset_length, vel_adjust=True -# ): -# if agent.me.location[1] * sign(agent.team) > agent.ball.location[1] * sign(agent.team) and vel_adjust: -# vel_difference = abs(angleBetweenVectors( -# agent.me.velocity.flatten(), target_ball_velocity.flatten() -# )) -# _direction = direction(target_ball_vec.flatten(), end_target_vec.flatten()) -# vel_difference = angleBetweenVectors(_direction.flatten(), target_ball_velocity.flatten()) -# ovd = vel_difference * 1 -# # alignment = abs(90 - abs(vel_difference - 90)) / 100 -# vel_difference -= 90 -# if vel_difference < 0: -# vel_difference += 180 -# -# if vel_difference > 90: -# alignment = abs((180 - vel_difference) / 100.0) -# else: -# alignment = abs((90 - vel_difference) / 100.0) -# -# # print(ovd, vel_difference, alignment) -# chunk = 100 / 90 -# percentage = alignment * chunk -# # print(percentage) -# divisor = 65.0 -# max_alteration = 15 -# clamped_max = clamp(max_alteration, 0, offset_length * 0.5) -# -# adjusted_target_location = target_ball_vec + target_ball_velocity.flatten().normalize().scale( -# clamp(clamped_max, 0, target_ball_velocity.flatten().magnitude() / divisor) -# * percentage -# ) -# angle = angleBetweenVectors(agent.me.velocity.flatten().normalize(), _direction) -# return ( -# adjusted_target_location -# + _direction.scale( -# offset_length - (target_ball_vec - adjusted_target_location).magnitude() -# ), -# angle, -# ) -# else: -# _direction = direction(target_ball_vec.flatten(), end_target_vec.flatten()) -# angle = angleBetweenVectors(agent.me.velocity.flatten().normalize(), _direction) -# return target_ball_vec + _direction.scale(offset_length), angle - -def get_aim_vector( - agent, end_target_vec, target_ball_vec, target_ball_velocity, offset_length, vel_adjust=True -): - if agent.me.location[1] * sign(agent.team) > agent.ball.location[1] * sign(agent.team) and vel_adjust: - # vel_difference = abs(angleBetweenVectors( - # agent.me.velocity.flatten(), target_ball_velocity.flatten() - # )) - _direction = direction(target_ball_vec.flatten(), end_target_vec.flatten()) - vel_difference = angleBetweenVectors(_direction.flatten(), target_ball_velocity.flatten()) - ovd = vel_difference * 1 - # alignment = abs(90 - abs(vel_difference - 90)) / 100 - vel_difference -= 90 - if vel_difference < 0: - vel_difference += 180 - - if vel_difference > 90: - alignment = abs((180 - vel_difference) / 100.0) - else: - alignment = abs((90 - vel_difference) / 100.0) - - #alignment = 1 - - # print(ovd, vel_difference, alignment) - chunk = 100 / 90 - percentage = alignment * chunk - # print(percentage) - divisor = 100 - max_alteration = 20 - clamped_max = clamp(max_alteration, 0, offset_length * 0.5) - - adjusted_target_location = target_ball_vec + target_ball_velocity.flatten().normalize().scale( - clamp(clamped_max, 0, target_ball_velocity.flatten().magnitude() / divisor) - * percentage - ) - angle = angleBetweenVectors(agent.me.velocity.flatten().normalize(), _direction) - return ( - adjusted_target_location - + _direction.scale( - offset_length - (target_ball_vec - adjusted_target_location).magnitude() - ), - angle, - ) - else: - _direction = direction(target_ball_vec.flatten(), end_target_vec.flatten()) - angle = angleBetweenVectors(agent.me.velocity.flatten().normalize(), _direction) - return target_ball_vec + _direction.scale(offset_length), angle - - - -def aim_wallshot_naive_hitless(agent, targ_bal_vec, targ_ball_vel, offset_length): - enemy_goal = Vector( - [0, (5120 + agent.ball_size * 2) * -sign(agent.team), targ_bal_vec.data[2]] - ) - - enemy_goal.data[0] = 4096 * 2 - # if not defensive: - if agent.me.location[0] > targ_bal_vec[0]: - enemy_goal.data[0] = -(4096 * 2) - # else: - # if targ_bal_vec[0] < 0: - # enemy_goal.data[0] = 4096 * -2 - - return get_aim_vector( - agent, enemy_goal, targ_bal_vec, targ_ball_vel, offset_length - )[0] - - -def aim_wallshot_naive(agent, _hit, offset_length, force_close=False): - target_vec = _hit.pred_vector - multi = 2.0 - if not agent.offensive and len(agent.allies) > 0: - multi = 1 - - force_close = ( - False if agent.goalPred is not None else agent.me.velocity[1] * sign(agent.team) > 0 - ) - # if not force_close and not agent.offensive and len(agent.enemies) > 1: - # multi = 1.25 - - enemy_goal = Vector( - [0, (5120 + agent.ball_size * 2) * -sign(agent.team), target_vec.data[2]] - ) - - if not force_close: - enemy_goal.data[0] = 4096 * multi - if agent.me.location[0] > target_vec[0]: - enemy_goal.data[0] = -(4096 * multi) - - else: - enemy_goal.data[0] = 4096 * multi - if target_vec[0] < 0: - enemy_goal.data[0] = -(4096 * multi) - - return get_aim_vector(agent, enemy_goal, target_vec, _hit.pred_vel, offset_length)[ - 0 - ] - - -def unroll_path_from_ground_to_wall(target_location: Vector) -> Vector: - # orange back wall = north - # 0 = orange backboard, 1 = east wall, 2 = blue backboard, 3 = west wall - wall = which_wall(target_location) - - if wall in [0, 2]: - index_g, index_a = 1, 2 - else: - index_g, index_a = 0, 2 - - ground_target = target_location.scale(1) - if ground_target.data[index_g] > 0: - ground_target.data[index_g] += target_location[index_a] - else: - ground_target.data[index_g] -= target_location[index_a] - - ground_target.data[index_a] = 0 - # if wall == 0: - # ground_target.data[1]+=200 - # elif wall == 1: - # ground_target.data[0]-=200 - # elif wall == 2: - # ground_target.data[1]-=200 - # else: - # ground_target.data[0] += 200 - - return ground_target - - -def unroll_path_from_wall_to_ground( - agent_location: Vector, target_location: Vector -) -> Vector: - # orange back wall = north - # 0 = orange backboard, 1 = east wall, 2 = blue backboard, 3 = west wall - - wall = which_wall(agent_location) - wall_target = target_location.scale(1) - wall_target.data[2] = 0 - - if wall in [0, 2]: - y_diff = distance2D(Vector([0, agent_location[1]]), Vector([0, wall_target[1]])) - wall_target.data[2] = -y_diff - wall_target.data[1] = agent_location[1] - - elif wall in [1, 3]: - # index_g,index_a = 0,2 - x_diff = distance2D(Vector([agent_location[0], 0]), Vector([wall_target[0], 0])) - wall_target.data[2] = -x_diff - wall_target.data[0] = agent_location[0] - - else: - wall_target.data[2] = -200 - - # if wall == 0: - # wall_target.data[1]-=200 - # elif wall == 1: - # wall_target.data[0]+=200 - # elif wall == 2: - # wall_target.data[1]+=200 - # else: - # wall_target.data[0] -= 200 - - return wall_target - - -def relativeSpeed(vec_a, vec_b): - # takes in 2 velocity vectors and returns the relative speed difference - return (vec_a - vec_b).magnitude() - - -def oldDirtyCarryCheck(agent): - # return False - - maxRange = 250 - ball_distance = findDistance(agent.me.location, agent.ball.location) - acceptableDistance = ball_distance <= maxRange - - error = "" - - ballRadius = 93 - # print("being called") - if agent.onSurface: - if abs(agent.ball.location[0]) < 3900: - if not agent.onWall: - if agent.touch.player_index == agent.index: - # if agent.time - agent.touch.time_seconds < 1: - if acceptableDistance: - if ( - agent.ball.location[2] >= ballRadius + 20 - and distance2D(agent.me.location, agent.ball.location) < 155 - ): - # if ( - # relativeSpeed( - # agent.ball.velocity, agent.me.velocity - # ) - # <= 500 - # ): - # print("dribbling") - # print(f"True {ball_distance} {agent.ball.location[2]}") - return True - - # print(f"False {ball_distance} {agent.ball.location[2]} {error}") - return False - - -def enemy_carry_check(agent): - maxRange = 275 - ball_distance = findDistance(agent.closestEnemyToBall.location, agent.ball.location) - acceptableDistance = ball_distance <= maxRange - ballRadius = agent.ball_size - xy_range = agent.carLength + (ballRadius * 0.7) - min_height = 35 - - if ( - agent.closestEnemyToBall.onSurface - and (abs(agent.ball.location[0]) < 3900) - # and not agent.onWall - and agent.touch.player_index == agent.closestEnemyToBall.index - and acceptableDistance - and ( - agent.ball.location[2] >= (ballRadius + min_height) - and distance2D(agent.closestEnemyToBall.location, agent.ball.location) < xy_range - ) - # testing velocity matching - and relativeSpeed(agent.ball.velocity, agent.closestEnemyToBall.velocity) < 500 - - ): - return True - - # print(f"False {ball_distance} {agent.ball.location[2]} {error}") - return False - -def dirtyCarryCheck(agent): - # return False - - maxRange = 250 - ball_distance = findDistance(agent.me.location, agent.ball.location) - acceptableDistance = ball_distance <= maxRange - - error = "" - - ballRadius = 93 - # print("being called") - if agent.onSurface: - if abs(agent.ball.location[0]) < 3900: - if not agent.onWall: - if agent.touch.player_index == agent.index: - # if agent.time - agent.touch.time_seconds < 1: - if acceptableDistance: - if ( - agent.ball.location[2] >= ballRadius + 20 - and distance2D(agent.me.location, agent.ball.location) < 155 - ): - # if ( - # relativeSpeed( - # agent.ball.velocity, agent.me.velocity - # ) - # <= 500 - # ): - # print("dribbling") - # print(f"True {ball_distance} {agent.ball.location[2]}") - return True - - # print(f"False {ball_distance} {agent.ball.location[2]} {error}") - return False -# def dirtyCarryCheck(agent): -# maxRange = 295 -# ball_distance = findDistance(agent.me.location, agent.ball.location) -# acceptableDistance = ball_distance <= maxRange -# ballRadius = agent.ball_size -# xy_range = agent.carLength + (ballRadius * 0.7) -# min_height = 25 -# -# if ( -# agent.onSurface -# and (abs(agent.ball.location[0]) < 3900) -# and not agent.onWall -# and agent.touch.player_index == agent.index -# and acceptableDistance -# and ( -# agent.ball.location[2] >= (ballRadius + min_height) -# and distance2D(agent.me.location, agent.ball.location) < xy_range -# ) -# and abs(agent.ball.velocity[2]) < 200 -# and relativeSpeed(agent.ball.velocity, agent.me.velocity) < 550 -# -# -# ): -# return True -# -# # print(f"False {ball_distance} {agent.ball.location[2]} {error}") -# return False - - -def simple_slope(p1: Vector, p2: Vector): - return Vector([(p2[1] - p1[1]), (p2[0] - p1[0])]) - - -def challenge_flip(agent, targetVec): - # challenge disabled 103:48 @ 70 minutes kam(blue) in lead vs Diablo 0.466 - # 74:34 @ 64 minutes as orange .4594 - # return False - if distance2D(agent.me.location, agent.ball.location) <= 200: - if targetVec[2] <= 120 and agent.ball.location[2] <= 120: - if len(agent.enemies) > 0: - if ( - distance2D(agent.closestEnemyToBall.location, agent.ball.location) - < 450 - ): - if agent.closestEnemyToBall.location[1] * sign( - agent.team - ) < agent.me.location[1] * sign(agent.team): - print("challenge flipping") - agent.setJumping(0) - - -def mirrorshot_qualifier(agent): - center_limit = 500 - wall_buffer = 93 - - error_codes = [] - - center = Vector([0, 5200 * -sign(agent.team), 0]) - targetVec = agent.currentHit.pred_vector - - # return False,error_codes - - if agent.me.location[1] * sign(agent.team) < targetVec[1] * sign(agent.team): - # return False - # error 1 : bot on wrong side of the ball - error_codes.append(1) - - wall_inter = extend_to_sidewall(agent, targetVec, agent.me.location) - if wall_inter[1] * -sign(agent.team) < -4000: - # return False - # error 2: mirror shot would bounce off corner - error_codes.append(2) - - x_scale = 1 - # if abs(targetVec[0]) >= 3900: - # x_scale = 2 - - if butterZone(targetVec) and targetVec[1] * sign(agent.team) < 0: - # error 3: ball is right in front of enemy goal - error_codes.append(3) - - if distance2D(targetVec, agent.me.location) > 5000: - # error 4: ball is too far away to force locking into mirror shot - error_codes.append(4) - - if targetVec[1] * sign(agent.team) < -3500: - # error 5: Much better to force center than do weird corner redirect - error_codes.append(5) - - vec_difference = targetVec.flatten() - agent.me.location.flatten() - - if abs(vec_difference[0]) * x_scale >= abs(vec_difference[1]): - if (targetVec[0] >= center_limit or not agent.offensive) and agent.me.location[0] < targetVec[0]: - return True, error_codes - - if (targetVec[0] < -center_limit or not agent.offensive) and agent.me.location[0] > targetVec[0]: - return True, error_codes - - return False, error_codes - - -def optimal_intercept_vector( - collider_location: Vector, collider_velocity: Vector, target_location: Vector -): - """Provides vector for correcting an object's velocity vector towards the target vector""" - target_dir = (target_location - collider_location).normalize() - correct_vel = target_dir.scale(collider_velocity.dotProduct(target_dir)) - incorrect_vel = collider_velocity - correct_vel - extra_vel = math.sqrt(math.pow(6000, 2) - math.pow(incorrect_vel.magnitude(), 2)) - return (target_dir.scale(extra_vel) - incorrect_vel).normalize().scale(-1) - - -def norm(vec: np.ndarray): - return math.sqrt(math.pow(vec[0], 2) + math.pow(vec[1], 2) + math.pow(vec[2], 2)) - - -def angleBetweenVectors(vec1: Vector, vec2: Vector): - return math.degrees(math.acos((vec1.normalize().dotProduct(vec2.normalize())))) - - -def dribble_carry_revised(agent): - target_speed = 1050 - max_offset = 30 - if agent.me.boostLevel > 20 and agent.forward: - max_offset = 40 - - speed_limiter = 0 - alignment_cap = 500 - y_targ = 5250 * -sign(agent.team) - x_targ = 0 - if agent.ball.location[0] > 1200: - x_targ = -400 - elif agent.ball.location[0] < -1200: - x_targ = 400 - min_offset = 8 - if not agent.forward: - min_offset = 12 - - carry_delay = 20 # agent.ball.velocity.magnitude()/10 # how many frames ahead are we shooting for? - cradled = agent.ball.location[2] <= agent.carHeight + 125 - cradle_location = agent.ball.location.flatten() + agent.ball.velocity.flatten().scale( - agent.fakeDeltaTime * carry_delay - ) - current_trajectory = agent.ball.velocity.flatten().normalize() - - extend_info = extendToGoal( - agent, - agent.ball.location.flatten(), - agent.ball.location.flatten() - - agent.ball.velocity.flatten().normalize().scale(20), - send_back=True, - ) - - extend_info[0] = ( - extend_info[0] - and distance2D(Vector([0, 5250 * -sign(agent.team), 0]), agent.ball.location) - > 3000 - ) - - if not agent.scorePred: - - if not extend_info[0]: - if ( - extend_info[1] > 0 - and agent.me.location[0] > 0 - or extend_info[1] < 0 - and agent.me.location[0] < 0 - ): - - test_y_targ = agent.ball.location[1] + 200 * -sign(agent.team) - if abs(test_y_targ) < 5250: - y_targ = test_y_targ - - enemy_goal = Vector([x_targ, y_targ, 0]) - target_trajectory = (cradle_location - enemy_goal).normalize() - - # happy = (agent.scorePred != None or extend_info[0]) and (agent.ball.velocity.flatten().magnitude() < target_speed and abs(target_speed - agent.ball.velocity.flatten().magnitude()) < 250) - happy = agent.scorePred is not None or extend_info[0] # and ( - # agent.ball.velocity.flatten().magnitude() < target_speed and abs( - # target_speed - agent.ball.velocity.flatten().magnitude()) < 200) - - if (not cradled or happy) and agent.ball.velocity.magnitude() >= target_speed - 500: - offset = min_offset - if not cradled and agent.me.boostLevel > 10: - offset = min_offset * 1.5 - else: - offset = max_offset - - flick = ( - agent.enemyBallInterceptDelay <= 0.55 - ) or agent.closestEnemyToBallDistance <= clamp( - 1000, 500, agent.ball.velocity.magnitude() * 0.6 - ) - - if ( - cradled - and not agent.scorePred - and cradle_location[1] * sign(agent.team) < -4300 - and abs(cradle_location[0]) < 1100 - ): - flick = True - - speed_alignment = ( - clamp(1, 0.0, (agent.ball.velocity.magnitude() - target_speed) * 1.0) / 500.0 - ) - - targetDirection = optimal_intercept_vector( - cradle_location.flatten(), agent.ball.velocity.flatten(), enemy_goal.flatten() - ) - - # blended_direction = (agent.ball.velocity.flatten().normalize().scale(speed_alignment)+ targetDirection.scale(1-speed_alignment)).normalize() - blended_direction = agent.ball.velocity.flatten().normalize().scale( - speed_alignment - ) + targetDirection.scale(1 - speed_alignment) - - target = cradle_location + blended_direction.scale(offset) - - if flick: - if cradled: - if ( - agent.scorePred is not None - and findDistance(agent.me.location, agent.ball.location) < 135 - ): # and distance2D(agent.ball.location,enemy_goal) > 1500: - if ( - distance2D( - agent.me.location, Vector([0, 5200 * -sign(agent.team), 0]) - ) - > 3000 - ): - # print("greater than 3k") - agent.setJumping(20) - # agent.setJumping(2) - # print("big pop!") - else: - # print("closer than 3k") - agent.setJumping(20) - # print("medium pop") - else: - # print("not on target") - agent.setJumping(0) - # print(f"mini jump? {agent.time}") - else: - if ( - distance2D(agent.me.location, agent.ball.location) < 40 - and agent.enemyAttacking - and not agent.scorePred - ): - # agent.setJumping(2) - # print("forcing hop") - agent.setJumping(2) - - # print(f"cradled: {cradled} happy: {happy} {agent.time}") - - if ( - cradled - and agent.ball.velocity[1] * sign(agent.team) > 50 - and agent.ball.location[1] * sign(agent.team) > 3500 - ): - agent.setJumping(0) - - return driveController( - agent, target, agent.time + carry_delay * agent.fakeDeltaTime, expedite=True - ) - - -def carry_flick_new(agent): # take the dot product of the wanted velocity and the ball velocity and add the negative to offset - target_speed = 1000 - #print(agent.ball.location[2]) - if agent.forward and agent.me.boostLevel > 20: - target_speed = 1700 - y_targ = 5250 * -sign(agent.team) - x_targ = 0 - cradle_location = agent.ball.location.flatten() + agent.ball.velocity.flatten().scale(0.16666667) - ball_speed = agent.ball.velocity.flatten().magnitude() - extend_info = extendToGoal( - agent, - agent.ball.location.flatten(), - agent.ball.location.flatten() - - agent.ball.velocity.flatten().normalize().scale(20), - buffer=agent.ball_size * 3, - send_back=True, - ) - lined_up = True - extend_info[0] = ( - extend_info[0] - and distance2D(Vector([0, 5250 * -sign(agent.team), 0]), agent.ball.location) - > 3000 - ) - - if extend_info[1] > 800: - x_targ = -700 - elif extend_info[1] < -800: - x_targ = 700 - - max_offset = 20 - # if ball_speed < 1000: - # max_offset = 35 - # if not agent.scorePred: - - if not extend_info[0]: - if ( - extend_info[1] > 0 - and agent.me.location[0] > 0 - or extend_info[1] < 0 - and agent.me.location[0] < 0 - ): - lined_up = False - test_y_targ = cradle_location[1] + 300 * -sign(agent.team) - if abs(test_y_targ) < 5250: - y_targ = test_y_targ - - target_speed = 500 - max_offset = clamp(75, max_offset, ball_speed) - - goal_loc = Vector([x_targ, y_targ, 0]) - # if not agent.forward: - # min_offset = 10 - if lined_up: - return old_reliable(agent) - - go_under = False - - cradled = agent.ball.location[2] <= agent.carHeight + 125 - if cradled and ball_speed < 1000: - max_offset = 35 - - # current_trajectory = agent.ball.velocity.flatten().normalize() - target_trajectory = (agent.ball.location.flatten() - goal_loc).normalize() - traj_dot_norm = target_trajectory.dotProduct(agent.ball.velocity.flatten().normalize()) - stupid_dot = -(agent.ball.velocity.flatten().dotProduct(target_trajectory) / target_speed) - - aligned_vel = ball_speed * traj_dot_norm - # print(traj_dot_norm, agent.currentSpd) - # 65 if cradled else 15 - max_vel_offset = clamp(max_offset * .5, -(max_offset * .5), max((agent.me.boostLevel, 30))) - - counter_vel_mag = clamp(max_vel_offset, -max_vel_offset, (ball_speed - target_speed) / 20) - if agent.ball.velocity[1] * sign(agent.team) > 100: - counter_vel_mag = 120 - max_offset = clamp(max_offset, 0, max_offset - abs(counter_vel_mag)) - diff = target_trajectory - corrective_offset = max_offset - if not lined_up: - corrective_offset = max_offset * clamp(1, -1, 1 + traj_dot_norm) - diff = diff.scale(corrective_offset) - # if diff.magnitude() > max_offset: - # diff = diff.normalize().scale(max_offset) - target = cradle_location + diff + agent.ball.velocity.flatten().normalize().scale(counter_vel_mag) - - # offset = bonus_offset - # print(offset) - - flick = ( - agent.enemyBallInterceptDelay <= 0.55 - ) or agent.closestEnemyToBallDistance <= clamp( - 1000, 500, agent.ball.velocity.magnitude() * 0.6 - ) - - if ( - cradled - and not agent.scorePred - and cradle_location[1] * sign(agent.team) < -4200 - and abs(cradle_location[0]) < 1100 - ): - flick = True - - if flick: - if not go_under: - # if cradled: - if ( - agent.scorePred != None - and findDistance(agent.me.location, agent.ball.location) < 135 - ): # and distance2D(agent.ball.location,enemy_goal) > 1500: - if ( - # distance2D( - # agent.me.location, Vector([0, 5200 * -sign(agent.team), 0]) - # ) - # >= 2500 - agent.currentSpd * 4 - > distance2D( - agent.me.location, Vector([0, 5120 * -sign(agent.team), 0]) - ) - ): - agent.setJumping(20) - else: - # agent.setJumping(-1) - agent.setJumping(20, target=False) - else: - if agent.forward: - agent.setJumping(6, target=cradle_location) - else: - agent.setHalfFlip() - # else: - # if ( - # distance2D(agent.me.location, agent.ball.location) < 40 - # and agent.enemyAttacking - # and not agent.scorePred - # ): - # if agent.forward: - # agent.setJumping(2) - # else: - # agent.setHalfFlip() - else: - print(f"Going under! {agent.time}") - offset = 200 - - # direction = (agent.enemyGoalLocations[1] - cradle_location).normalize().scale(-40) - # offset = target_trajectory.scale(offset) - # offset += direction - # offset = offset.scale(0.5) - # print(offset.magnitude()) - # target = cradle_location + offset - - if ( - cradled - and agent.ball.velocity[1] * sign(agent.team) > 50 - and agent.ball.location[1] * sign(agent.team) > 3500 - ): - agent.setJumping(0) - - agent.update_action({"type": "BALL", "time": agent.time + 0.166666667}) - - return driveController(agent, target, agent.time + 0.166666667, expedite=True) - - -""" -above: new mess -below: mid creation copy? -""" - -# def carry_flick_new(agent): -# target_speed = 1050 -# max_offset = 35 -# if agent.me.boostLevel > 20 and agent.forward: -# max_offset = 45 -# -# speed_limiter = 0 -# alignment_cap = 500 -# y_targ = 5250 * -sign(agent.team) -# x_targ = 0 -# if agent.ball.location[0] > 1200: -# x_targ = -500 -# elif agent.ball.location[0] < -1200: -# x_targ = 500 -# -# # max_bouncing_corrective_offset = 20 -# min_offset = 8 -# # if agent.me.boostLevel > 15 and agent.currentSpd < 1800 and agent.forward: -# # min_offset = 12 -# if not agent.forward: -# min_offset = 20 -# -# go_under = len(agent.enemies) < 2 and not agent.closestEnemyToBall.onSurface -# -# # carry_delay = 10 # agent.ball.velocity.magnitude()/10 # how many frames ahead are we shooting for? -# cradled = agent.ball.location[2] <= agent.carHeight + 125 -# cradle_location = agent.ball.location.flatten() + agent.ball.velocity.flatten().scale( -# 0.16666667 -# ) -# current_trajectory = agent.ball.velocity.flatten().normalize() -# -# extend_info = extendToGoal( -# agent, -# agent.ball.location.flatten(), -# agent.ball.location.flatten() -# - agent.ball.velocity.flatten().normalize().scale(20), -# buffer=agent.ball_size * 3, -# send_back=True, -# ) -# -# extend_info[0] = ( -# extend_info[0] -# and distance2D(Vector([0, 5250 * -sign(agent.team), 0]), agent.ball.location) -# > 3000 -# ) -# -# if not agent.scorePred: -# -# if not extend_info[0]: -# if ( -# extend_info[1] > 0 -# and agent.me.location[0] > 0 -# or extend_info[1] < 0 -# and agent.me.location[0] < 0 -# ): -# -# test_y_targ = agent.ball.location[1] + 200 * -sign(agent.team) -# if abs(test_y_targ) < 5250: -# y_targ = test_y_targ -# -# enemy_goal = Vector([x_targ, y_targ, 0]) -# target_trajectory = (cradle_location - enemy_goal).normalize() -# happy = agent.scorePred != None or extend_info[0] -# -# if (not cradled or happy) and agent.ball.velocity.magnitude() >= target_speed - 500: -# offset = min_offset -# if not cradled and agent.me.boostLevel > 10 and agent.forward: -# offset = min_offset * 1.5 -# -# else: -# offset = max_offset -# -# # flick = (agent.enemyBallInterceptDelay <= 0.6 -# # and agent.enemyAttacking -# # or agent.enemyBallInterceptDelay <= 0.4 -# # ) or agent.closestEnemyToBallDistance <= clamp( -# # 1200, 600, agent.ball.velocity.magnitude() * 0.6 -# # ) -# flick = ( -# agent.enemyBallInterceptDelay <= 0.55 -# ) or agent.closestEnemyToBallDistance <= clamp( -# 1000, 500, agent.ball.velocity.magnitude() * 0.6 -# ) -# -# if ( -# cradled -# and not agent.scorePred -# and cradle_location[1] * sign(agent.team) < -4200 -# and abs(cradle_location[0]) < 1100 -# ): -# flick = True -# -# speed_alignment = ( -# clamp(1, 0.0, (agent.ball.velocity.magnitude() - target_speed) * 1.0) / 500.0 -# ) -# -# targetDirection = optimal_intercept_vector( -# cradle_location.flatten(), agent.ball.velocity.flatten(), enemy_goal.flatten() -# ) -# -# # blended_direction = (agent.ball.velocity.flatten().normalize().scale(speed_alignment)+ targetDirection.scale(1-speed_alignment)).normalize() -# blended_direction = agent.ball.velocity.flatten().normalize().scale( -# speed_alignment -# ) + targetDirection.scale(1 - speed_alignment) -# -# if flick: -# if not go_under: -# if cradled: -# if ( -# agent.scorePred != None -# and findDistance(agent.me.location, agent.ball.location) < 135 -# ): # and distance2D(agent.ball.location,enemy_goal) > 1500: -# if ( -# # distance2D( -# # agent.me.location, Vector([0, 5200 * -sign(agent.team), 0]) -# # ) -# # >= 2500 -# agent.currentSpd * 4 -# > distance2D( -# agent.me.location, Vector([0, 5120 * -sign(agent.team), 0]) -# ) -# ): -# agent.setJumping(20) -# else: -# # agent.setJumping(-1) -# agent.setJumping(20, target=False) -# else: -# if agent.forward: -# agent.setJumping(6, target=cradle_location) -# else: -# agent.setHalfFlip() -# else: -# if ( -# distance2D(agent.me.location, agent.ball.location) < 40 -# and agent.enemyAttacking -# and not agent.scorePred -# ): -# if agent.forward: -# agent.setJumping(2) -# else: -# agent.setHalfFlip() -# else: -# print(f"Going under! {agent.time}") -# offset = 200 -# target = cradle_location + blended_direction.scale(offset) -# -# if ( -# cradled -# and agent.ball.velocity[1] * sign(agent.team) > 50 -# and agent.ball.location[1] * sign(agent.team) > 3500 -# ): -# agent.setJumping(0) -# -# agent.update_action({"type": "BALL", "time": agent.time + 0.166666667}) -# -# return driveController(agent, target, agent.time + 0.166666667, expedite=True) - -""" -old hotness -""" - - -def old_reliable(agent): - target_speed = 1050 - max_offset = 30 - if agent.me.boostLevel > 20 and agent.forward: - max_offset = 40 - - speed_limiter = 0 - alignment_cap = 500 - y_targ = 5250 * -sign(agent.team) - x_targ = 0 - - min_offset = 8 - if agent.me.boostLevel > 20 and agent.currentSpd < 1600 and agent.forward: - min_offset = 12 - if not agent.forward: - min_offset = 20 - - # vels_difference = angleBetweenVectors(agent.ball.velocity.flatten(),direction(Vector([0,5250*-sign(agent.team),0]),agent.ball.location.flatten())) - # c_offset = clamp(max_offset,min_offset,((max_offset/180)*clamp(180,0,vels_difference*2))*current_saturation) - - - go_under = False # agent.closestEnemyToBall.location[2] > 75 - - carry_delay = 20 # agent.ball.velocity.magnitude()/10 # how many frames ahead are we shooting for? - cradled = agent.ball.location[2] <= agent.carHeight + 125 - cradle_location = agent.ball.location.flatten() + agent.ball.velocity.flatten().scale( - agent.fakeDeltaTime * carry_delay - ) - current_trajectory = agent.ball.velocity.flatten().normalize() - - extend_info = extendToGoal( - agent, - agent.ball.location.flatten(), - agent.ball.location.flatten() - - agent.ball.velocity.flatten().normalize().scale(20), - buffer=agent.ball_size * 3, - send_back=True, - ) - - extend_info[0] = ( - extend_info[0] - and distance2D(Vector([0, 5250 * -sign(agent.team), 0]), agent.ball.location) - > 3000 - ) - - if extend_info[1] > 800: - x_targ = -700 - elif extend_info[1] < -800: - x_targ = 700 - - if not agent.scorePred: - - if not extend_info[0]: - if ( - extend_info[1] > 0 - and agent.me.location[0] > 0 - or extend_info[1] < 0 - and agent.me.location[0] < 0 - ): - - test_y_targ = cradle_location[1] + 10 * -sign(agent.team) - if abs(test_y_targ) < 5250: - y_targ = test_y_targ - - enemy_goal = Vector([x_targ, y_targ, 0]) - target_trajectory = (cradle_location - enemy_goal).normalize() - happy = agent.scorePred is not None or extend_info[0] - - offset = min_offset - - # if (not cradled or not happy) and agent.ball.velocity.magnitude() >= target_speed: - # offset = min_offset - # if not cradled and agent.me.boostLevel > 10 and agent.forward: - # offset = min_offset * 1.5 - # else: - # offset = max_offset - if cradled and not happy: - offset = max_offset - - - - flick = ( - agent.enemyBallInterceptDelay <= 0.45 - and agent.enemyAttacking - or agent.enemyBallInterceptDelay <= 0.3 - ) or agent.closestEnemyToBallDistance <= clamp( - 1000, 500, agent.ball.velocity.magnitude() * 0.5 - ) - - if ( - cradled - and not agent.scorePred - and cradle_location[1] * sign(agent.team) < -4000 - and abs(cradle_location[0]) < 1500 - ): - flick = True - - speed_alignment = ( - clamp(1, 0.0, (agent.ball.velocity.magnitude() - target_speed) * 1.0) / 500.0 - ) - - targetDirection = optimal_intercept_vector( - cradle_location.flatten(), agent.ball.velocity.flatten(), enemy_goal.flatten() - ) - - # blended_direction = (agent.ball.velocity.flatten().normalize().scale(speed_alignment)+ targetDirection.scale(1-speed_alignment)).normalize() - blended_direction = agent.ball.velocity.flatten().normalize().scale(speed_alignment) + targetDirection.scale(1 - speed_alignment) - - if flick: - if not go_under: - if cradled: - if ( - agent.scorePred is not None - and findDistance(agent.me.location, agent.ball.location) < 135 - ): # and distance2D(agent.ball.location,enemy_goal) > 1500: - if ( - distance2D( - agent.me.location, Vector([0, 5200 * -sign(agent.team), 0]) - ) - > 3000 - ): - # print("greater than 3k") - agent.setJumping(20) - # agent.setJumping(2) - # print("big pop!") - else: - # print("closer than 3k") - agent.setJumping(20) - # print("medium pop") - else: - if agent.forward: - agent.setJumping(6, target=cradle_location) - else: - agent.setHalfFlip() - else: - if ( - distance2D(agent.me.location, agent.ball.location) < 40 - and agent.enemyAttacking - and not agent.scorePred - ): - if agent.forward: - agent.setJumping(2) - else: - agent.setHalfFlip() - else: - # print(f"Going under! {agent.time}") - offset = 100 - target = cradle_location + blended_direction.scale(offset) - - if ( - cradled - and agent.ball.velocity[1] * sign(agent.team) > 50 - and agent.ball.location[1] * sign(agent.team) > 3500 - ): - agent.setJumping(0) - - return driveController( - agent, target, agent.time + carry_delay * agent.fakeDeltaTime, expedite=True - ) - - -def inTheMiddle(testNumber, guardNumbersList): - return min(guardNumbersList) <= testNumber <= max(guardNumbersList) - - -def handleWallShot(agent): - enemyGoal = Vector([0, -sign(agent.team) * 5200, 1500]) - myGoal = enemyGoal = Vector([0, sign(agent.team) * 5200, 500]) - targetVec = agent.currentHit.pred_vector - destination = targetVec - wall = which_wall(targetVec) - _direction = direction(myGoal.flatten(), targetVec.flatten()) - modified = targetVec + _direction.scale(70) - - if wall == 0: - modified.data[1] = 5120 - agent.defaultElevation - - elif wall == 2: - modified.data[1] = -5120 + agent.defaultElevation - - elif wall == 1: - modified.data[0] = -4096 + agent.defaultElevation - - else: - modified.data[0] = 4096 - agent.defaultElevation - - destination = modified - - agent.update_action({"type": "BALL", "time": agent.currentHit.prediction_time}) - - return driveController( - agent, - destination, - agent.time + agent.currentHit.time_difference(), - expedite=True, - ) - - -def wallMover(agent, target, targetSpd, arrivalTime, expedite=False): - # agent.forward = True - if agent.boostMonster: - expedite = True - target = getLocation(target) - currentSpd = agent.currentSpd - controller_state = SimpleControllerState() - if agent.forward: - controller_state.throttle = 1 - else: - controller_state.throttle = -1 - # print(f"on wall backwards? {agent.time}") - - if targetSpd > maxPossibleSpeed: - targetSpd = maxPossibleSpeed - jumpingDown = False - - if agent.currentHit.hit_type != 2: - target = unroll_path_from_wall_to_ground(agent.me.location, target) - - location = toLocal(target, agent.me) - angle_to_target = math.atan2(location.data[1], location.data[0]) - angle_degrees = correctAngle(math.degrees(angle_to_target)) - # angle_degrees = math.degrees(angle_to_target) - if agent.onWall and not agent.wallShot: - if abs(angle_degrees) < 5: - if agent.me.location[2] < 1500: - jumpingDown = True - if agent.currentHit.hit_type != 2: - _distance = agent.me.location.data[2] + distance2D(agent.me.location, target) - else: - _distance = findDistance(agent.me.location, target) - createTriangle(agent, target) - steering, slide = rockSteer(angle_to_target, _distance) - if not agent.forward: - # steering = -steering - slide = False - if slide: - if abs(agent.me.avelocity[2]) < 1: - slide = False - - if abs(steering) >= 0.90 and not agent.dribbling: - optimalSpd = maxSpeedAdjustment(agent, target) - - if targetSpd > optimalSpd: - targetSpd = clamp(maxPossibleSpeed, 0, math.ceil(optimalSpd)) - - if targetSpd > currentSpd: - if agent.onSurface and not slide: - spedup = False - if not agent.boostMonster: - if agent.me.location[2] > 200: - if agent.currentSpd > 300: - if not agent.forward: - targetAngle = abs( - correctAngle(math.degrees(angle_to_target)) - 180 - ) - else: - targetAngle = abs( - correctAngle(math.degrees(angle_to_target)) - ) - if targetAngle < 5: - spedup = agent.wallHyperSpeedJump() - - if not spedup: - if agent.forward: - if ( - targetSpd > agent.currentSpd + agent.accelerationTick * 8 - and agent.currentSpd < maxPossibleSpeed - ): - if agent.currentSpd < maxPossibleSpeed - 50: - if expedite: - controller_state.boost = True - - elif ( - targetSpd < currentSpd - ): # and (targetSpd < maxPossibleSpeed and currentSpd >maxPossibleSpeed): - if agent.forward: - controller_state.throttle = -1 - else: - controller_state.throttle = 1 - controller_state.steer = steering - if jumpingDown: - if abs(correctAngle(math.degrees(angle_to_target))) < 5: - if agent.me.location[2] >= agent.wallLimit: - agent.setJumping(-1) - # agent.log.append("jumping down") - - return controller_state - -@jit -def decelerationSim(dt, current_spd, timeAlloted): - # def decelerationSim(agent, timeAlloted): - increment = 525 * dt - currentSpeed = current_spd * 1 - distance = 0 - while timeAlloted > 0 or currentSpeed > 0: - timeAlloted -= dt - currentSpeed = clamp(currentSpeed, 0, currentSpeed - increment) - distance += currentSpeed * dt - return distance - - -# @jit -def brake_sim(dt, current_spd, timeAlloted): - # def brake_sim(agent, timeAlloted): - increment = 3500 * dt - currentSpeed = current_spd * 1 - distance = 0 - while timeAlloted > 0 or currentSpeed > 0: - timeAlloted -= dt - currentSpeed = clamp(currentSpeed, 0, currentSpeed - increment) - distance += currentSpeed * dt - return distance - -def brake_time(spd): - return spd/3500.0 - - -# def decelerationSim(agent, timeAlloted): -# increment = 525 * agent.fakeDeltaTime -# currentSpeed = agent.currentSpd * 1 -# distance = 0 -# while timeAlloted > 0 or currentSpeed > 0: -# timeAlloted -= agent.fakeDeltaTime -# currentSpeed -= increment -# distance += currentSpeed * agent.fakeDeltaTime -# return distance -# -# -# def brake_sim(agent, timeAlloted): -# increment = 3500 * agent.fakeDeltaTime -# currentSpeed = agent.currentSpd * 1 -# distance = 0 -# while timeAlloted > 0 or currentSpeed > 0: -# timeAlloted -= agent.fakeDeltaTime -# currentSpeed -= increment -# distance += currentSpeed * agent.fakeDeltaTime -# return distance - - -def lastManFinder(agent): - lastMan = None - lastManY = math.inf * -sign(agent.team) - allies = agent.allies + [agent.me] - sorted(allies, key=lambda x: x.index) - back_count = 0 - - if agent.team == 0: - # lastManY = math.inf - for ally in allies: - if ally.location[1] < lastManY: - lastManY = ally.location[1] - lastMan = ally - if ally.location[1] * sign(agent.team) > agent.ball.location[1] * sign( - agent.team - ): - back_count += 1 - else: - # lastManY = -math.inf - for ally in allies: - if ally.location[1] > lastManY: - lastManY = ally.location[1] - lastMan = ally - if ally.location[1] * sign(agent.team) > agent.ball.location[1] * sign( - agent.team - ): - back_count += 1 - - agent.ally_back_count = back_count - - return lastMan - - -def in_goal_check(agent): - if abs(agent.me.location[1]) >= 4900 and abs(agent.me.location[0]) < 900: - return True - return False - - -def goalBoxFixer(agent, target): - y_limit = 5085 - if abs(agent.me.location[1]) < y_limit: - return target - # not in goal, continue as normal - else: - xMin = -825 - xMax = 825 - y_extension = 400 - - if agent.me.location[1] > y_limit: - # in orange goal - yMax = y_limit + y_extension - - if target[0] < xMin: - target.data[0] = xMin - elif target[0] > xMax: - target.data[0] = xMax - - if target[1] > yMax: - target.data[1] = yMax - - elif agent.me.location[1] < -y_limit or target[1] < -y_limit: - # in blue goal - yMin = -y_limit - y_extension - - if target[0] < xMin: - target.data[0] = xMin - elif target[0] > xMax: - target.data[0] = xMax - - if target[1] < yMin: - target.data[1] = yMin - return target - - -def greedy_mover(agent, target_object): - controller_state = SimpleControllerState() - controller_state.handbrake = False - location = toLocal(target_object, agent.me) - angle = math.atan2(location.data[1], location.data[0]) - controller_state.throttle = 1 - if getVelocity(agent.me.velocity) < maxPossibleSpeed: - if agent.onSurface: - controller_state.boost = True - controller_state.jump = False - - controller_state.steer = Gsteer(angle) - - return controller_state - - -def driveController( - agent, - target, - arrivalTime, - expedite=False, - flippant=False, - maintainSpeed=False, - flips_enabled=True, - kickoff=False, - demos=False, - floppies=True, - going_for_aerial=False, - fudging=False, - offset_dist=0 -): - tta = clamp(6, 0.001, arrivalTime - agent.time) - - OT = target.scale(1) - - if not kickoff: - - if agent.boostMonster: - expedite = True - if agent.forward: - flips_enabled = False - flippant = False - - # testing - if ( - flips_enabled - and agent.forward - and agent.goalPred == None - and not agent.boostMonster - and not agent.demo_monster - and not demos - and agent.contested - and agent.rotationNumber == 1 - and agent.lastMan == agent.me.location - and agent.me.location[1] * sign(agent.team) - > agent.ball.location[1] * sign(agent.team) - ): - flips_enabled = agent.enemyBallInterceptDelay > 1 - - if not agent.forward: - expedite = True - flips_enabled = True - - if target[2] == 0 or target[2] < agent.defaultElevation: - target.data[2] = agent.defaultElevation - - if (agent.me.location[1] * sign(agent.team)) - (sign(agent.team) * 65) < agent.ball.location[1] * sign( - agent.team - ): - own_goal_info = own_goal_check( - agent, - agent.ball.location.flatten(), - agent.me.location.flatten(), - buffer=-90, - send_back=True, - ) - - if own_goal_info[0] and agent.ball.location[2] <= 160: - #target = (agent.ball.location.flatten()) + agent.ball.velocity.flatten().normalize().scale(200) - target = agent.ball.location.flatten() + Vector([0,sign(agent.team)*300, 0]) - if own_goal_info[1] > 0: - target += Vector([-200, 0, 0]) - else: - target += Vector([200, 0, 0]) - - tta = 0.001 - fudging = True - - if not agent.demo_monster: - - if agent.onWall: - flips_enabled = False - if ( - agent.currentHit != None - and agent.currentHit.hit_type != 2 - and agent.me.location[2] > 75 - ): - target = unroll_path_from_wall_to_ground(agent.me.location, target) - else: - placeVecWithinArena( - target, offset=agent.defaultElevation - ) - - else: - if agent.currentHit.hit_type == 2: - target = unroll_path_from_ground_to_wall(target) - else: - placeVecWithinArena( - target, offset=agent.defaultElevation - ) - prefixer = target.scale(1) - target = goalBoxFixer(agent, target) - if prefixer != target: - maintainSpeed = False - flips_enabled = False - tta = 0.000001 - if agent.goalPred is None: - expedite = False - flippant = False - - if abs(agent.me.location[1]) > 5100: - flips_enabled = False - - if not kickoff: - _distance = findDistance(agent.me.location, target) - if fudging and offset_dist > 100: - _distance += offset_dist - #flat_dist = distance2D(agent.me.location, target) - else: - _distance = distance2D(agent.me.location, target) - #flat_dist = _distance - - # if OT != target: - # OT_dist = findDistance(agent.me.location, OT) - # #tta = max(0.0001, tta * OT_dist/_distance) - # _distance = OT_dist - - localTarget = toLocal(target, agent.me) - angle = math.atan2(localTarget[1], localTarget[0]) - angle_degrees = math.degrees(angle) - avoiding = False - target_to_avoid = Vector([0, 0, 0]) - boost_req = agent.boost_req - if agent.dribbling: - boost_req = agent.boost_req * 2 - - goForward = agent.forward - - if avoiding: - localTarget = toLocal(target_to_avoid, agent.me) - angle = math.atan2(localTarget[1], localTarget[0]) - angle_degrees = math.degrees(angle) - - if _distance < 700 or agent.currentSpd < 500 or agent.goalPred is not None: - goForward = abs(angle_degrees) <= 100 - - - if maintainSpeed: - goForward = True - - if not goForward: - expedite = True - flips_enabled = True - angle_degrees -= 180 - if angle_degrees < -180: - angle_degrees += 360 - if angle_degrees > 180: - angle_degrees -= 360 - - angle = math.radians(angle_degrees) - - path_info = get_path_info(localTarget, angle_degrees) # radius, c, distance - if not kickoff and not agent.onWall: - _distance = path_info[2] - - idealSpeed = clamp(maxPossibleSpeed, 0, math.ceil(_distance / tta)) - - createTriangle(agent, target) - if idealSpeed >= 200: - if ruleOneCheck(agent): - agent.setJumping(6, target=target) - - if goForward: - throttle = 1 - else: - throttle = -1 - - if not goForward or fudging: - if agent.onSurface and arrivalTime > 1.85: - # if _distance > clamp(maxPossibleSpeed, agent.currentSpd, agent.currentSpd + 500) * 2.2: - if ( - clamp(math.inf, 1, _distance - 160) - > clamp(maxPossibleSpeed, agent.currentSpd, agent.currentSpd + 500) - * 1.85 - ): - if abs(angle_degrees) <= clamp(5, 0, _distance / 1000): - if not agent.onWall and flips_enabled and goForward == agent.forward: - if not goForward: - agent.setHalfFlip() - else: - agent.setJumping(1) - - wallFlip = False - if agent.onWall and target[2] <= agent.defaultElevation: - bot_wall = which_wall(agent.me.location) - index = 0 - if bot_wall == 0 or bot_wall == 2: - index = 1 - _target = target.scale(1) - _target.data[index] = agent.me.location[index] - wall_localTarget = toLocal(_target, agent.me) - wall_angle = math.atan2(wall_localTarget[1], wall_localTarget[0]) - wall_angle_degrees = math.degrees(wall_angle) - if not goForward: - wall_angle_degrees -= 180 - wall_angle_degrees = correctAngle(wall_angle_degrees) - # print(f"wall angle is: {wall_angle_degrees}") - - if abs(wall_angle_degrees) < 5: - if ( - 2500 > agent.me.location[2] > 300 - and (tta > 1.5 or _distance / agent.currentSpd > 1.5) - and (agent.forward == goForward) - ): - agent.setJumping(-1) - # print("jumping off wall!") - elif ( - agent.me.location[2] <= 500 - and not agent.demo_monster - and agent.currentHit.hit_type != 2 - and (tta > 1.5 or _distance / agent.currentSpd > 1.5) - and (agent.forward == goForward) - ): - wallFlip = True - - boost = False - - steer, handbrake = rockSteer(angle, _distance, modifier=300, turnLimit=1) - - if not going_for_aerial and (40 < abs(angle_degrees) < 140) and floppies: - if 250 > _distance > 30: - if agent.currentSpd <= 600: - if ( - not agent.dribbling - and not agent.onWall - and agent.currentHit.hit_type != 1 - and agent.currentHit.hit_type != 4 - ): - if tta < 0.5: - agent.setJumping(6, target=target) - # print(f"YOLO!!! {agent.time}") - if ( - abs(90 - angle_degrees) * 10 >= _distance > 30 - and agent.currentSpd <= 600 - and not maintainSpeed - and not agent.dribbling - and not demos - and not agent.demo_monster - ): - handbrake = True - # print(f"Scrambling! {agent.time}") - # else: - # steer, handbrake = newSteer(angle) - - - if not goForward and not agent.forward: - steer = -steer - - if goForward != agent.forward: - #if not agent.forward: - steer = -steer - - if avoiding: - steer = -steer - - nearTurnLimit = False - turn_limiter = 10 - - speed_limit = maxSpeedAdjustment(agent, localTarget, angle_degrees, _distance, path_info[1], fudging) - if abs(angle_degrees) > 90: - limit = max(agent.currentSpd, 600) - if limit < speed_limit: - speed_limit = limit - - if not kickoff and not maintainSpeed and not demos and not agent.demo_monster and not agent.dribbling: - idealSpeed = clamp(speed_limit, 0, idealSpeed) - # if agent.currentSpd > idealSpeed or abs(agent.currentSpd - idealSpeed) < turn_limiter: - if speed_limit - agent.currentSpd <= 75: - nearTurnLimit = True - steer = 1 if steer > 0 else -1 - - if agent.currentSpd > idealSpeed: - # if going_for_aerial or len(agent.allies) > 0: - required_decel = idealSpeed - agent.currentSpd - braking_power = -3500 * tta - coasting_power = -525 * tta - mode = 0 - if going_for_aerial or (nearTurnLimit and not maintainSpeed): # not agent.dribbling - mode = 1 - - if mode == 0: - if agent.rotationNumber == 1 and ( - _distance < 50 - or tta < agent.fakeDeltaTime * 5 - or nearTurnLimit - or agent.dribbling - #or brake_time(agent.currentSpd)+agent.fakeDeltaTime*4 > tta - or (braking_power - (agent.active_decel * 2) * -1) < agent.currentSpd - ): - # if _distance < 50 or tta < agent.fakeDeltaTime * 6 or agent.dribbling or ( - # braking_power - (agent.active_decel * 4) * -1) < agent.currentSpd: - mode = 1 - elif agent.rotationNumber == 1 and agent.currentHit.shotlimit != None: - if ( - tta > (agent.currentHit.shotlimit + (agent.fakeDeltaTime * 3)) - and agent.currentSpd * tta < _distance - ): - mode = 0 - else: - mode = 1 - else: - mode = 0 - # mode = 1 - - if mode == 0: - if braking_power + (3500 * agent.fakeDeltaTime * 2) < required_decel: - #if brake_time(agent.currentSpd) + agent.fakeDeltaTime * 4 < tta: - throttle = 0.1 if goForward else -0.1 - else: - throttle = -1 if goForward else 1 - - elif mode == 1: - if required_decel < agent.active_decel: - throttle = -1 if goForward else 1 - elif required_decel <= agent.coast_decel: - if ( - agent.currentSpd - - agent.coast_decel * (tta / agent.fakeDeltaTime) - <= 0 - ): - throttle = 0 - else: - throttle = -1 if goForward else 1 - else: - throttle = 0.1 if goForward else -0.1 - - else: - print("error in drive controller!", agent.time) - - elif agent.currentSpd < idealSpeed: - if ( - idealSpeed >= agent.currentSpd + boost_req - ): # or idealSpeed >= maxPossibleSpeed: - if ( - agent.me.boostLevel > 0 - and agent.onSurface - and expedite - and agent.currentSpd < (maxPossibleSpeed - 50) - and goForward - and not nearTurnLimit - and idealSpeed >= 1000 - and (inaccurateArrivalEstimatorBoostless(agent, target, onWall=agent.onWall, offset=-offset_dist) > tta) - ): - # print(f"setting boost to true {agent.time}") - boost = True - - if agent.me.boostLevel > 0 and expedite: - minFlipSpeed = maxPossibleSpeed - 500 - else: - minFlipSpeed = 1075 - - if ( - agent.currentSpd > minFlipSpeed - and flips_enabled - #and ((agent.currentHit != None and agent.currentHit.hit_type != 2) or agent.rotationNumber != 1) - ): - if ( - clamp(math.inf, 1, _distance - 90) - > clamp(maxPossibleSpeed, agent.currentSpd, agent.currentSpd + 500) - * 1.85 - or flippant - ): - if abs(angle_degrees) <= clamp(5, 0, _distance / 500): - if not agent.onWall or wallFlip: # or not agent.wallShot: - if agent.onSurface: - if goForward: - agent.setJumping(1) - # print(f"pew pew? {flips_enabled} {agent.boostMonster}") - else: - agent.setHalfFlip() - # agent.stubbornessTimer = 1.7 - # agent.stubborness = agent.stubbornessMax - - else: - if goForward: - throttle = 0.1 - else: - throttle = -0.1 - - handbrake_barrier = clamp(0.9, 0.5, agent.currentSpd / maxPossibleSpeed) - - # if nearTurnLimit and not maintainSpeed and not fudging and abs(angle_degrees) > 20: - # handbrake = True - - if handbrake: - if abs(agent.me.avelocity[2]) < handbrake_barrier or agent.forward != goForward: - handbrake = False - if agent.currentSpd < speed_limit and not nearTurnLimit: - handbrake = False - - if handbrake: - boost = False - - if maintainSpeed or demos: # or agent.demo_monster: - handbrake = False - throttle = 1 - if not agent.demo_monster and not demos: - boost = False - # print(f'setting boost false {agent.time}') - - if boost: - if not agent.forward or not goForward: - boost = False - - if kickoff: - handbrake = False - throttle = 1 - if agent.currentSpd < 2200: - boost = True - - controler = SimpleControllerState() - controler.steer = steer - controler.throttle = throttle - controler.handbrake = handbrake - controler.boost = boost - - return controler - - -def Gsteer(angle): - final = ((10 * angle + sign(angle)) ** 3) / 20 - return clamp(1, -1, final) - - -def rockSteer(angle, distance, forward=True, modifier=600, turnLimit=1): - turn = Gsteer(angle) - # turn = clamp(1,-1,angle*4) - slide = False - distanceMod = clamp(10, 0.3, distance / modifier) - _angle = correctAngle(math.degrees(angle)) - - adjustedAngle = _angle / distanceMod - if abs(turn) >= turnLimit: - if abs(adjustedAngle) > 90: - slide = True - - return turn, slide - - -def isBallHitNearWall(ball_vec, defaultDistance=120): - if abs(ball_vec[0]) < 950: - return False - - if ball_vec[0] > 4096 - defaultDistance: - return True - if ball_vec[0] < -4096 + defaultDistance: - return True - - if ball_vec[1] < -5120 + defaultDistance: - return True - - if ball_vec[1] > 5120 - defaultDistance: - return True - - return False - - -def isBallNearWall(ballstruct, defaultDistance=120): - if abs(ballstruct.physics.location.x) < 950: - return False - - if ballstruct.physics.location.x > 4096 - defaultDistance: - return True - if ballstruct.physics.location.x < -4096 + defaultDistance: - return True - - if ballstruct.physics.location.y < -5120 + defaultDistance: - return True - - if ballstruct.physics.location.y > 5120 - defaultDistance: - return True - - return False - - -def isBallHittable_hit(hit, agent, maxHeight, defaultDistance=110): - if agent.wallShotsEnabled: - multi = 20 - else: - multi = 1 - if hit.pred_vector[2] <= maxHeight: - return True - if hit.pred_vector[0] > 4096 - defaultDistance: - if hit.pred_vector[2] <= 200 * multi: - return True - if hit.pred_vector[0] < -4096 + defaultDistance: - if hit.pred_vector[2] <= 200 * multi: - return True - if len(agent.allies) > 0: - if hit.pred_vector[1] < -5120 + defaultDistance: - if hit.pred_vector[2] <= 200 * multi: - if abs(hit.pred_vector[0]) > 900: - return True - if hit.pred_vector[1] > 5120 - defaultDistance: - if hit.pred_vector[2] <= 200 * multi: - if abs(hit.pred_vector[0]) > 900: - return True - - return False - - -def isBallHittable(ballStruct, agent, maxHeight, defaultDistance=110): - # multi = clamp(3, 1, len(agent.allies)+1) - # offset = (agent.carHeight + 93) * .9 - if agent.wallShotsEnabled: - multi = 20 - else: - multi = 1 - if ballStruct.physics.location.z <= maxHeight: - return True - if ballStruct.physics.location.x > 4096 - defaultDistance: - if ballStruct.physics.location.z <= 200 * multi: - return True - if ballStruct.physics.location.x < -4096 + defaultDistance: - if ballStruct.physics.location.z <= 200 * multi: - return True - if len(agent.allies) > 0: - if ballStruct.physics.location.y < -5120 + defaultDistance: - if ballStruct.physics.location.z <= 200 * multi: - if abs(ballStruct.physics.location.x) > 900: - return True - if ballStruct.physics.location.y > 5120 - defaultDistance: - if ballStruct.physics.location.z <= 200 * multi: - if abs(ballStruct.physics.location.x) > 900: - return True - - return False - - -def find_ally_hit(agent, ally): - enemyOnWall = False - enemyInAir = False - enemyOnGround = True - enemyTarget = None - found = False - jumpshotLimit = agent.doubleJumpLimit - if ally and not ally.demolished: - - if ally.onSurface: - if ally.location[2] > 100: - enemyOnWall = True - # enemyOnGround = False - else: - enemyOnGround = True - else: - if ally.boostLevel > 0: - if ally.location[2] > 500: - enemyInAir = True - else: - enemyInAir = False - enemyOnGround = True - else: - enemyInAir = False - enemyOnGround = True - - for i in range(0, agent.ballPred.num_slices): - if i % 5 != 0: - continue - pred = agent.ballPred.slices[i] - location = convertStructLocationToVector(pred) - if pred.game_seconds - agent.gameInfo.seconds_elapsed <= 0: - continue - - if enemyOnWall: - if isBallNearWall(pred, defaultDistance=400): - timeToTarget, distance = enemyWallMovementEstimator( - ally, location, agent - ) - if ( - timeToTarget - < pred.game_seconds - agent.gameInfo.seconds_elapsed - ): - found = True - ally_hit = predictionStruct(location, pred.game_seconds) - break - - if enemyOnGround: - if location[2] > jumpshotLimit + agent.allowableJumpDifference: - continue - else: - timeToTarget = enemyArrivalEstimator(agent, ally, location) - if ( - timeToTarget - <= pred.game_seconds - agent.gameInfo.seconds_elapsed - ): - found = True - ally_hit = predictionStruct(location, pred.game_seconds) - break - - if enemyInAir: - if ally.velocity[2] > 0 and ally.boostLevel > 0: - if findDistance(location, ally.location) < 2300 * ( - pred.game_seconds - agent.gameInfo.seconds_elapsed - ): - found = True - ally_hit = predictionStruct(location, pred.game_seconds) - break - - if not found: - ally_hit = predictionStruct( - convertStructLocationToVector( - agent.ballPred.slices[agent.ballPred.num_slices - 2] - ), - agent.time + 20, - ) - - return ally_hit - - -def findEnemyHits(agent): - enemyOnWall = False - enemyInAir = False - enemyOnGround = True - enemyTarget = None - found = False - jumpshotLimit = agent.doubleJumpLimit - if agent.closestEnemyToBall: - - # if agent.closestEnemyToBall.onSurface: - if agent.closestEnemyToBall.location[2] > 200: - enemyOnWall = True - # enemyOnGround = False - else: - enemyOnGround = True - # else: - # if agent.closestEnemyToBall.boostLevel > 0: - # if agent.closestEnemyToBall.location[2] > 350: - # enemyInAir = True - # else: - # enemyOnGround = True - # else: - # enemyInAir = False - # enemyOnGround = True - - for i in range(0, agent.ballPred.num_slices): - if i % 5 != 0: - continue - pred = agent.ballPred.slices[i] - if pred.game_seconds - agent.gameInfo.seconds_elapsed <= 0: - continue - location = convertStructLocationToVector(pred) - - if ( - isBallNearWall(pred, defaultDistance=250) - and location[2] > jumpshotLimit - ): - if enemyOnWall: - timeToTarget = enemyArrivalEstimator( - agent, agent.closestEnemyToBall, location - ) - - if enemyOnGround: - timeToTarget, distance = enemyWallMovementEstimator( - agent.closestEnemyToBall, location, agent - ) - - if timeToTarget < pred.game_seconds - agent.gameInfo.seconds_elapsed: - agent.enemyBallInterceptDelay = ( - pred.game_seconds - agent.gameInfo.seconds_elapsed - ) - agent.enemyTargetVec = location - found = True - agent.enemyPredTime = pred.game_seconds - agent.enemyTargetVel = convertStructVelocityToVector( - agent.ballPred.slices[i] - ) - # print(f"enemy on wall {timeToTarget}") - break - - if enemyOnGround: - if location[2] > jumpshotLimit: - continue - else: - timeToTarget = enemyArrivalEstimator( - agent, agent.closestEnemyToBall, location - ) - if ( - timeToTarget - <= pred.game_seconds - agent.gameInfo.seconds_elapsed - ): - agent.enemyBallInterceptDelay = ( - pred.game_seconds - agent.gameInfo.seconds_elapsed - ) - agent.enemyTargetVec = location - found = True - agent.enemyPredTime = pred.game_seconds - agent.enemyTargetVel = convertStructVelocityToVector( - agent.ballPred.slices[i] - ) - # print(f"enemy Delay: {agent.enemyBallInterceptDelay}, my Delay: {agent.ballDelay} || {agent.contested} || {agent.timid}") - break - - if enemyInAir: - if location.data[2] <= agent.closestEnemyToBall.location.data[2] or ( - location.data[2] >= agent.closestEnemyToBall.location.data[2] - and agent.closestEnemyToBall.velocity.data[2] > -50 - ): - # print(agent.closestEnemyToBall.velocity.data[2]) - distance = ( - findDistance(location, agent.closestEnemyToBall.location) - 150 - ) - _time = pred.game_seconds - agent.gameInfo.seconds_elapsed - - wrong_intercept_time = inaccurateArrivalEstimatorHacked( - agent.closestEnemyToBall, - agent.closestEnemyToBall.location, - location, - agent.gravity, - ) - - if ( - wrong_intercept_time - <= pred.game_seconds - agent.gameInfo.seconds_elapsed - ): - agent.enemyBallInterceptDelay = pred.game_seconds - agent.time - agent.enemyTargetVec = location - found = True - agent.enemyPredTime = pred.game_seconds - agent.enemyTargetVel = convertStructVelocityToVector( - agent.ballPred.slices[i] - ) - print(f"Found aerial threat! {agent.time}") - print( - f"distance: {int(distance)} , time: {_time} , possible distance: {int(2300 * _time)}" - ) - break - - if not found: - agent.enemyBallInterceptDelay = 6 - agent.enemyTargetVec = convertStructLocationToVector( - agent.ballPred.slices[agent.ballPred.num_slices - 2] - ) - agent.enemyTargetVel = convertStructVelocityToVector( - agent.ballPred.slices[agent.ballPred.num_slices - 2] - ) - agent.enemyPredTime = agent.time + 6 - # print("got here") - - -def npVector(nparray): - return Vector([nparray[0], nparray[1], nparray[2]]) - - -def convertToArray(agent): - predictions = np.ctypeslib.as_array(agent.ballPred.slices).view(agent.dtype)[ - : agent.ballPred.num_slices - ] - - -def newConvertToArray(agent): - buf_from_mem = ctypes.pythonapi.PyMemoryView_FromMemory - buf_from_mem.restype = ctypes.py_object - buf_from_mem.argtypes = (ctypes.c_void_p, ctypes.c_int, ctypes.c_int) - ball_prediction = agent.ballPred - - buffer = buf_from_mem( - ctypes.addressof(ball_prediction.slices), - agent.Dtype.itemsize * ball_prediction.num_slices, - 0x100, - ) - return np.frombuffer(buffer, agent.Dtype) - - -# def find_pred_at_time(agent, _time): -# t_offset = 1.0 / 120.0 -# pred = None -# for i in range(0, agent.ballPred.num_slices): -# if _time < agent.ballPred.slices[i].game_seconds + t_offset: -# pred = agent.ballPred.slices[i] -# break -# return pred - - -def find_pred_at_time(agent, _time): - start_time = agent.ballPred.slices[0].game_seconds - approx_index = int( - (_time - start_time) * 60 - ) # We know that there are 60 slices per second. - if 0 <= approx_index < agent.ballPred.num_slices: - return agent.ballPred.slices[approx_index] - return None - - -def determine_if_shot_goalward(shot_vel: Vector, team: int): - if shot_vel[1] * sign(team) > 5: - return True - return False - - -def calculate_delta_acceleration( - displacement: Vector, initial_velocity: Vector, time: float, gravity: float -) -> Vector: - # Adapated from dacoolone's tutorial - time = clamp(10, 0.000001, time) - return Vector( - [ - (2 * (displacement[0] - initial_velocity[0] * time)) / (time * time), - (2 * (displacement[1] - initial_velocity[1] * time)) / (time * time), - (2 * (displacement[2] - initial_velocity[2] * time)) / (time * time) - - gravity, - ] - ) - - -def validate_ground_shot(agent, groundHit, grounder_cutoff): - if groundHit.time_difference() <= 0: - return False - offset = agent.reachLength # if agent.team == 0 else agent.groundReachLength - if groundHit.pred_vector[2] <= grounder_cutoff: - if not agent.onWall: - timeToTarget = inaccurateArrivalEstimator( - agent, groundHit.pred_vector, False, offset=offset - ) - else: - timeToTarget = new_ground_wall_estimator(agent, groundHit.pred_vector)[0] - - if timeToTarget < groundHit.time_difference(): - return True - - return False - - -def validate_jump_shot( - agent, jumpshotHit, grounder_cutoff, jumper_cutoff, doublejump_cutoff -): - if jumpshotHit.time_difference() <= 0: - return False - offset = agent.reachLength - if ( - grounder_cutoff < jumpshotHit.pred_vector[2] < jumper_cutoff - ): - if isBallHittable_hit(jumpshotHit, agent, jumper_cutoff): - if not agent.onWall: - distance = distance2D(jumpshotHit.pred_vector, agent.me.location) - timeToTarget = inaccurateArrivalEstimator( - agent, jumpshotHit.pred_vector, False, offset=offset - ) - else: - timeToTarget, distance, valid = new_ground_wall_estimator( - agent, jumpshotHit.pred_vector - ) - - if timeToTarget <= jumpshotHit.time_difference(): - jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array(agent.me.velocity.data, dtype=np.dtype(float)), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array(agent.me.location.data, dtype=np.dtype(float)), - float32(agent.defaultElevation), - float32(jumpshotHit.time_difference()), - float32(jumpshotHit.pred_vector[2]), - False, - ) - jumpshotHit.jumpSim = jumpSim - if ( - abs(jumpSim[2] - jumpshotHit.pred_vector[2]) - <= agent.ball_size - ): - - if jumpshotHit.time_difference() > jumpSim[3]: - #jumpshotHit.jumpSim = jumpSim - return True - - return False - - -def validate_double_jump_shot( - agent, doubleJumpShotHit, jumper_cutoff, doublejump_cutoff -): - if doubleJumpShotHit.time_difference() < 0: - return False - offset = agent.reachLength # if agent.team == 0 else agent.groundReachLength - if ( - jumper_cutoff < doubleJumpShotHit.pred_vector[2] <= doublejump_cutoff - ): - if isBallHittable_hit(doubleJumpShotHit, agent, doublejump_cutoff): - if not agent.onWall: - distance = distance2D(doubleJumpShotHit.pred_vector, agent.me.location) - timeToTarget = inaccurateArrivalEstimator( - agent, doubleJumpShotHit.pred_vector, False, offset=offset - ) - else: - timeToTarget, distance, valid = new_ground_wall_estimator( - agent, doubleJumpShotHit.pred_vector - ) - - if timeToTarget <= doubleJumpShotHit.time_difference(): - jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array(agent.me.velocity.data, dtype=np.dtype(float)), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array(agent.me.location.data, dtype=np.dtype(float)), - float32(agent.defaultElevation), - float32(doubleJumpShotHit.time_difference()), - float32(doubleJumpShotHit.pred_vector[2]), - True, - ) - doubleJumpShotHit.jumpSim = jumpSim - if ( - abs(jumpSim[2] - doubleJumpShotHit.pred_vector[2]) - <= agent.allowableJumpDifference - ): - - if doubleJumpShotHit.time_difference() > jumpSim[3]: - return True - - return False - - -def validate_wall_shot(agent, wallshot_hit, grounder_cutoff): - pred_vec = wallshot_hit.pred_vector - tth = wallshot_hit.time_difference() - if tth <= 0: - return False - offset = agent.groundReachLength - - if isBallHittable_hit(wallshot_hit, agent, grounder_cutoff): - if isBallHitNearWall(pred_vec, defaultDistance=grounder_cutoff): - if agent.onWall: - distance = findDistance(agent.me.location, pred_vec) - timeToTarget = inaccurateArrivalEstimator( - agent, pred_vec, True, offset=offset - ) - - if timeToTarget <= tth: - agent.targetDistance = distance - agent.timeEstimate = timeToTarget - return True - - else: - timeToTarget, distance, valid = new_ground_wall_estimator( - agent, pred_vec - ) - if timeToTarget <= tth: - if valid: - agent.targetDistance = distance - agent.timeEstimate = timeToTarget - return True - - return False - - -def validate_aerial_shot(agent, aerial_shot: hit, aerial_min, doubleCutOff): - pred_vec = aerial_shot.pred_vector - pred_vel = aerial_shot.pred_vel - target = aerial_shot.aim_target - tth = aerial_shot.time_difference() - offset = agent.reachLength - center = Vector([0, 5500 * -sign(agent.team), 0]) - myGoal = Vector([0, 5200 * sign(agent.team), 0]) - if tth <= 0: - return False - - if agent.me.boostLevel >= 1 or not agent.onSurface: - if agent.me.velocity[2] > -50 or pred_vec[2] < agent.me.location[2]: - if inaccurateArrivalEstimator(agent, pred_vec, False, offset=offset) < tth: - - aerial_accepted = False - takeoff_tth = tth - agent.takeoff_speed - # accel_req_limit = 1057 - accel_req_limit = agent.aerial_accel_limit - - if agent.onSurface and not agent.aerialsLimited: - if tth > agent.takeoff_speed: - if pred_vec[2] > doubleCutOff + agent.min_aerial_buffer: - if agent.me.location[1] * sign(agent.team) > pred_vec[ - 1 - ] * sign(agent.team): - - # if not agent.onWall: - # accel_req_limit = 1057 - - aerial_jump_sim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array( - agent.me.velocity.data, dtype=np.dtype(float) - ), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array( - agent.me.location.data, dtype=np.dtype(float) - ), - float32(agent.defaultElevation), - float32(agent.takeoff_speed), - float32(pred_vec[2]), - True, - ) - aerial_shot.jumpSim = aerial_jump_sim - - delta_a = calculate_delta_acceleration( - target - Vector(aerial_jump_sim[4]), - Vector(aerial_jump_sim[5]), - takeoff_tth, - agent.gravity, - ) - - if delta_a.magnitude() < accel_req_limit: - total_req_delta_a = ( - delta_a.magnitude() * takeoff_tth - ) - if ( - total_req_delta_a - < agent.calculate_delta_velocity(takeoff_tth) - ): - # if delta_a.magnitude() < agent.calculate_delta_velocity( - # takeoff_tth - # ): - if ( - agent.me.velocity + delta_a - ).magnitude() < maxPossibleSpeed: - aerial_accepted = True - - ideal_velocity = Vector(aerial_jump_sim[5]) + delta_a - if ideal_velocity.magnitude() >= maxPossibleSpeed: - aerial_accepted = False - - else: - if pred_vec[2] > agent.aerial_min: - delta_a = calculate_delta_acceleration( - target - agent.me.location, - agent.me.velocity, - tth, - agent.gravity, - ) - accel_req_limit = clamp( - 1000, 750, 1060 - (((6 - tth) * 0.1)) * 100, - ) - # accel_req_limit = clamp( - # 1060, 850, 1060 - (((6 - tth) * 0.05)) * 100, - # ) - # accel_req_limit = 1057 - - if delta_a.magnitude() <= accel_req_limit: - total_req_delta_a = delta_a.magnitude() * tth - if total_req_delta_a < agent.calculate_delta_velocity(tth): - aerial_accepted = True - - if aerial_accepted: - return True - - return False - - -def findHits(agent, grounder_cutoff, jumpshot_cutoff, doubleCutOff, resolution=3): - ground_shot = None - jumpshot = None - wall_shot = None - doubleJumpShot = None - ballInGoal = None - aerialShot = None - catchCanidate = None - in_goalbox = in_goal_check(agent) - agent.first_hit = None - - leftPost = Vector([893 * sign(agent.team), 5120 * -sign(agent.team), 0]) - center = Vector([0, 5500 * -sign(agent.team), 0]) - rightPost = Vector([893 * -sign(agent.team), 5120 * -sign(agent.team), 0]) - myGoal = Vector([0, 5200 * sign(agent.team), 0]) - - o_max_y = 5350 - d_max_y = 5210 - # d_max_y = 5200 - - offset = agent.groundReachLength - ground_offset = agent.groundReachLength - reposition = False - - aboveThreshold = False - # testing - checkAngles = len(agent.allies) < 1 - - grounded = True - - agent.goalPred = None - agent.scorePred = None - pred = agent.ballPred.slices[0] - aerialsValid = True - - if agent.demo_monster or agent.me.demolished: - ground_shot = hit( - agent.time, - agent.time + 6, - 0, - convertStructLocationToVector( - agent.ballPred.slices[agent.ballPred.num_slices - 1] - ), - convertStructVelocityToVector( - agent.ballPred.slices[agent.ballPred.num_slices - 1] - ), - False, - 6, - # [agent.enemyGoalLocations[0],agent.enemyGoalLocations[2]] - agent.team, - ) - agent.first_hit = ground_shot - - return ground_shot, jumpshot, wall_shot, doubleJumpShot, aerialShot - - early_exit = len(agent.allies) > 1 - scorable = None - - start_time = agent.time - if agent.touch.player_index == agent.index: - start_time = agent.touch.time_seconds + 1 - for i in range(0, agent.ballPred.num_slices): - if i > 30 and not i % resolution: - continue - - pred = agent.ballPred.slices[i] - tth = pred.game_seconds - agent.gameInfo.seconds_elapsed - - if tth <= 0: - continue - - pred_vec = convertStructLocationToVector(pred) - pred_vel = convertStructVelocityToVector(pred) - offensive = pred_vec[1] * sign(agent.team) < 0 - - if grounded: - if pred_vec[1] > grounder_cutoff: - agent.grounded_timer = tth - grounded = False - - grounder = False - if not aboveThreshold: - if pred.physics.location.z > doubleCutOff: - aboveThreshold = True - - if aboveThreshold: - if pred.physics.location.z <= doubleCutOff: - aerialsValid = False - - if not early_exit or agent.first_hit is None: - - if ( - findDistance(agent.me.location, pred_vec) - agent.aerial_reach - ) <= 2300 * tth: - #if checkAngles: - scorable = is_shot_scorable(agent.team, pred_vec) - - if ground_shot is None or wall_shot is None: - if isBallHittable(pred, agent, grounder_cutoff): - wallshot = isBallNearWall(pred) - # testing - if not wallshot or (pred_vec[2] <= grounder_cutoff): - grounder = True - if ground_shot is None: - if not agent.onWall: - timeToTarget = inaccurateArrivalEstimator( - agent, - Vector( - [ - pred.physics.location.x, - pred.physics.location.y, - pred.physics.location.z, - ] - ), - False, - offset=ground_offset, - reposition=reposition - ) - else: - timeToTarget = new_ground_wall_estimator( - agent, pred_vec - )[0] - - if timeToTarget <= tth: - # testing - if (scorable or agent.first_hit == None or not checkAngles): - ground_shot = hit( - agent.time, - pred.game_seconds, - 0, - pred_vec, - convertStructVelocityToVector(pred), - True, - timeToTarget, - agent.team, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = ground_shot - - if checkAngles and not scorable: - ground_shot = None - - # if early_exit: - # return ( - # ground_shot, - # jumpshot, - # wall_shot, - # doubleJumpShot, - # aerialShot, - # ) - else: - if ( - wall_shot is None - and wallshot - and not in_goalbox - ): - if offensive or pred_vel[1] * sign(agent.team) < 10: - _wall = which_wall(pred_vec) - if not ( - (agent.team == 0 and _wall == 0) - or (agent.team == 1 and _wall == 2) - ): - if agent.onWall: - distance = findDistance( - agent.me.location, pred_vec - ) - timeToTarget = inaccurateArrivalEstimator( - agent, pred_vec, True, offset=ground_offset,reposition=reposition - ) - - if timeToTarget <= tth: - if ( - scorable - or agent.first_hit is None - or not checkAngles - ): - wall_shot = hit( - agent.time, - pred.game_seconds, - 2, - pred_vec, - convertStructVelocityToVector(pred), - True, - timeToTarget, - # [agent.enemyGoalLocations[0],agent.enemyGoalLocations[2]], - agent.team, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = wall_shot - if checkAngles and not scorable: - wall_shot = None - agent.targetDistance = distance - agent.timeEstimate = timeToTarget - # if early_exit and not agent.dribbler: - # return ground_shot, jumpshot, wall_shot, doubleJumpShot, aerialShot - - else: - if wallshot: - ( - timeToTarget, - distance, - valid, - ) = new_ground_wall_estimator( - agent, pred_vec - ) - if timeToTarget <= tth: - if valid: - if ( - scorable - or agent.first_hit is None - or not checkAngles - ): - wall_shot = hit( - agent.time, - pred.game_seconds, - 2, - pred_vec, - convertStructVelocityToVector( - pred - ), - True, - timeToTarget, - # [agent.enemyGoalLocations[0],agent.enemyGoalLocations[2]], - agent.team, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = wall_shot - if ( - checkAngles - and not scorable - ): - wall_shot = None - agent.targetDistance = distance - agent.timeEstimate = ( - timeToTarget - ) - - if ( - jumpshot is None - and pred.game_seconds > start_time - and not agent.aerial_hog - ): - if ( - grounder_cutoff < pred.physics.location.z <= jumpshot_cutoff - and tth >= agent.fakeDeltaTime * 6 - ): - - if isBallHittable(agent.ballPred.slices[i], agent, jumpshot_cutoff): - if not agent.onWall: - distance = distance2D(pred_vec, agent.me.location) - timeToTarget = inaccurateArrivalEstimator( - agent, pred_vec, False, offset=offset,reposition=reposition - ) - else: - timeToTarget, distance, valid = new_ground_wall_estimator( - agent, pred_vec - ) - - if timeToTarget <= tth: - jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array(agent.me.velocity.data, dtype=np.dtype(float)), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array(agent.me.location.data, dtype=np.dtype(float)), - float32(agent.defaultElevation), - float32(tth), - float32(pred.physics.location.z), - False, - ) - - # print(f"{jumpSim[2],pred.physics.location.z,tth}") - if ( - abs(jumpSim[2] - pred.physics.location.z) - <= agent.ball_size - ): - # if jumpSim[2] + agent.allowableJumpDifference >= pred.physics.location.z: - if tth > jumpSim[3]: - if ( - scorable - or agent.first_hit is None - or not checkAngles - ): - - jumpshot = hit( - agent.time, - pred.game_seconds, - 1, - pred_vec, - convertStructVelocityToVector(pred), - True, - timeToTarget, - # [agent.enemyGoalLocations[0], agent.enemyGoalLocations[2]], - agent.team, - jumpSim=jumpSim, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = jumpshot - if checkAngles and not scorable: - jumpshot = None - - if agent.DoubleJumpShotsEnabled: - if ( - doubleJumpShot is None - and pred.game_seconds > start_time - and not agent.aerial_hog - ): - if ( - jumpshot_cutoff < pred_vec[2] <= doubleCutOff - and ( - pred_vec[2] < 500 - or not butterZone(pred_vec) - or pred_vec.data[1] * sign(agent.team) > 0 - ) - and tth >= 0.2 - ): - if isBallHittable( - agent.ballPred.slices[i], agent, doubleCutOff - ): - if not agent.onWall: - distance = distance2D(pred_vec, agent.me.location) - timeToTarget = inaccurateArrivalEstimator( - agent, pred_vec, False, offset=offset,reposition=reposition - ) - else: - ( - timeToTarget, - distance, - valid, - ) = new_ground_wall_estimator(agent, pred_vec) - # filtering out predictions that would likely hit top bar on offfense - if pred_vec[1] * -sign(agent.team) > 0: - if butterZone(pred_vec): - if pred_vec[2] > 880 - (93.5 * 2): - timeToTarget = 100 # setting simulated arrival time to fake number to dissuade attempt - - if timeToTarget <= tth: - # jumpSim = jumpSimulatorNormalizing(agent, tth, pred.physics.location.z) - jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array( - agent.me.velocity.data, dtype=np.dtype(float) - ), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array( - agent.me.location.data, dtype=np.dtype(float) - ), - float32(agent.defaultElevation), - float32(tth), - float32(pred.physics.location.z), - True, - ) - # print(f"target height: {pred_vec[2]} simulated max height: {jumpSim[2]}") - - # print(f"{jumpSim[2],pred.physics.location.z,tth}") - if ( - abs(jumpSim[2] - pred.physics.location.z) - <= agent.allowableJumpDifference - ): - # if jumpSim[2] + agent.allowableJumpDifference >= pred.physics.location.z: - if tth > jumpSim[3]: - if ( - scorable - or agent.first_hit is None - or not checkAngles - ): - doubleJumpShot = hit( - agent.time, - pred.game_seconds, - 4, - pred_vec, - convertStructVelocityToVector(pred), - True, - timeToTarget, - # [agent.enemyGoalLocations[0], agent.enemyGoalLocations[2]], - agent.team, - jumpSim=jumpSim, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = doubleJumpShot - if checkAngles and not scorable: - doubleJumpShot = None - - if ( - aerialShot is None - and agent.first_hit is None - and agent.goalPred is None - and agent.scorePred is None - and agent.aerialsEnabled - and not in_goalbox - and (agent.onSurface or tth < agent.aerial_timer_limit) - ): - aerial_jump_sim = None - if ( - pred_vec[2] < 760 - or abs(pred_vec[0]) > 2000 - or pred_vec[2] - < (5120 - (pred_vec[1] * -sign(agent.team))) * agent.aerial_slope - or agent.aerial_hog - ): - - if ( - (agent.me.boostLevel >= 1 or not agent.onSurface) - and (not checkAngles or scorable) - ): - - if ( - agent.me.velocity[2] > -50 - or pred_vec[2] < agent.me.location[2] - ): - if ( - inaccurateArrivalEstimator( - agent, pred_vec, False, offset=offset,reposition=reposition - ) - < tth - ): - - if distance2D(pred_vec, myGoal) < 3000 or ( - agent.me.location[1] * sign(agent.team) < pred_vec[1] * sign( - agent.team) and not offensive): - target = aim_wallshot_naive_hitless( - agent, - pred_vec, - pred_vel, - agent.aerial_reach * 0.7, - ) - - # elif ( - # distance2D(pred_vec, center) > 2000 - # or pred_vec[2] < 760 - # ): - else: - target = get_aim_vector( - agent, - center + Vector([0, 0, pred_vec[2]]), - pred_vec, - pred_vel, - agent.aerial_reach * 0.8, - )[0] - # else: - # target = get_aim_vector( - # agent, - # Vector([0, 5120 * -sign(agent.team), 0]), - # pred_vec, # + Vector([0, 0, 25]), - # pred_vel, - # agent.aerial_reach * 0.85, - # )[0] - - aerial_accepted = False - takeoff_tth = tth - agent.takeoff_speed - accel_req_limit = agent.aerial_accel_limit - if agent.onSurface and not agent.aerialsLimited: - # if tth > 0.28 and ( - if ( - tth > agent.takeoff_speed - and abs(agent.me.location[1]) < 5140 - ): - if ( - pred_vec[2] - > doubleCutOff + agent.min_aerial_buffer - ): # and tth < agent.enemyBallInterceptDelay: - # testing - if agent.me.location[1] * sign( - agent.team - ) > pred_vec[1] * sign(agent.team): - - # if not agent.onWall: - # accel_req_limit = 1057 - - aerial_jump_sim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array( - agent.me.velocity.data, - dtype=np.dtype(float), - ), - np.array( - agent.up.data, - dtype=np.dtype(float), - ), - np.array( - agent.me.location.data, - dtype=np.dtype(float), - ), - float32(agent.defaultElevation), - float32(agent.takeoff_speed), - float32(pred.physics.location.z), - True, - ) - - delta_a = calculate_delta_acceleration( - target - Vector(aerial_jump_sim[4]), - Vector(aerial_jump_sim[5]), - takeoff_tth, - agent.gravity, - ) - - if ( - delta_a.magnitude() - < accel_req_limit - ): - total_req_delta_a = ( - delta_a.magnitude() - * takeoff_tth - ) - if ( - total_req_delta_a + 5 - < agent.calculate_delta_velocity( - takeoff_tth - ) - ): - if ( - agent.me.velocity + delta_a - ).magnitude() < maxPossibleSpeed: - aerial_accepted = True - - ideal_velocity = ( - Vector(aerial_jump_sim[5]) + delta_a - ) - if ( - ideal_velocity.magnitude() - >= maxPossibleSpeed - ): - aerial_accepted = False - - else: - if agent.me.location[2] > 500: - - if pred_vec[2] > agent.aerial_min: - delta_a = calculate_delta_acceleration( - target - agent.me.location, - agent.me.velocity, - tth, - agent.gravity, - ) - - if delta_a.magnitude() <= accel_req_limit: - req_delta_v = delta_a.magnitude() * tth - if ( - req_delta_v + 10 - < agent.calculate_delta_velocity( - tth - ) - ): - aerial_accepted = True - ideal_velocity = agent.me.velocity + delta_a - if ( - ideal_velocity.magnitude() - >= maxPossibleSpeed - ): - aerial_accepted = False - - if aerial_accepted and agent.aerialsLimited: - if findDistance( - agent.me.location, pred_vec - ) > 1000 or pred_vec[1] * sign( - agent.team - ) > agent.me.location[ - 1 - ] * sign( - agent.team - ): - aerial_accepted = False - - if aerial_accepted: - # modded_loc = pred_vec.scale(1) - # modded_loc.data[0], modded_loc.data[2] = ( - # modded_loc.data[2], - # modded_loc.data[0], - # ) - # - # modded_left = agent.enemyGoalLocations[0].scale(1) - # modded_right = agent.enemyGoalLocations[2].scale(1) - - # modded_left.data[0] = 0 - # modded_right.data[0] = 642 - if ( - scorable - or agent.first_hit is None - or not checkAngles - ): - - _aerial = agent.aerialGetter(pred, target, tth) - - aerialShot = hit( - agent.time, - pred.game_seconds, - 5, - pred_vec, - convertStructVelocityToVector(pred), - True, - tth, - # [agent.enemyGoalLocations[0], agent.enemyGoalLocations[2]], - agent.team, - jumpSim=aerial_jump_sim, - aerialState=_aerial, - aim_target=target, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = aerialShot - if checkAngles and not scorable: - aerialShot = None - - precariousSituation = False - if agent.team == 0: - if pred.physics.location.y <= -d_max_y: - precariousSituation = True - elif agent.team == 1: - if pred.physics.location.y >= d_max_y: - precariousSituation = True - - if agent.scorePred is None: - if not precariousSituation: - if abs(pred.physics.location.y) >= o_max_y: - # (self, location, _time): - agent.scorePred = predictionStruct(pred_vec, pred.game_seconds) - - if precariousSituation: - timeToTarget = inaccurateArrivalEstimator( - agent, - Vector( - [ - pred.physics.location.x, - pred.physics.location.y, - pred.physics.location.z, - ] - ), - False, - offset=offset,reposition=reposition - ) - if ( - agent.ballPred.slices[i].physics.location.z <= grounder_cutoff - and ground_shot is None - ): - ground_shot = hit( - agent.time, - agent.ballPred.slices[i].game_seconds, - 0, - convertStructLocationToVector(agent.ballPred.slices[i]), - convertStructVelocityToVector(agent.ballPred.slices[i]), - False, - timeToTarget, - # [agent.enemyGoalLocations[0],agent.enemyGoalLocations[2]], - agent.team, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = ground_shot - - elif ( - agent.ballPred.slices[i].physics.location.z <= jumpshot_cutoff - and jumpshot is None - ): - # jumpSim = jumpSimulatorNormalizing(agent, tth, pred.physics.location.z, doubleJump=False) - jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array(agent.me.velocity.data, dtype=np.dtype(float)), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array(agent.me.location.data, dtype=np.dtype(float)), - float32(agent.defaultElevation), - float32(tth), - float32(pred.physics.location.z), - False, - ) - # if jumpSim[2] + agent.allowableJumpDifference >= pred.physics.location.z: - # if tth > jumpSim[3]: - jumpshot = hit( - agent.time, - pred.game_seconds, - 1, - convertStructLocationToVector(pred), - convertStructVelocityToVector(pred), - True, - timeToTarget, - # [agent.enemyGoalLocations[0], agent.enemyGoalLocations[2]], - agent.team, - jumpSim=jumpSim, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = jumpshot - - else: - if agent.DoubleJumpShotsEnabled and doubleJumpShot is None: - # jumpSim = jumpSimulatorNormalizing(agent, tth, pred.physics.location.z) - jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array(agent.me.velocity.data, dtype=np.dtype(float)), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array(agent.me.location.data, dtype=np.dtype(float)), - float32(agent.defaultElevation), - float32(tth), - float32(pred.physics.location.z), - True, - ) - doubleJumpShot = hit( - agent.time, - pred.game_seconds, - 4, - convertStructLocationToVector(pred), - convertStructVelocityToVector(pred), - True, - timeToTarget, - # [agent.enemyGoalLocations[0], agent.enemyGoalLocations[2]], - agent.team, - jumpSim=jumpSim, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = doubleJumpShot - - # agent.goalPred = agent.ballPred.slices[i] - agent.goalPred = predictionStruct( - pred_vec, agent.ballPred.slices[i].game_seconds - ) - if ( - ground_shot is None - and jumpshot is None - and wall_shot is None - and doubleJumpShot is None - ): - - if pred_vec[2] <= agent.groundCutOff: - ground_shot = hit( - agent.time, - pred.game_seconds, - 0, - convertStructLocationToVector(agent.ballPred.slices[i]), - convertStructVelocityToVector(agent.ballPred.slices[i]), - False, - tth, - # [agent.enemyGoalLocations[0],agent.enemyGoalLocations[2]], - agent.team, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = ground_shot - elif ( - agent.groundCutOff < pred_vec[2] < agent.doubleJumpLimit - ): - jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array(agent.me.velocity.data, dtype=np.dtype(float)), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array(agent.me.location.data, dtype=np.dtype(float)), - float32(agent.defaultElevation), - float32(tth), - float32(pred.physics.location.z), - False, - ) - jumpshot = hit( - agent.time, - pred.game_seconds, - 1, - convertStructLocationToVector(pred), - convertStructVelocityToVector(pred), - True, - timeToTarget, - # [agent.enemyGoalLocations[0], agent.enemyGoalLocations[2]], - agent.team, - jumpSim=jumpSim, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = jumpshot - - else: - - if agent.DoubleJumpShotsEnabled: - jumpSim = jumpSimulatorNormalizingJit( - float32(agent.gravity), - float32(agent.physics_tick), - np.array(agent.me.velocity.data, dtype=np.dtype(float)), - np.array(agent.up.data, dtype=np.dtype(float)), - np.array(agent.me.location.data, dtype=np.dtype(float)), - float32(agent.defaultElevation), - float32(tth), - float32(pred.physics.location.z), - True, - ) - doubleJumpShot = hit( - agent.time, - pred.game_seconds, - 4, - convertStructLocationToVector(pred), - convertStructVelocityToVector(pred), - True, - timeToTarget, - # [agent.enemyGoalLocations[0], agent.enemyGoalLocations[2]], - agent.team, - jumpSim=jumpSim, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = doubleJumpShot - if grounded: - agent.grounded_timer = tth - grounded = False - # testing - # return ground_shot, jumpshot, wall_shot, doubleJumpShot, aerialShot - - if ( - ground_shot is None - and jumpshot is None - and wall_shot is None - and doubleJumpShot is None - ): - ground_shot = hit( - agent.time, - agent.time + 6, - 0, - convertStructLocationToVector(agent.ballPred.slices[i]), - convertStructVelocityToVector(agent.ballPred.slices[i]), - False, - 6, - # [agent.enemyGoalLocations[0], agent.enemyGoalLocations[2]], - agent.team, - scorable=scorable, - ) - if agent.first_hit is None: - agent.first_hit = ground_shot - - if grounded: - agent.grounded_timer = tth - grounded = False - - return ground_shot, jumpshot, wall_shot, doubleJumpShot, aerialShot - - -def inaccurateArrivalEstimatorRemote(agent, start, destination): - distance = clamp(math.inf, 1, distance2D(start, destination)) - currentSpd = clamp(2300, 1, agent.currentSpd) - - if agent.me.boostLevel > 0: - maxSpd = clamp(2300, currentSpd, currentSpd + (distance * 0.3)) - else: - maxSpd = clamp(maxPossibleSpeed, currentSpd, currentSpd + (distance * 0.15)) - - return distance / maxSpd - - -def inaccurateArrivalEstimatorHacked( - phys_obj, starting_loc, destination, gravity, offset=140 -): - distance = clamp(math.inf, 0.00001, distance2D(starting_loc, destination) - offset) - - moreAccurateEstimation = timeWithAccelAgentless( - 991.66667, - abs(phys_obj.velocity.magnitude()), - phys_obj.boostLevel, - distance, - 1 / 60, - 33.334 / 60, - gravity, - False, - ) - - return moreAccurateEstimation - -# def enemyArrivalEstimator(agent, phys_obj, destination): -# distance = clamp( -# math.inf, 0.00001, findDistance(phys_obj.location, destination) - 180, -# ) -# -# enemy_agent = {} -# #moreAccurateEstimation = calcEnemyTimeWithAcceleration(agent, distance, phys_obj) -# return moreAccurateEstimation -# -# -# def calcEnemyTimeWithAcceleration(agent, distance, enemyPhysicsObject): -# estimatedSpd = abs(enemyPhysicsObject.velocity.magnitude()) -# estimatedTime = 0 -# distanceTally = 0 -# boostAmount = enemyPhysicsObject.boostLevel -# boostingCost = 33.334 * agent.deltaTime -# # print("enemy started") -# while distanceTally < distance and estimatedTime < 6: -# if estimatedSpd < maxPossibleSpeed: -# acceleration = getNaturalAccelerationJitted( -# estimatedSpd, agent.gravity, False -# ) -# if boostAmount > 0: -# acceleration += 991.667 -# boostAmount -= boostingCost -# if acceleration > 0: -# estimatedSpd += acceleration * agent.deltaTime -# distanceTally += estimatedSpd * agent.deltaTime -# estimatedTime += agent.deltaTime -# else: -# distanceTally += estimatedSpd * agent.deltaTime -# estimatedTime += agent.deltaTime -# -# # print("enemy ended") -# return estimatedTime - -def inaccurateArrivalEstimator(agent, destination, onWall=False, offset=120, reposition=False): - bonus_time = 0 - start_loc = agent.me.location - agent_spd = agent.currentSpd - wall_value = agent.onWall - if not agent.onSurface: - bonus_time = agent.on_ground_estimate - agent.time - start_loc = agent.collision_location - agent_spd = agent.simulated_velocity.magnitude() - wall_value = agent.wall_landing - - if onWall: - distance = clamp( - math.inf, 0.00001, findDistance(start_loc, destination) - offset - ) - else: - distance = clamp(math.inf, 0.00001, distance2D(start_loc, destination) - offset) - if reposition and agent.goalPred is None : - _direction = (agent.enemyGoalLocations[1] - destination.flatten()).normalize() - new_destination = destination + _direction.scale(offset) - distance = clamp(math.inf, 0.00001, distance2D(start_loc, new_destination)) - - #if agent.team == 0: - # if distance > 0.00001: - # vel_target_alignment = angleBetweenVectors(agent.me.velocity.flatten(), destination.flatten()-agent.me.location.flatten()) - # braking_time = brake_time(agent.currentSpd) - # if agent.forward: - # if vel_target_alignment >= 90: - # bonus_time += braking_time * ((vel_target_alignment-90)/90) - # else: - # if vel_target_alignment <= 90: - # bonus_time += braking_time * (vel_target_alignment / 90) - - moreAccurateEstimation = timeWithAccelAgentless( - agent.boostAccelerationRate, - agent_spd, - agent.me.boostLevel, - distance, - agent.fakeDeltaTime, - agent.boostConsumptionRate, - agent.gravity, - wall_value, - ) - - return moreAccurateEstimation + bonus_time - - -def inaccurateArrivalEstimatorBoostless(agent, destination, onWall=False, offset=120): - if onWall: - distance = clamp( - math.inf, 0.00001, findDistance(agent.me.location, destination) - offset - ) - else: - distance = clamp( - math.inf, 0.00001, distance2D(agent.me.location, destination) - offset - ) - moreAccurateEstimation = timeWithAccelAgentless( - agent.boostAccelerationRate, - agent.currentSpd, - 0, - distance, - agent.fakeDeltaTime, - agent.boostConsumptionRate, - agent.gravity, - False, - ) - - return moreAccurateEstimation - - -def enemyArrivalEstimator(agent, phys_obj, destination): - distance = clamp( - math.inf, 0.00001, findDistance(phys_obj.location, destination) - 160, - ) - moreAccurateEstimation = calcEnemyTimeWithAcceleration(agent, distance, phys_obj) - return moreAccurateEstimation - - -def calcEnemyTimeWithAcceleration(agent, distance, enemyPhysicsObject): - estimatedSpd = abs(enemyPhysicsObject.velocity.magnitude()) - estimatedTime = 0 - distanceTally = 0 - boostAmount = enemyPhysicsObject.boostLevel - boostingCost = 33.334 * agent.deltaTime - # print("enemy started") - while distanceTally < distance and estimatedTime < 6: - if estimatedSpd < maxPossibleSpeed: - acceleration = getNaturalAccelerationJitted( - estimatedSpd, agent.gravity, False - ) - if boostAmount > 0: - acceleration += 991.667 - boostAmount -= boostingCost - if acceleration > 0: - estimatedSpd += acceleration * agent.deltaTime - distanceTally += estimatedSpd * agent.deltaTime - estimatedTime += agent.deltaTime - else: - distanceTally += estimatedSpd * agent.deltaTime - estimatedTime += agent.deltaTime - - # print("enemy ended") - return estimatedTime - - -def which_wall(destination): - # orange = north - if destination[1] >= 4800: - # orange backboard - return 0 - elif destination[1] < -4800: - # blue backboard - return 2 - elif destination[0] < -3800: - # east wall - return 1 - - elif destination[0] > 3800: - # west wall - return 3 - else: - # not near wall - return -1 - - -def find_wall_intersection(phys_obj, destination): - y_intercept = (destination.data[1] + phys_obj.location[1]) / 2 - x_intercept = (destination.data[0] + phys_obj.location[0]) / 2 - - wall = which_wall(destination) - if wall == 0: - intersection = Vector([x_intercept, 5200, 0]) - elif wall == 1: - intersection = Vector([-4100, y_intercept, 0]) - elif wall == 2: - intersection = Vector([x_intercept, -5200, 0]) - else: - intersection = Vector([4100, y_intercept, 0]) - return intersection, wall - - -def enemyWallMovementEstimator(phys_obj, destination, agent): - intersection = find_wall_intersection(phys_obj, destination)[0] - _distance = clamp( - math.inf, 0.0001, findDistance(intersection, phys_obj.location) - 140 - ) - _distance += findDistance(intersection, destination) - return ( - timeWithAccelAgentless( - agent.boostAccelerationRate, - phys_obj.velocity.magnitude(), - phys_obj.boostLevel, - _distance, - agent.fakeDeltaTime, - agent.boostConsumptionRate, - agent.gravity, - False, - ), - _distance, - ) - - -def new_ground_wall_estimator(agent, destination): - offset = agent.reachLength - if agent.onWall: - flattened_destination = unroll_path_from_wall_to_ground( - agent.me.location, destination - ) - else: - flattened_destination = unroll_path_from_ground_to_wall(destination) - offset = 90 - estimation = inaccurateArrivalEstimator( - agent, flattened_destination, True, offset=1, - ) - return ( - estimation, - distance2D(agent.me.location, flattened_destination), - True, - ) - - -def lerp(v0, v1, t): # linear interpolation - return (1 - t) * v0 + t * v1 - - -@jit(float32(float32, float32, boolean), nopython=True) -def getNaturalAccelerationJitted(currentSpd, gravityValue, onWall): - normalIncrement = 1440.0 / 1400.0 - topIncrement = 160.0 / 10.0 - - if currentSpd <= 1400: - if not onWall: - return (1440 - (currentSpd * normalIncrement)) + 160 - else: - return clamp( - 5000, 0, (1440 - (currentSpd * normalIncrement)) + 160 - gravityValue - ) - elif currentSpd <= 1410: - if not onWall: - return 160 - ((currentSpd - 1400) * topIncrement) - else: - return clamp( - 5000, 0, 160 - ((currentSpd - 1400) * topIncrement) - gravityValue - ) - else: - return 0 - - -# (agent.currentSpd,agent.me.boostLevel,distance,agent.fakeDeltaTime,agent.boostConsumptionRate) -@jit(float32(float32, float32, float32, float32, float32, float32, float32, boolean), nopython=True) -def timeWithAccelAgentless( - accel, estimatedSpd, boostAmount, distance, fakeDelta, boostingCost, gravity, onWall -): - estimatedTime = 0 - distanceTally = 0 - flipped = 2 - while distanceTally < distance and estimatedTime < 6: - flipped += fakeDelta - if estimatedSpd < 2300: - acceleration = getNaturalAccelerationJitted(estimatedSpd, gravity, onWall) - if boostAmount > 0: - acceleration += accel - boostAmount -= boostingCost - else: - if ( - flipped > 2 - and (distance - distanceTally) > clamp(2300, 0.0001, estimatedSpd + 500) * 1.85 - and not onWall - and estimatedSpd > 1075 - ): - flipped = 0 - estimatedSpd = clamp(2300, 1, estimatedSpd + 500) - if acceleration > 0: - estimatedSpd = clamp( - 2300, 0.0001, estimatedSpd + (acceleration * fakeDelta) - ) - distanceTally += estimatedSpd * fakeDelta - estimatedTime += fakeDelta - else: - distanceTally += estimatedSpd * fakeDelta - estimatedTime += fakeDelta - - return estimatedTime - - -@jit( - typeof(np.array([float32(1.1), float32(1.1), float32(1.1)], dtype=np.dtype(float)))( - typeof(np.array([float32(1), float32(1), float32(1)], dtype=np.dtype(float))) - ), - nopython=True -) -def normalize(v): - norm = np.linalg.norm(v) - if norm == 0: - return v - return v / norm - - -@jit( - typeof( - ( - float32(1), - float32(1), - float32(1), - float32(1), - np.array([float32(1), float32(1), float32(1)], dtype=np.dtype(float)), - np.array([float32(1), float32(1), float32(1)], dtype=np.dtype(float)), - True, - ) - )( - float32, - float32, - typeof(np.array([float32(1), float32(1), float32(1)], dtype=np.dtype(float))), - typeof(np.array([float32(1), float32(1), float32(1)], dtype=np.dtype(float))), - typeof(np.array([float32(1), float32(1), float32(1)], dtype=np.dtype(float))), - float32, - float32, - float32, - typeof(False), - ), - cache=True, -) -def jumpSimulatorNormalizingJit( - gravity, - fakeDeltaTime, - velocity_np, - local_up_np, - current_position_np, - defaultElevation, - timeAllloted, - targetHeight, - doubleJump, -): - initialJumpVel = 292 - jumpHoldBonusVelocity = 1458 - firstJumpBonusMaxTimer = 0.2 - minimumHoldTimer = fakeDeltaTime * 3 - stickyforce = -325 # magnetic force pulling wheels to ground/walls - stickyTimer = fakeDeltaTime * 3 - secondJumpVel = 292 - # second jump timer limit = 1.25s after first jump is released or 0.2s, whichever is soonest - # secondJumpTimeLimit = 1.25 - - secondJumped = False - if not doubleJump: - simTimeMax = clamp(1.44, 0.001, timeAllloted) - else: - simTimeMax = clamp(6, 0, timeAllloted) # allowing for weird gravity - if not doubleJump: - if simTimeMax < 0.2 + fakeDeltaTime * 2: - simTimeMax -= fakeDeltaTime * 2 - simTime = float(0) - firstJumpTimer = float(0) - secondJumpTimer = float(0) - simulated_position = current_position_np - _gravity = np.array([0, 0, gravity]) - - estimatedVelocity = np.linalg.norm(velocity_np) - - heightMax = float32(current_position_np[2]) - maxHeightTime = float32(0) - - targetHeightTimer = float32(0) - - firstPauseTimer = 0 - secondPauseTimer = 0 - - while simTime < simTimeMax: - # upwardsVelocity = 0 - if simTime == 0: - # velocity_np += local_up_np * initialJumpVel - np.add(velocity_np, local_up_np * initialJumpVel, velocity_np) - - if simTime < stickyTimer: - # velocity_np += local_up_np * (stickyforce * fakeDeltaTime) - np.add( - velocity_np, local_up_np * (stickyforce * fakeDeltaTime), velocity_np - ) - - if simTime < 0.2 and simTime < simTimeMax: - # velocity_np += local_up_np * (jumpHoldBonusVelocity * fakeDeltaTime) - np.add( - velocity_np, - local_up_np * (jumpHoldBonusVelocity * fakeDeltaTime), - velocity_np, - ) - - else: - if doubleJump: - if not secondJumped: - velocity_np += local_up_np * secondJumpVel - secondJumped = True - - # velocity_np += _gravity * fakeDeltaTime - np.add(velocity_np, _gravity * fakeDeltaTime, velocity_np) - - estimatedVelocity = np.linalg.norm(velocity_np) - if estimatedVelocity > 2300: - velocity_np = np.multiply( - velocity_np / np.sqrt(np.sum(velocity_np ** 2)), 2300 - ) - - # simulated_position += velocity_np*fakeDeltaTime - np.add(simulated_position, velocity_np * fakeDeltaTime, simulated_position) - - simTime += fakeDeltaTime - - if simulated_position[2] > heightMax: - heightMax = simulated_position[2] * 1 - maxHeightTime = simTime * 1 - - if targetHeightTimer == 0: - if simulated_position[2] >= targetHeight: - targetHeightTimer = simTime - - if simulated_position[2] < heightMax: - break - - return ( - float32(targetHeight), - float32(targetHeightTimer), - float32(heightMax), - float32(maxHeightTime - fakeDeltaTime), - simulated_position, - velocity_np, - doubleJump, - ) - - -def enemy_float_simulation(car_obj, current_time, tick_length=6): - car_elevation = 17 - tick_duration = 1/120 - default_gravity = -650 - x_limit = 4096 - car_elevation - y_limit = 5120 - car_elevation - ground_limit = car_elevation - ceiling_limit = 2044 - car_elevation - collision_timer = 0 - collision_location = Vector([0, 0, 0]) - simulated_location = car_obj.location.scale(1) - simulated_velocity = car_obj.velocity.scale(1) - simulated_time = 0 - sim_frames = [] - - while ( - simulated_time < 10 - ): - simulated_time += tick_duration * tick_length - simulated_velocity = simulated_velocity + Vector([0, 0, default_gravity]).scale( - tick_duration * tick_length - ) - if simulated_velocity.magnitude() > 2300: - simulated_velocity = simulated_velocity.normalize().scale(2300) - simulated_location = simulated_location + simulated_velocity.scale( - tick_duration * tick_length - ) - sim_frames.append([simulated_location, simulated_velocity, current_time + simulated_time]) - - - if simulated_location[2] >= ceiling_limit: - break - elif simulated_location[2] <= ground_limit: - break - - elif simulated_location[0] <= -x_limit: - break - - elif simulated_location[0] >= x_limit: - break - - elif simulated_location[1] <= -y_limit: - break - - elif simulated_location[1] >= y_limit: - break - - car_obj.collision_timer = simulated_time - car_obj.on_ground_estimate = current_time + simulated_time - car_obj.collision_location = simulated_location - car_obj.simulated_velocity = simulated_velocity - car_obj.sim_frames = sim_frames - -def run_float_simulation(agent, tick_length=3): - x_limit = 4096 - agent.defaultElevation - y_limit = 5120 - agent.defaultElevation - ground_limit = agent.defaultElevation - ceiling_limit = 2044 - agent.defaultElevation - ideal_orientation = Vector([0, 0, 0]) - #tick_length = 3 - squash_index = 0 - collision_timer = 0 - collision_location = Vector([0, 0, 0]) - aim_direction = None - recovery_limit = 1.5 - simulated_location = agent.me.location.scale(1) - simulated_velocity = agent.me.velocity.scale(1) - simulated_time = 0 - agent.last_float_sim_time = agent.time - sim_frames = [] - - while ( - simulated_time < 10 - ): - simulated_time += agent.fakeDeltaTime * tick_length - simulated_velocity = simulated_velocity + Vector([0, 0, agent.gravity]).scale( - (agent.fakeDeltaTime) * tick_length - ) - if simulated_velocity.magnitude() > 2300: - simulated_velocity = simulated_velocity.normalize().scale(2300) - simulated_location = simulated_location + simulated_velocity.scale( - (agent.fakeDeltaTime) * tick_length - ) - sim_frames.append([simulated_location, simulated_velocity, agent.time + simulated_time]) - - - if simulated_location[2] >= ceiling_limit: - agent.roll_type = 2 - agent.squash_index = 2 - # print(f"ceiling recovery {self.agent.time}") - aim_direction = Vector([0, 0, 1]) - break - if simulated_location[2] <= ground_limit: - agent.roll_type = 1 - agent.squash_index = 2 - # print(f"ground recovery {self.agent.time}") - break - - if simulated_location[0] <= -x_limit: - # on blue's right wall - # print(f"side wall recovery {self.agent.time}") - agent.squash_index = 0 - if simulated_velocity[1] < 0: - # need to keep top right - agent.roll_type = 4 - - else: - # need to keep top left - agent.roll_type = 3 - break - - if simulated_location[0] >= x_limit: - # on blue's left wall - agent.squash_index = 0 - # print(f"side wall recovery {self.agent.time}") - if simulated_velocity[1] < 0: - # need to keep top left - agent.roll_type = 3 - - else: - # need to keep top right - agent.roll_type = 4 - break - - if simulated_location[1] <= -y_limit: - # on blue's backboard - # print(f"back wall recovery {self.agent.time}") - if abs(simulated_location[0]) < 893: - if simulated_location[2] < 642: - agent.roll_type = 1 - agent.squash_index = 2 - break - agent.squash_index = 1 - if simulated_velocity[0] < 0: - # need to keep top left - agent.roll_type = 3 - - else: - # need to keep top right - agent.roll_type = 4 - break - - if simulated_location[1] >= y_limit: - # on orange's backboard - # print(f"side wall recovery {self.agent.time}") - if abs(simulated_location[0]) < 893: - if simulated_location[2] < 642: - agent.roll_type = 1 - agent.squash_index = 2 - break - agent.squash_index = 1 - if simulated_velocity[0] < 0: - # need to keep top right - agent.roll_type = 4 - - else: - # need to keep top left - agent.roll_type = 3 - break - if simulated_time >= 10: - agent.roll_type = 1 - agent.squash_index = 2 - - if aim_direction is None: - agent.aim_direction = Vector([0, 0, -1]) - else: - agent.aim_direction = aim_direction - - agent.collision_timer = simulated_time - agent.on_ground_estimate = agent.time + simulated_time - agent.collision_location = simulated_location - # agent.simulated_velocity = simulated_velocity - simulated_velocity.data[agent.squash_index] = 0 - agent.simulated_velocity = simulated_velocity - - agent.wall_landing = agent.roll_type == 1 - agent.sim_frames = sim_frames - - -def jumpSimulatorNormalizing(agent, timeAllloted, targetHeight, doubleJump=True): - initialJumpVel = 292 - jumpHoldBonusVelocity = 1458 - firstJumpBonusMaxTimer = 0.2 - minimumHoldTimer = agent.fakeDeltaTime * 3 - stickyforce = -325 # magnetic force pulling wheels to ground/walls - stickyTimer = agent.fakeDeltaTime * 3 - secondJumpVel = 292 - # second jump timer limit = 1.25s after first jump is released or 0.2s, whichever is soonest - secondJumpTimeLimit = 1.25 - cached_simulation = [] # simulated time, simulated z velocity, simulated height - - secondJumped = False - simTimeMax = clamp(1.6, 0, timeAllloted) - if simTimeMax < 0.2 + agent.fakeDeltaTime * 2: - simTimeMax -= agent.fakeDeltaTime * 2 - simTime = 0 - firstJumpTimer = 0 - secondJumpTimer = 0 - additionalAltitude = agent.defaultElevation * 1 - - estimatedVelocity = agent.me.velocity.scale(1) - - heightMax = 0 - maxHeightTime = 0 - - targetHeightTimer = 0 - - firstPauseTimer = 0 - secondPauseTimer = 0 - - while simTime < simTimeMax: - upwardsVelocity = 0 - if simTime == 0: - upwardsVelocity += initialJumpVel - - if simTime < stickyTimer: - upwardsVelocity += stickyforce * agent.fakeDeltaTime - - if simTime < 0.2 and simTime < simTimeMax: - upwardsVelocity += jumpHoldBonusVelocity * agent.fakeDeltaTime - - else: - if doubleJump: - if not secondJumped: - upwardsVelocity += secondJumpVel - secondJumped = True - - upwardsVelocity += agent.gravity * agent.fakeDeltaTime - - estimatedVelocity.data[2] += upwardsVelocity - - magnitude = estimatedVelocity.magnitude() - # print(f"magnitude is {magnitude}") - if magnitude > 2300: - normalized = estimatedVelocity.normalize() - estimatedVelocity = normalized.scale(2300) - - additionalAltitude += estimatedVelocity[2] * agent.fakeDeltaTime - simTime += agent.fakeDeltaTime - - if additionalAltitude > heightMax: - heightMax = additionalAltitude * 1 - maxHeightTime = simTime * 1 - - if targetHeightTimer == 0: - if additionalAltitude >= targetHeight: - targetHeightTimer = simTime - - cached_simulation.append([simTime, estimatedVelocity[2], additionalAltitude]) - - return targetHeight, targetHeightTimer, heightMax, maxHeightTime, cached_simulation - - -def ballHeadedTowardsMyGoal_testing(agent, hit): - return hit.pred_vel[1] * sign(agent.team) > 10 - - -def ballHeadedTowardsMyGoal(agent): - myGoal = Vector([0, 5100 * sign(agent.team), 200]) - if ( - distance1D(myGoal, agent.ball.location, 1) - - distance1D(myGoal, agent.ball.location + agent.ball.velocity, 1) - ) > 0: - if agent.ball.velocity.magnitude() > 5: - return True - - return False - - -def objectHeadedTowardMyGoal(phys_object, team): - myGoal = Vector([0, 5100 * sign(team), 200]) - if ( - distance1D(myGoal, phys_object.location, 1) - - distance1D(myGoal, phys_object.location + phys_object.velocity, 1) - ) > 0: - if phys_object.velocity.magnitude() > 5: - return True - - return False - - -def openGoalOpportunity(agent): - enemyGoal = Vector([0, 5100 * -sign(agent.team), 200]) - ballDistance = distance2D(agent.ball.location, enemyGoal) - playerDistance = distance2D(agent.me.location, enemyGoal) - - for e in agent.enemies: - _dist = distance2D(e.location, enemyGoal) - if _dist < ballDistance or _dist < playerDistance: - return False - - return True - - -def radius(v): - return 139.059 + (0.1539 * v) + (0.0001267716565 * v * v) - - -def turnController(_angle, turnRate): - return clamp(1, -1, (_angle + turnRate) * 7) - - -def align_car_to( - controller: SimpleControllerState, angular_velocity: Vector, forward: Vector, agent -): - # local_forward = rotation.cast_local(forward) - local_forward = localizeRotation(forward, agent) - ang_vel_local = localizeRotation(angular_velocity, agent) - - pitch_angle = math.atan2(-local_forward[2], local_forward[0]) - yaw_angle = math.atan2(-local_forward[1], local_forward[0]) - - pitch_angular_velocity = ang_vel_local[1] - yaw_angular_velocity = ang_vel_local[2] - - p = 4 - d = 0.9 - - controller.pitch = clamp(1, -1, -pitch_angle * p + pitch_angular_velocity * d) - controller.yaw = clamp(1, -1, -yaw_angle * p - yaw_angular_velocity * d) - - -def point_at_position(agent, position: Vector): - local_position = toLocal(position, agent.me) - - yaw_angle = math.atan2(local_position[1], local_position[0]) - steer = turnController(yaw_angle, 1) - yaw = turnController(yaw_angle, -agent.me.rotational_velocity[2] / 4) - pitch_angle = math.atan2(local_position[2], local_position[0]) - pitch = turnController(pitch_angle, agent.me.rotational_velocity[1] / 4) - roll = turnController(-agent.me.rotation[2], agent.me.rotational_velocity[0] / 4) - - return steer, yaw, pitch, roll, abs(yaw_angle) + abs(pitch_angle) - - -def matrixDot(_matrix, vector): - return Vector( - [ - _matrix[0].dotProduct(vector), - _matrix[1].dotProduct(vector), - _matrix[2].dotProduct(vector), - ] - ) - - -def drawAsterisks(vec, agent): - if agent.debugging: - if agent.team == 0: - color = agent.renderer.red - else: - color = agent.renderer.green - - segmentLength = 55 - - topVertical = vec + Vector([0, 0, segmentLength]) - bottomVertical = vec + Vector([0, 0, -segmentLength]) - leftHorizontal = vec + Vector([-segmentLength, 0, 0]) - rightHorizontal = vec + Vector([segmentLength, 0, 0]) - forwardHorizontal = vec + Vector([0, -segmentLength, 0]) - backHorizontal = vec + Vector([0, segmentLength, 0]) - - topLeftFrontDiagnal = vec + Vector( - [-segmentLength, segmentLength, segmentLength] - ) - topRightFrontDiagnal = vec + Vector( - [segmentLength, segmentLength, segmentLength] - ) - bottomLeftFrontDiagnal = vec + Vector( - [-segmentLength, segmentLength, -segmentLength] - ) - bottomRightFrontDiagnal = vec + Vector( - [segmentLength, segmentLength, -segmentLength] - ) - - bottomRightBackDiagnal = vec + Vector( - [segmentLength, -segmentLength, -segmentLength] - ) - bottomLeftBackDiagnal = vec + Vector( - [-segmentLength, -segmentLength, -segmentLength] - ) - topRightBackDiagnal = vec + Vector( - [segmentLength, -segmentLength, segmentLength] - ) - topLeftBackDiagnal = vec + Vector( - [-segmentLength, -segmentLength, segmentLength] - ) - - points = [ - topVertical, - bottomVertical, - leftHorizontal, - rightHorizontal, - forwardHorizontal, - backHorizontal, - topLeftFrontDiagnal, - topRightFrontDiagnal, - bottomLeftFrontDiagnal, - bottomRightFrontDiagnal, - bottomRightBackDiagnal, - bottomLeftBackDiagnal, - topRightBackDiagnal, - topLeftBackDiagnal, - ] - - for p in points: - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - p.toList(), - (vec + Vector([agent.index, agent.index, agent.index])).toList(), - color, - ) - ) - - -def createBox(agent, _vector): - if agent.debugging: - if agent.team == 0: - color = agent.renderer.blue - else: - color = agent.renderer.orange - half = 55 - tbl = _vector + Vector([-half, half, half]) - tbr = _vector + Vector([half, half, half]) - tfl = _vector + Vector([-half, -half, half]) - tfr = _vector + Vector([half, -half, half]) - - bbl = _vector + Vector([-half, half, -half]) - bbr = _vector + Vector([half, half, -half]) - bfl = _vector + Vector([-half, -half, -half]) - bfr = _vector + Vector([half, -half, -half]) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, tbl.toList(), tbr.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, tfr.toList(), tbr.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, tfr.toList(), tfl.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, tbl.toList(), tfl.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, bbl.toList(), bbr.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, bfr.toList(), bbr.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, bfr.toList(), bfl.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, bfl.toList(), bbl.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, bbl.toList(), tbl.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, bbr.toList(), tbr.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, bfl.toList(), tfl.toList(), color) - ) - - agent.renderCalls.append( - renderCall(agent.renderer.draw_line_3d, bfr.toList(), tfr.toList(), color) - ) - - -def createTriangle(agent, _vector): - if agent.debugging: - _vector = _vector.scale(1) - _vector.data[2] = 20 - length = 65 - two_pi = math.pi * 2 - right = _vector + Vector([length * math.sin(two_pi * 0.333334), length * math.cos(two_pi * 0.333334), 0]) - left = _vector + Vector([length * math.sin(two_pi * 0.6666667), length * math.cos(two_pi * 0.6666667), 0]) - back = _vector + Vector([length * math.sin(two_pi), length * math.cos(two_pi), 0]) - - # right = _vector + Vector([length, length, 0]) - # left = _vector + Vector([-length, length, 0]) - # back = _vector + Vector([0, -length, 0]) - top = _vector.scale(1) - top.data[2] = _vector.data[2] + length - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - top.toList(), - right.toList(), - agent.renderer.purple, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - top.toList(), - left.toList(), - agent.renderer.purple, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - top.toList(), - back.toList(), - agent.renderer.purple, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - left.toList(), - right.toList(), - agent.renderer.purple, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - back.toList(), - right.toList(), - agent.renderer.purple, - ) - ) - - agent.renderCalls.append( - renderCall( - agent.renderer.draw_line_3d, - back.toList(), - left.toList(), - agent.renderer.purple, - ) - ) - - -def createSphere(agent, _vector, _radius=92.5, frequency=25, num_points=100): - if agent.debugging: - if agent.team == 0: - color = agent.renderer.blue - else: - color = agent.renderer.orange - - t = np.linspace(-1, 1, num_points) - x = np.sqrt(1 - t ** 2) * np.cos(t * frequency) - y = np.sqrt(1 - t ** 2) * np.sin(t * frequency) - z = t - - points = [] - for i in range(num_points): - points.append((Vector([x[i]*_radius, y[i]*_radius, z[i]*_radius])+_vector).data) - - agent.renderer.begin_rendering('sphere') - agent.renderer.draw_polyline_3d( points, color()) - agent.renderer.end_rendering() - # agent.renderCalls.append( - # renderCall(agent.renderer.draw_polyline_3d, points, color) - # ) - -if __name__ == "__main__": - print("Surprise! You did a silly thing!") - #createCircle(None, Vector([0,0,0]), 1, 50, 200) diff --git a/RLBotPack/Kamael_family/kam_appearance.cfg b/RLBotPack/Kamael_family/kam_appearance.cfg deleted file mode 100644 index d4295880..00000000 --- a/RLBotPack/Kamael_family/kam_appearance.cfg +++ /dev/null @@ -1,100 +0,0 @@ -[Bot Loadout] -# Primary Color selection -team_color_id = 37 -# Secondary Color selection -custom_color_id = 0 -# Car type (Octane, Merc, etc) -car_id = 26 -# Type of decal -decal_id = 329 -# Wheel selection -wheels_id = 690 -# Boost selection -boost_id = 5023 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 2318 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 3073 -# Car trail Selection -trails_id = 5587 -# Goal Explosion Selection -goal_explosion_id = 1908 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Loadout Orange] -# Primary Color selection -team_color_id = 37 -# Secondary Color selection -custom_color_id = 0 -# Car type (Octane, Merc, etc) -car_id = 26 -# Type of decal -decal_id = 329 -# Wheel selection -wheels_id = 690 -# Boost selection -boost_id = 5023 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 2318 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 3073 -# Car trail Selection -trails_id = 5587 -# Goal Explosion Selection -goal_explosion_id = 1908 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Paint Blue] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 12 -# wheels_paint_id -wheels_paint_id = 12 -# boost_paint_id -boost_paint_id = 0 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 12 -# trails_paint_id -trails_paint_id = 5 -# goal_explosion_paint_id -goal_explosion_paint_id = 5 - -[Bot Paint Orange] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 12 -# wheels_paint_id -wheels_paint_id = 12 -# boost_paint_id -boost_paint_id = 0 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 12 -# trails_paint_id -trails_paint_id = 12 -# goal_explosion_paint_id -goal_explosion_paint_id = 1 - diff --git a/RLBotPack/Kamael_family/kam_loadout_gen.py b/RLBotPack/Kamael_family/kam_loadout_gen.py deleted file mode 100644 index 256f87ea..00000000 --- a/RLBotPack/Kamael_family/kam_loadout_gen.py +++ /dev/null @@ -1,24 +0,0 @@ -import random -from pathlib import Path - -from rlbot.agents.base_loadout_generator import BaseLoadoutGenerator -from rlbot.matchconfig.loadout_config import LoadoutConfig - - -class SimpleLoadoutGenerator(BaseLoadoutGenerator): - def generate_loadout(self, player_index: int, team: int) -> LoadoutConfig: - - # if team == 0: - # loadout = self.load_cfg_file(Path("loadouts/kam_dom.cfg"), team) - # else: - choice = random.randint(0,100) - if choice <= 33 : - loadout = self.load_cfg_file(Path("loadouts/kam_gizmo.cfg"), team) - elif choice <= 66: - # loadout = self.load_cfg_file(Path('loadouts/kam_octane.cfg'), team) - loadout = self.load_cfg_file(Path("loadouts/kam_octane.cfg"), team) - else: - loadout = self.load_cfg_file(Path('loadouts/kam_marauder.cfg'), team) - - - return loadout diff --git a/RLBotPack/Kamael_family/kam_logo.png b/RLBotPack/Kamael_family/kam_logo.png deleted file mode 100644 index e38f8db6..00000000 Binary files a/RLBotPack/Kamael_family/kam_logo.png and /dev/null differ diff --git a/RLBotPack/Kamael_family/nebulous.png b/RLBotPack/Kamael_family/nebulous.png deleted file mode 100644 index b7601db0..00000000 Binary files a/RLBotPack/Kamael_family/nebulous.png and /dev/null differ diff --git a/RLBotPack/Kamael_family/nebulous_appearance.cfg b/RLBotPack/Kamael_family/nebulous_appearance.cfg deleted file mode 100644 index 699e7abf..00000000 --- a/RLBotPack/Kamael_family/nebulous_appearance.cfg +++ /dev/null @@ -1,100 +0,0 @@ -[Bot Loadout] -# Primary Color selection -team_color_id = 66 -# Secondary Color selection -custom_color_id = 9 -# Car type (Octane, Merc, etc) -car_id = 4906 -# Type of decal -decal_id = 6775 -# Wheel selection -wheels_id = 4690 -# Boost selection -boost_id = 35 -# Antenna Selection -antenna_id = 786 -# Hat Selection -hat_id = 3907 -# Paint Type (for first color) -paint_finish_id = 1703 -# Paint Type (for secondary color) -custom_finish_id = 4737 -# Engine Audio Selection -engine_audio_id = 4075 -# Car trail Selection -trails_id = 3575 -# Goal Explosion Selection -goal_explosion_id = 3020 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Loadout Orange] -# Primary Color selection -team_color_id = 52 -# Secondary Color selection -custom_color_id = 8 -# Car type (Octane, Merc, etc) -car_id = 2269 -# Type of decal -decal_id = 1917 -# Wheel selection -wheels_id = 2767 -# Boost selection -boost_id = 4570 -# Antenna Selection -antenna_id = 151 -# Hat Selection -hat_id = 3838 -# Paint Type (for first color) -paint_finish_id = 4728 -# Paint Type (for secondary color) -custom_finish_id = 5657 -# Engine Audio Selection -engine_audio_id = 2373 -# Car trail Selection -trails_id = 5674 -# Goal Explosion Selection -goal_explosion_id = 3977 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Paint Blue] -# car_paint_id -car_paint_id = 13 -# decal_paint_id -decal_paint_id = 1 -# wheels_paint_id -wheels_paint_id = 4 -# boost_paint_id -boost_paint_id = 1 -# antenna_paint_id -antenna_paint_id = 5 -# hat_paint_id -hat_paint_id = 5 -# trails_paint_id -trails_paint_id = 7 -# goal_explosion_paint_id -goal_explosion_paint_id = 8 - -[Bot Paint Orange] -# car_paint_id -car_paint_id = 7 -# decal_paint_id -decal_paint_id = 5 -# wheels_paint_id -wheels_paint_id = 10 -# boost_paint_id -boost_paint_id = 6 -# antenna_paint_id -antenna_paint_id = 13 -# hat_paint_id -hat_paint_id = 9 -# trails_paint_id -trails_paint_id = 0 -# goal_explosion_paint_id -goal_explosion_paint_id = 3 - diff --git a/RLBotPack/Kamael_family/nebulous_loadout.py b/RLBotPack/Kamael_family/nebulous_loadout.py deleted file mode 100644 index b7aa8bda..00000000 --- a/RLBotPack/Kamael_family/nebulous_loadout.py +++ /dev/null @@ -1,80 +0,0 @@ -import csv -import random - -from rlbot.agents.base_loadout_generator import BaseLoadoutGenerator -from rlbot.csv.items import get_items_path -from rlbot.matchconfig.loadout_config import LoadoutConfig - - -def generate_items_dict(): - items_dict = dict() - with open(get_items_path(), 'r') as f: - csv_reader = csv.reader(f) - for item in csv_reader: - # 0: id, 1: type, 2: useless garbage, 3: name - if item[3].find("Mystery") == -1 and item[3].find("Import") == -1: - if item[1] not in items_dict: - items_dict[item[1]] = [item] - else: - items_dict[item[1]].append(item) - return items_dict - - -def decal_picker(body_string, items_dict): - special_body_suffixes = ["Type-S", "GT", "ZSR", "XL", "RX-T", "Mk-2", "GXT"] - suitable_decals = [] - for decal in items_dict["Skin"]: - if decal[3].find(body_string) != -1: - for suffix in special_body_suffixes: - if decal[3][len(body_string):].find(suffix) != -1: - break - else: - suitable_decals.append(decal) - else: - for body in items_dict["Body"]: - if decal[3].find(body[3]) != -1: - break - else: - suitable_decals.append(decal) - return int(random.choice(suitable_decals)[0]) - - -def make_base_picks(items: dict, loadout_file: LoadoutConfig): - loadout_file.team_color_id = random.randint(0, 69) - loadout_file.custom_color_id = random.randint(0, 104) - body = random.choice(items["Body"]) - loadout_file.car_id = int(body[0]) - loadout_file.decal_id = int(decal_picker(body[3], items)) - loadout_file.antenna_id = int(random.choice(items["Antenna"])[0]) - loadout_file.wheels_id = int(random.choice(items["Wheels"])[0]) - loadout_file.boost_id = int(random.choice(items["Boost"])[0]) - loadout_file.hat_id = int(random.choice(items["Hat"])[0]) - loadout_file.engine_audio_id = int(random.choice(items["EngineAudio"])[0]) - loadout_file.trails_id = int(random.choice(items["SupersonicTrail"])[0]) - loadout_file.goal_explosion_id = int(random.choice(items["GoalExplosion"])[0]) - - -def make_item_color_picks(loadout: LoadoutConfig): - loadout.paint_config.car_paint_id = random.randint(0, 13) - loadout.paint_config.decal_paint_id = random.randint(0, 13) - loadout.paint_config.wheels_paint_id = random.randint(0, 13) - loadout.paint_config.boost_paint_id = random.randint(0, 13) - loadout.paint_config.antenna_paint_id = random.randint(0, 13) - loadout.paint_config.hat_paint_id = random.randint(0, 13) - loadout.paint_config.trails_paint_id = random.randint(0, 13) - loadout.paint_config.goal_explosion_paint_id = random.randint(0, 13) - - -class RandomLoadoutGenerator(BaseLoadoutGenerator): - def generate_loadout(self, player_index: int, team: int) -> LoadoutConfig: - loadout = LoadoutConfig() - #loadout = self.load_cfg_file(Path('stock_appearance.cfg'), team) - items = generate_items_dict() - make_base_picks(items, loadout) - make_item_color_picks(loadout) - - return loadout - - -if __name__ == "__main__": - RandomLoadoutGenerator.generate_loadout(1,1,1) diff --git a/RLBotPack/Kamael_family/peter_appaearance.cfg b/RLBotPack/Kamael_family/peter_appaearance.cfg deleted file mode 100644 index 87827874..00000000 --- a/RLBotPack/Kamael_family/peter_appaearance.cfg +++ /dev/null @@ -1,100 +0,0 @@ -[Bot Loadout] -# Primary Color selection -team_color_id = 37 -# Secondary Color selection -custom_color_id = 0 -# Car type (Octane, Merc, etc) -car_id = 5713 -# Type of decal -decal_id = 5854 -# Wheel selection -wheels_id = 2614 -# Boost selection -boost_id = 36 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 232 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 1788 -# Car trail Selection -trails_id = 4507 -# Goal Explosion Selection -goal_explosion_id = 4523 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Loadout Orange] -# Primary Color selection -team_color_id = 37 -# Secondary Color selection -custom_color_id = 0 -# Car type (Octane, Merc, etc) -car_id = 5713 -# Type of decal -decal_id = 5854 -# Wheel selection -wheels_id = 2614 -# Boost selection -boost_id = 36 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 232 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 1788 -# Car trail Selection -trails_id = 1898 -# Goal Explosion Selection -goal_explosion_id = 4523 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Paint Blue] -# car_paint_id -car_paint_id = 12 -# decal_paint_id -decal_paint_id = 12 -# wheels_paint_id -wheels_paint_id = 12 -# boost_paint_id -boost_paint_id = 4 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 12 -# trails_paint_id -trails_paint_id = 12 -# goal_explosion_paint_id -goal_explosion_paint_id = 12 - -[Bot Paint Orange] -# car_paint_id -car_paint_id = 12 -# decal_paint_id -decal_paint_id = 12 -# wheels_paint_id -wheels_paint_id = 12 -# boost_paint_id -boost_paint_id = 10 -# antenna_paint_id -antenna_paint_id = 12 -# hat_paint_id -hat_paint_id = 12 -# trails_paint_id -trails_paint_id = 12 -# goal_explosion_paint_id -goal_explosion_paint_id = 12 - diff --git a/RLBotPack/Kamael_family/peter_logo.png b/RLBotPack/Kamael_family/peter_logo.png deleted file mode 100644 index d6227da7..00000000 Binary files a/RLBotPack/Kamael_family/peter_logo.png and /dev/null differ diff --git a/RLBotPack/Kamael_family/raph_appaearance.cfg b/RLBotPack/Kamael_family/raph_appaearance.cfg deleted file mode 100644 index 0a245310..00000000 --- a/RLBotPack/Kamael_family/raph_appaearance.cfg +++ /dev/null @@ -1,100 +0,0 @@ -[Bot Loadout] -# Primary Color selection -team_color_id = 67 -# Secondary Color selection -custom_color_id = 0 -# Car type (Octane, Merc, etc) -car_id = 1018 -# Type of decal -decal_id = 1030 -# Wheel selection -wheels_id = 690 -# Boost selection -boost_id = 1166 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 3137 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 1842 -# Car trail Selection -trails_id = 3561 -# Goal Explosion Selection -goal_explosion_id = 1908 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Loadout Orange] -# Primary Color selection -team_color_id = 65 -# Secondary Color selection -custom_color_id = 0 -# Car type (Octane, Merc, etc) -car_id = 1018 -# Type of decal -decal_id = 1030 -# Wheel selection -wheels_id = 690 -# Boost selection -boost_id = 36 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 3137 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 1842 -# Car trail Selection -trails_id = 1899 -# Goal Explosion Selection -goal_explosion_id = 1908 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Paint Blue] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 12 -# wheels_paint_id -wheels_paint_id = 12 -# boost_paint_id -boost_paint_id = 0 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 4 -# trails_paint_id -trails_paint_id = 5 -# goal_explosion_paint_id -goal_explosion_paint_id = 5 - -[Bot Paint Orange] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 12 -# wheels_paint_id -wheels_paint_id = 12 -# boost_paint_id -boost_paint_id = 0 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 6 -# trails_paint_id -trails_paint_id = 12 -# goal_explosion_paint_id -goal_explosion_paint_id = 1 - diff --git a/RLBotPack/Kamael_family/rapha-logo.png b/RLBotPack/Kamael_family/rapha-logo.png deleted file mode 100644 index 77c39de9..00000000 Binary files a/RLBotPack/Kamael_family/rapha-logo.png and /dev/null differ diff --git a/RLBotPack/Kamael_family/requirements.txt b/RLBotPack/Kamael_family/requirements.txt deleted file mode 100644 index 1be91329..00000000 --- a/RLBotPack/Kamael_family/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -rlbot==1.* -numba==0.56.* -numpy -scipy>=1.0.0 diff --git a/RLBotPack/Kamael_family/wyrm_appaearance.cfg b/RLBotPack/Kamael_family/wyrm_appaearance.cfg deleted file mode 100644 index 21aa1c08..00000000 --- a/RLBotPack/Kamael_family/wyrm_appaearance.cfg +++ /dev/null @@ -1,100 +0,0 @@ -[Bot Loadout] -# Primary Color selection -team_color_id = 37 -# Secondary Color selection -custom_color_id = 8 -# Car type (Octane, Merc, etc) -car_id = 404 -# Type of decal -decal_id = 587 -# Wheel selection -wheels_id = 3152 -# Boost selection -boost_id = 36 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 0 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 2358 -# Car trail Selection -trails_id = 3561 -# Goal Explosion Selection -goal_explosion_id = 2044 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Loadout Orange] -# Primary Color selection -team_color_id = 37 -# Secondary Color selection -custom_color_id = 18 -# Car type (Octane, Merc, etc) -car_id = 404 -# Type of decal -decal_id = 587 -# Wheel selection -wheels_id = 3152 -# Boost selection -boost_id = 36 -# Antenna Selection -antenna_id = 0 -# Hat Selection -hat_id = 0 -# Paint Type (for first color) -paint_finish_id = 270 -# Paint Type (for secondary color) -custom_finish_id = 270 -# Engine Audio Selection -engine_audio_id = 2358 -# Car trail Selection -trails_id = 2047 -# Goal Explosion Selection -goal_explosion_id = 2044 -# Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] -primary_color_lookup = None -# Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] -secondary_color_lookup = None - -[Bot Paint Blue] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 4 -# wheels_paint_id -wheels_paint_id = 5 -# boost_paint_id -boost_paint_id = 4 -# antenna_paint_id -antenna_paint_id = 0 -# hat_paint_id -hat_paint_id = 12 -# trails_paint_id -trails_paint_id = 0 -# goal_explosion_paint_id -goal_explosion_paint_id = 0 - -[Bot Paint Orange] -# car_paint_id -car_paint_id = 0 -# decal_paint_id -decal_paint_id = 10 -# wheels_paint_id -wheels_paint_id = 6 -# boost_paint_id -boost_paint_id = 10 -# antenna_paint_id -antenna_paint_id = 12 -# hat_paint_id -hat_paint_id = 12 -# trails_paint_id -trails_paint_id = 0 -# goal_explosion_paint_id -goal_explosion_paint_id = 0 - diff --git a/RLBotPack/Kamael_family/wyrm_logo.png b/RLBotPack/Kamael_family/wyrm_logo.png deleted file mode 100644 index 23e86145..00000000 Binary files a/RLBotPack/Kamael_family/wyrm_logo.png and /dev/null differ