Skip to content

Commit

Permalink
Merge branch 'master' of github.com:project-neon/NeonFC
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexsandr0x committed Nov 9, 2020
2 parents 2f48ff4 + 31f2740 commit 6d0fb01
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
69 changes: 58 additions & 11 deletions strategy/offensive_strategy/Attacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def point_in_rect(point,rect):

class Attacker(Strategy):
def __init__(self, match, plot_field=False):
super().__init__(match)
super().__init__(match, controller_kwargs={'l': 0.0765})

"""
Ambiente para rascunhar novas estrategias com
Expand Down Expand Up @@ -116,7 +116,7 @@ def s(m):

weight = 1/2 + 1/2 * min((dist/radius), 1)

return weight * 0.75 if m.ball.y < 0.65 else 0
return weight * 0.85 if m.ball.y < 0.65 else 0

return s

Expand All @@ -133,7 +133,7 @@ def s(m):

weight = 1/2 + 1/2 * min((dist/radius), 1)

return weight * 0.75 if m.ball.y >= 0.65 else 0
return weight * 0.85 if m.ball.y >= 0.65 else 0

return s

Expand Down Expand Up @@ -310,13 +310,13 @@ def ttr(m):
pos_x = (
m.ball.x -
math.cos(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))) * 0.025 +
math.cos(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))+ math.pi/2)*0.2 + m.ball.vx/10
math.cos(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))+ math.pi/2)*0.12 + m.ball.vx/10
)

pos_y = (
m.ball.y -
math.sin(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))) * 0.025 +
math.sin(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))+ math.pi/2)*0.2 + m.ball.vy/10
math.sin(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))+ math.pi/2)*0.12 + m.ball.vy/10
)

return (pos_x, pos_y)
Expand Down Expand Up @@ -347,6 +347,36 @@ def ttr(m):
)
)

# self.seek.add_field(
# algorithims.fields.PointField(
# self.match,
# target= lambda m: (m.ball.x, m.ball.y - 0.05),
# radius=0.15,
# radius_max=0.15,
# decay = lambda x: x,
# field_limits = [0.75* 2 , 0.65*2],
# multiplier = 1
# )
# )

self.seek.add_field(
algorithims.fields.LineField(
self.match,
target= lambda m: (
m.ball.x - math.cos(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))) * 0.025,
m.ball.y - math.sin(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))) * 0.025
),
theta=lambda m: ( -math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))),
line_size = 1,
line_size_single_side = True,
line_dist = 0.15,
line_dist_max = 0.15,
decay = lambda x: x**2,
field_limits = [0.75* 2 , 0.65*2],
multiplier = 1 # 75 cm/s
)
)

self.seek.add_field(
algorithims.fields.PointField(
self.match,
Expand Down Expand Up @@ -395,6 +425,23 @@ def ttr(m):
multiplier = lambda m: max(0.80, math.sqrt(m.ball.vx**2 + m.ball.vy**2) + 0.1) # 50 cm/s
)
)
self.carry.add_field(
algorithims.fields.LineField(
self.match,
target= lambda m: (
m.ball.x - math.cos(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))) * 0.025,
m.ball.y - math.sin(math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))) * 0.025
),
theta=lambda m: ( -math.atan2((0.65-m.ball.y), (0.75*2 - m.ball.x))),
line_size = 1,
line_size_single_side = True,
line_dist = 0.15,
line_dist_max = 0.15,
decay = lambda x: x**2,
field_limits = [0.75* 2 , 0.65*2],
multiplier = 1 # 75 cm/s
)
)

self.maintain.add_field(self.base_rules)

Expand Down Expand Up @@ -436,7 +483,7 @@ def ttr(m):
radius = 0.04,
radius_max = 2,
clockwise = lambda m: (m.ball.y < 0.65),
decay=lambda x: 1,
decay=lambda x: 1 if x > 0.5 else 0.5,
field_limits = [0.75* 2 , 0.65*2],
multiplier = 1
)
Expand All @@ -460,10 +507,10 @@ def decide(self):
of_goal_area = [1.30, 0.30, 0.30, 0.70]
goal_area = [-0.05, 0.30, 0.20, 0.70]

angle_ball_to_goal = -math.atan2((self.match.ball.y - 0.65), (self.match.ball.x - 0.75*2))
min_angle_ball_to_goal = -math.atan2((self.match.ball.y - 0.55), (self.match.ball.x - 0.75*2))
angle_robot_to_ball = -math.atan2((self.robot.y - self.match.ball.y), (self.robot.x - self.match.ball.x ))

angle_to_goal = abs(angle_ball_to_goal - angle_robot_to_ball)
min_angle_to_goal = abs(min_angle_ball_to_goal - angle_robot_to_ball)

dist_to_ball = math.sqrt(
(self.robot.x - self.match.ball.x)**2 + (self.robot.y - self.match.ball.y)**2
Expand All @@ -472,7 +519,7 @@ def decide(self):
dist_to_ball_goal = math.sqrt(
(0 - self.match.ball.x)**2 + (0.65 - self.match.ball.y)**2
)

if point_in_rect(ball, of_goal_area):
behaviour = self.carry
elif point_in_rect(ball ,goal_area):
Expand All @@ -484,11 +531,11 @@ def decide(self):
or
(ball[1] <= 0.2 and self.robot.y <= 0.25)) and self.robot.x < ball[0]:
behaviour = self.carry
elif (angle_to_goal <= 0.75) and (dist_to_ball <= 0.20):
elif (min_angle_to_goal <= 0.60) and (dist_to_ball <= 0.25):
behaviour = self.carry
else:
behaviour = self.seek

print(self.robot.get_name(), "::", behaviour.name)

if self.exporter:
Expand Down
3 changes: 1 addition & 2 deletions strategy/offensive_strategy/MidFielder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def point_in_rect(point,rect):

class MidFielder(Strategy):
def __init__(self, match, plot_field=False):
super().__init__(
match)
super().__init__(match, controller_kwargs={'l': 0.0765})

"""
Essa estrategia descreve a um goleiro base, simples, que
Expand Down

0 comments on commit 6d0fb01

Please sign in to comment.