Strategy #31
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -0,0 +1,76 @@
 | 
			
		|||
package ch.zhaw.pm2.racetrack.strategy;
 | 
			
		||||
 | 
			
		||||
import ch.zhaw.pm2.racetrack.PositionVector;
 | 
			
		||||
import ch.zhaw.pm2.racetrack.Track;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class PathFinderStrategy implements MoveStrategy{
 | 
			
		||||
    private ArrayList<tryOutPaths> possiblePaths;
 | 
			
		||||
    private Track track;
 | 
			
		||||
    List<PositionVector.Direction> directions = Arrays.asList(PositionVector.Direction.values());
 | 
			
		||||
 | 
			
		||||
    public PathFinderStrategy(Track track, int carIndex) {
 | 
			
		||||
        this.track = track;
 | 
			
		||||
        possiblePaths = new ArrayList<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void test(){
 | 
			
		||||
        ArrayList<tryOutPaths> temporary = new ArrayList<>();
 | 
			
		||||
        Iterator<tryOutPaths> it = possiblePaths.iterator();
 | 
			
		||||
        while(it.hasNext()) {
 | 
			
		||||
            tryOutPaths current = it.next();
 | 
			
		||||
            if (!current.isFeasible()) {
 | 
			
		||||
                it.remove();
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                for (PositionVector.Direction direction : directions) {
 | 
			
		||||
                    temporary.add(current);
 | 
			
		||||
                    temporary.get(temporary.size() - 1).takeDirection(direction);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        //ab hier zu löschen
 | 
			
		||||
        for (tryOutPaths paths : possiblePaths){
 | 
			
		||||
            for (PositionVector.Direction direction : directions) {
 | 
			
		||||
                temporary.add(paths);
 | 
			
		||||
                temporary.get(temporary.size() - 1).takeDirection(direction);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        //bis hier löschen
 | 
			
		||||
        possiblePaths.clear();
 | 
			
		||||
        possiblePaths.addAll(temporary);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PositionVector.Direction nextMove() {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
    public class tryOutPaths {
 | 
			
		||||
        ArrayList<PositionVector.Direction>  directionsTaken = new ArrayList<>();
 | 
			
		||||
        PositionVector currentPosition;
 | 
			
		||||
        Track track;
 | 
			
		||||
        private boolean feasible;
 | 
			
		||||
        private boolean finished;
 | 
			
		||||
        public tryOutPaths(Track track){
 | 
			
		||||
            this.track = track;
 | 
			
		||||
        }
 | 
			
		||||
        public boolean isFeasible(){
 | 
			
		||||
            return feasible;
 | 
			
		||||
        }
 | 
			
		||||
        public void takeDirection(PositionVector.Direction direction) {
 | 
			
		||||
            if(directionsTaken.size() >= 50){
 | 
			
		||||
                feasible = false;
 | 
			
		||||
            }
 | 
			
		||||
            else if(finished){
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                //check if possible eventuell hier??
 | 
			
		||||
                directionsTaken.add(direction);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue