Giter Club home page Giter Club logo

pathfinding-cpp's Introduction

PathFinding

  • A Star
  • B Star (with bugs!)
  • BFS
  • DFS

设置障碍物

  • 手动设置:

    • 鼠标左键点击设置障碍物,右键点击清除障碍物。按住左/右键不松,移动鼠标,可连续设置/清除障碍物。
    • 左键点击一个点,然后按住shift键,再点击一个点,即可生成水平或竖直直线。

    manual

  • 随机生成: 点击Random Obstacles按钮,输入千分比,自动随机生成相应比例的障碍物

    random

修改颜色

双击颜色块,即可修改相应的颜色

set-colors

添加新的寻路算法

如果要写其他寻路算法,只需要继承自FindPathBase类,

并重写std::list<Coordinate> findPath(src, dest)函数。

例如,假设有一个新的 算法 C Star :

注意: 标有 [Required] 的地方是必须要写的 !

class CStar : public FindPathBase
{
public:
    std::list<Coordinate> findPath(const Coordinate& src, const Coordinate& dest) {
        stopFindPath = false;  // [Required]

        // ...

        //  开始寻路
        while (...) {

            // 是否强制终止寻路, [Required]
            if (stopFindPath) {
                return {};
            }

            // ...

            // 新的点 newCoord
            Coordinate newCoord = ...;

            // 该点是障碍物
            if (detectObstacle(newCoord)) {
                continue;
            }

            // 该点是目标,返回
            else if (newCoord == dest) {
                std::list<Coordinate> path;
                // add coord to path
                // ...
                return path;
            }

            else {
                // 通知GUI线程,绘制该点(已经访问的点,默认为橘色)  [Required]
                notifyVisitedCoordinate(newCoord);
                // ...
            }

            // ...
        }

        // ...
        
        return {};  // 返回空路径
    }
}

然后在src/controldialog.cpp中,将该算法添加到候选列表中

1、构造函数中,添加

comboxFindPathList->addItem("C Star"); // 算法名称

2、onFindPathMethodChanged函数中,添加

    else if (methodName == "C Star") {
        findPathBaseNew = new CStar();
        if (controlPanelExtend) {
            delete controlPanelExtend;
            controlPanelExtend = nullptr;
        }
        // 扩展控制面板(该算法的独有的设置项,如果没有,就忽略)
        //controlPanelExtend = new ControlPanelExtendCStar(world, nullptr);
    }

Screenshots

[1/4] A Star

astar

astar-2

[2/4] BFS

bfs

[3/4] DFS

dfs

dfs-2

[4/4] B Star (With bugs)

Only suitable for situations with few obstacles. (At least)

bstar

END

Author: github@Leopard-C

Email: [email protected]

pathfinding-cpp's People

Contributors

leopard-c avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.