public int CompareTo(object obj)
    {
        if (obj == null)
        {
            return(1);
        }

        HelperNode node = obj as HelperNode;

        if (node != null)
        {
            return(priority.CompareTo(node.getPriority()));
        }
        return(1);
    }
Beispiel #2
0
 public bool contains(MazeCell cell, int p)
 {
     for (int i = 0; i < list.Count; i++)
     {
         if (list[i] != null)
         {
             HelperNode node = list[i] as HelperNode;
             if (node.getMazeCell() == cell && node.getPriority() <= p)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #3
0
    public void help()
    {
        //Debug.Log("HELP!!!");
        if (currentCell.getPassages() > 2)
        {
            MazeCellEdge suggest              = currentCell.GetEdges()[1];
            PriorityQueue <HelperNode> open   = new PriorityQueue <HelperNode>();
            PriorityQueue <HelperNode> closed = new PriorityQueue <HelperNode>();
            open.Enqueue(new HelperNode(currentCell, getDistance(currentCell), 0, getDistance(currentCell), currentCell.GetEdges()[1]));
            bool flag = false;
            while (!flag && !open.isEmpty())
            {
                HelperNode q = open.Dequeue();
                foreach (MazeCellEdge edge in q.getMazeCell().GetEdges())
                {
                    if (edge is MazePassage)
                    {
                        MazeCell     newCell = edge.otherCell;
                        int          g       = q.getG() + 1;
                        int          h       = getDistance(newCell);
                        int          f       = g + h;
                        MazeCellEdge e;
                        if (q.getMazeCell() == currentCell)
                        {
                            e = edge;
                        }
                        else
                        {
                            e = q.getEdge();
                        }
                        if (newCell.getIsWinner())
                        {
                            flag    = true;
                            suggest = e;
                            break;
                        }
                        if (!(open.contains(newCell, f) || closed.contains(newCell, f)))
                        {
                            open.Enqueue(new HelperNode(newCell, f, g, h, e));
                            //Debug.Log("New Node");
                        }
                    }
                }
                closed.Enqueue(new HelperNode(q.getMazeCell(), q.getPriority(), q.getG(), q.getH(), q.getEdge()));
                //Debug.Log("Bye Node");
            }
            //Do fun gui stuff
            Debug.Log(suggest.direction);
            System.Random rng = new System.Random();
            int           helper;
            if (Data.Difficulty == 1)
            {
                helper = 1;
            }
            else if (Data.Difficulty == 2)
            {
                helper = rng.Next(1, 5);
            }
            else
            {
                helper = rng.Next(1, 9);
            }
            string s = "Helper " + helper + " Suggests:\nGo ";
            switch (suggest.direction)
            {
            case MazeDirection.North:
                if (helper == 1 || helper == 5)
                {
                    s += "Up";
                }
                else if (helper == 3 || helper == 7)
                {
                    s += "Down";
                }
                else if (helper == 2 || helper == 8)
                {
                    s += "Right";
                }
                else
                {
                    s += "Left";
                }
                break;

            case MazeDirection.East:
                if (helper == 4 || helper == 8)
                {
                    s += "Up";
                }
                else if (helper == 2 || helper == 6)
                {
                    s += "Down";
                }
                else if (helper == 1 || helper == 7)
                {
                    s += "Right";
                }
                else
                {
                    s += "Left";
                }
                break;

            case MazeDirection.South:
                if (helper == 3 || helper == 7)
                {
                    s += "Up";
                }
                else if (helper == 1 || helper == 5)
                {
                    s += "Down";
                }
                else if (helper == 4 || helper == 6)
                {
                    s += "Right";
                }
                else
                {
                    s += "Left";
                }
                break;

            default:
                if (helper == 2 || helper == 6)
                {
                    s += "Up";
                }
                else if (helper == 4 || helper == 8)
                {
                    s += "Down";
                }
                else if (helper == 3 || helper == 5)
                {
                    s += "Right";
                }
                else
                {
                    s += "Left";
                }
                break;
            }
            text.newDirection(s);
        }
    }