Skip to content

Commit

Permalink
Bug fix: Fix out of range error in run away and chase ghost behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
ll-nick authored and orzechow committed Oct 4, 2024
1 parent 52966c2 commit f199a48
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions demo/include/demo/environment_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class EnvironmentModel {
bool isWall(const Position& position) const {
return maze_->isWall(position);
}
Position positionConsideringTunnel(const Position& position) const {
return maze_->positionConsideringTunnel(position);
}

protected:
void updateEntities(const entt::Registry& registry);
Expand Down
2 changes: 1 addition & 1 deletion demo/src/avoid_ghost_behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Command AvoidGhostBehavior::getCommand(const Time& time) {

double maxDistance = -1;
for (const auto& move : Move::possibleMoves()) {
auto nextPosition = pacmanPosition + move.deltaPosition;
auto nextPosition = environmentModel_->positionConsideringTunnel(pacmanPosition + move.deltaPosition);

if (environmentModel_->isWall(nextPosition)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion demo/src/chase_ghost_behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Command ChaseGhostBehavior::getCommand(const Time& time) {

double minDistance = std::numeric_limits<double>::max();
for (const auto& move : Move::possibleMoves()) {
auto nextPosition = pacmanPosition + move.deltaPosition;
auto nextPosition = environmentModel_->positionConsideringTunnel(pacmanPosition + move.deltaPosition);

if (environmentModel_->isWall(nextPosition)) {
continue;
Expand Down

0 comments on commit f199a48

Please sign in to comment.