A Star Algorithm - githeim/windheim_archive GitHub Wiki

A Start Algorithm

Reference code

https://github.com/justinhj/astar-algorithm-cpp

How to use

findpath.cpp๋ฅผ ์ฐธ์กฐํ•œ๋‹ค.

ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ฒ˜๋Ÿผ ํ™œ์šฉํ•˜๋ ค๋ฉด,

  • stlastar.h ์™€ fsa.h๋ฅผ include path์— ์ถ”๊ฐ€
  • using namespace std; ๋ฃจํ‹ด์ถ”๊ฐ€ ๋˜๋Š” unordered_set, hash , vector ์•ž์ชฝ์— std:: prefix๋ฅผ ๋ถ™์—ฌ์ค€๋‹ค
  • findpath.cpp์˜ world_map ์ „์—ญ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ map ์ ์šฉ
  • 0~5๊นŒ์ง€๋Š” ์ด๋™ cost๊ฐ’ , ์ปค์งˆ์ˆ˜๋ก ์ด๋™ ๋น„์šฉ์ด ์ปค์ง
  • 9 ์ ‘๊ทผ ๋ถˆ๊ฐ€ ์ง€์—ญ
int world_map[ MAP_WIDTH * MAP_HEIGHT ] =         
{                                                 
                                                  
// 0001020304050607080910111213141516171819       
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   // 00
  1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,1,   // 01
  1,9,9,1,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1,   // 02
  1,9,9,1,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1,   // 03
  1,9,1,1,1,1,9,9,1,9,1,9,1,1,1,1,9,9,1,1,   // 04
  1,9,1,1,9,1,1,1,1,9,1,1,1,1,9,1,1,1,1,1,   // 05
  1,9,9,9,9,1,1,1,1,1,1,9,9,9,9,1,1,1,1,1,   // 06
  1,9,9,9,9,9,9,9,9,1,1,1,9,9,9,9,9,9,9,1,   // 07
  1,9,1,1,1,1,1,1,1,1,1,9,1,1,1,1,1,1,1,1,   // 08
  1,9,1,9,9,9,9,9,9,9,1,1,9,9,9,9,9,9,9,1,   // 09
  1,9,1,1,1,1,9,1,1,9,1,1,1,1,1,1,1,1,1,1,   // 10
  1,9,9,9,9,9,1,9,1,9,1,9,9,9,9,9,1,1,1,1,   // 11
  1,9,1,9,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1,   // 12
  1,9,1,9,1,9,9,9,1,9,1,9,1,9,1,9,9,9,1,1,   // 13
  1,9,1,1,1,1,9,9,1,9,1,9,1,1,1,1,9,9,1,1,   // 14
  1,9,1,1,9,1,1,1,1,9,1,1,1,1,9,1,1,1,1,1,   // 15
  1,9,9,9,9,1,1,1,1,1,1,9,9,9,9,1,1,1,1,1,   // 16
  1,1,9,9,9,9,9,9,9,1,1,1,9,9,9,1,9,9,9,9,   // 17
  1,9,1,1,1,1,1,1,1,1,1,9,1,1,1,1,1,1,1,1,   // 18
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   // 19
                                                  
};                                                
  • AStarSearch ํ…œํ”Œ๋ฆฟ์—๊ฒŒ ์ œ๊ณตํ•  MapSearchNode ํด๋ž˜์Šค ์ ์šฉ (findpath.cpp์— ์œ„์น˜)
  • ํ•„์š”์— ๋งž์ถฐ GetMap() ๊ตฌํ˜„