国际象棋中的javascript路径查找?二维阵列搜索

kyks70gy  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(228)

我目前正在开发一个国际象棋应用程序。我已经创建了一个数组,它是 board 在这个板上是 Sqaure 持有 Piece 还有一个位置是 [x,y] 它所在位置的坐标。
我开始着手在项目中实施运动的第一步。
我的问题是,给定一个像这样的数组的当前位置 [1, 0] 如何找到通向目标位置的路径 [2,5] 我知道这不是一个可能的棋步,我只是想在我开始工作之前能够刺激任何动作。我目前的功能非常简单,但我不确定我的解释是否足够好

const calculateMovement = (board, piece, x , y, index) => {
    // board is a global array, holding all position -
    // board = [[0, 0], [1, 0]]
    // Current Location of the piece I want to move

    // x is row
    // y is col
    // how to get every piece between the currentLocation and wantedLocation
    let currentLocation = [x, y]
    let wantedLocation = [8, 8]
  }
xnifntxz

xnifntxz1#

通常,可以使用广度优先搜索来实现寻路。wikipeda这是一个很好的起点,对于像《骑士》这样的复杂作品尤其有用。下一步可能是看看a*寻路算法。维基百科
国际象棋编程维基是构建这样一个项目的好资源

相关问题