Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
57919a7
add halt_test_play fsm
StarrryNight Feb 15, 2026
061e6d6
update halt_test_play.h
StarrryNight Feb 15, 2026
8dae978
convert halt_test_play.cpp
StarrryNight Feb 15, 2026
ed8a8cf
add test and update build
StarrryNight Feb 15, 2026
ca79647
fix bugs
StarrryNight Feb 15, 2026
f886ed8
pass fsm test
StarrryNight Feb 15, 2026
c6c8c8b
finish fsm.h for move
StarrryNight Feb 15, 2026
322884f
finish constructor for move_test_play
StarrryNight Feb 15, 2026
de66e65
fix bugs:
StarrryNight Feb 15, 2026
d5f3530
update build
StarrryNight Feb 15, 2026
5788d40
add test and test passes
StarrryNight Feb 15, 2026
dc128ef
reorganize shoot or chip
StarrryNight Feb 15, 2026
9d813b8
finish shoot or chip fsm
StarrryNight Feb 15, 2026
d564bae
fix bugs
StarrryNight Feb 15, 2026
b77ad5e
fix more bugs and integrate into original shoot or chip play'
StarrryNight Feb 15, 2026
df3988f
finish integration
StarrryNight Feb 15, 2026
5fe618c
update BUILD
StarrryNight Feb 15, 2026
9bb32fc
fix import issues and all shoot_or_pass test passes
StarrryNight Feb 15, 2026
59c5aea
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Feb 16, 2026
ad60d5d
Fix include statement for halt_test_play_fsm.h
StarrryNight Feb 21, 2026
a4c9cf0
Fix include statement for move_test_play_fsm.h
StarrryNight Feb 21, 2026
95d4cd4
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Feb 21, 2026
015a52e
add doc comments
Feb 24, 2026
0b19293
remove halt tactic
StarrryNight Mar 1, 2026
34c1c0c
move to fsm.file
StarrryNight Mar 3, 2026
7d4f75e
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Mar 3, 2026
b24c04e
Merge branch 'master' of github.com:UBC-Thunderbots/Software into cor…
StarrryNight Mar 7, 2026
b589bca
remove test plays
StarrryNight Mar 7, 2026
ee89931
fix comments
StarrryNight Mar 7, 2026
f97599e
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Mar 7, 2026
32b8750
Merge remote-tracking branch 'upstream' into coroutines_to_fsm_#2359
StarrryNight Mar 9, 2026
7ee2d51
revert formatting changes
StarrryNight Mar 9, 2026
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
14 changes: 14 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

```

## [ShootOrPassPlayFSM](/src/software/ai/hl/stp/play/shoot_or_pass/shoot_or_pass_play_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 @@ -121,6 +96,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 @@ -189,36 +165,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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include "proto/parameters.pb.h"
#include "shared/constants.h"
#include "software/ai/hl/stp/play/play_fsm.hpp"
#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"

struct ShootOrChipPlayFSM : PlayFSM<ShootOrChipPlayFSM>
{
struct ControlParams
{
};

class ShootOrChipState;

explicit ShootOrChipPlayFSM(
std::shared_ptr<const TbotsProto::AiConfig> ai_config_ptr);

void updateShootOrChip(const Update& event);

bool attackerDone(const Update& event);



auto operator()()
{
using namespace boost::sml;

DEFINE_SML_STATE(ShootOrChipState)
DEFINE_SML_EVENT(Update)
DEFINE_SML_ACTION(updateShootOrChip)
DEFINE_SML_GUARD(attackerDone)

return make_transition_table(
// src_state + event [guard] / action = dest_state
*ShootOrChipState_S + Update_E[!attackerDone_G] / updateShootOrChip_A =
ShootOrChipState_S,
ShootOrChipState_S + Update_E[attackerDone_G] / updateShootOrChip_A = X,
X + Update_E = X);
}

private:
std::array<std::shared_ptr<CreaseDefenderTactic>, 2> crease_defender_tactics;
std::array<std::shared_ptr<MoveTactic>, 2> move_to_open_area_tactics;
std::shared_ptr<AttackerTactic> attacker;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "software/ai/hl/stp/play/shoot_or_chip_play.h"
#include "software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play.h"

#include <gtest/gtest.h>

Expand Down
Loading