Skip to content

Commit

Permalink
Shoot ball at max speed
Browse files Browse the repository at this point in the history
  • Loading branch information
raymond212 committed Jun 22, 2024
1 parent 28f114f commit a984e18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ void FreeKickPlayFSM::setupPosition(const Update &event)
tactics_to_run[0].emplace_back(offensive_positioning_tactics[1]);

crease_defender_tactics[0]->updateControlParams(
event.common.world_ptr->ball().position(), TbotsProto::CreaseDefenderAlignment::LEFT);
event.common.world_ptr->ball().position(),
TbotsProto::CreaseDefenderAlignment::LEFT);
crease_defender_tactics[1]->updateControlParams(
event.common.world_ptr->ball().position(), TbotsProto::CreaseDefenderAlignment::RIGHT);
event.common.world_ptr->ball().position(),
TbotsProto::CreaseDefenderAlignment::RIGHT);
tactics_to_run[0].emplace_back(crease_defender_tactics[0]);
tactics_to_run[0].emplace_back(crease_defender_tactics[1]);

Expand Down Expand Up @@ -106,7 +108,7 @@ void FreeKickPlayFSM::shootBall(const Update &event)

shoot_tactic->updateControlParams(
ball_pos, (shot->getPointToShootAt() - ball_pos).orientation(),
BALL_MAX_SPEED_METERS_PER_SECOND - 0.5);
BALL_MAX_SPEED_METERS_PER_SECOND);
tactics_to_run[0].emplace_back(shoot_tactic);

event.common.set_tactics(tactics_to_run);
Expand Down Expand Up @@ -160,9 +162,11 @@ void FreeKickPlayFSM::lookForPass(const FreeKickPlayFSM::Update &event)

// Maintain crease defenders
crease_defender_tactics[0]->updateControlParams(
event.common.world_ptr->ball().position(), TbotsProto::CreaseDefenderAlignment::LEFT);
event.common.world_ptr->ball().position(),
TbotsProto::CreaseDefenderAlignment::LEFT);
crease_defender_tactics[1]->updateControlParams(
event.common.world_ptr->ball().position(), TbotsProto::CreaseDefenderAlignment::RIGHT);
event.common.world_ptr->ball().position(),
TbotsProto::CreaseDefenderAlignment::RIGHT);
tactics_to_run[0].emplace_back(crease_defender_tactics[0]);
tactics_to_run[0].emplace_back(crease_defender_tactics[1]);

Expand All @@ -176,12 +180,17 @@ void FreeKickPlayFSM::lookForPass(const FreeKickPlayFSM::Update &event)
bool FreeKickPlayFSM::passFound(const Update &event)
{
double time_since_pass_optimization_start_seconds =
(event.common.world_ptr->getMostRecentTimestamp() - pass_optimization_start_time).toSeconds();
(event.common.world_ptr->getMostRecentTimestamp() - pass_optimization_start_time)
.toSeconds();

// To get the best pass possible we start by aiming for a perfect one and then
// decrease the minimum score over time
double min_score = 1 - (1 - ai_config.free_kick_play_config().min_acceptable_pass_score()) * (time_since_pass_optimization_start_seconds / ai_config.free_kick_play_config().max_time_commit_to_pass_seconds());
LOG(DEBUG) << "Score: " << best_pass_and_score_so_far.rating << " Min score: " << min_score;
double min_score =
1 - (1 - ai_config.free_kick_play_config().min_acceptable_pass_score()) *
(time_since_pass_optimization_start_seconds /
ai_config.free_kick_play_config().max_time_commit_to_pass_seconds());
LOG(DEBUG) << "Score: " << best_pass_and_score_so_far.rating
<< " Min score: " << min_score;

return best_pass_and_score_so_far.rating > min_score;
}
Expand Down
2 changes: 1 addition & 1 deletion src/software/ai/hl/stp/play/free_kick/free_kick_play_fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "software/ai/evaluation/calc_best_shot.h"
#include "software/ai/hl/stp/play/play.h"
#include "software/ai/hl/stp/tactic/chip/chip_tactic.h"
#include "software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic.h"
#include "software/ai/hl/stp/tactic/kick/kick_tactic.h"
#include "software/ai/hl/stp/tactic/move/move_tactic.h"
#include "software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic.h"
#include "software/ai/hl/stp/tactic/receiver/receiver_tactic.h"
#include "software/ai/passing/eighteen_zone_pitch_division.h"
#include "software/ai/passing/pass_generator.hpp"
Expand Down

0 comments on commit a984e18

Please sign in to comment.