Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1.     public void breadthfirstsearch() {
  2.         createPanelList();
  3.         linkcoordinates();
  4.         recognizeCars();    
  5.         MoveWhichWay();
  6.         CanMoveWhere(); //Initial search to get the first level of moves this writes to PossibleMoves
  7.         for (Move move : PossibleMoves){
  8.             ArrayList<Move> newlist = new ArrayList<>();
  9.             newlist.add(move);  
  10.             moves.add(newlist); //Save those moves an an integer
  11.         }  
  12.         int counter = 0;    //This counter is used to get through the moves array
  13.         while (true){ //Keep going untill the red car is out, then a break is used
  14.             resetWindow();  //Make sure every car is in the begin position
  15.             for(Move c : moves.get(counter)){   //Redo the old steps first
  16.                 createPanelList();
  17.                 linkcoordinates();
  18.                 recognizeCars();
  19.                 MoveWhichWay();
  20.                 MakeMove(c);
  21.             }
  22.            
  23.             createPanelList();
  24.             linkcoordinates();
  25.             recognizeCars(); //Group panels to define what a car is
  26.             MoveWhichWay(); //See if each car can move left/right or up/down
  27.             CanMoveWhere(); //Create new steps into PossibleMoves()
  28.            
  29.             for (Move next_move: PossibleMoves){
  30.                 new_array.clear();
  31.                 new_array = (ArrayList<Move>) moves.get(counter).clone();
  32.                 new_array.add(next_move);    //Add the new step and put it into the moves array
  33.                 moves.add(new_array);
  34.             }
  35.             if(panelByCoordinates.get(new Coordinates(6, 3).coordinates).color.equals(Color.RED)){  //Check if the red car is at the exit.
  36.                 break;
  37.             }
  38.             counter++;
  39.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement