|  | @@ -1,61 +1,118 @@
 | 
	
		
			
				|  |  | -package pathgame.logging;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -import pathgame.algorithm.SaleRoute;
 | 
	
		
			
				|  |  | -import pathgame.gameplay.Player;
 | 
	
		
			
				|  |  | -import pathgame.tilemap.TileMap;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -import java.util.ArrayList;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -public class Logger
 | 
	
		
			
				|  |  | -{
 | 
	
		
			
				|  |  | -    public static void onLevelReset(int level, Player p, TileMap map)
 | 
	
		
			
				|  |  | -    {
 | 
	
		
			
				|  |  | -        System.out.println("Level Reset " + level);
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    public static void onTileEnter(Player p, TileMap map, int x, int y)
 | 
	
		
			
				|  |  | -    {
 | 
	
		
			
				|  |  | -        System.out.println("Tile Enter " + x + " " + y);
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    public static void onTileLeave(Player p, TileMap map, int x, int y)
 | 
	
		
			
				|  |  | -    {
 | 
	
		
			
				|  |  | -        System.out.println("Tile Leave " + x + " " + y);
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    public static void onWin(Player p, TileMap map)
 | 
	
		
			
				|  |  | -    {
 | 
	
		
			
				|  |  | -        System.out.println("Win");
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    public static void onAlgoDone(ArrayList<ArrayList<SaleRoute>> salesPitch, ArrayList<Integer> eulerTour) {
 | 
	
		
			
				|  |  | -        System.out.println("algorithm done");
 | 
	
		
			
				|  |  | -        /*TODO: follow the eulerTour, getting salesPitch.get(x).get(y).get(path)
 | 
	
		
			
				|  |  | -          TODO: and getting the x and y value of each coord in that list and logging them*/
 | 
	
		
			
				|  |  | -        /*x and y correspond indirectly to values of the eulerTour
 | 
	
		
			
				|  |  | -        * salesPitch is structured like so:
 | 
	
		
			
				|  |  | -        *          [town0]  [town1]  [town2]  [town3] ...
 | 
	
		
			
				|  |  | -        * [town0]     -     x:0/y:0  x:0/y:1  x:0/y:2
 | 
	
		
			
				|  |  | -        * [town1]     -        -     x:1/y:0  x:1/y:1
 | 
	
		
			
				|  |  | -        * [town2]     -        -        -     x:2/y:0
 | 
	
		
			
				|  |  | -        * [town3]     -        -        -        -
 | 
	
		
			
				|  |  | -        * ...*/
 | 
	
		
			
				|  |  | -        /*so to get the path between node 0 and 1 use salesPitch.get(0).get(0).get(path);
 | 
	
		
			
				|  |  | -        * (x is equal to [townRowIndex], y is equal to [townColIndex] - x - 1 (!!!))
 | 
	
		
			
				|  |  | -        * note that paths between x and y are equal to paths between y and x, but only one can be found in salesPitch
 | 
	
		
			
				|  |  | -        * so the path between 0 - 1 and 1 - 0 are the same, but only 0 - 1 can be accessed
 | 
	
		
			
				|  |  | -        * make sure that x <= y to not go out of bounds*/
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        /*Example eulerTour: 3, 0, 1, 2, 3
 | 
	
		
			
				|  |  | -        * Therefore, the paths logged need to be:
 | 
	
		
			
				|  |  | -        * salesPitch.get(0).get(2).get(path)
 | 
	
		
			
				|  |  | -        * salesPitch.get(0).get(0).get(path)
 | 
	
		
			
				|  |  | -        * salesPitch.get(1).get(0).get(path)
 | 
	
		
			
				|  |  | -        * salesPitch.get(2).get(0).get(path)
 | 
	
		
			
				|  |  | -        * */
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        /*NOTE: for visual representation, algorithm coordinates don't have to be logged in order
 | 
	
		
			
				|  |  | -        * for the final representation to be correct. If the end-output is a list of coordinates, though,
 | 
	
		
			
				|  |  | -        * it may be necessary to order the coordinates to form a continuous path*/
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | +package pathgame.logging;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import pathgame.algorithm.SaleRoute;
 | 
	
		
			
				|  |  | +import pathgame.gameplay.Player;
 | 
	
		
			
				|  |  | +import pathgame.tilemap.TileMap;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.io.IOException;
 | 
	
		
			
				|  |  | +import java.nio.charset.StandardCharsets;
 | 
	
		
			
				|  |  | +import java.nio.file.Files;
 | 
	
		
			
				|  |  | +import java.nio.file.Paths;
 | 
	
		
			
				|  |  | +import java.util.ArrayList;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +public class Logger
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    private static int leaveX = 0;
 | 
	
		
			
				|  |  | +    private static int leaveY = 0;
 | 
	
		
			
				|  |  | +    private static int currentLevel = 0;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static List<String> path = new ArrayList<String>();
 | 
	
		
			
				|  |  | +    private static List<String> pathCoords = new ArrayList<String>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static void logFile(){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            Files.write(Paths.get("logfiles/level"+ currentLevel +".txt"), path, StandardCharsets.UTF_8);
 | 
	
		
			
				|  |  | +        } catch (IOException e) {
 | 
	
		
			
				|  |  | +            e.printStackTrace();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            Files.write(Paths.get("logfiles/level"+ currentLevel +"Coords.txt"), pathCoords, StandardCharsets.UTF_8);
 | 
	
		
			
				|  |  | +        } catch (IOException e) {
 | 
	
		
			
				|  |  | +            e.printStackTrace();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        path.clear();
 | 
	
		
			
				|  |  | +        pathCoords.clear();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static void onLevelReset(int level, Player p, TileMap map)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        currentLevel = level;
 | 
	
		
			
				|  |  | +        System.out.println("Level Reset " + level);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    public static void onTileEnter(Player p, TileMap map, int x, int y)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        //System.out.println("Tile Enter " + x + " " + y);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if(leaveX < x){
 | 
	
		
			
				|  |  | +            System.out.println("Right");
 | 
	
		
			
				|  |  | +            path.add("Right");
 | 
	
		
			
				|  |  | +        } else if(leaveX > x) {
 | 
	
		
			
				|  |  | +            System.out.println("Left");
 | 
	
		
			
				|  |  | +            path.add("Left");
 | 
	
		
			
				|  |  | +        } else if(leaveY > y) {
 | 
	
		
			
				|  |  | +            System.out.println("Up");
 | 
	
		
			
				|  |  | +            path.add("Up");
 | 
	
		
			
				|  |  | +        } else if(leaveY < y) {
 | 
	
		
			
				|  |  | +            System.out.println("Down");
 | 
	
		
			
				|  |  | +            path.add("Down");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    public static void onTileLeave(Player p, TileMap map, int x, int y)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        leaveX = x;
 | 
	
		
			
				|  |  | +        leaveY = y;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        pathCoords.add("x:" + x + " y:" + y);
 | 
	
		
			
				|  |  | +        //System.out.println("Tile Leave " + x + " " + y);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    public static void onWin(Player p, TileMap map)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        System.out.println("Win");
 | 
	
		
			
				|  |  | +        int playerValue = p.getEnergyUsed();
 | 
	
		
			
				|  |  | +        int algoValue = p.getEnergySupply()/130*100;
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        if(playerValue < algoValue){
 | 
	
		
			
				|  |  | +            logFile();
 | 
	
		
			
				|  |  | +            System.out.println("saving...");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static void onAlgoDone(ArrayList<ArrayList<SaleRoute>> salesPitch, ArrayList<Integer> eulerTour) {
 | 
	
		
			
				|  |  | +        System.out.println("algorithm done");
 | 
	
		
			
				|  |  | +        /*TODO: follow the eulerTour, getting salesPitch.get(x).get(y).get(path)
 | 
	
		
			
				|  |  | +          TODO: and getting the x and y value of each coord in that list and logging them*/
 | 
	
		
			
				|  |  | +        /*x and y correspond indirectly to values of the eulerTour
 | 
	
		
			
				|  |  | +        * salesPitch is structured like so:
 | 
	
		
			
				|  |  | +        *          [town0]  [town1]  [town2]  [town3] ...
 | 
	
		
			
				|  |  | +        * [town0]     -     x:0/y:0  x:0/y:1  x:0/y:2
 | 
	
		
			
				|  |  | +        * [town1]     -        -     x:1/y:0  x:1/y:1
 | 
	
		
			
				|  |  | +        * [town2]     -        -        -     x:2/y:0
 | 
	
		
			
				|  |  | +        * [town3]     -        -        -        -
 | 
	
		
			
				|  |  | +        * ...*/
 | 
	
		
			
				|  |  | +        /*so to get the path between node 0 and 1 use salesPitch.get(0).get(0).get(path);
 | 
	
		
			
				|  |  | +        * (x is equal to [townRowIndex], y is equal to [townColIndex] - x - 1 (!!!))
 | 
	
		
			
				|  |  | +        * note that paths between x and y are equal to paths between y and x, but only one can be found in salesPitch
 | 
	
		
			
				|  |  | +        * so the path between 0 - 1 and 1 - 0 are the same, but only 0 - 1 can be accessed
 | 
	
		
			
				|  |  | +        * make sure that x <= y to not go out of bounds*/
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /*Example eulerTour: 3, 0, 1, 2, 3
 | 
	
		
			
				|  |  | +        * Therefore, the paths logged need to be:
 | 
	
		
			
				|  |  | +        * salesPitch.get(0).get(2).get(path)
 | 
	
		
			
				|  |  | +        * salesPitch.get(0).get(0).get(path)
 | 
	
		
			
				|  |  | +        * salesPitch.get(1).get(0).get(path)
 | 
	
		
			
				|  |  | +        * salesPitch.get(2).get(0).get(path)
 | 
	
		
			
				|  |  | +        * */
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /*NOTE: for visual representation, algorithm coordinates don't have to be logged in order
 | 
	
		
			
				|  |  | +        * for the final representation to be correct. If the end-output is a list of coordinates, though,
 | 
	
		
			
				|  |  | +        * it may be necessary to order the coordinates to form a continuous path*/
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |