Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.deploy.util.StringUtils;
- import javax.swing.text.StringContent;
- import java.util.List;
- import java.util.PriorityQueue;
- /**
- * Created by אביב on 11/30/2016.
- */
- public class UCS {
- private PriorityQueue<Node> queue;
- private GameTactic gt;
- public UCS(GameTactic gt) {
- this.queue=new PriorityQueue<Node>(new UcsComparator());
- this.gt=gt;
- }
- public String SolveSearch(){
- int pathSize;
- int timeStamp=1;
- Node temp;
- Node begin=new Node(0,0);
- begin.setCost(0);
- begin.setTimeStamp(0);
- this.queue.add(begin);
- List<Node> tempList;
- int listSize;
- while(true) {
- if (this.queue.isEmpty()){
- return "no path";
- }
- temp=this.queue.poll();
- pathSize=temp.getPath().split("-").length;
- if(this.gt.IsGoal(temp)){
- String result=temp.getPath();
- result=result+" "+Integer.toString(temp.getCost());
- return result;
- }
- tempList=gt.GetPossibleNeigh(temp,timeStamp);
- listSize=tempList.size();
- if(pathSize<=((this.gt.size*this.gt.size/2)+this.gt.size)){
- for(int i=0;i<listSize;i++) {
- //this.queue.add(tempList.get(i));
- if (!this.queue.contains(tempList.get(i))) {
- this.queue.add(tempList.get(i));
- } else {
- }
- }
- }
- timeStamp++;
- }
- }
- }
Add Comment
Please, Sign In to add comment