GithubHelp home page GithubHelp logo

astar's Introduction

A* 算法



介绍

使用 A* 算法解决八数码问题


启发式搜索

估价函数 f(n) = g(n) + h(n)

  • 估价函数h1 放错位置数目的数字的个数
  • 估价函数h2 所有数字当前位置以最短路径走到正确位置的步数之和

拓展

解决九数码问题

此处将空格变成0,在计算估值的时候包含,移动规则与八数码相同


使用

编译

g++ ./src/main.cpp ./src/astar.hpp -o a -std=c++11

运行

a.exe [估价函数] [八数码问题or九数码问题]
  • 使用估价函数h1解决八数码问题
    # 方式1
    a.exe
    
    # 方式2
    a.exe h1
    
    # 方式2
    a.exe h1 8
    
  • 使用估价函数h1解决八数码问题
    # 方式1
    a.exe h2
    
    # 方式2
    a.exe h2 8
    
  • 使用估价函数h1解决九数码问题
    a.exe h1 9
    
  • 使用估价函数h2解决九数码问题
    a.exe h2 9
    

注意

  • 输入的检查比较少,请按照提示输入,否则可能出现神奇的bug

astar's People

Contributors

liu-yt avatar

Watchers

James Cloos 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.