|
| 1 | +from pathlib import Path |
| 2 | +from dataclasses import dataclass, field |
| 3 | +from math import pi |
| 4 | + |
| 5 | +from rlbot.utils.game_state_util import GameState, BoostState, BallState, CarState, Physics, Vector3, Rotator |
| 6 | +from rlbot.matchconfig.match_config import MatchConfig, PlayerConfig, Team |
| 7 | +from rlbottraining.common_exercises.common_base_exercises import StrikerExercise |
| 8 | +from rlbottraining.rng import SeededRandomNumberGenerator |
| 9 | +from rlbottraining.match_configs import make_empty_match_config |
| 10 | +from rlbottraining.grading.grader import Grader |
| 11 | +from rlbottraining.training_exercise import TrainingExercise, Playlist |
| 12 | + |
| 13 | +import training_util |
| 14 | +from drive_to_ball_grader import DriveToBallGrader |
| 15 | + |
| 16 | + |
| 17 | +def make_match_config_with_my_bot() -> MatchConfig: |
| 18 | + # Makes a config which only has our bot in it for now. |
| 19 | + # For more defails: https://youtu.be/uGFmOZCpel8?t=375 |
| 20 | + match_config = make_empty_match_config() |
| 21 | + match_config.player_configs = [ |
| 22 | + PlayerConfig.bot_config( |
| 23 | + Path(__file__).absolute().parent.parent / 'python_example' / 'python_example.cfg', |
| 24 | + Team.BLUE |
| 25 | + ), |
| 26 | + ] |
| 27 | + return match_config |
| 28 | + |
| 29 | +@dataclass |
| 30 | +class StrikerPatience(StrikerExercise): |
| 31 | + """ |
| 32 | + Drops the ball from a certain height, requiring the bot to not drive |
| 33 | + underneath the ball until it's in reach. |
| 34 | + """ |
| 35 | + |
| 36 | + car_start_x: float = 0 |
| 37 | + |
| 38 | + def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState: |
| 39 | + return GameState( |
| 40 | + ball=BallState(physics=Physics( |
| 41 | + location=Vector3(0, 4400, 1000), |
| 42 | + velocity=Vector3(0, 0, 200), |
| 43 | + angular_velocity=Vector3(0, 0, 0))), |
| 44 | + cars={ |
| 45 | + 0: CarState( |
| 46 | + physics=Physics( |
| 47 | + location=Vector3(self.car_start_x, 3000, 0), |
| 48 | + rotation=Rotator(0, pi / 2, 0), |
| 49 | + velocity=Vector3(0, 0, 0), |
| 50 | + angular_velocity=Vector3(0, 0, 0)), |
| 51 | + jumped=False, |
| 52 | + double_jumped=False, |
| 53 | + boost_amount=0) |
| 54 | + }, |
| 55 | + boosts={i: BoostState(0) for i in range(34)}, |
| 56 | + ) |
| 57 | + |
| 58 | +@dataclass |
| 59 | +class DrivesToBallExercise(TrainingExercise): |
| 60 | + """ |
| 61 | + Checks that we drive to the ball when it's in the center of the field. |
| 62 | + """ |
| 63 | + grader: Grader = field(default_factory=DriveToBallGrader) |
| 64 | + |
| 65 | + def make_game_state(self, rng: SeededRandomNumberGenerator) -> GameState: |
| 66 | + return GameState( |
| 67 | + ball=BallState(physics=Physics( |
| 68 | + location=Vector3(0, 0, 100), |
| 69 | + velocity=Vector3(0, 0, 0), |
| 70 | + angular_velocity=Vector3(0, 0, 0))), |
| 71 | + cars={ |
| 72 | + 0: CarState( |
| 73 | + physics=Physics( |
| 74 | + location=Vector3(0, 2000, 0), |
| 75 | + rotation=Rotator(0, -pi / 2, 0), |
| 76 | + velocity=Vector3(0, 0, 0), |
| 77 | + angular_velocity=Vector3(0, 0, 0)), |
| 78 | + jumped=False, |
| 79 | + double_jumped=False, |
| 80 | + boost_amount=100) |
| 81 | + }, |
| 82 | + boosts={i: BoostState(0) for i in range(34)}, |
| 83 | + ) |
| 84 | + |
| 85 | + |
| 86 | +def make_default_playlist() -> Playlist: |
| 87 | + exercises = [ |
| 88 | + StrikerPatience('start perfectly center'), |
| 89 | + StrikerPatience('start on the right', car_start_x=-1000), |
| 90 | + DrivesToBallExercise('Get close to ball'), |
| 91 | + DrivesToBallExercise('Get close-ish to ball', grader=DriveToBallGrader(min_dist_to_pass=1000)) |
| 92 | + ] |
| 93 | + for exercise in exercises: |
| 94 | + exercise.match_config = make_match_config_with_my_bot() |
| 95 | + |
| 96 | + return exercises |
0 commit comments