Skip to content

Commit

Permalink
Manticore update (#141)
Browse files Browse the repository at this point in the history
* Make Manticore work in 1v1 and use quickchat.

* Update Manticore.

* Updated Manticore's TMCP.

* Disable TMCP if outdated.

* Manticore: Define requirements files and update tmcp.

* Manticore new rendering system and wall recovery.
  • Loading branch information
NicEastvillage authored Jul 21, 2021
1 parent 26d8f33 commit c5087d1
Show file tree
Hide file tree
Showing 21 changed files with 509 additions and 157 deletions.
7 changes: 3 additions & 4 deletions RLBotPack/manticore/behaviour/carry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from maneuvers.dodge import DodgeManeuver
from strategy.objective import Objective
from strategy.utility_system import UtilityState
from utility import predict
from utility import predict, draw
from utility.easing import lin_fall
from utility.rlmath import clip01, lerp
from utility.vec import norm, Vec3, angle_between, normalize, dot, xy
from utility.vec import norm, Vec3, angle_between, normalize, xy


class Carry(UtilityState):
Expand Down Expand Up @@ -77,8 +77,7 @@ def run(self, bot) -> SimpleControllerState:
else:
self.flick_timer = 0

if bot.do_rendering:
bot.renderer.draw_line_3d(car.pos, target, bot.renderer.pink())
draw.line(car.pos, target, draw.pink())

return bot.drive.towards_point(bot, target, target_vel=speed, slide=False, can_keep_speed=False, can_dodge=True, wall_offset_allowed=0)

Expand Down
9 changes: 4 additions & 5 deletions RLBotPack/manticore/behaviour/clear_ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from controllers.aim_cone import AimCone
from strategy.objective import Objective
from strategy.utility_system import UtilityState
from utility import predict, rendering
from utility import predict, draw
from utility.info import Field
from utility.rlmath import clip01, remap, lerp
from utility.vec import Vec3
Expand Down Expand Up @@ -55,12 +55,11 @@ def run(self, bot) -> SimpleControllerState:
shoot_controls = bot.shoot.with_aiming(bot, self.aim_cone, predict.time_till_reach_ball(bot.info.my_car, bot.info.ball))
hit_pos = bot.shoot.ball_when_hit.pos

if bot.do_rendering:
self.aim_cone.draw(bot, hit_pos, r=0, g=170, b=255)
self.aim_cone.draw(hit_pos, r=0, g=170, b=255)

if bot.shoot.can_shoot:
if bot.shoot.using_curve and bot.do_rendering:
rendering.draw_bezier(bot, [car.pos, bot.shoot.curve_point, hit_pos])
if bot.shoot.using_curve:
draw.bezier([car.pos, bot.shoot.curve_point, hit_pos], draw.color(100, 100, 255))
return shoot_controls

else:
Expand Down
5 changes: 2 additions & 3 deletions RLBotPack/manticore/behaviour/save_goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from utility import predict
from utility.info import Ball, Goal
from utility.rlmath import sign, clip
from utility.vec import Vec3, norm
from utility.vec import norm


class SaveGoal(UtilityState):
Expand Down Expand Up @@ -48,8 +48,7 @@ def run(self, bot) -> SimpleControllerState:
self.ball_to_goal_left = bot.info.own_goal.left_post - reachable_ball.pos
self.aim_cone = AimCone(self.ball_to_goal_left, self.ball_to_goal_right)

if bot.do_rendering:
self.aim_cone.draw(bot, reachable_ball.pos, r=200, g=0, b=160)
self.aim_cone.draw(reachable_ball.pos, r=200, g=0, b=160)

shoot_controls = bot.shoot.with_aiming(bot, self.aim_cone, reach_time)

Expand Down
22 changes: 9 additions & 13 deletions RLBotPack/manticore/behaviour/shoot_at_goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from maneuvers.collect_boost import CollectClosestBoostManeuver, filter_pads
from strategy.objective import Objective
from strategy.utility_system import UtilityState
from utility import predict, rendering
from utility import predict, draw
from utility.easing import ease_out
from utility.info import Field, Ball
from utility.rlmath import clip01, remap, is_closer_to_goal_than, lerp
Expand Down Expand Up @@ -69,12 +69,10 @@ def run(self, bot) -> SimpleControllerState:
enemy_hit_time = predict.time_till_reach_ball(closest_enemy, ball)
enemy_hit_pos = predict.ball_predict(bot, enemy_hit_time).pos
if enemy_hit_time < 1.5 * my_hit_time:
if bot.do_rendering:
bot.renderer.draw_line_3d(closest_enemy.pos, enemy_hit_pos, bot.renderer.red())
draw.line(closest_enemy.pos, enemy_hit_pos, draw.red())
return bot.drive.home(bot)

if bot.do_rendering:
bot.renderer.draw_line_3d(car.pos, offset_ball, bot.renderer.yellow())
draw.line(car.pos, offset_ball, draw.yellow())

return bot.drive.towards_point(bot, offset_ball, target_vel=2200, slide=False, boost_min=0)

Expand All @@ -85,18 +83,16 @@ def run(self, bot) -> SimpleControllerState:
wait_point = hit_pos + enemy_to_ball * enemy_dist # a point 50% closer to the center of the field
wait_point = lerp(wait_point, ball.pos + Vec3(0, bot.info.team_sign * 3000, 0), 0.5)

if bot.do_rendering:
bot.renderer.draw_line_3d(car.pos, wait_point, bot.renderer.yellow())
draw.line(car.pos, wait_point, draw.yellow())

return bot.drive.towards_point(bot, wait_point, norm(car.pos - wait_point), slide=False, can_keep_speed=True, can_dodge=False)

elif bot.shoot.can_shoot:

# Shoot !
if bot.do_rendering:
aim_cone.draw(bot, bot.shoot.ball_when_hit.pos, r=0, b=0)
if bot.shoot.using_curve:
rendering.draw_bezier(bot, [car.pos, bot.shoot.curve_point, hit_pos])
aim_cone.draw(bot.shoot.ball_when_hit.pos, r=0, b=0)
if bot.shoot.using_curve:
draw.bezier([car.pos, bot.shoot.curve_point, hit_pos], draw.color(100, 255, 100))
return shoot_controls

else:
Expand All @@ -109,9 +105,9 @@ def run(self, bot) -> SimpleControllerState:
for corner in corners:
ctrls = bot.shoot.towards(bot, corner, bot.info.my_car.reach_ball_time)
if bot.shoot.can_shoot:
aim_cone.draw(bot, bot.shoot.ball_when_hit.pos, b=0)
aim_cone.draw(bot.shoot.ball_when_hit.pos, b=0)
if bot.shoot.using_curve:
rendering.draw_bezier(bot, [car.pos, bot.shoot.curve_point, hit_pos])
draw.bezier([car.pos, bot.shoot.curve_point, hit_pos], draw.color(100, 255, 100))
return ctrls

enemy_to_ball = normalize(xy(ball.pos - closest_enemy.pos))
Expand Down
23 changes: 6 additions & 17 deletions RLBotPack/manticore/controllers/aim_cone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math

from utility import rendering
from utility import draw
from utility.curves import curve_from_arrival_dir
from utility.info import Field
from utility.rlmath import fix_ang, clip
Expand Down Expand Up @@ -66,24 +66,13 @@ def get_goto_point(self, bot, src, point):
goto.x = clip(goto.x, -Field.WIDTH / 2, Field.WIDTH / 2)
goto.y = clip(goto.y, -Field.LENGTH / 2, Field.LENGTH / 2)

if bot.do_rendering:
bot.renderer.draw_line_3d(car_pos, goto, bot.renderer.create_color(255, 150, 150, 150))
bot.renderer.draw_line_3d(point, goto, bot.renderer.create_color(255, 150, 150, 150))

# Bezier
rendering.draw_bezier(bot, [car_pos, goto, point])
draw.line(car_pos, goto, draw.color(150, 150, 150))
draw.line(point, goto, draw.color(150, 150, 150))
draw.bezier([car_pos, goto, point], draw.grey())

return goto, 0.5
else:
return None, 1

def draw(self, bot, center, arm_len=500, arm_count=5, r=255, g=255, b=255):
renderer = bot.renderer
ang_step = self.span_size() / (arm_count - 1)

for i in range(arm_count):
ang = self.right_ang - ang_step * i
arm_dir = Vec3(math.cos(ang), math.sin(ang), 0)
end = center + arm_dir * arm_len
alpha = 255 if i == 0 or i == arm_count - 1 else 110
renderer.draw_line_3d(center, end, renderer.create_color(alpha, r, g, b))
def draw(self, center, arm_len=500, r=255, g=255, b=255):
draw.fan(center, self.right_ang, self.span_size(), arm_len, draw.color(r, g, b))
13 changes: 6 additions & 7 deletions RLBotPack/manticore/controllers/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from maneuvers.dodge import DodgeManeuver
from maneuvers.halfflip import HalfFlipManeuver
from maneuvers.recovery import RecoveryManeuver
from utility import rendering
from utility import draw
from utility.info import Field, is_near_wall, Goal
from utility.rlmath import lerp, sign, clip
from utility.vec import Vec3, angle_between, xy, dot, norm, proj_onto_size, normalize
Expand Down Expand Up @@ -89,12 +89,12 @@ def towards_point(self, bot, point: Vec3, target_vel=1430, slide=False, boost_mi
tr_center_local = Vec3(0, tr * tr_side, 10)
point_is_in_turn_radius_deadzone = norm(point_local - tr_center_local) < tr
# Draw turn radius deadzone
if car.on_ground and bot.do_rendering and False:
if car.on_ground and False:
tr_center_world = car.pos + dot(car.rot, tr_center_local)
tr_center_world_2 = car.pos + dot(car.rot, -1 * tr_center_local)
color = bot.renderer.orange()
rendering.draw_circle(bot, tr_center_world, car.up, tr, 22, color)
rendering.draw_circle(bot, tr_center_world_2, car.up, tr, 22, color)
color = draw.orange()
draw.circle(tr_center_world, car.up, tr, color)
draw.circle(tr_center_world_2, car.up, tr, color)

if point_is_in_turn_radius_deadzone:
# Hard turn
Expand Down Expand Up @@ -170,8 +170,7 @@ def _avoid_goal_post(bot, point):
# Adjustment is needed
point.x = clip(point.x, -goalx, goalx)
point.y = clip(point.y, -goaly, goaly)
if bot.do_rendering:
bot.renderer.draw_line_3d(car.pos, point, bot.renderer.green())
draw.line(car.pos, point, draw.green())

def stay_at(self, bot, point: Vec3, looking_at: Vec3):

Expand Down
3 changes: 1 addition & 2 deletions RLBotPack/manticore/controllers/shots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from controllers.aim_cone import AimCone
from maneuvers.jump_shot import JumpShotManeuver
from maneuvers.small_jump import SmallJumpManeuver
from utility.curves import curve_from_arrival_dir
from utility.info import Field, Ball
from utility.predict import ball_predict, next_ball_landing
Expand Down Expand Up @@ -177,7 +176,7 @@ def towards(self, bot, target: Vec3, time: float, allowed_uncertainty: float = 0
left = dot(axis_to_rotation(Vec3(z=-allowed_uncertainty)), ball_soon_to_target_dir)
aim_cone = AimCone(right, left)

aim_cone.draw(bot, ball_soon.pos, r=0, g=0)
aim_cone.draw(ball_soon.pos, r=0, g=0)

return self.with_aiming(bot, aim_cone, time, dodge_hit)

Expand Down
3 changes: 2 additions & 1 deletion RLBotPack/manticore/maneuvers/collect_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tmcp import TMCPMessage

from maneuvers.maneuver import Maneuver
from utility import draw
from utility.info import BoostPad
from utility.vec import norm, proj_onto_size

Expand Down Expand Up @@ -56,7 +57,7 @@ def exec(self, bot) -> SimpleControllerState:
if dist < 50 + vel * 0.2 or car.boost > 50 or not self.target_pad.is_active:
self.done = True

bot.renderer.draw_line_3d(car.pos, self.target_pad.pos, bot.renderer.yellow())
draw.line(car.pos, self.target_pad.pos, bot.renderer.yellow())
return bot.drive.towards_point(bot, self.target_pad.pos, target_vel=self.target_vel, slide=True, boost_min=0, can_dodge=self.target_pad.is_big)


Expand Down
18 changes: 9 additions & 9 deletions RLBotPack/manticore/maneuvers/jump_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tmcp import TMCPMessage

from maneuvers.maneuver import Maneuver
from utility import predict, rendering
from utility import predict, draw
from utility.info import GRAVITY, JUMP_MAX_DUR, THROTTLE_AIR_ACCEL, JUMP_ACCEL, JUMP_SPEED, BOOST_ACCEL, \
BOOST_PR_SEC, MAX_SPEED, Ball
from utility.rlmath import clip01, clip, lerp, sign
Expand Down Expand Up @@ -151,14 +151,14 @@ def exec(self, bot):
self.done = True
bot.send_quick_chat(QuickChats.CHAT_EVERYONE, QuickChats.Apologies_Cursing)

if bot.do_rendering:
car_to_hit_dir = normalize(self.hit_pos - car.pos)
color = bot.renderer.pink()
rendering.draw_cross(bot, self.hit_pos, color, arm_length=100)
rendering.draw_circle(bot, lerp(car.pos, self.hit_pos, 0.25), car_to_hit_dir, 40, 12, color)
rendering.draw_circle(bot, lerp(car.pos, self.hit_pos, 0.5), car_to_hit_dir, 40, 12, color)
rendering.draw_circle(bot, lerp(car.pos, self.hit_pos, 0.75), car_to_hit_dir, 40, 12, color)
bot.renderer.draw_line_3d(car.pos, self.hit_pos, color)
# Draw
car_to_hit_dir = normalize(self.hit_pos - car.pos)
color = bot.renderer.pink()
draw.cross(self.hit_pos, color, arm_length=100)
draw.circle(lerp(car.pos, self.hit_pos, 0.25), car_to_hit_dir, 40, color)
draw.circle(lerp(car.pos, self.hit_pos, 0.5), car_to_hit_dir, 40, color)
draw.circle(lerp(car.pos, self.hit_pos, 0.75), car_to_hit_dir, 40, color)
draw.line(car.pos, self.hit_pos, color)

return controls

Expand Down
3 changes: 2 additions & 1 deletion RLBotPack/manticore/maneuvers/kickoff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rlbot.agents.base_agent import SimpleControllerState

from maneuvers.maneuver import Maneuver
from utility import draw
from utility.curves import curve_from_arrival_dir
from utility.rlmath import sign
from utility.vec import Vec3, norm, proj_onto_size
Expand Down Expand Up @@ -138,7 +139,7 @@ def exec(self, bot) -> SimpleControllerState:
point.y = bot.info.team_sign * 2790

self.done = not bot.info.is_kickoff
bot.renderer.draw_line_3d(car.pos, point, bot.renderer.white())
draw.line(car.pos, point, bot.renderer.white())

return bot.drive.towards_point(bot, point, target_vel=speed, slide=False, boost_min=0,
can_dodge=False, can_keep_speed=False)
Expand Down
27 changes: 25 additions & 2 deletions RLBotPack/manticore/maneuvers/recovery.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from rlbot.agents.base_agent import SimpleControllerState

from maneuvers.maneuver import Maneuver
from utility.info import Car
from utility import predict
from utility.info import Car, Field
from utility.plane import intersects_plane
from utility.predict import DummyObject
from utility.vec import normalize, xy, Vec3, cross, Mat33, norm


Expand All @@ -17,7 +20,27 @@ def exec(self, bot) -> SimpleControllerState:
@staticmethod
def find_landing_orientation(car: Car) -> Mat33:

# FIXME: If we knew the arena's mesh we could test if we are landing on a wall or something
# FIXME: This uses a cheap approximation of the walls to find landing orientation

obj = DummyObject(car)
prev_pos = obj.pos
for i in range(100):
predict.fall(obj, 0.1)

# Checking for intersections
for plane in Field.SIDE_WALLS_AND_GROUND:
if intersects_plane(prev_pos, obj.pos, plane):
# Bingo!
fall_dir = normalize(obj.pos - prev_pos)
left = -cross(fall_dir, plane.normal)
forward = -cross(plane.normal, left)

return Mat33.from_columns(forward, left, plane.normal)

prev_pos = obj.pos

# No wall/ground intersections found in fall
# Default to looking in direction of velocity, but upright

forward = normalize(xy(car.vel)) if norm(xy(car.vel)) > 20 else car.forward
up = Vec3(z=1)
Expand Down
2 changes: 0 additions & 2 deletions RLBotPack/manticore/manticore.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ github = https://github.com/NicEastvillage/RLBot-Manticore

# Programming language
language = Python

tags = teamplay
29 changes: 16 additions & 13 deletions RLBotPack/manticore/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from strategy.analyzer import GameAnalyzer
from strategy.objective import Objective
from strategy.utility_system import UtilitySystem
from utility import draw
from utility.info import GameInfo, tcmp_to_quick_chat
from utility.vec import Vec3

Expand Down Expand Up @@ -51,6 +52,8 @@ def initialize_agent(self):
self.tmcp_handler = TMCPHandler(self)
if TMCP_VERSION != [0, 9]:
self.tmcp_handler.disable()
if RENDER:
draw.setup(self.renderer)

def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
# Read packet
Expand All @@ -72,19 +75,19 @@ def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
controller = self.use_brain()

# Additional rendering
if self.do_rendering:
doing = self.maneuver or self.choice
state_color = {
Objective.GO_FOR_IT: self.renderer.lime(),
Objective.FOLLOW_UP: self.renderer.yellow(),
Objective.ROTATING: self.renderer.red(),
Objective.SOLO: self.renderer.team_color(alt_color=True),
Objective.UNKNOWN: self.renderer.team_color(alt_color=True)
}[self.info.my_car.objective]
if doing is not None:
self.renderer.draw_string_2d(330, 700 + self.index * 20, 1, 1, f"{self.name}:", self.renderer.team_color(alt_color=True))
self.renderer.draw_string_2d(500, 700 + self.index * 20, 1, 1, doing.__class__.__name__, state_color)
self.renderer.draw_rect_3d(self.info.my_car.pos + Vec3(z=60), 16, 16, True, state_color)
doing = self.maneuver or self.choice
state_color = {
Objective.GO_FOR_IT: draw.lime(),
Objective.FOLLOW_UP: draw.yellow(),
Objective.ROTATING: draw.red(),
Objective.SOLO: draw.team_color_sec(),
Objective.UNKNOWN: draw.team_color_sec()
}[self.info.my_car.objective]
if doing is not None:
draw.string_2d(330, 700 + self.index * 20, 1, f"{self.name}:", draw.team_color())
draw.string_2d(500, 700 + self.index * 20, 1, doing.__class__.__name__, state_color)
draw.rect_3d(self.info.my_car.pos + Vec3(z=60), 16, 16, state_color)
draw.string_3d(self.info.my_car.pos + Vec3(z=110), 1, f"{self.info.my_car.last_ball_touch:.1f}", state_color)

self.renderer.end_rendering()

Expand Down
Loading

0 comments on commit c5087d1

Please sign in to comment.