Skip to content

Commit 8b2d9fb

Browse files
Merge branch 'fsm' into passReceive
2 parents 9a58288 + 6031170 commit 8b2d9fb

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

role/_GoToPoint_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
def init(_kub,target,theta):
4343
global kub,GOAL_POINT,rotate,FLAG_turn,FLAG_move,FIRST_CALL
4444
kub = _kub
45-
GOAL_POINT = point_2d()
45+
GOAL_POINT = Vector2D()
4646
rotate = theta
4747
GOAL_POINT.x = target.x
4848
GOAL_POINT.y = target.y

utils/math_functions.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def intersection_with_line(self, line2):
105105
try:
106106
P.x = (c2 - c1) / (m1 - m2)
107107
P.y = (m1 * c2 - m2 * c1) / (m1 - m2)
108+
return P
108109
except:
109110
return None
110111
return P
@@ -166,7 +167,13 @@ def normalized_vector(self):
166167
# angle = math.atan(self.slope)
167168
angle = self.angle
168169
return Vector2D(math.cos(angle), math.sin(angle))
169-
170+
171+
def nearest_point_on_line(self,point):
172+
t=(point.y-self.point.y)*math.sin(self.angle)+(point.x-self.point.x)*(math.cos(self.angle))
173+
x1=self.point.x+math.cos(self.angle)*t
174+
y1=self.point.y+math.sin(self.angle)*t
175+
point=Vector2D(x1,y1)
176+
return point
170177

171178
##
172179
## @var slope
@@ -239,10 +246,10 @@ def stan_inverse(self,y,x):
239246
return atan2(y,x)+3.14159265
240247

241248

242-
# def getPointBehindTheBall(point ,theta):
243-
# x = point.x +(3.5 * BOT_RADIUS) *(math.cos(theta))
244-
# y = point.y +(3.5 * BOT_RADIUS) *(math.sin(theta))
245-
# return Vector2D(int(x), int(y))
249+
def getPointBehindTheBall(point ,theta, factor=3.5):
250+
x = point.x +(factor * BOT_RADIUS) *(math.cos(theta))
251+
y = point.y +(factor * BOT_RADIUS) *(math.sin(theta))
252+
return Vector2D(int(x), int(y))
246253

247254
def vicinity_points(point1, point2, thresh=10):
248255
return dist(point1, point2) < thresh
@@ -289,4 +296,4 @@ def kub_has_ball(state, kub_id):
289296
theta2 = math.atan2(state.ballPos.y - state.homePos[kub_id].y,
290297
state.ballPos.x - state.homePos[kub_id].x)
291298
return vicinity_theta(theta1, theta2, thresh=0.25) and vicinity_points(state.homePos[kub_id],
292-
state.ballPos, thresh=BOT_RADIUS * 1.5)
299+
state.ballPos, thresh=BOT_RADIUS * 1.5)

utils/state_functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def ball_moving_towards_our_goal(state):
3737
ptA = Vector2D(-HALF_FIELD_MAXX, DBOX_HEIGHT)
3838
ptB = Vector2D(-HALF_FIELD_MAXX, -DBOX_HEIGHT)
3939
defend_line = Line(point1=ptA,point2=ptB)
40-
opponent_aim = Line.intersection_with_line(ball_movement)
40+
opponent_aim = defend_line.intersection_with_line(ball_movement)
4141
if opponent_aim.y > -DBOX_HEIGHT and opponent_aim.y < DBOX_HEIGHT:
4242
return True
4343
return False
@@ -84,7 +84,7 @@ def closest_opponent(state, position):
8484
def our_bot_closest_to_ball(state):
8585
distance_from_ball = 99999999
8686
our_bot_closest_to_ball = 0
87-
for i in range(state.homePos.size()):
87+
for i in range(len(state.homePos)):
8888
dist = math.sqrt(pow((state.homePos[i].x - state.ballPos.x),2) + pow((state.homePos[i].y - state.ballPos.y) , 2))
8989
if dist < distance_from_ball :
9090
distance_from_ball = dist
@@ -95,7 +95,7 @@ def our_bot_closest_to_ball(state):
9595
def opp_bot_closest_to_ball(state):
9696
distance_from_ball = 99999999
9797
opp_bot_closest_to_ball = 0
98-
for i in range(state.awayPos.size()):
98+
for i in range(len(state.awayPos)):
9999
dist = math.sqrt(pow((state.awayPos[i].x - state.ballPos.x),2) + pow((state.awayPos[i].y - state.ballPos.y) , 2))
100100
if dist < distance_from_ball :
101101
distance_from_ball = dist

0 commit comments

Comments
 (0)