Skip to content

Commit 0575948

Browse files
committed
Only go for kickoff if closest or joint closest and on left. Demobot fix + goalie fix. Commenting.
Instead of going for kickoff if closest or joint closest not FormularBot only goes for kickoff if closest or (joint closest and on left). It's usual in Rocket League for the player on the left to go for kickoff unles otherwise agreed. DemoBot fix. When I moved all decision making and stack clearing code to FormularBot.py I moved code which worked out closest enemy as well. That code has now been moved back to routines.py as it's only used for demo_nearest_enemy routine and is needed by both FormularBot and DemoBot. Fixed goalie code. In 1.3.2 I made it so goalie is false if shooting is true, however I forgot that'd make goalie rush out and shoot when ball is near enemies goal. I've now changed it to goalie is False if me_onside and (closest_to_ball or distance_ball_friendly_goal < 3000), the other two conditions of shooting. Commented some code in FormularBot.py and DemoBot.py
1 parent 71a35b9 commit 0575948

3 files changed

Lines changed: 72 additions & 48 deletions

File tree

DemoBot.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,27 @@
55

66
class DemoBot(GoslingAgent):
77
def run(agent):
8+
#Works out kickoff position and passes that variable onto kickoff function in routines
9+
x_position = int(agent.me.location.x * side(agent.team))
10+
if x_position == 2047 or x_position == 2048:
11+
kickoff_position = 'diagonal_right'
12+
elif x_position == -2047 or x_position == -2048:
13+
kickoff_position = 'diagonal_left'
14+
elif x_position == -255 or x_position == -256:
15+
kickoff_position = 'back_left'
16+
elif x_position == 255 or x_position == 256:
17+
kickoff_position = 'back_right'
18+
else:
19+
kickoff_position = 'back_centre'
20+
821
if agent.index == 0:
922
agent.debug_stack()
1023
if len(agent.stack) < 1:
1124
if agent.kickoff_flag:
12-
agent.push(kickoff(int(agent.me.location.x * side(agent.team))))
25+
agent.push(kickoff(kickoff_position))
1326
else:
27+
#If not going doing kickoff pushes demo routine to stack
1428
agent.push(demo_enemy_closest_ball)
29+
30+
# print(agent.ball.velocity) - testing for dribbling
31+
# print(agent.game.time_remaining)

FormularBot.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ def run(agent):
1717
distance_ball_friendly_goal = (agent.ball.location - agent.friend_goal.location).magnitude()
1818
distance_ball_foe_goal = (agent.ball.location - agent.foe_goal.location).magnitude()
1919

20-
if len(agent.foes) > 0:
21-
enemies = agent.foes
22-
closest = enemies[0]
23-
closest_distance = (enemies[0].location - agent.ball.location).magnitude()
24-
x = 0
25-
y = 0
26-
for item in enemies:
27-
item_distance = (item.location - agent.ball.location).magnitude()
28-
if item_distance < closest_distance:
29-
closest = item
30-
closest_distance = item_distance
31-
y = x
32-
x =+ 1
33-
3420
my_goal_to_ball,my_ball_distance = (agent.ball.location - agent.friend_goal.location).normalize(True)
3521
goal_to_me = agent.me.location - agent.friend_goal.location
3622
my_distance = my_goal_to_ball.dot(goal_to_me)
@@ -69,22 +55,42 @@ def run(agent):
6955
closest_ally_to_ball_distance = ally_to_ball_distance
7056
closest_ally_friendly_goal_distance = ally_to_friendly_goal_distance
7157

72-
closest_to_ball = distance_to_ball <= closest_ally_to_ball_distance
58+
closest_to_ball = distance_to_ball < closest_ally_to_ball_distance
59+
joint_closest_to_ball = distance_to_ball == closest_ally_to_ball_distance
7360
closest_to_friendly_goal = distance_to_friendly_goal <= closest_ally_friendly_goal_distance
7461

75-
62+
#Works out kickoff position and passes that variable onto kickoff function in routines
63+
x_position = int(agent.me.location.x * side(agent.team))
64+
if x_position == 2047 or x_position == 2048:
65+
kickoff_position = 'diagonal_right'
66+
elif x_position == -2047 or x_position == -2048:
67+
kickoff_position = 'diagonal_left'
68+
elif x_position == -255 or x_position == -256:
69+
kickoff_position = 'back_left'
70+
elif x_position == 255 or x_position == 256:
71+
kickoff_position = 'back_right'
72+
else:
73+
kickoff_position = 'back_centre'
7674

75+
#Shoots if onside and (closest to ball or ball within 4000 of foe goal and between -1250 and 1250 x or ball is within 3000 of own goal)
7776
if me_onside and (closest_to_ball or (distance_ball_foe_goal < 4000 and -1250 < agent.ball.location.x < 1250) or distance_ball_friendly_goal < 3000):
7877
shooting = True
7978
else:
8079
shooting = False
8180

82-
if not(shooting) and closest_to_friendly_goal and not(close and not me_onside) and len(agent.friends) > 0:
81+
#Leaves goal to hit ball if onside and (closest to ball or ball within 3000 of goal. Stays in goal if that is false and closest to goal and not close and offside (to not score own goals))
82+
if not(me_onside and (closest_to_ball or distance_ball_friendly_goal < 3000)) and closest_to_friendly_goal and not(close and not me_onside):
8383
goalie = True
8484
else:
8585
goalie = False
86+
87+
#Only go for kickoff if closest or joint closeset and on left side
88+
if agent.kickoff_flag and (closest_to_ball or (joint_closest_to_ball and (kickoff_position == 'diagonal_left' or kickoff_position == 'back_left'))):
89+
go_for_kickoff = True
90+
else:
91+
go_for_kickoff = False
8692

87-
# if agent.index == 0:
93+
# if agent.index == 0:
8894
# agent.debug_stack()
8995
# print(shooting,goalie)
9096
# print(closest_to_ball)
@@ -97,19 +103,20 @@ def run(agent):
97103
# agent.line(agent.friend_goal.location, agent.ball.location, [255,255,255])
98104
# my_point = agent.friend_goal.location + (my_goal_to_ball * my_distance)
99105
# agent.line(my_point - Vector3(0,0,100), my_point + Vector3(0,0,500), [0,255,0])
100-
106+
107+
#Decision making code
101108
if len(agent.stack) < 1:
102-
if agent.kickoff_flag and closest_to_ball:
109+
if go_for_kickoff:
103110
stack = 'kickoff'
104-
agent.push(kickoff(int(agent.me.location.x * side(agent.team))))
111+
agent.push(kickoff(kickoff_position))
105112
elif goalie:
106113
stack = 'goalie'
107114
agent.push(goto_friendly_goal)
108115
elif shooting:
109116
stack = 'shooting'
110117
if len(shots["goal"]) > 0:
111118
agent.push(shots["goal"][0])
112-
#send(random.choice(chat_ids))
119+
#send(random.choice(chat_ids)) - TODO
113120
elif len(shots["upfield"]) > 0 and abs(agent.friend_goal.location.y - agent.ball.location.y) < 8490:
114121
agent.push(shots["upfield"][0])
115122
else:
@@ -133,9 +140,9 @@ def run(agent):
133140
stack = 'getting boost'
134141
agent.push(get_nearest_big_boost)
135142

136-
if not stack == kickoff and not(stack == 'shooting' and (close and me_onside)) and not(stack == 'getting boost' and agent.me.boost < 20 and len(agent.friends) > 1):
137-
138-
if agent.kickoff_flag and closest_to_ball:
143+
#Stack clearing code (decides when to clear stack and do something else)
144+
if not(stack == 'kickoff') and not(stack == 'shooting' and (close and me_onside)) and not(stack == 'getting boost' and agent.me.boost < 20 and len(agent.friends) > 1):
145+
if go_for_kickoff:
139146
if stack != 'kickoff':
140147
agent.clear()
141148
elif goalie:
@@ -160,10 +167,11 @@ def run(agent):
160167
elif stack != 'getting boost':
161168
agent.clear()
162169

163-
170+
#Jumps if turtling
164171
if agent.me.velocity[0] == 0 and int(agent.me.location.z) == 40:
165172
agent.controller.jump = True
166173

174+
#Boost if going centre and offside (getting back)
167175
if stack == 'going centre':
168176
if not me_onside:
169177
agent.controller.boost = True

routines.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,24 @@ def run(agent):
110110
agent.push(get_nearest_big_boost)
111111
else:
112112
try:
113-
relative_target = agent.foes[y].location - agent.me.location
114-
local_target = agent.me.local(relative_target)
115-
defaultPD(agent, local_target)
116-
defaultThrottle(agent, 2300)
117-
distance_remaining = local_target.flatten().magnitude()
113+
if len(agent.foes) > 0:
114+
enemies = agent.foes
115+
closest = enemies[0]
116+
closest_distance = (enemies[0].location - agent.ball.location).magnitude()
117+
x = 0
118+
y = 0
119+
for item in enemies:
120+
item_distance = (item.location - agent.ball.location).magnitude()
121+
if item_distance < closest_distance:
122+
closest = item
123+
closest_distance = item_distance
124+
y = x
125+
x =+ 1
126+
127+
local_target = agent.me.local(agent.foes[y].location - agent.me.location)
128+
defaultPD(agent, local_target)
129+
defaultThrottle(agent, 2300)
130+
distance_remaining = local_target.flatten().magnitude()
118131

119132
if distance_remaining < 2000 or agent.me.boost > 50 and distance_remaining < 5000:
120133
agent.controller.boost = True
@@ -589,25 +602,11 @@ def run(self,agent):
589602
agent.controller.yaw = self.y if abs(self.y) > 0.3 else 0
590603

591604
class kickoff():
592-
def __init__(self,x_position):
605+
def __init__(self,kickoff_position):
593606
#the time the jump began
594607
self.time = -1
595608
self.counter = 0
596-
try:
597-
temp = self.kickoff
598-
del temp
599-
except:
600-
#Works out kickoff position spawned in
601-
if x_position == 2047 or x_position == 2048:
602-
self.kickoff = 'diagonal_right'
603-
elif x_position == -2047 or x_position == -2048:
604-
self.kickoff = 'diagonal_left'
605-
elif x_position == -255 or x_position == -256:
606-
self.kickoff = 'back_left'
607-
elif x_position == 255 or x_position == 256:
608-
self.kickoff = 'back_right'
609-
else:
610-
self.kickoff = 'back_centre'
609+
self.kickoff = kickoff_position
611610
def run(self,agent):
612611
if agent.kickoff_flag == False:
613612
agent.pop()

0 commit comments

Comments
 (0)