Search code examples
c#algorithmartificial-intelligencea-star

A* how to calculate G cost


I read this article: http://www.policyalmanac.org/games/aStarTutorial.htm, but i don't understand how is calculated G cost. I know those child's on corner of his parent have bigger score but there is probably another calculation to check distance from current to start node.

Please help.


Solution

  • In the article,
    It was stated that G=10 if you move horizontal or vertical and
    G=14 if you go diagonal from one square to another square.

    Hence if you move horizontal from start square G = 0+10
    where initially G is 0. Then you move vertical or horizontal from there implies G=10+10
    and if diagonal means G=10+14