public bool addResults(Floor f)
    {
        ReturnBestPath    bpath = new ReturnBestPath();
        ReturnLongestPath lpath = new ReturnLongestPath();
        Edge PrevEdge;
        Edge GoalEdge;
        bool turns      = false;
        int  turnsCount = 0;
        int  totalLen   = 0;

        //bestpath
        List <Edge> BestPathE = new List <Edge>();

        BestPathE.AddRange(bpath.RunAlg(f));
        List <Cell> BestPathC = new List <Cell>();

        BestPathC = bpath.BestPath;
        totalLen  = bpath.bestPathLen;
        //longestPath
        int LongestPath = 0;

        lpath.RunAlg(f);
        LongestPath = lpath.LongestPath;
        LongestRoomDist.Add(LongestPath);

        /*
         * //reset path if it Is > size
         * if((float)LongestPath >  (float)Xsize * (float)Ysize  * 0.75f)
         * {
         *  //modify main so that if we return false we rebuild the floor
         * return false
         * }
         */


        if ((f.floorNumber % 2) == 0) //POSSIBLE BROKE?
        {                             //first floor, and odd floors
            //Debug.Log("first floor");
            PrevEdge = new Edge(null, null, 0, Ysize, false);
            // GoalEdge = new Edge(null, null, Xsize, 0, false);
        }
        else
        {
            //Debug.Log("odd floor");

            PrevEdge = new Edge(null, null, Xsize, Ysize, false);
            //GoalEdge = new Edge(null,null, 0, 0, false);
        }

        //check v first edge

        for (int c = 1; c < BestPathE.Count; c++) //was C
        {
            if (BestPathE[c].getUp() != turns)
            {
                turns      = BestPathE[c].getUp();
                turnsCount = turnsCount + 1;
            }
            else
            {
                if (PrevEdge.getX() == BestPathE[c].getX() && BestPathE[c].getUp() == false)
                {
                    turnsCount = turnsCount + 2;
                }
                else if (PrevEdge.getY() == BestPathE[c].getY() && BestPathE[c].getUp() == true)
                {
                    turnsCount = turnsCount + 2;
                }
            }

            PrevEdge = BestPathE[c];
        }
        //Debug.Log(turnsCount);
        totalRooms.Add(f.cells.Count);
        visitedRooms.Add(BestPathC.Count);
        Turns.Add(turnsCount);
        Length.Add(totalLen); //for some reason the 2nd last length is alsways +1 and the last is always -1
        //Debug.Log(totalLen);
        //add TIME!
        //Debug.Log("LEN:" + totalLen);
        return(true);
    }
Exemplo n.º 2
0
    public List <Edge> RunAlg(Floor cur_floor)
    {
        ///ISSUUE WITH THE ODD FLOORS AND THE STARTEDGE


        Cell Startcell = cur_floor.cells[0];
        Cell GoalCell  = cur_floor.cells[0];

        ReturnBestPath bpath    = new ReturnBestPath();
        List <Cell>    BestPath = new List <Cell>();

        bpath.RunAlg(cur_floor);
        BestPath = bpath.BestPath;

        if ((cur_floor.floorNumber % 2) == 0)
        {
            //Debug.Log("FIRST");
            //if its an even floor
            startedge = new Edge(Startcell, Startcell, 0, cur_floor.getY() - 1, false);
            goaledge  = new Edge(Startcell, Startcell, cur_floor.getX(), 0, false);
            foreach (Cell c in cur_floor.cells)
            {
                if (c.YLoc > Startcell.YLoc && c.XLoc == 0)
                {
                    Startcell = c;
                }
            }
            foreach (Cell c in cur_floor.cells)
            {
                if (c.XLoc + c.Xsize == cur_floor.getX() && c.YLoc == 0)
                {
                    GoalCell = c;
                }
            }
        }
        else
        {   //odd floor
            //Debug.Log("SECOND");

            int counter = 0;
            startedge = new Edge(Startcell, Startcell, cur_floor.getX(), cur_floor.getY() - 1, false);
            goaledge  = new Edge(Startcell, Startcell, 0, 0, false);
            foreach (Cell c in cur_floor.cells)
            {
                if (c.YLoc + c.XLoc > counter)
                {
                    counter   = c.YLoc + c.XLoc;
                    Startcell = c;
                }
            }
            foreach (Cell c in cur_floor.cells)
            {
                if (c.XLoc == 0 && c.YLoc == 0)
                {
                    GoalCell = c;
                }
            }
        }

        //  Debug.Log("goal = " + GoalCell.XLoc + "," + GoalCell.YLoc);


        foreach (Cell c in cur_floor.cells)
        {
            if ((c != GoalCell || c != Startcell) && !BestPath.Contains(c))
            {
                List <Cell> curPath     = new List <Cell>();
                List <Cell> DefaultPath = new List <Cell>();

                paths   = new List <List <Cell> >();
                visited = new List <List <int> >();

                DefaultPath.Add(Startcell);
                paths.Add(DefaultPath);
                List <Edge> newList = new List <Edge>();
                newList.Add(startedge);
                //Debug.Log("start");
                Dfirst(Startcell, GoalCell, c, DefaultPath, newList, cur_floor, 0);
                //Debug.Log("SEARCH FINISHED");
            }
        }

        LongestPath = LongestPath + 1; //so we step inside the last cell.



        return(visitedEdges);
    }