From d856ede7028b1d5f57ae3cb11c8b2d63e8683b4a Mon Sep 17 00:00:00 2001 From: Bryson Zimmerman Date: Thu, 7 Nov 2024 14:26:26 -0500 Subject: [PATCH] Added maze coloring to show the final path and tiles checked by the pathfinder --- src/main/kotlin/World.kt | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/World.kt b/src/main/kotlin/World.kt index 95c7280..670d483 100644 --- a/src/main/kotlin/World.kt +++ b/src/main/kotlin/World.kt @@ -45,13 +45,36 @@ object World { //TODO: https://en.wikipedia.org/wiki/Box-drawing_characters //^ make the maze look like a maze override fun toString(): String { - val str = StringBuilder() + val ANSI_RESET = "\u001B[0m"; + val ANSI_BLACK = "\u001B[30m"; + val ANSI_RED = "\u001B[31m"; + val ANSI_GREEN = "\u001B[32m"; + val ANSI_YELLOW = "\u001B[33m"; + val ANSI_BLUE = "\u001B[34m"; + val ANSI_PURPLE = "\u001B[35m"; + val ANSI_CYAN = "\u001B[36m"; + val ANSI_WHITE = "\u001B[37m"; + val str = StringBuilder() + var inPath = false + var checked = false //Reading left to right, top to bottom - can do a simple for each on the rows for (y in 0..tiles.value[0].size - 1) { //Upper line: Print each tile, print right-hand connections for (x in 0..tiles.value[0].size - 1) { + if(World.get(Tile(x, y)).connections and(INPATH.dir) != 0) + inPath = true + else if (World.get(Tile(x, y)).connections and(FRONTIERIFIED.dir) != 0) + checked = true + if(inPath) + str.append(ANSI_GREEN) + else if(checked) + str.append(ANSI_YELLOW) str.append(getTileShapeDoubles(World.get(Tile(x, y)))) + if(inPath || checked) + str.append(ANSI_RESET) + inPath = false + checked = false } str.appendLine() }