Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1313 from RoboTeamTwente/fix/defendShotIssues
Browse files Browse the repository at this point in the history
Fix segfault and small issue in defendShot/Pass
  • Loading branch information
alexander-de-ranitz authored Jan 20, 2022
2 parents 03a75a9 + 71d0128 commit 830d0e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/stp/plays/defensive/DefendPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ DefendPass::DefendPass() : Play() {
}

uint8_t DefendPass::score(PlayEvaluator &playEvaluator) noexcept {
auto world = playEvaluator.getWorld();
auto field = world->getField().value();
auto enemyRobot = world->getWorld()->getRobotClosestToBall(world::them);
auto position = distanceFromPointToLine(field.getBottomLeftCorner(), field.getTopLeftCorner(), enemyRobot->get()->getPos());
return 255 * (position / field.getFieldLength());
Expand Down Expand Up @@ -67,10 +69,10 @@ void DefendPass::calculateInfoForDefenders() noexcept {

auto remainingEnemy = world->getWorld()->getRobotClosestToPoint(field.getOurGoalCenter(), enemyRobots);

stpInfos["defender_1"].setPositionToDefend(remainingEnemy->get()->getPos());
stpInfos["defender_1"].setPositionToDefend(enemyClosestToOurGoal->get()->getPos());
stpInfos["defender_1"].setBlockDistance(BlockDistance::HALFWAY);

stpInfos["defender_2"].setPositionToDefend(enemyClosestToOurGoal->get()->getPos());
stpInfos["defender_2"].setPositionToDefend(remainingEnemy->get()->getPos());
stpInfos["defender_2"].setBlockDistance(BlockDistance::HALFWAY);
}

Expand Down
2 changes: 2 additions & 0 deletions src/stp/plays/defensive/DefendShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ DefendShot::DefendShot() : Play() {
}

uint8_t DefendShot::score(PlayEvaluator &playEvaluator) noexcept {
auto world = playEvaluator.getWorld();
auto field = world->getField().value();
auto enemyRobot = world->getWorld()->getRobotClosestToBall(world::them);
auto position = distanceFromPointToLine(field.getBottomLeftCorner(), field.getTopLeftCorner(), enemyRobot->get()->getPos());
return 255 * (field.getFieldLength() - position) / field.getFieldLength();
Expand Down

0 comments on commit 830d0e8

Please sign in to comment.