From f709e4dc010ec0b2dc79d88c3ffaf722289eee81 Mon Sep 17 00:00:00 2001 From: Bryson Zimmerman Date: Sat, 26 Oct 2024 18:35:07 -0400 Subject: [PATCH] Some initial PathFinder work --- .idea/misc.xml | 2 +- src/main/kotlin/PathFinder.kt | 40 +++++++++++++++++++++++++++++++++++ src/main/kotlin/Pathfinder.kt | 10 --------- 3 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/PathFinder.kt delete mode 100644 src/main/kotlin/Pathfinder.kt diff --git a/.idea/misc.xml b/.idea/misc.xml index 40daec2..ee3319a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/src/main/kotlin/PathFinder.kt b/src/main/kotlin/PathFinder.kt new file mode 100644 index 0000000..9410470 --- /dev/null +++ b/src/main/kotlin/PathFinder.kt @@ -0,0 +1,40 @@ +package technology.zim + +import technology.zim.data.Tile +import kotlin.math.abs + +//A* to be upgraded with hierarchies + +//Needs https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/PriorityQueue.html +//and https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Comparator.html + +object PathFinder { + val path = ArrayDeque() + + //work along the path, marking tiles with VISITED along the way + //if marking with visited is too expensive, just make the path and finalize it + fun generatePath(start: Tile, end: Tile) { + if(!start.isInBounds() || !end.isInBounds()) { + throw IndexOutOfBoundsException("Cannot generate a path to or from an out of bounds tile") + } + + + + + + + + } + + //Heuristic value, to estimate the cost of a given tile + fun hValue(prospect: Tile, end: Tile): Int { + return abs(prospect.x() - end.x()) + abs(prospect.y() - end.y()) + } + + + //Step through the path, marking each Tile with INPATH + fun finalizePath() { + + } + +} \ No newline at end of file diff --git a/src/main/kotlin/Pathfinder.kt b/src/main/kotlin/Pathfinder.kt deleted file mode 100644 index 4bf5256..0000000 --- a/src/main/kotlin/Pathfinder.kt +++ /dev/null @@ -1,10 +0,0 @@ -package technology.zim - -//A* to be upgraded with hierarchies - -//Needs https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/PriorityQueue.html -//and https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Comparator.html - -class Pathfinder { - -} \ No newline at end of file