From 320619c9b54dd6574724ee4df5065a920aa7fc75 Mon Sep 17 00:00:00 2001 From: Joachim Nielandt Date: Fri, 24 Aug 2018 09:26:39 +0200 Subject: [PATCH] Lol, it's working --- src/main/kotlin/be/nielandt/CrossSolver.kt | 94 +++++++++++++--------- src/main/kotlin/be/nielandt/EdgeModel.kt | 39 ++++++++- 2 files changed, 93 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/be/nielandt/CrossSolver.kt b/src/main/kotlin/be/nielandt/CrossSolver.kt index 5560cb7..ba6e868 100644 --- a/src/main/kotlin/be/nielandt/CrossSolver.kt +++ b/src/main/kotlin/be/nielandt/CrossSolver.kt @@ -17,6 +17,14 @@ enum class Move { } return result } + + fun combo(counter: Counter): List { + val res = mutableListOf() + for (i in 0 until counter.size()) { + res.add(Move.values()[counter.digit(i)]) + } + return res + } } } @@ -36,14 +44,16 @@ fun l(colorIndex: Short): String { } fun main(args: Array) { -// val edgeModel = EdgeModel() + val edgeModel = EdgeModel() // println(edgeModel) // println("edgeModel.whiteCrossSolved() = ${edgeModel.whiteCrossSolved()}") -// -// val doMove = edgeModel.doMove(Move.D) + +// val u2 = Move.U2 +// val doMove = edgeModel.doMove(Move.U2) +// println(u2) // println(doMove) // println("doMove.whiteCrossSolved() = ${doMove.whiteCrossSolved()}") -// + // val message = EdgeModel().doMoves(Move.R, Move.U, Move.R_) // println(message) // println("message.whiteCrossSolved() = ${message.whiteCrossSolved()}") @@ -60,16 +70,43 @@ fun main(args: Array) { // i++ // } // println("i = ${i}") - - val counter = Counter(4, 3) - while (counter.increase()) { - println("counter = ${counter}") - } +// +// val counter = Counter(4, 3) +// while (counter.increase()) { +// println("counter = ${counter}") +// } // make a beginning model, then start doing crazy shit - val beginModel = EdgeModel(10) + val moves = Move.random(15) + println("Scramble: $moves") + val scrambledModel = EdgeModel(moves) + println(scrambledModel) + val whiteCrossMoveCount = whiteCrossMoveCount(scrambledModel) + println("whiteCrossMoveCount: $whiteCrossMoveCount") +} + +fun whiteCrossMoveCount(edgeModel: EdgeModel): Int { + for (moveCount in 1..8) { + // build a counter of moveCount big + val counter = Counter(moveCount, Move.values().size) + + // count up, each state of the counter corresponds to a combination of moves + do { + // what is the move combination we're looking at? + val moves = Move.combo(counter) + // execute the moves + val afterMoves = edgeModel.doMoves(moves) + // check whitecross! + if(afterMoves.whiteCrossSolved()) { + println("White cross found!") + println("moves = $moves") + return@whiteCrossMoveCount moveCount + } + } while (counter.increase()) + } + return Int.MAX_VALUE } /** @@ -94,6 +131,14 @@ class Counter(size: Int, val base: Int = 10) { return true } + fun size(): Int { + return this.counter.size + } + + fun digit(index: Int): Int { + return counter[index] + } + override fun toString(): String = this.counter.joinToString(".") fun atMax(): Boolean { @@ -103,32 +148,3 @@ class Counter(size: Int, val base: Int = 10) { } } -const val GO = 3 -const val GW = 0 -const val GR = 1 -const val GY = 2 - -const val WG = 18 -const val WO = 19 -const val WB = 16 -const val WR = 17 - -const val YG = 20 -const val YO = 23 -const val YB = 22 -const val YR = 21 - -const val RG = 7 -const val RW = 4 -const val RB = 5 -const val RY = 6 - -const val BR = 11 -const val BW = 8 -const val BO = 9 -const val BY = 10 - -const val OB = 15 -const val OW = 12 -const val OG = 13 -const val OY = 14 diff --git a/src/main/kotlin/be/nielandt/EdgeModel.kt b/src/main/kotlin/be/nielandt/EdgeModel.kt index 51390e5..5e7fce6 100644 --- a/src/main/kotlin/be/nielandt/EdgeModel.kt +++ b/src/main/kotlin/be/nielandt/EdgeModel.kt @@ -63,6 +63,12 @@ class EdgeModel { this.model = model } + constructor(moves: List) { + val edgeModel = EdgeModel() + val newModel = edgeModel.doMoves(moves) + this.model = newModel.model + } + /** * Do a single move and calculate the resulting edge model. */ @@ -178,4 +184,35 @@ class EdgeModel { return model[WB] == WHITE && model[WG] == WHITE && model[WO] == WHITE && model[WR] == WHITE && model[GW] == GREEN && model[OW] == ORANGE && model[RW] == RED && model[BW] == BLUE } -} \ No newline at end of file +} + +// sticker index constants for edges +const val GO = 3 +const val GW = 0 +const val GR = 1 +const val GY = 2 + +const val WG = 18 +const val WO = 19 +const val WB = 16 +const val WR = 17 + +const val YG = 20 +const val YO = 23 +const val YB = 22 +const val YR = 21 + +const val RG = 7 +const val RW = 4 +const val RB = 5 +const val RY = 6 + +const val BR = 11 +const val BW = 8 +const val BO = 9 +const val BY = 10 + +const val OB = 15 +const val OW = 12 +const val OG = 13 +const val OY = 14