Skip to content

Commit

Permalink
Merge branch 'robocup_2019' of github.com:UBC-Thunderbots/Software in…
Browse files Browse the repository at this point in the history
…to robocup_2019
  • Loading branch information
henryymliu committed Jul 16, 2019
2 parents 70998c2 + 4c651bd commit f7a6ad7
Show file tree
Hide file tree
Showing 19 changed files with 474 additions and 63 deletions.
7 changes: 7 additions & 0 deletions src/thunderbots/software/ai/hl/stp/play/corner_kick_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ void CornerKickPlay::getNextTactics(TacticCoroutine::push_type &yield)
PassGenerator pass_generator(world, world.ball().position(),
PassType::ONE_TOUCH_SHOT);

// Target any pass in the enemy half of the field, shifted up by 1 meter
// from the center line
pass_generator.setTargetRegion(Rectangle(
Point(1, world.field().width()/2),
world.field().enemyCornerNeg()
));

std::pair<Pass, double> best_pass_and_score_so_far =
pass_generator.getBestPassSoFar();

Expand Down
9 changes: 5 additions & 4 deletions src/thunderbots/software/ai/hl/stp/play/defense_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void DefensePlay::getNextTactics(TacticCoroutine::push_type &yield)

std::shared_ptr<ShadowEnemyTactic> shadow_enemy_tactic =
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
world.enemyTeam(), true, true);
world.enemyTeam(), true, world.ball(), true);


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

if (enemy_threats.size() > 1) {
shadow_enemy_tactic->updateParams(
enemy_threats.at(0), world.field(), world.friendlyTeam(),
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
enemy_threats.at(1), world.field(), world.friendlyTeam(),
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3,
enemy_team_can_pass, world.ball());
result.emplace_back(shadow_enemy_tactic);
} else {
Robot nearest_enemy_robot = *std::min_element(
Expand Down
10 changes: 5 additions & 5 deletions src/thunderbots/software/ai/hl/stp/play/enemy_freekick_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void EnemyFreekickPlay::getNextTactics(TacticCoroutine::push_type &yield)

// Init Shadow Enemy Tactics for extra robots
auto shadow_tactic_main = std::make_shared<ShadowEnemyTactic>(
world.field(), world.friendlyTeam(), world.enemyTeam(), true, true);
world.field(), world.friendlyTeam(), world.enemyTeam(), true, world.ball(), true);
auto shadow_tactic_secondary = std::make_shared<ShadowEnemyTactic>(
world.field(), world.friendlyTeam(), world.enemyTeam(), true, true);
world.field(), world.friendlyTeam(), world.enemyTeam(), true, world.ball(), true);

// Init Move Tactics for extra robots (These will be used if there are no robots to
// shadow)
Expand Down Expand Up @@ -114,7 +114,7 @@ void EnemyFreekickPlay::getNextTactics(TacticCoroutine::push_type &yield)
{
shadow_tactic_main->updateParams(
enemy_threats.at(1), world.field(), world.friendlyTeam(),
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass, world.ball());
move_tactic_main->updateParams(
world.field().friendlyGoal() + Point(0, 2 * ROBOT_MAX_RADIUS_METERS),
(world.ball().position() - world.field().friendlyGoal()).orientation(),
Expand All @@ -127,10 +127,10 @@ void EnemyFreekickPlay::getNextTactics(TacticCoroutine::push_type &yield)
{
shadow_tactic_main->updateParams(
enemy_threats.at(1), world.field(), world.friendlyTeam(),
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass, world.ball());
shadow_tactic_secondary->updateParams(
enemy_threats.at(2), world.field(), world.friendlyTeam(),
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass);
world.enemyTeam(), ROBOT_MAX_RADIUS_METERS * 3, enemy_team_can_pass, world.ball());

tactics_to_run.emplace_back(shadow_tactic_main);
tactics_to_run.emplace_back(shadow_tactic_secondary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ void KickoffEnemyPlay::getNextTactics(TacticCoroutine::push_type &yield)
// on the field to be evenly spread out
std::vector<std::shared_ptr<ShadowEnemyTactic>> shadow_enemy_tactics = {
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
world.enemyTeam(), true, true),
world.enemyTeam(), true, world.ball(), true),
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
world.enemyTeam(), true, true),
world.enemyTeam(), true, world.ball(), true),
std::make_shared<ShadowEnemyTactic>(world.field(), world.friendlyTeam(),
world.enemyTeam(), true, true)};
world.enemyTeam(), true, world.ball(), true)};

// these positions are picked according to the following slide
// https://images.slideplayer.com/32/9922349/slides/slide_2.jpg
Expand Down Expand Up @@ -118,7 +118,7 @@ void KickoffEnemyPlay::getNextTactics(TacticCoroutine::push_type &yield)
// anyway
shadow_enemy_tactics.at(i)->updateParams(
enemy_threat, world.field(), world.friendlyTeam(), world.enemyTeam(),
shadow_dist, false);
shadow_dist, false, world.ball());
result.emplace_back(shadow_enemy_tactics.at(i));
}
else
Expand Down
9 changes: 4 additions & 5 deletions src/thunderbots/software/ai/hl/stp/play/penalty_kick_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,17 @@ void PenaltyKickPlay::getNextTactics(TacticCoroutine::push_type &yield)
move_tactic_6->addWhitelistedAvoidArea(AvoidArea::ENEMY_HALF);
move_tactic_6->addWhitelistedAvoidArea(AvoidArea::FRIENDLY_HALF);

Timestamp start_of_shoot = world.getMostRecentTimestamp();
do
{
std::vector<std::shared_ptr<Tactic>> tactics_to_run;


Vector behind_ball_direction = (world.ball().position() - world.field().enemyGoalpostPos()).norm();
Angle shoot_angle = (world.field().enemyGoalpostPos() - world.ball().position()).orientation();
Vector behind_ball_direction = (world.ball().position() - world.field().enemyGoal()).norm();
Angle shoot_angle = (world.field().enemyGoal() - world.ball().position()).orientation();

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

printf("\nX=%f", behind_ball.x());
printf("\nY=%f", behind_ball.y());
move_tactic_2->updateParams(Point(0, 0), world.field().enemyGoal().orientation(),
0);
move_tactic_3->updateParams(Point(0, 4 * ROBOT_MAX_RADIUS_METERS),
Expand All @@ -78,7 +77,7 @@ void PenaltyKickPlay::getNextTactics(TacticCoroutine::push_type &yield)
world.field().enemyGoal().orientation(), 0);
move_tactic_6->updateParams(Point(0, -8 * ROBOT_MAX_RADIUS_METERS),
world.field().enemyGoal().orientation(), 0);
penalty_shot_tactic->updateParams(world.ball(), world.enemyTeam().goalie(), world.field());
penalty_shot_tactic->updateParams(world.ball(), world.enemyTeam().goalie(), world.field(), start_of_shoot);
shooter_setup_move->updateParams(behind_ball, shoot_angle, 0.0);

// If we are setting up for penalty kick, move our robots to position
Expand Down
37 changes: 35 additions & 2 deletions src/thunderbots/software/ai/hl/stp/play/shoot_or_chip_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ai/hl/stp/tactic/crease_defender_tactic.h"
#include "ai/hl/stp/tactic/goalie_tactic.h"
#include "ai/hl/stp/tactic/move_tactic.h"
#include "ai/hl/stp/tactic/patrol_tactic.h"
#include "ai/hl/stp/tactic/shadow_enemy_tactic.h"
#include "ai/hl/stp/tactic/shoot_goal_tactic.h"
#include "ai/hl/stp/tactic/stop_tactic.h"
Expand All @@ -31,12 +32,21 @@ std::string ShootOrChipPlay::getName() const

bool ShootOrChipPlay::isApplicable(const World &world) const
{
return world.gameState().isPlaying() &&
bool use_shoot_or_pass_instead_of_shoot_or_chip =
Util::DynamicParameters::HighLevelStrategy::
use_shoot_or_pass_instead_of_shoot_or_chip.value();

return !use_shoot_or_pass_instead_of_shoot_or_chip && world.gameState().isPlaying() &&
Evaluation::teamHasPossession(world, world.friendlyTeam());
}

bool ShootOrChipPlay::invariantHolds(const World &world) const
{

// bool use_shoot_or_pass_instead_of_shoot_or_chip =
// Util::DynamicParameters::HighLevelStrategy::
// use_shoot_or_pass_instead_of_shoot_or_chip.value();

return world.gameState().isPlaying() &&
Evaluation::teamHasPossession(world, world.friendlyTeam());
}
Expand Down Expand Up @@ -65,6 +75,23 @@ void ShootOrChipPlay::getNextTactics(TacticCoroutine::push_type &yield)
CreaseDefenderTactic::LeftOrRight::RIGHT),
};

std::array<std::shared_ptr<PatrolTactic>, 2> patrol_tactics = {
std::make_shared<PatrolTactic>(
std::vector<Point>(
{Point(world.field().enemyCornerPos().x() - 3 * ROBOT_MAX_RADIUS_METERS,
world.field().enemyCornerPos().y() - 3 * ROBOT_MAX_RADIUS_METERS),
Point(3 * ROBOT_MAX_RADIUS_METERS,
world.field().width() / 2 - 3 * ROBOT_MAX_RADIUS_METERS)}),
.03, 0),
std::make_shared<PatrolTactic>(
std::vector<Point>(
{Point(3 * ROBOT_MAX_RADIUS_METERS,
-world.field().width() / 2 + 3 * ROBOT_MAX_RADIUS_METERS),
Point(
world.field().enemyCornerNeg().x() - 3 * ROBOT_MAX_RADIUS_METERS,
world.field().enemyCornerNeg().y() + 3 * ROBOT_MAX_RADIUS_METERS)}),
.03, 0)};

std::array<std::shared_ptr<MoveTactic>, 2> move_to_open_area_tactics = {
std::make_shared<MoveTactic>(true), std::make_shared<MoveTactic>(true)};

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

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

// If we can't do anything else then patrol?
for (auto &patrol_tactic : patrol_tactics)
{
result.emplace_back(patrol_tactic);
}

// yield the Tactics this Play wants to run, in order of priority
yield(result);

Expand Down
Loading

0 comments on commit f7a6ad7

Please sign in to comment.