Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/fsm-diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ Terminate:::terminate --> Terminate:::terminate
```

## [ShootOrChipPlayFSM](/src/software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play_fsm.h)

```mermaid
stateDiagram-v2
classDef terminate fill:white,color:black,font-weight:bold
direction LR
[*] --> ShootOrChipState
ShootOrChipState --> ShootOrChipState : [!attackerDone]\n<i>updateShootOrChip</i>
ShootOrChipState --> Terminate:::terminate : [attackerDone]\n<i>updateShootOrChip</i>
Terminate:::terminate --> Terminate:::terminate : <i>updateShootOrChip</i>
```

## [ShootOrPassPlayFSM](/src/software/ai/hl/stp/play/shoot_or_pass/shoot_or_pass_play_fsm.h)

```mermaid
Expand All @@ -225,6 +239,33 @@ Terminate:::terminate --> AttemptShotState : <i>startLookingForPass</i>
```

## [HaltTestPlayFSM](/src/software/ai/hl/stp/play/test_plays/halt_test_play_fsm.h)

```mermaid
stateDiagram-v2
classDef terminate fill:white,color:black,font-weight:bold
direction LR
[*] --> HaltTestState
HaltTestState --> HaltTestState : <i>updateHalt</i>
Terminate:::terminate --> Terminate:::terminate : <i>updateHalt</i>
```

## [MoveTestPlayFSM](/src/software/ai/hl/stp/play/test_plays/move_test_play_fsm.h)

```mermaid
stateDiagram-v2
classDef terminate fill:white,color:black,font-weight:bold
direction LR
[*] --> MoveTestState
MoveTestState --> MoveTestState : [!moveDone]\n<i>updateMove</i>
MoveTestState --> Terminate:::terminate : [moveDone]\n<i>updateMove</i>
Terminate:::terminate --> Terminate:::terminate : <i>updateMove</i>
```

## [AttackerFSM](/src/software/ai/hl/stp/tactic/attacker/attacker_fsm.h)

```mermaid
Expand Down
56 changes: 1 addition & 55 deletions src/software/ai/hl/stp/play/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,6 @@ cc_library(
alwayslink = True,
)

cc_library(
name = "shoot_or_chip_play",
srcs = ["shoot_or_chip_play.cpp"],
hdrs = ["shoot_or_chip_play.h"],
deps = [
":play",
"//proto/message_translation:tbots_protobuf",
"//shared:constants",
"//software/ai/evaluation:enemy_threat",
"//software/ai/evaluation:find_open_areas",
"//software/ai/evaluation:possession",
"//software/ai/hl/stp/tactic/attacker:attacker_tactic",
"//software/ai/hl/stp/tactic/crease_defender:crease_defender_tactic",
"//software/ai/hl/stp/tactic/goalie:goalie_tactic",
"//software/ai/hl/stp/tactic/halt:halt_tactic",
"//software/ai/hl/stp/tactic/move:move_tactic",
"//software/ai/hl/stp/tactic/shadow_enemy:shadow_enemy_tactic",
"//software/logger",
"//software/util/generic_factory",
"//software/world:game_state",
],
alwayslink = True,
)

cc_library(
name = "stop_play",
srcs = ["stop_play.cpp"],
Expand Down Expand Up @@ -108,7 +84,6 @@ cc_library(
deps = [
":kickoff_enemy_play",
":kickoff_friendly_play",
":shoot_or_chip_play",
":stop_play",
"//software/ai/hl/stp/play/ball_placement:ball_placement_play",
"//software/ai/hl/stp/play/crease_defense:crease_defense_play",
Expand All @@ -125,6 +100,7 @@ cc_library(
"//software/ai/hl/stp/play/offense:offense_play",
"//software/ai/hl/stp/play/penalty_kick:penalty_kick_play",
"//software/ai/hl/stp/play/penalty_kick_enemy:penalty_kick_enemy_play",
"//software/ai/hl/stp/play/shoot_or_chip:shoot_or_chip_play",
"//software/ai/hl/stp/play/shoot_or_pass:shoot_or_pass_play",
],
)
Expand Down Expand Up @@ -193,36 +169,6 @@ cc_test(
],
)

cc_test(
name = "shoot_or_chip_play_cpp_test",
srcs = ["shoot_or_chip_play_test.cpp"],
deps = [
"//shared/test_util:tbots_gtest_main",
"//software/ai/hl/stp/play:shoot_or_chip_play",
"//software/simulated_tests:simulated_er_force_sim_play_test_fixture",
"//software/simulated_tests/validation:validation_function",
"//software/test_util",
"//software/time:duration",
"//software/world",
],
)

py_test(
name = "shoot_or_chip_play_test",
srcs = [
"shoot_or_chip_play_test.py",
],
# TODO (#2619) Remove tag to run in parallel
tags = [
"exclusive",
],
deps = [
"//software:conftest",
"//software/simulated_tests:validation",
requirement("pytest"),
],
)

cc_library(
name = "assigned_tactics_play",
srcs = ["assigned_tactics_play.cpp"],
Expand Down
62 changes: 62 additions & 0 deletions src/software/ai/hl/stp/play/shoot_or_chip/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
load("@simulated_tests_deps//:requirements.bzl", "requirement")

package(default_visibility = ["//visibility:public"])

cc_library(
name = "shoot_or_chip_play",
srcs = [
"shoot_or_chip_play.cpp",
"shoot_or_chip_play_fsm.cpp",
],
hdrs = [
"shoot_or_chip_play.h",
"shoot_or_chip_play_fsm.h",
],
deps = [
"//proto/message_translation:tbots_protobuf",
"//shared:constants",
"//software/ai/evaluation:enemy_threat",
"//software/ai/evaluation:find_open_areas",
"//software/ai/evaluation:possession",
"//software/ai/hl/stp/play",
"//software/ai/hl/stp/tactic/attacker:attacker_tactic",
"//software/ai/hl/stp/tactic/crease_defender:crease_defender_tactic",
"//software/ai/hl/stp/tactic/halt:halt_tactic",
"//software/ai/hl/stp/tactic/move:move_tactic",
"//software/ai/hl/stp/tactic/shadow_enemy:shadow_enemy_tactic",
"//software/logger",
"//software/util/generic_factory",
"//software/world:game_state",
],
alwayslink = True,
)

cc_test(
name = "shoot_or_chip_play_cpp_test",
srcs = ["shoot_or_chip_play_test.cpp"],
deps = [
":shoot_or_chip_play",
"//shared/test_util:tbots_gtest_main",
"//software/simulated_tests:simulated_er_force_sim_play_test_fixture",
"//software/simulated_tests/validation:validation_function",
"//software/test_util",
"//software/time:duration",
"//software/world",
],
)

py_test(
name = "shoot_or_chip_play_test",
srcs = [
"shoot_or_chip_play_test.py",
],
# TODO (#2619) Remove tag to run in parallel
tags = [
"exclusive",
],
deps = [
"//software:conftest",
"//software/simulated_tests:validation",
requirement("pytest"),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play.h"

#include "proto/message_translation/tbots_protobuf.h"
#include "shared/constants.h"
#include "software/logger/logger.h"
#include "software/util/generic_factory/generic_factory.h"
#include "software/world/game_state.h"

ShootOrChipPlay::ShootOrChipPlay(
std::shared_ptr<const TbotsProto::AiConfig> ai_config_ptr)
: PlayBase<ShootOrChipPlayFSM>(ai_config_ptr, true)
{
}

void ShootOrChipPlay::getNextTactics(TacticCoroutine::push_type &yield,
const WorldPtr &world_ptr)
{
// This function doesn't get called, it should be removed once coroutines
// are phased out
}


void ShootOrChipPlay::updateTactics(const PlayUpdate &play_update)
{
fsm.process_event(ShootOrChipPlayFSM::Update(control_params, play_update));
}

// Register this play in the genericFactory
static TGenericFactory<std::string, Play, ShootOrChipPlay,
std::shared_ptr<const TbotsProto::AiConfig>>
factory;
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

#include "proto/parameters.pb.h"
#include "software/ai/hl/stp/play/play.h"
#include "software/ai/hl/stp/play/play_base.hpp"
#include "software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play_fsm.h"

/**
* The Defense Play tries to grab the ball from the enemy that has it, and all other
* robots shadow the enemy robots in order of how threatening they are.
*/
class ShootOrChipPlay : public Play
class ShootOrChipPlay : public PlayBase<ShootOrChipPlayFSM>
{
public:
ShootOrChipPlay(std::shared_ptr<const TbotsProto::AiConfig> ai_config_ptr);

void getNextTactics(TacticCoroutine::push_type &yield,
const WorldPtr &world_ptr) override;

void updateTactics(const PlayUpdate &play_update) override;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play_fsm.h"

#include "proto/message_translation/tbots_protobuf.h"
#include "shared/constants.h"
#include "software/ai/evaluation/enemy_threat.h"
#include "software/ai/evaluation/find_open_areas.h"
#include "software/ai/evaluation/possession.h"
#include "software/ai/hl/stp/tactic/attacker/attacker_tactic.h"
#include "software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic.h"
#include "software/ai/hl/stp/tactic/move/move_tactic.h"
#include "software/ai/hl/stp/tactic/shadow_enemy/shadow_enemy_tactic.h"

ShootOrChipPlayFSM::ShootOrChipPlayFSM(
std::shared_ptr<const TbotsProto::AiConfig> ai_config_ptr)
: PlayFSM<ShootOrChipPlayFSM>(ai_config_ptr),
crease_defender_tactics{
std::make_shared<CreaseDefenderTactic>(ai_config_ptr),
std::make_shared<CreaseDefenderTactic>(ai_config_ptr),
},
move_to_open_area_tactics{
std::make_shared<MoveTactic>(ai_config_ptr),
std::make_shared<MoveTactic>(ai_config_ptr),
},
attacker(std::make_shared<AttackerTactic>(ai_config_ptr))
{
}

void ShootOrChipPlayFSM::updateShootOrChip(const Update& event)
{
/**
* Our general strategy here is:
* - 1 goalie
* - 2 crease defenders moving around the friendly defense box
* - 2 robots moving into the first and second largest open free space on
* the enemy half
* - 1 robot trying to shoot on the goal. If an enemy gets too close to this
* robot, it will chip to right in front of the robot in the largest open free area
*/

// Figure out where the fallback chip target is
// Experimentally determined to be a reasonable value
double fallback_chip_target_x_offset = 1.5;

Point fallback_chip_target = event.common.world_ptr->field().enemyGoalCenter() -
Vector(fallback_chip_target_x_offset, 0);

// Update chipper
std::optional<Point> chip_target = fallback_chip_target;


PriorityTacticVector result = {{}};

// Update crease defenders
std::get<0>(crease_defender_tactics)
->updateControlParams(event.common.world_ptr->ball().position(),
TbotsProto::CreaseDefenderAlignment::LEFT);
result[0].emplace_back(std::get<0>(crease_defender_tactics));
std::get<1>(crease_defender_tactics)
->updateControlParams(event.common.world_ptr->ball().position(),
TbotsProto::CreaseDefenderAlignment::RIGHT);
result[0].emplace_back(std::get<1>(crease_defender_tactics));

// Update tactics moving to open areas
std::vector<Circle> chip_targets = findGoodChipTargets(*event.common.world_ptr);
for (unsigned i = 0; i < chip_targets.size() && i < move_to_open_area_tactics.size();
i++)
{
// Face towards the ball
Angle orientation =
(event.common.world_ptr->ball().position() - chip_targets[i].origin())
.orientation();
// Move a bit backwards to make it more likely we'll receive the chip
Point position =
chip_targets[i].origin() -
Vector::createFromAngle(orientation).normalize(ROBOT_MAX_RADIUS_METERS);
;
move_to_open_area_tactics[i]->updateControlParams(position, orientation);
result[0].emplace_back(move_to_open_area_tactics[i]);
}

if (!chip_targets.empty())
{
chip_target = chip_targets[0].origin();
}
attacker->updateControlParams(chip_target);

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

// set the the Tactics this Play wants to run, in order of priority
event.common.set_tactics(result);
}

bool ShootOrChipPlayFSM::attackerDone(const Update& event)
{
return attacker->done();
}
Loading