仅使用正交移动查找最短路径

问题描述 投票:0回答:1

我正在制作一个必须将棋子押到节点F的游戏。存储在2D数组中的值表示:

Pawn (starting point): I    
Destination: F

例如,

Node [row=2, col=1]
Node [row=2, col=2]
Node [row=1, col=2]
Node [row=0, col=2]
Node [row=0, col=3]
Node [row=0, col=4]
Node [row=1, col=4]
Node [row=2, col=4]
Node [row=2, col=5]

Search Path without diagonals
     0   1   2   3   4   5   6
0    -   -   *   *   *   -   -
1    -   -   *   B   *   -   -
2    -   I*  *   B   *  *F   -
3    -   -   -   B   -   -   -
4    -   -   -   -   -   -   -
5    -   -   -   -   -   -   -

This is the A* implementation I'm using

此实现的问题在于它一步一步走。我希望能够检测到方向改变的时间并仅添加此动作,我该如何完成?例如,我不想像以前的示例那样一个接一个地访问所有节点,而是:

Node [row=2, col=1] 
Node [row=2, col=2] // Right

Node [row=0, col=2] // Top

Node [row=0, col=4] // Right

Node [row=2, col=4] // Bottom
Node [row=2, col=5] // Right

我该如何完成?

我正在做一个游戏,其中必须将棋子陪送到节点F。存储在2D数组中的值表示:Pawn(起点):I目的地:F例如,节点[row = 2,col = 1] [row = 2,...

java shortest-path dijkstra a-star
1个回答
1
投票

我没有检查算法的实现,但是tt显示您将得到的结果作为Node对象的列表。它可能看起来像这样:

© www.soinside.com 2019 - 2024. All rights reserved.