forked from breandan/galoisenne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRewriter.kt
29 lines (28 loc) · 958 Bytes
/
Rewriter.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import ai.hypergraph.kaliningraph.graphs.LabeledGraph
import ai.hypergraph.kaliningraph.types.cc
import org.w3c.dom.events.KeyboardEvent
import kotlin.random.Random
@ExperimentalStdlibApi
fun rewriter() {
animate(
LabeledGraph("abcdecfghia").also { println(it) }
) { event: KeyboardEvent, graphs: MutableList<LabeledGraph> ->
when {
"h" in event.key -> {}
"l" in event.key -> {
val current = graphs.last()
if (current.none { it.occupied }) {
current.takeWhile { Random.Default.nextDouble() < 0.5 }.forEach { it.occupied = true }
} else current.propagate()
}
"k" in event.key -> if (graphs.size > 1) graphs.removeLastOrNull()
"j" in event.key -> {
val current = graphs.last()
val sub = "cdec" cc "ijkl"
graphs.add(current.rewrite(sub).also {
it.description = "${current.randomWalk().take(20).joinToString("")}...$sub"
})
}
}
}
}