Exemplo n.º 1
0
        public static bool Solve(string level, ref string solution)
        {
            Level.levelFromString(level);

            SolFunc.initArrays();
            Console.WriteLine("Starting Solve");
            Global.solvable        = true;
            Global.levelSol.length = 0;
            LevelInfo.preprocessLevel();
            DeadlockTable.calculateStaticDeadlocks();
            //Level.printLevel(Global.level);

            SolvingRoutine.trySolveLevel();
            if (Global.solvable)
            {
                if (!SolFunc.checkSolution(Global.levelSol, Global.level))
                {
                    Global.solvable = false;
                    return(false);
                }
                for (int i = 0; i < Global.levelSol.length; i++)
                {
                    solution += Global.levelSol.move[i];
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public static void addMove(int x, int y, int from, int xto, int yto, int to, int pd)
        {
            Position.pushBox(ref mov.pos, ref newMove.pos, from, to, x, y);
            newMove.magic = mov.magic ^ (int)Global.levelInfo.magic[y, x] ^ (int)Global.levelInfo.magic[yto, xto] ^ (int)LevelInfo.magicForSokoban(Global.level.px, Global.level.py)
                            ^ (int)LevelInfo.magicForSokoban(x, y);

            if (!DeadlockTable.testStaticDeadlocks(newMove.pos, to) && Hashtable.addToHashtable(newMove))
            {
                //echoMove(mov, newMove);
                newMove.parent    = mov;
                newMove.heuristic = mov.heuristic + (uint)pd - (uint)Global.levelInfo.goalDists[from] + (uint)Global.levelInfo.goalDists[to] + (uint)(Global.HIBYTES * pd);
                Queue.appendQueueNode(Queue.createQueueNode(newMove), Global.moveQueue[newMove.heuristic % Global.HIBYTES]);
                newMove = Allocator.mallocMove();
            }
        }