Пример #1
0
        private List <RubickColorMatrix> GetBestNeighbors(RubickColorMatrix _node)
        {
            List <RubickColorMatrix> neighbors = new List <RubickColorMatrix>();
            int min = int.MaxValue;
            RubickColorMatrix minNeightbor = null;

            var moves = System.Enum.GetValues(typeof(RubickMovementTypes));

            for (int i = 0; i < moves.Length; i++)
            {
                RubickMovementTypes val = (RubickMovementTypes)moves.GetValue(i);
                if (val != RubickMovementTypes.None)
                {
                    RubickColorMatrix clone = (RubickColorMatrix)_node.Clone();
                    clone.Transform(val);
                    int cost = clone.HeuristicCostEstimate();
                    if (cost < min)
                    {
                        min          = cost;
                        minNeightbor = clone;
                    }
                }
            }

            if (min == _node.HeuristicCostEstimate())
            {
                UnityEngine.Debug.Log("Duh");
            }
            neighbors.Add(minNeightbor);
            return(neighbors);
        }
Пример #2
0
        public ArrayList getSuccessors(object state)
        {
            RubickColorMatrix   node       = (RubickColorMatrix)state;
            ArrayList           successors = new ArrayList();
            RubickMovementTypes lastMove   = node.stackSize > 0 ? node.moveStack[node.moveStack.Count - 1] : RubickMovementTypes.None;

            if (lastMove != RubickMovementTypes.None)
            {
                lastMove = (RubickMovementTypes)(-((int)lastMove));
            }

            var moves = System.Enum.GetValues(typeof(RubickMovementTypes));

            for (int i = 0; i < moves.Length; i++)
            {
                RubickMovementTypes val = (RubickMovementTypes)moves.GetValue(i);
                if (val != RubickMovementTypes.None && val != lastMove)
                {
                    RubickColorMatrix clone = (RubickColorMatrix)node.Clone();
                    clone.Transform(val);
                    successors.Add(new Successor(val.ToString(), clone));
                }
            }

            return(successors);
        }
Пример #3
0
        private List <RubickColorMatrix> GenerateNeighbors(RubickColorMatrix _node)
        {
            List <RubickColorMatrix> neighbors = new List <RubickColorMatrix>();

            RubickMovementTypes lastMove = _node.stackSize > 0 ? _node.moveStack[_node.moveStack.Count - 1] : RubickMovementTypes.None;

            if (lastMove != RubickMovementTypes.None)
            {
                lastMove = (RubickMovementTypes)(-((int)lastMove));
            }

            var moves = System.Enum.GetValues(typeof(RubickMovementTypes));

            for (int i = 0; i < moves.Length; i++)
            {
                RubickMovementTypes val = (RubickMovementTypes)moves.GetValue(i);
                if (val != RubickMovementTypes.None && val != lastMove)
                {
                    RubickColorMatrix clone = (RubickColorMatrix)_node.Clone();
                    clone.Transform(val);
                    neighbors.Add(clone);
                }
            }

            return(neighbors);
        }