|
@@ -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: and getting the x and y value of each coord in that list and logging them*/
|
|
|
-
|
|
|
- * 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] - - - -
|
|
|
- * ...*/
|
|
|
-
|
|
|
- * (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*/
|
|
|
-
|
|
|
-
|
|
|
- * 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)
|
|
|
- * */
|
|
|
-
|
|
|
-
|
|
|
- * 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)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ 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: and getting the x and y value of each coord in that list and logging them*/
|
|
|
+
|
|
|
+ * 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] - - - -
|
|
|
+ * ...*/
|
|
|
+
|
|
|
+ * (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*/
|
|
|
+
|
|
|
+
|
|
|
+ * 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)
|
|
|
+ * */
|
|
|
+
|
|
|
+
|
|
|
+ * 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*/
|
|
|
+ }
|
|
|
+}
|