pathfinding_demo/cpp/src/pathfinder.hpp
2025-09-27 18:36:22 +02:00

62 lines
1.2 KiB
C++

#pragma once
#include <vector>
#include <memory>
#include "math.hpp"
#include "map.hpp"
namespace pathfinder {
using Path = std::vector<WorldPos>;
enum class PathFinderType {
LINEAR = 1,
BFS,
COUNT,
};
class PathFinderBase {
public:
PathFinderBase() = default;
~PathFinderBase() = default;
PathFinderBase(const PathFinderBase&) = delete;
PathFinderBase(PathFinderBase&&) = delete;
PathFinderBase& operator=(const PathFinderBase&) = delete;
PathFinderBase& operator=(PathFinderBase&&) = delete;
void SetMap(std::shared_ptr<Map> map);
virtual const std::string_view& GetName() const = 0;
virtual Path CalculatePath(WorldPos target) = 0;
private:
std::shared_ptr<Map> m_Map;
};
class LinearPathFinder : public PathFinderBase {
public:
Path CalculatePath(WorldPos target) override;
const std::string_view& GetName() const override { return m_Name; }
private:
const std::string_view m_Name = "Linear Path";
};
class BFS: public PathFinderBase {
public:
Path CalculatePath(WorldPos target) override;
const std::string_view& GetName() const override { return m_Name; }
private:
const std::string_view m_Name = "Breadth First Search";
};
std::unique_ptr<PathFinderBase> create(PathFinderType type);
} // pathfinder namespace