|
|
@ -1,18 +1,24 @@
|
|
|
|
|
|
|
|
import technology.zim.ArrayBackedPathfinder
|
|
|
|
import technology.zim.data.Tile
|
|
|
|
import technology.zim.data.Tile
|
|
|
|
import technology.zim.data.TileHeap
|
|
|
|
import technology.zim.data.TileHeap
|
|
|
|
|
|
|
|
import kotlin.math.abs
|
|
|
|
import kotlin.test.Test
|
|
|
|
import kotlin.test.Test
|
|
|
|
import kotlin.test.BeforeTest
|
|
|
|
import kotlin.test.BeforeTest
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: update to use Tile adjustment to heap
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TileHeapTest {
|
|
|
|
class TileHeapTest {
|
|
|
|
companion object {
|
|
|
|
companion object {
|
|
|
|
var gVals = HashMap<Tile, Int>()
|
|
|
|
var gVals = HashMap<Tile, Int>()
|
|
|
|
var heap = TileHeap(Tile(20, 20), gVals)
|
|
|
|
var heap = TileHeap(Tile(20, 20), this::fValue)
|
|
|
|
|
|
|
|
private fun fValue(prospect: Tile, end: Tile): Int {
|
|
|
|
|
|
|
|
return hValue(prospect, end).plus(gVals.get(prospect) ?: 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun hValue(prospect: Tile, end:Tile): Int {
|
|
|
|
|
|
|
|
return abs(prospect.x() - end.x()) + abs(prospect.y() - end.y())
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@BeforeTest
|
|
|
|
@BeforeTest
|
|
|
|
fun setUp() {
|
|
|
|
fun setUp() {
|
|
|
|
heap = TileHeap(Tile(20, 20), gVals)
|
|
|
|
heap = TileHeap(Tile(20, 20), Companion::fValue)
|
|
|
|
arrayOf(Tile(0, 0), Tile(1, 1), Tile(5, 5), Tile(4, 4), Tile(19, 19), Tile(2, 2)).forEach { item ->
|
|
|
|
arrayOf(Tile(0, 0), Tile(1, 1), Tile(5, 5), Tile(4, 4), Tile(19, 19), Tile(2, 2)).forEach { item ->
|
|
|
|
heap.insert(item)
|
|
|
|
heap.insert(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|