我在项目javafx github上找到了此代码,但我不了解马的动作...有人可以帮助我....
return ((Math.abs(newRow - oldRow) == 2 && Math.abs(newCol - oldCol) == 1)
|| (Math.abs(newRow - oldRow) == 1 && Math.abs(newCol - oldCol) == 2));
[如果骑士处于下面标记为N
的位置,则此条件的第一部分,Math.abs(newRow - oldRow) == 2 && Math.abs(newCol - oldCol) == 1
检查目标方块是否为下面由1
标记的方块,第二部分,Math.abs(newRow - oldRow) == 1 && Math.abs(newCol - oldCol) == 2
检查是否目标正方形是用2
标记的任何正方形。
+---+---+---+---+---+---+---+---+
| | | | | | | | |
+---+---+---+---+---+---+---+---+
| | | | | | | | |
+---+---+---+---+---+---+---+---+
| | | 1 | | 1 | | | |
+---+---+---+---+---+---+---+---+
| | 2 | | | | 2 | | |
+---+---+---+---+---+---+---+---+
| | | | N | | | | |
+---+---+---+---+---+---+---+---+
| | 2 | | | | 2 | | |
+---+---+---+---+---+---+---+---+
| | | 1 | | 1 | | | |
+---+---+---+---+---+---+---+---+
| | | | | | | | |
+---+---+---+---+---+---+---+---+