From 54d36d11010699c193be39f191fff0ffe695df91 Mon Sep 17 00:00:00 2001 From: Piotr Spieker Date: Fri, 6 Dec 2024 17:49:25 +0100 Subject: [PATCH] Always return a valid maze position in Maze::positionConsideringTunnel() --- demo/include/utils/maze.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/demo/include/utils/maze.hpp b/demo/include/utils/maze.hpp index 8758ce11..ca81f646 100644 --- a/demo/include/utils/maze.hpp +++ b/demo/include/utils/maze.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -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 { @@ -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); @@ -112,7 +113,7 @@ class MazeAdapter { using MazeStateConstPtr = std::shared_ptr; 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}]) {