public ArrayList<Square> getLongestPath(Square where)
    {
        ArrayList[][] grid=makeGrid();
        
        grid[where.x()][where.y()]=new ArrayList<Square>();
        grid[where.x()][where.y()].add(where);
        Queue<Square> active=new Queue<Square>();
        active.push_back(where);
        int longestPath=0;
        Square furthest=where;
        while (active.notEmpty())
        {
            Square current=active.pop_front();
            ArrayList<Square> curPath=(ArrayList<Square>)getPath(where, grid);
            int curLeng=getPath(where, grid).size();
            if (curLeng > longestPath) 
            {
                System.out.println("len= "+curLeng);
                longestPath=curLeng;
                furthest=current;
            }
            for (int d=0;d<4;d++)
            {
                Square nayb=current.transform(Dir.getDir(d));
                if (nayb.notError() && nayb.isFree())
                {
                    if (pathLength(nayb,grid)<=curLeng)
                    {
                        boolean alreadyVisited=false;
                        if (getPath(where,grid)!=null) 
                        {//if the naybors curPath is null, it's certainly not already in the curPath
                            alreadyVisited= (curPath.contains(nayb));
                        }
                        if (!alreadyVisited) {
//                            active.purge(nayb);
                            active.push_back(nayb);
                            grid[nayb.x()][nayb.y()]=(ArrayList)curPath.clone();
                            grid[nayb.x()][nayb.y()].add(nayb);
                        }
                    }
                }
            }
        }
        return getPath(furthest,grid);
        /*
        if (gridLookup(where,squaresChecked)!=null)
            return gridLookup(where,squaresChecked);
        else
        {
            squaresChecked[where.x()][where.y()]=new ArrayList<Square>();
            gridLookup(where,squaresChecked).add(where);
        }
//        System.out.println("checking "+where.toString());
        ArrayList<Square> longest=new ArrayList<Square>();
        Dir direc=dir.getOpp();
        for (int r=0;r<3;r++)
        {
            direc=direc.rotate(true);
            Square to=where.transform(direc);
            if (to.isFree())
            {
                ArrayList<Square> thisPath=getLongestPath(to,direc,squaresChecked);
                if (thisPath.size()>longest.size())
                    longest=thisPath;
            }
        }
        longest=(ArrayList<Square>)longest.clone();
        longest.add(where);
        squaresChecked[where.x()][where.y()]=longest;
        return longest;
                
                */
    }