Example #1
0
        public override bool Evaluate(
            SolverState state,
            ISolverQueue queue,
            ISolverPool pool,
            ISolverPool solutionPool,
            SolverNode node)
        {
            if (node.HasChildren)
            {
                throw new InvalidOperationException();
            }


            node.Status = SolverNodeStatus.Evaluting;
            var toEnqueue = new List <SolverNode>(); // TODO: Could be reused
            var toPool    = new List <SolverNode>(); // TODO: Could be reused

            var solution = false;

            foreach (var move in node.MoveMap.TruePositions())
            {
                foreach (var dir in VectorInt2.Directions)
                {
                    var p   = move;
                    var pp  = p + dir;
                    var ppp = pp + dir;
                    if (node.CrateMap[pp] &&                                 // crate to push
                        state.StaticMaps.FloorMap[ppp] && !node.CrateMap[ppp] && // into free space?
                        !state.StaticMaps.DeadMap[ppp])                      // Valid Push
                    {
                        EvaluateValidPush(state, pool, solutionPool, node, pp, ppp, p, dir, toEnqueue, toPool, ref solution);
                    }
                }
            }

            if (solution)
            {
                node.Status = SolverNodeStatus.SolutionPath;
            }
            else if (node.HasChildren)
            {
                node.Status = SolverNodeStatus.Evaluted;
                state.Statistics.TotalDead += node.CheckDead();    // Children may be evaluated as dead already
            }
            else
            {
                node.Status = SolverNodeStatus.Dead;
                state.Statistics.TotalDead++;
                if (node.Parent != null)
                {
                    state.Statistics.TotalDead += node.Parent.CheckDead();
                }
            }

            queue.Enqueue(toEnqueue);
            pool.Add(toPool);

            return(solution);
        }
Example #2
0
        public bool Evaluate(SolverState state, ISolverQueue queue, ISolverPool myPool,
                             ISolverPool solutionPool, SolverNode node)
        {
            if (node.HasChildren)
            {
                throw new InvalidOperationException();
            }

            node.Status = SolverNodeStatus.Evaluting;

            var solution  = false;
            var toEnqueue = new List <SolverNode>();

            foreach (var move in node.MoveMap.TruePositions())
            {
                foreach (var dir in VectorInt2.Directions)
                {
                    var p  = move;
                    var pc = p + dir;
                    var pp = p - dir;
                    if (node.CrateMap[pc] && // crate to push
                        state.StaticMaps.FloorMap[pp] && !node.CrateMap[p] &&
                        !CheckDeadReverse(state, pp))
                    {
                        EvaluateValidPull(state, myPool, solutionPool, node, pc, p, pp, toEnqueue, ref solution);
                    }
                }
            }

            if (solution)
            {
                node.Status = SolverNodeStatus.SolutionPath;
            }
            else if (node.HasChildren)
            {
                node.Status = SolverNodeStatus.Evaluted;
                state.Statistics.TotalDead += node.CheckDead(); // Children may be evaluated as dead already
            }
            else
            {
                node.Status = SolverNodeStatus.Dead;
                state.Statistics.TotalDead++;
                if (node.Parent != null)
                {
                    state.Statistics.TotalDead += node.Parent.CheckDead();
                }
            }


            queue.Enqueue(toEnqueue);
            myPool.Add(toEnqueue);

            return(solution);
        }