Skip to content

Commit

Permalink
Rename all instances of stop tactic to halt tactic (UBC-Thunderbots#3339
Browse files Browse the repository at this point in the history
)

* Refactor `StopTactic` to `HaltTactic`, refactoring variables where necessary

Files still need to be refactored, which will be done in the next commit

* Rename `stop_tactic.cpp` and `stop_tactic.h` to `halt_tactic.cpp` and `halt_tactic.h`, renaming variables and strings where necessary

Variables and strings renamed for consistency and to allow tests to successfully run

* Rename `stop_tactic_test.cpp` to `halt_tactic_test.cpp`

* Rename `stop_fsm` and `stop_fsm_test` to `halt_fsm` and `halt_fsm_test`, renaming where necessary

* Rename `tactic/stop` folder to `tactic/halt`, renaming addresses where necessary

* [pre-commit.ci lite] apply automatic fixes

* Small consistency improvements

* Small consistency improvements

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and Lmh-java committed Oct 25, 2024
1 parent f5fc2e9 commit 208e02d
Show file tree
Hide file tree
Showing 33 changed files with 172 additions and 173 deletions.
30 changes: 15 additions & 15 deletions docs/fsm-diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@ Terminate:::terminate --> Terminate:::terminate
```

## [HaltFSM](/src/software/ai/hl/stp/tactic/halt/halt_fsm.h)

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

## [KickFSM](/src/software/ai/hl/stp/tactic/kick/kick_fsm.h)

```mermaid
Expand Down Expand Up @@ -441,18 +456,3 @@ Terminate:::terminate --> Terminate:::terminate : <i>SET_STOP_PRIMITIVE_ACTION</
```

## [StopFSM](/src/software/ai/hl/stp/tactic/stop/stop_fsm.h)

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

4 changes: 2 additions & 2 deletions src/proto/tactic.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ message Tactic
PivotKickTactic pivot_kick = 11;
ReceiverTactic receiver = 12;
ShadowEnemyTactic shadow_enemy = 13;
StopTactic stop = 14;
HaltTactic halt = 14;
PassDefenderTactic pass_defender = 15;
}
}
Expand Down Expand Up @@ -176,4 +176,4 @@ message ShadowEnemyTactic
required double shadow_distance = 2;
}

message StopTactic {}
message HaltTactic {}
8 changes: 4 additions & 4 deletions src/software/ai/hl/stp/play/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cc_library(
deps = [
":play",
"//shared:constants",
"//software/ai/hl/stp/tactic/stop:stop_tactic",
"//software/ai/hl/stp/tactic/halt:halt_tactic",
"//software/logger",
"//software/util/generic_factory",
],
Expand Down Expand Up @@ -82,9 +82,9 @@ cc_library(
"//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/ai/hl/stp/tactic/stop:stop_tactic",
"//software/logger",
"//software/util/generic_factory",
"//software/world:game_state",
Expand Down Expand Up @@ -119,7 +119,7 @@ cc_library(
deps = [
"//software/ai/hl/stp/tactic",
"//software/ai/hl/stp/tactic/goalie:goalie_tactic",
"//software/ai/hl/stp/tactic/stop:stop_tactic",
"//software/ai/hl/stp/tactic/halt:halt_tactic",
"//software/ai/motion_constraint:motion_constraint_set_builder",
"//software/ai/navigator/trajectory:trajectory_planner",
"//software/ai/passing:pass_with_rating",
Expand Down Expand Up @@ -303,7 +303,7 @@ cc_library(
deps = [
":play",
"//shared:constants",
"//software/ai/hl/stp/tactic/stop:stop_tactic",
"//software/ai/hl/stp/tactic/halt:halt_tactic",
"//software/logger",
"//software/util/generic_factory",
],
Expand Down
2 changes: 1 addition & 1 deletion src/software/ai/hl/stp/play/enemy_free_kick/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ cc_library(
"//software/ai/hl/stp/play/defense:defense_play_base",
"//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/pass_defender:pass_defender_tactic",
"//software/ai/hl/stp/tactic/stop:stop_tactic",
"//software/logger",
"//software/util/generic_factory",
"//software/world:game_state",
Expand Down
18 changes: 9 additions & 9 deletions src/software/ai/hl/stp/play/halt_play.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include "software/ai/hl/stp/play/halt_play.h"

#include "software/ai/hl/stp/tactic/stop/stop_tactic.h"
#include "software/ai/hl/stp/tactic/halt/halt_tactic.h"
#include "software/util/generic_factory/generic_factory.h"

HaltPlay::HaltPlay(TbotsProto::AiConfig config) : Play(config, false) {}

void HaltPlay::getNextTactics(TacticCoroutine::push_type &yield,
const WorldPtr &world_ptr)
{
auto stop_tactic_1 = std::make_shared<StopTactic>();
auto stop_tactic_2 = std::make_shared<StopTactic>();
auto stop_tactic_3 = std::make_shared<StopTactic>();
auto stop_tactic_4 = std::make_shared<StopTactic>();
auto stop_tactic_5 = std::make_shared<StopTactic>();
auto stop_tactic_6 = std::make_shared<StopTactic>();
auto halt_tactic_1 = std::make_shared<HaltTactic>();
auto halt_tactic_2 = std::make_shared<HaltTactic>();
auto halt_tactic_3 = std::make_shared<HaltTactic>();
auto halt_tactic_4 = std::make_shared<HaltTactic>();
auto halt_tactic_5 = std::make_shared<HaltTactic>();
auto halt_tactic_6 = std::make_shared<HaltTactic>();

do
{
// yield the Tactics this Play wants to run, in order of priority
yield({{stop_tactic_1, stop_tactic_2, stop_tactic_3, stop_tactic_4, stop_tactic_5,
stop_tactic_6}});
yield({{halt_tactic_1, halt_tactic_2, halt_tactic_3, halt_tactic_4, halt_tactic_5,
halt_tactic_6}});
} while (true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "proto/parameters.pb.h"
#include "shared/constants.h"
#include "software/ai/hl/stp/play/play_fsm.h"
#include "software/ai/hl/stp/tactic/halt/halt_tactic.h"
#include "software/ai/hl/stp/tactic/move/move_tactic.h"
#include "software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic.h"
#include "software/ai/hl/stp/tactic/stop/stop_tactic.h"
#include "software/logger/logger.h"


Expand Down
10 changes: 5 additions & 5 deletions src/software/ai/hl/stp/play/play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
#include <Tracy.hpp>

#include "proto/message_translation/tbots_protobuf.h"
#include "software/ai/hl/stp/tactic/stop/stop_tactic.h"
#include "software/ai/hl/stp/tactic/halt/halt_tactic.h"
#include "software/ai/motion_constraint/motion_constraint_set_builder.h"
#include "software/logger/logger.h"


Play::Play(TbotsProto::AiConfig ai_config, bool requires_goalie)
: ai_config(ai_config),
goalie_tactic(std::make_shared<GoalieTactic>(ai_config)),
stop_tactics(),
halt_tactics(),
requires_goalie(requires_goalie),
tactic_sequence(boost::bind(&Play::getNextTacticsWrapper, this, _1)),
world_ptr_(std::nullopt),
obstacle_factory(ai_config.robot_navigation_obstacle_config())
{
for (unsigned int i = 0; i < MAX_ROBOT_IDS; i++)
{
stop_tactics.push_back(std::make_shared<StopTactic>());
halt_tactics.push_back(std::make_shared<HaltTactic>());
}
}

Expand Down Expand Up @@ -189,10 +189,10 @@ std::unique_ptr<TbotsProto::PrimitiveSet> Play::get(
else if (i == (priority_tactics.size() - 1))
{
// If assigning the last tactic vector, then assign rest of robots with
// StopTactics
// HaltTactics
for (unsigned int ii = 0; ii < (robots.size() - num_tactics); ii++)
{
tactic_vector.push_back(stop_tactics[ii]);
tactic_vector.push_back(halt_tactics[ii]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/software/ai/hl/stp/play/play.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class Play
virtual void getNextTactics(TacticCoroutine::push_type& yield,
const WorldPtr& world_ptr) = 0;

// Stop tactic common to all plays for robots that don't have tactics assigned
TacticVector stop_tactics;
// HaltTactics common to all plays for robots that don't have tactics assigned
TacticVector halt_tactics;

// Whether this play requires a goalie
const bool requires_goalie;
Expand Down
2 changes: 1 addition & 1 deletion src/software/ai/hl/stp/play/shoot_or_chip_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#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/halt/halt_tactic.h"
#include "software/ai/hl/stp/tactic/move/move_tactic.h"
#include "software/ai/hl/stp/tactic/shadow_enemy/shadow_enemy_tactic.h"
#include "software/ai/hl/stp/tactic/stop/stop_tactic.h"
#include "software/logger/logger.h"
#include "software/util/generic_factory/generic_factory.h"
#include "software/world/game_state.h"
Expand Down
2 changes: 1 addition & 1 deletion src/software/ai/hl/stp/play/test_plays/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cc_library(
hdrs = ["halt_test_play.h"],
deps = [
"//software/ai/hl/stp/play",
"//software/ai/hl/stp/tactic/stop:stop_tactic",
"//software/ai/hl/stp/tactic/halt:halt_tactic",
"//software/util/generic_factory",
],
alwayslink = True,
Expand Down
10 changes: 5 additions & 5 deletions src/software/ai/hl/stp/play/test_plays/halt_test_play.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "software/ai/hl/stp/play/test_plays/halt_test_play.h"

#include "software/ai/hl/stp/tactic/stop/stop_tactic.h"
#include "software/ai/hl/stp/tactic/halt/halt_tactic.h"
#include "software/geom/algorithms/contains.h"
#include "software/util/generic_factory/generic_factory.h"

Expand All @@ -9,13 +9,13 @@ HaltTestPlay::HaltTestPlay(TbotsProto::AiConfig config) : Play(config, false) {}
void HaltTestPlay::getNextTactics(TacticCoroutine::push_type &yield,
const WorldPtr &world_ptr)
{
auto stop_test_tactic_1 = std::make_shared<StopTactic>();
auto stop_test_tactic_2 = std::make_shared<StopTactic>();
auto stop_test_tactic_3 = std::make_shared<StopTactic>();
auto halt_test_tactic_1 = std::make_shared<HaltTactic>();
auto halt_test_tactic_2 = std::make_shared<HaltTactic>();
auto halt_test_tactic_3 = std::make_shared<HaltTactic>();

do
{
yield({{stop_test_tactic_1, stop_test_tactic_2, stop_test_tactic_3}});
yield({{halt_test_tactic_1, halt_test_tactic_2, halt_test_tactic_3}});
} while (true);
}

Expand Down
50 changes: 25 additions & 25 deletions src/software/ai/hl/stp/stp_tactic_assignment_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "software/ai/hl/stp/play/halt_play.h"
#include "software/ai/hl/stp/stp.h"
#include "software/ai/hl/stp/tactic/all_tactics.h"
#include "software/ai/hl/stp/tactic/stop/stop_tactic.h"
#include "software/ai/hl/stp/tactic/halt/halt_tactic.h"
#include "software/test_util/test_util.h"

/**
Expand Down Expand Up @@ -160,12 +160,12 @@ TEST_F(STPTacticAssignmentTest,
world.updateFriendlyTeamState(friendly_team);

auto move_tactic_1 = std::make_shared<MoveTactic>();
auto stop_tactic_1 = std::make_shared<StopTactic>();
auto halt_tactic_1 = std::make_shared<HaltTactic>();

move_tactic_1->updateControlParams(Point(-1, 0), Angle::zero(),
TbotsProto::MaxAllowedSpeedMode::PHYSICAL_LIMIT);

ConstTacticVector tactics = {move_tactic_1, stop_tactic_1};
ConstTacticVector tactics = {move_tactic_1, halt_tactic_1};

// Both robots are now closest to move_tactic_1's destination. We do NOT want
// robot_0 to be assigned to move_tactic_1, because then robot_1 has to move all the
Expand All @@ -175,11 +175,11 @@ TEST_F(STPTacticAssignmentTest,
auto asst = stp.assignRobotsToTactics({tactics}, world, false);


// move_tactic_1 should be the only Tactic assigned a robot, since stop_tactic_1 is a
// move_tactic_1 should be the only Tactic assigned a robot, since halt_tactic_1 is a
// lower priority than move_tactic_1 so it should be dropped since there's only 1
// robot
EXPECT_TRUE(asst.find(move_tactic_1) != asst.end());
EXPECT_FALSE(asst.find(stop_tactic_1) != asst.end());
EXPECT_FALSE(asst.find(halt_tactic_1) != asst.end());
}


Expand Down Expand Up @@ -329,21 +329,21 @@ TEST_F(STPTacticAssignmentTest,
friendly_team.updateRobots({robot_0, robot_1, robot_2});
world.updateFriendlyTeamState(friendly_team);

auto stop_tactic_1 = std::make_shared<StopTactic>();
auto stop_tactic_2 = std::make_shared<StopTactic>();
auto stop_tactic_3 = std::make_shared<StopTactic>();
auto halt_tactic_1 = std::make_shared<HaltTactic>();
auto halt_tactic_2 = std::make_shared<HaltTactic>();
auto halt_tactic_3 = std::make_shared<HaltTactic>();

ConstTacticVector tactics = {stop_tactic_1, stop_tactic_2, stop_tactic_3};
ConstTacticVector tactics = {halt_tactic_1, halt_tactic_2, halt_tactic_3};

// If all costs are equal, the robots and tactics are simply paired in order
auto asst = stp.assignRobotsToTactics({tactics}, world, false);

ASSERT_TRUE(asst.find(stop_tactic_1) != asst.end());
ASSERT_TRUE(asst.find(stop_tactic_2) != asst.end());
ASSERT_TRUE(asst.find(stop_tactic_3) != asst.end());
EXPECT_EQ(asst.find(stop_tactic_1)->second, robot_0);
EXPECT_EQ(asst.find(stop_tactic_2)->second, robot_1);
EXPECT_EQ(asst.find(stop_tactic_3)->second, robot_2);
ASSERT_TRUE(asst.find(halt_tactic_1) != asst.end());
ASSERT_TRUE(asst.find(halt_tactic_2) != asst.end());
ASSERT_TRUE(asst.find(halt_tactic_3) != asst.end());
EXPECT_EQ(asst.find(halt_tactic_1)->second, robot_0);
EXPECT_EQ(asst.find(halt_tactic_2)->second, robot_1);
EXPECT_EQ(asst.find(halt_tactic_3)->second, robot_2);
}

TEST_F(STPTacticAssignmentTest,
Expand All @@ -359,26 +359,26 @@ TEST_F(STPTacticAssignmentTest,
friendly_team.updateRobots({robot_0, robot_1, robot_2});
world.updateFriendlyTeamState(friendly_team);

auto stop_tactic_1 = std::make_shared<StopTactic>();
auto halt_tactic_1 = std::make_shared<HaltTactic>();
auto move_tactic_1 = std::make_shared<MoveTactic>();
auto stop_tactic_2 = std::make_shared<StopTactic>();
auto halt_tactic_2 = std::make_shared<HaltTactic>();

// The destination of the move_tactic is relatively close to the robot positions, so
// the cost of assigning any robot to the move_tactic should be less than the
// stop_tactics
// halt_tactics
move_tactic_1->updateControlParams(Point(0, 0), Angle::zero(),
TbotsProto::MaxAllowedSpeedMode::PHYSICAL_LIMIT);

ConstTacticVector tactics = {stop_tactic_1, move_tactic_1, stop_tactic_2};
ConstTacticVector tactics = {halt_tactic_1, move_tactic_1, halt_tactic_2};

auto asst = stp.assignRobotsToTactics({tactics}, world, false);

ASSERT_TRUE(asst.find(stop_tactic_1) != asst.end());
ASSERT_TRUE(asst.find(halt_tactic_1) != asst.end());
ASSERT_TRUE(asst.find(move_tactic_1) != asst.end());
ASSERT_TRUE(asst.find(stop_tactic_2) != asst.end());
EXPECT_EQ(asst.find(stop_tactic_1)->second, robot_2);
ASSERT_TRUE(asst.find(halt_tactic_2) != asst.end());
EXPECT_EQ(asst.find(halt_tactic_1)->second, robot_2);
EXPECT_EQ(asst.find(move_tactic_1)->second, robot_0);
EXPECT_EQ(asst.find(stop_tactic_2)->second, robot_1);
EXPECT_EQ(asst.find(halt_tactic_2)->second, robot_1);
}

TEST_F(STPTacticAssignmentTest,
Expand Down Expand Up @@ -450,9 +450,9 @@ TEST_F(STPTacticAssignmentTest,
}

TEST_F(STPTacticAssignmentTest,
test_assigning_stop_tactics_to_unassigned_non_goalie_robots)
test_assigning_halt_tactics_to_unassigned_non_goalie_robots)
{
// Test that StopTactic is assigned to remaining robots without tactics
// Test that HaltTactic is assigned to remaining robots without tactics

Team friendly_team(Duration::fromSeconds(0));
Robot robot_0(0, Point(-1, 1), Vector(), Angle::zero(), AngularVelocity::zero(),
Expand Down
2 changes: 1 addition & 1 deletion src/software/ai/hl/stp/stp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ TEST_F(STPTest, test_get_play_info)

std::string expected_play_name, expected_tactic_name;
expected_play_name = "HaltPlay";
expected_tactic_name = "StopTactic";
expected_tactic_name = "HaltTactic";

TbotsProto::PlayInfo expected_play_info_msg = TbotsProto::PlayInfo();
expected_play_info_msg.mutable_play()->set_play_name(expected_play_name);
Expand Down
2 changes: 1 addition & 1 deletion src/software/ai/hl/stp/tactic/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ cc_library(
"//software/ai/hl/stp/tactic/dribble:dribble_tactic",
"//software/ai/hl/stp/tactic/get_behind_ball:get_behind_ball_tactic",
"//software/ai/hl/stp/tactic/goalie:goalie_tactic",
"//software/ai/hl/stp/tactic/halt:halt_tactic",
"//software/ai/hl/stp/tactic/kick:kick_tactic",
"//software/ai/hl/stp/tactic/move:move_tactic",
"//software/ai/hl/stp/tactic/pass_defender:pass_defender_tactic",
"//software/ai/hl/stp/tactic/penalty_kick:penalty_kick_tactic",
"//software/ai/hl/stp/tactic/pivot_kick:pivot_kick_tactic",
"//software/ai/hl/stp/tactic/receiver:receiver_tactic",
"//software/ai/hl/stp/tactic/shadow_enemy:shadow_enemy_tactic",
"//software/ai/hl/stp/tactic/stop:stop_tactic",
],
)

Expand Down
Loading

0 comments on commit 208e02d

Please sign in to comment.