import java
ArrayList; import java
List; /** * * @author dudizi * @version 1
0 * @date 2013/3/15 */ public class BaShuMa { //方向数组 int[][] dir = { { 0, -1 }, { -1, 0 }, { 0, 1 }, { 1, 0 } }; //搜索表 static Node[] all = new Node[1000000]; //搜索成功后的搜索节点到初始节点的路径上的节点列表 static List result = new ArrayList(); //判断此节点的八数码状态是否在搜索表中已经存在 public static boolean hasSame(Node node) { for (int i = 0; i < all
length; i++) { if (all[i]
= null && node
equals(all[i])) return true; } return false; } //搜索八数码解的方法 public void Search(Node node) { int i = 0; int cur = 0; // 把初始状态放到状态表中 all[i++] = node; while (cur < 1000000) { if (node
= null) { int x = 0; int y = 0; Node exNode = null; int[][] st = null; if (
isEndState()) { // 从四个方向去扩展八数码的状态 for (int j = 0; j < 4; j++) { //计算移动后新的x,y 坐标 x = node