Skip to content

Commit

Permalink
Always return a valid maze position in Maze::positionConsideringTunnel()
Browse files Browse the repository at this point in the history
  • Loading branch information
orzechow committed Dec 6, 2024
1 parent dd1903a commit 54d36d1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions demo/include/utils/maze.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <algorithm>
#include <optional>
#include <utility>

Expand Down Expand Up @@ -56,7 +57,7 @@ class Maze {
if (isPassableCell(wrappedPosition)) {
return wrappedPosition;
}
return position;
return {std::clamp(position.x, 0, width() - 1), std::clamp(position.y, 0, height() - 1)};
}

bool isDot(const Position& position) const {
Expand Down Expand Up @@ -87,7 +88,7 @@ struct BaseCell {
using TileType = demo::TileType;
using Position = demo::Position;

BaseCell(const Position& position, const TileType& type) : position(position), type(type) {};
BaseCell(const Position& position, const TileType& type) : position(position), type(type){};

double manhattanDistance(const Position& other) const {
return std::abs(position.x - other.x) + std::abs(position.y - other.y);
Expand All @@ -112,7 +113,7 @@ class MazeAdapter {
using MazeStateConstPtr = std::shared_ptr<const MazeState>;
using Position = demo::Position;

explicit MazeAdapter(Maze::ConstPtr maze) : maze_(std::move(maze)), cells_({maze_->width(), maze_->height()}) {};
explicit MazeAdapter(Maze::ConstPtr maze) : maze_(std::move(maze)), cells_({maze_->width(), maze_->height()}){};

CellT& cell(const Position& position) const {
if (!cells_[{position.x, position.y}]) {
Expand Down

0 comments on commit 54d36d1

Please sign in to comment.