Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void breadthfirstsearch() {
- createPanelList();
- linkcoordinates();
- recognizeCars();
- MoveWhichWay();
- CanMoveWhere(); //Initial search to get the first level of moves this writes to PossibleMoves
- for (Move move : PossibleMoves){
- ArrayList<Move> newlist = new ArrayList<>();
- newlist.add(move);
- moves.add(newlist); //Save those moves an an integer
- }
- int counter = 0; //This counter is used to get through the moves array
- while (true){ //Keep going untill the red car is out, then a break is used
- resetWindow(); //Make sure every car is in the begin position
- for(Move c : moves.get(counter)){ //Redo the old steps first
- createPanelList();
- linkcoordinates();
- recognizeCars();
- MoveWhichWay();
- MakeMove(c);
- }
- createPanelList();
- linkcoordinates();
- recognizeCars(); //Group panels to define what a car is
- MoveWhichWay(); //See if each car can move left/right or up/down
- CanMoveWhere(); //Create new steps into PossibleMoves()
- for (Move next_move: PossibleMoves){
- new_array.clear();
- new_array = (ArrayList<Move>) moves.get(counter).clone();
- new_array.add(next_move); //Add the new step and put it into the moves array
- moves.add(new_array);
- }
- if(panelByCoordinates.get(new Coordinates(6, 3).coordinates).color.equals(Color.RED)){ //Check if the red car is at the exit.
- break;
- }
- counter++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement