void FillAvaliable() { explorer.Explore(); int x, y, pos; for (int i = 0; i < newStatesCount; ++i) { map.XY2Pos(accessXYs[i], out x, out y, out pos); if ((explorer.cells[pos] & SokobanSolverExplorer.O_EXPLORED) == 0) { continue; } distance[newStatesAvaliableCount] = explorer.distance[pos]; order[newStatesAvaliableCount] = i; ++newStatesAvaliableCount; } Array.Sort(distance, order, 0, newStatesAvaliableCount); }
ushort[] BuildPath(ushort[] stateFrom, ushort[] stateTo) { ushort boxFromXY = stateTo[map.boxesCount]; ushort boxToXY = boxFromXY; for (int i = 0; i < map.boxesCount; ++i) { if (Array.BinarySearch(stateFrom, 0, map.boxesCount, stateTo[i]) < 0) { boxToXY = stateTo[i]; break; } } int boxFromX, boxFromY; int boxToX, boxToY; map.XY2Pos(boxFromXY, out boxFromX, out boxFromY); map.XY2Pos(boxToXY, out boxToX, out boxToY); int playerToX = (boxFromX << 1) - boxToX; int playerToY = (boxFromY << 1) - boxToY; ushort playerToXY = (ushort)(playerToX | (playerToY << 8)); ushort playerFromXY = stateFrom[map.boxesCount]; if (playerFromXY == playerToXY) { return new ushort[] { playerToXY } } ; explorer.ApplyState(stateFrom); explorer.Explore(); return(explorer.GetPath(playerToXY)); } }