added counter
This commit is contained in:
parent
3614a7d746
commit
2dc3fb3d6e
@ -36,22 +36,71 @@ fun l(colorIndex: Short): String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val edgeModel = EdgeModel()
|
// val edgeModel = EdgeModel()
|
||||||
println(edgeModel)
|
// println(edgeModel)
|
||||||
println("edgeModel.whiteCrossSolved() = ${edgeModel.whiteCrossSolved()}")
|
// println("edgeModel.whiteCrossSolved() = ${edgeModel.whiteCrossSolved()}")
|
||||||
|
//
|
||||||
|
// val doMove = edgeModel.doMove(Move.D)
|
||||||
|
// println(doMove)
|
||||||
|
// println("doMove.whiteCrossSolved() = ${doMove.whiteCrossSolved()}")
|
||||||
|
//
|
||||||
|
// val message = EdgeModel().doMoves(Move.R, Move.U, Move.R_)
|
||||||
|
// println(message)
|
||||||
|
// println("message.whiteCrossSolved() = ${message.whiteCrossSolved()}")
|
||||||
|
//
|
||||||
|
// val doMoves = EdgeModel().doMoves(Move.random(15))
|
||||||
|
// println("random 15 moves = ${doMoves}")
|
||||||
|
// println("doMoves.whiteCrossSolved() = ${doMoves.whiteCrossSolved()}")
|
||||||
|
|
||||||
val doMove = edgeModel.doMove(Move.D)
|
|
||||||
println(doMove)
|
|
||||||
println("doMove.whiteCrossSolved() = ${doMove.whiteCrossSolved()}")
|
|
||||||
|
|
||||||
val message = EdgeModel().doMoves(Move.R, Move.U, Move.R_)
|
// val begin = Instant.now()
|
||||||
println(message)
|
// var i: Long = 0
|
||||||
println("message.whiteCrossSolved() = ${message.whiteCrossSolved()}")
|
// while (Duration.between(begin, Instant.now()) < Duration.ofMinutes(1)) {
|
||||||
|
// EdgeModel().doMoves(Move.random(15))
|
||||||
|
// i++
|
||||||
|
// }
|
||||||
|
// println("i = ${i}")
|
||||||
|
|
||||||
val doMoves = EdgeModel().doMoves(Move.random(15))
|
val counter = Counter(4, 3)
|
||||||
println("random 15 moves = ${doMoves}")
|
while (counter.increase()) {
|
||||||
println("doMoves.whiteCrossSolved() = ${doMoves.whiteCrossSolved()}")
|
println("counter = ${counter}")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// make a beginning model, then start doing crazy shit
|
||||||
|
val beginModel = EdgeModel(10)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counter for X digits of a given base.
|
||||||
|
*/
|
||||||
|
class Counter(size: Int, val base: Int = 10) {
|
||||||
|
|
||||||
|
// start the counter at [0,0,...0]
|
||||||
|
private var counter: Array<Int> = Array(size) { 0 }
|
||||||
|
|
||||||
|
fun increase(): Boolean {
|
||||||
|
if (atMax()) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for (i in this.counter.size - 1 downTo 0) {
|
||||||
|
this.counter[i]++
|
||||||
|
if (this.counter[i] == base)
|
||||||
|
this.counter[i] = 0
|
||||||
|
else
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String = this.counter.joinToString(".")
|
||||||
|
|
||||||
|
fun atMax(): Boolean {
|
||||||
|
return counter.all {
|
||||||
|
it == this.base - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const val GO = 3
|
const val GO = 3
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class EdgeModel {
|
|||||||
constructor() {
|
constructor() {
|
||||||
// do a sanity check
|
// do a sanity check
|
||||||
val entries = mutableListOf(F, B, L, U, D, R).flatMap { it.asList() }.groupBy { it }.entries
|
val entries = mutableListOf(F, B, L, U, D, R).flatMap { it.asList() }.groupBy { it }.entries
|
||||||
println("entries = ${entries}")
|
// println("entries = ${entries}")
|
||||||
if (entries.any {
|
if (entries.any {
|
||||||
it.value.size != 2
|
it.value.size != 2
|
||||||
}) {
|
}) {
|
||||||
@ -53,6 +53,12 @@ class EdgeModel {
|
|||||||
YELLOW, YELLOW, YELLOW, YELLOW)
|
YELLOW, YELLOW, YELLOW, YELLOW)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(randomMoves: Int) {
|
||||||
|
val edgeModel = EdgeModel()
|
||||||
|
val doMoves = edgeModel.doMoves(Move.random(randomMoves))
|
||||||
|
this.model = doMoves.model
|
||||||
|
}
|
||||||
|
|
||||||
constructor(model: ShortArray) {
|
constructor(model: ShortArray) {
|
||||||
this.model = model
|
this.model = model
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user