Ejemplo n.º 1
0
        public bool isGoalState(object state)
        {
            RubickColorMatrix node = (RubickColorMatrix)state;

            return(node.IsResolved());
        }
Ejemplo n.º 2
0
 public RubickCubeResolvedOutputEvent(RubickColorMatrix _cube, int _iterations)
 {
     rubickCube = _cube;
     iterations = _iterations;
     success    = _cube != null && _cube.IsResolved();
 }
Ejemplo n.º 3
0
        public void Search(RubickColorMatrix _start)
        {
            result = null;
            closedSet.Clear();
            openSet.Clear();
            openSet.Add(_start);

            gScore.Clear();
            gScore[_start] = 0;

            fScore.Clear();
            fScore[_start] = HeuristicCostEstimate(_start);
            iterations     = 0;
            RubickColorMatrix current = null;
            int attepts = 2000;

            while (openSet.Count > 0 && attepts > 0)
            {
                attepts--;
                iterations++;

                if (attepts == 0)
                {
                    UnityEngine.Debug.Log("Hola");
                }
                current = FindLowestFScore();
                if (current.IsResolved())
                {
                    result = current;
                    return;
                }

                openSet.Remove(current);
                closedSet.Add(current);

                IList <RubickColorMatrix> neighbors = GenerateNeighbors(current);

                foreach (var nb in neighbors)
                {
                    RubickColorMatrix neighbor = nb;
                    if (closedSet.Contains(neighbor))
                    {
                        continue;
                    }

                    int tentativeGScore = GetGScore(current) + DistanceBetween(current, neighbor);
                    if (!openSet.Contains(neighbor))
                    {
                        openSet.Add(neighbor);
                    }
                    else
                    {
                        neighbor = openSet.Find(n => n == neighbor);
                        if (tentativeGScore >= GetGScore(neighbor))
                        {
                            continue;
                        }
                    }

                    gScore[neighbor] = tentativeGScore;
                    fScore[neighbor] = gScore[neighbor] + HeuristicCostEstimate(neighbor);
                }
            }
        }