I'm a student and me and my team have to make a simulation of student's behaviour in a campus (like making "groups of friends") walking etc. For finding path that student has to go, I used A* algorithm (as I found out that its one of fastest path-finding algorithms). Unfortunately our simulation doesn't run fluently (it takes like 1-2 sec between successive iterations). I wanted to optimize the algorithm but I don't have any idea what I can do more. Can you guys help me out and share with me information if its possible to optimize my A* algorithm? Here goes code:

public LinkedList getPath(Field start, Field exit) { LinkedList foundPath = new LinkedList(); LinkedList opensList= new LinkedList(); LinkedList closedList= new LinkedList(); Hashtable gscore = new Hashtable(); Hashtable cameFrom = new Hashtable(); Field x = new Field(); gscore.put(start, 0); opensList.add(start); while(!opensList.isEmpty()){ int min = -1; //searching for minimal F score for(Field f : opensList){ if(min==-1){ min = gscore.get(f)+getH(f,exit); x = f; }else{ int currf = gscore.get(f)+getH(f,exit); if(min > currf){ min = currf; x = f; } } } if(x == exit){ //path reconstruction Field curr = exit; while(curr != start){ foundPath.addFirst(curr); curr = cameFrom.get(curr); } return foundPath; } opensList.remove(x); closedList.add(x); for(Field y : x.getNeighbourhood()){ if(!(y.getType()==FieldTypes.PAVEMENT ||y.getType() == FieldTypes.GRASS) || listaZamkni

Check Solution