Skip to content

Commit f7a6ad7

Browse files
committed
Merge branch 'robocup_2019' of github.com:UBC-Thunderbots/Software into robocup_2019
2 parents 70998c2 + 4c651bd commit f7a6ad7

19 files changed

+474
-63
lines changed

src/thunderbots/software/ai/hl/stp/play/corner_kick_play.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ void CornerKickPlay::getNextTactics(TacticCoroutine::push_type &yield)
130130
PassGenerator pass_generator(world, world.ball().position(),
131131
PassType::ONE_TOUCH_SHOT);
132132

133+
// Target any pass in the enemy half of the field, shifted up by 1 meter
134+
// from the center line
135+
pass_generator.setTargetRegion(Rectangle(
136+
Point(1, world.field().width()/2),
137+
world.field().enemyCornerNeg()
138+
));
139+
133140
std::pair<Pass, double> best_pass_and_score_so_far =
134141
pass_generator.getBestPassSoFar();
135142

src/thunderbots/software/ai/hl/stp/play/defense_play.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void DefensePlay::getNextTactics(TacticCoroutine::push_type &yield)
5050

5151
std::shared_ptr<ShadowEnemyTactic> shadow_enemy_tactic =
5252
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
53-
world.enemyTeam(), true, true);
53+
world.enemyTeam(), true, world.ball(), true);
5454

5555

5656
std::array<std::shared_ptr<CreaseDefenderTactic>, 2> crease_defender_tactics = {
@@ -100,7 +100,7 @@ void DefensePlay::getNextTactics(TacticCoroutine::push_type &yield)
100100
shoot_goal_tactic->addWhitelistedAvoidArea(AvoidArea::HALF_METER_AROUND_BALL);
101101
auto shoot_goal_robot = shoot_goal_tactic->getAssignedRobot();
102102
if(shoot_goal_robot && (dist(shoot_goal_robot->position(), world.ball().position()) < 4 * ROBOT_MAX_RADIUS_METERS)
103-
&& shoot_goal_robot->velocity().len() < 0.75) {
103+
&& shoot_goal_robot->velocity().len() < 0.5) {
104104
shoot_goal_tactic->addWhitelistedAvoidArea(AvoidArea::ENEMY_ROBOTS);
105105
LOG(DEBUG) << "ignoring enemy" << std::endl;
106106
}
@@ -152,8 +152,9 @@ void DefensePlay::getNextTactics(TacticCoroutine::push_type &yield)
152152

153153
if (enemy_threats.size() > 1) {
154154
shadow_enemy_tactic->updateParams(
155-
enemy_threats.at(0), world.field(), world.friendlyTeam(),
156-
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
155+
enemy_threats.at(1), world.field(), world.friendlyTeam(),
156+
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3,
157+
enemy_team_can_pass, world.ball());
157158
result.emplace_back(shadow_enemy_tactic);
158159
} else {
159160
Robot nearest_enemy_robot = *std::min_element(

src/thunderbots/software/ai/hl/stp/play/enemy_freekick_play.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ void EnemyFreekickPlay::getNextTactics(TacticCoroutine::push_type &yield)
5353

5454
// Init Shadow Enemy Tactics for extra robots
5555
auto shadow_tactic_main = std::make_shared<ShadowEnemyTactic>(
56-
world.field(), world.friendlyTeam(), world.enemyTeam(), true, true);
56+
world.field(), world.friendlyTeam(), world.enemyTeam(), true, world.ball(), true);
5757
auto shadow_tactic_secondary = std::make_shared<ShadowEnemyTactic>(
58-
world.field(), world.friendlyTeam(), world.enemyTeam(), true, true);
58+
world.field(), world.friendlyTeam(), world.enemyTeam(), true, world.ball(), true);
5959

6060
// Init Move Tactics for extra robots (These will be used if there are no robots to
6161
// shadow)
@@ -114,7 +114,7 @@ void EnemyFreekickPlay::getNextTactics(TacticCoroutine::push_type &yield)
114114
{
115115
shadow_tactic_main->updateParams(
116116
enemy_threats.at(1), world.field(), world.friendlyTeam(),
117-
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
117+
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass, world.ball());
118118
move_tactic_main->updateParams(
119119
world.field().friendlyGoal() + Point(0, 2 * ROBOT_MAX_RADIUS_METERS),
120120
(world.ball().position() - world.field().friendlyGoal()).orientation(),
@@ -127,10 +127,10 @@ void EnemyFreekickPlay::getNextTactics(TacticCoroutine::push_type &yield)
127127
{
128128
shadow_tactic_main->updateParams(
129129
enemy_threats.at(1), world.field(), world.friendlyTeam(),
130-
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
130+
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass, world.ball());
131131
shadow_tactic_secondary->updateParams(
132132
enemy_threats.at(2), world.field(), world.friendlyTeam(),
133-
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
133+
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass, world.ball());
134134

135135
tactics_to_run.emplace_back(shadow_tactic_main);
136136
tactics_to_run.emplace_back(shadow_tactic_secondary);

src/thunderbots/software/ai/hl/stp/play/kickoff_enemy_play.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ void KickoffEnemyPlay::getNextTactics(TacticCoroutine::push_type &yield)
3535
// on the field to be evenly spread out
3636
std::vector<std::shared_ptr<ShadowEnemyTactic>> shadow_enemy_tactics = {
3737
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
38-
world.enemyTeam(), true, true),
38+
world.enemyTeam(), true, world.ball(), true),
3939
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
40-
world.enemyTeam(), true, true),
40+
world.enemyTeam(), true, world.ball(), true),
4141
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
42-
world.enemyTeam(), true, true)};
42+
world.enemyTeam(), true, world.ball(), true)};
4343

4444
// these positions are picked according to the following slide
4545
// https://images.slideplayer.com/32/9922349/slides/slide_2.jpg
@@ -118,7 +118,7 @@ void KickoffEnemyPlay::getNextTactics(TacticCoroutine::push_type &yield)
118118
// anyway
119119
shadow_enemy_tactics.at(i)->updateParams(
120120
enemy_threat, world.field(), world.friendlyTeam(), world.enemyTeam(),
121-
shadow_dist, false);
121+
shadow_dist, false, world.ball());
122122
result.emplace_back(shadow_enemy_tactics.at(i));
123123
}
124124
else

src/thunderbots/software/ai/hl/stp/play/penalty_kick_play.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,17 @@ void PenaltyKickPlay::getNextTactics(TacticCoroutine::push_type &yield)
5656
move_tactic_6->addWhitelistedAvoidArea(AvoidArea::ENEMY_HALF);
5757
move_tactic_6->addWhitelistedAvoidArea(AvoidArea::FRIENDLY_HALF);
5858

59+
Timestamp start_of_shoot = world.getMostRecentTimestamp();
5960
do
6061
{
6162
std::vector<std::shared_ptr<Tactic>> tactics_to_run;
6263

6364

64-
Vector behind_ball_direction = (world.ball().position() - world.field().enemyGoalpostPos()).norm();
65-
Angle shoot_angle = (world.field().enemyGoalpostPos() - world.ball().position()).orientation();
65+
Vector behind_ball_direction = (world.ball().position() - world.field().enemyGoal()).norm();
66+
Angle shoot_angle = (world.field().enemyGoal() - world.ball().position()).orientation();
6667

6768
Point behind_ball = world.ball().position() + behind_ball_direction.norm(DIST_TO_FRONT_OF_ROBOT_METERS + BALL_MAX_RADIUS_METERS + 0.1);
6869

69-
printf("\nX=%f", behind_ball.x());
70-
printf("\nY=%f", behind_ball.y());
7170
move_tactic_2->updateParams(Point(0, 0), world.field().enemyGoal().orientation(),
7271
0);
7372
move_tactic_3->updateParams(Point(0, 4 * ROBOT_MAX_RADIUS_METERS),
@@ -78,7 +77,7 @@ void PenaltyKickPlay::getNextTactics(TacticCoroutine::push_type &yield)
7877
world.field().enemyGoal().orientation(), 0);
7978
move_tactic_6->updateParams(Point(0, -8 * ROBOT_MAX_RADIUS_METERS),
8079
world.field().enemyGoal().orientation(), 0);
81-
penalty_shot_tactic->updateParams(world.ball(), world.enemyTeam().goalie(), world.field());
80+
penalty_shot_tactic->updateParams(world.ball(), world.enemyTeam().goalie(), world.field(), start_of_shoot);
8281
shooter_setup_move->updateParams(behind_ball, shoot_angle, 0.0);
8382

8483
// If we are setting up for penalty kick, move our robots to position

src/thunderbots/software/ai/hl/stp/play/shoot_or_chip_play.cpp

+35-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "ai/hl/stp/tactic/crease_defender_tactic.h"
1313
#include "ai/hl/stp/tactic/goalie_tactic.h"
1414
#include "ai/hl/stp/tactic/move_tactic.h"
15+
#include "ai/hl/stp/tactic/patrol_tactic.h"
1516
#include "ai/hl/stp/tactic/shadow_enemy_tactic.h"
1617
#include "ai/hl/stp/tactic/shoot_goal_tactic.h"
1718
#include "ai/hl/stp/tactic/stop_tactic.h"
@@ -31,12 +32,21 @@ std::string ShootOrChipPlay::getName() const
3132

3233
bool ShootOrChipPlay::isApplicable(const World &world) const
3334
{
34-
return world.gameState().isPlaying() &&
35+
bool use_shoot_or_pass_instead_of_shoot_or_chip =
36+
Util::DynamicParameters::HighLevelStrategy::
37+
use_shoot_or_pass_instead_of_shoot_or_chip.value();
38+
39+
return !use_shoot_or_pass_instead_of_shoot_or_chip && world.gameState().isPlaying() &&
3540
Evaluation::teamHasPossession(world, world.friendlyTeam());
3641
}
3742

3843
bool ShootOrChipPlay::invariantHolds(const World &world) const
3944
{
45+
46+
// bool use_shoot_or_pass_instead_of_shoot_or_chip =
47+
// Util::DynamicParameters::HighLevelStrategy::
48+
// use_shoot_or_pass_instead_of_shoot_or_chip.value();
49+
4050
return world.gameState().isPlaying() &&
4151
Evaluation::teamHasPossession(world, world.friendlyTeam());
4252
}
@@ -65,6 +75,23 @@ void ShootOrChipPlay::getNextTactics(TacticCoroutine::push_type &yield)
6575
CreaseDefenderTactic::LeftOrRight::RIGHT),
6676
};
6777

78+
std::array<std::shared_ptr<PatrolTactic>, 2> patrol_tactics = {
79+
std::make_shared<PatrolTactic>(
80+
std::vector<Point>(
81+
{Point(world.field().enemyCornerPos().x() - 3 * ROBOT_MAX_RADIUS_METERS,
82+
world.field().enemyCornerPos().y() - 3 * ROBOT_MAX_RADIUS_METERS),
83+
Point(3 * ROBOT_MAX_RADIUS_METERS,
84+
world.field().width() / 2 - 3 * ROBOT_MAX_RADIUS_METERS)}),
85+
.03, 0),
86+
std::make_shared<PatrolTactic>(
87+
std::vector<Point>(
88+
{Point(3 * ROBOT_MAX_RADIUS_METERS,
89+
-world.field().width() / 2 + 3 * ROBOT_MAX_RADIUS_METERS),
90+
Point(
91+
world.field().enemyCornerNeg().x() - 3 * ROBOT_MAX_RADIUS_METERS,
92+
world.field().enemyCornerNeg().y() + 3 * ROBOT_MAX_RADIUS_METERS)}),
93+
.03, 0)};
94+
6895
std::array<std::shared_ptr<MoveTactic>, 2> move_to_open_area_tactics = {
6996
std::make_shared<MoveTactic>(true), std::make_shared<MoveTactic>(true)};
7097

@@ -140,13 +167,19 @@ void ShootOrChipPlay::getNextTactics(TacticCoroutine::push_type &yield)
140167
shoot_or_chip_tactic->addWhitelistedAvoidArea(AvoidArea::HALF_METER_AROUND_BALL);
141168
auto shoot_goal_robot = shoot_or_chip_tactic->getAssignedRobot();
142169
if(shoot_goal_robot && (dist(shoot_goal_robot->position(), world.ball().position()) < 4 * ROBOT_MAX_RADIUS_METERS)
143-
&& shoot_goal_robot->velocity().len() < 0.75) {
170+
&& shoot_goal_robot->velocity().len() < 0.5) {
144171
shoot_or_chip_tactic->addWhitelistedAvoidArea(AvoidArea::ENEMY_ROBOTS);
145172
}
146173

147174
// We want this second in priority only to the goalie
148175
result.insert(result.begin() + 1, shoot_or_chip_tactic);
149176

177+
// If we can't do anything else then patrol?
178+
for (auto &patrol_tactic : patrol_tactics)
179+
{
180+
result.emplace_back(patrol_tactic);
181+
}
182+
150183
// yield the Tactics this Play wants to run, in order of priority
151184
yield(result);
152185

0 commit comments

Comments
 (0)