Flipping bits game: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Removed 'incorrect example' warning as now fixed.)
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 1,795: Line 1,795:
}
}


/** starting from the target we make 9 random row or column flips */
/** starting from the target we make 9 random row or column flips */
fun initBoard() {
fun initBoard() {
for (i in 0..2) {
for (i in 0..2) {
Line 1,827: Line 1,827:
}
}
return true
return true
}
}


fun main(args: Array<String>) {
fun main(args: Array<String>) {
Line 1,846: Line 1,846:
print("Enter row number or column letter to be flipped: ")
print("Enter row number or column letter to be flipped: ")
val input = readLine()!!
val input = readLine()!!
val ch = if (input.length > 0) input[0].toLowerCase() else '0'
val ch = if (input.isNotEmpty()) input[0].toLowerCase() else '0'
if (ch !in "123abc") {
if (ch !in "123abc") {
println("Must be 1, 2, 3, a, b or c")
println("Must be 1, 2, 3, a, b or c")
Line 1,853: Line 1,853:
if (ch in '1'..'3') {
if (ch in '1'..'3') {
n = ch.toInt() - 49
n = ch.toInt() - 49
}
}
else {
else {
isRow = false
isRow = false
Line 1,864: Line 1,864:
if (isRow) flipRow(n) else flipCol(n)
if (isRow) flipRow(n) else flipCol(n)
val plural = if (flips == 1) "" else "S"
val plural = if (flips == 1) "" else "S"
printBoard("\nBOARD AFTER $flips FLIP$plural")
printBoard("\nBOARD AFTER $flips FLIP$plural")
}
}
while (!gameOver())
while (!gameOver())


val plural = if (flips == 1) "" else "s"
val plural = if (flips == 1) "" else "s"
println("You've succeeded in $flips flip$plural")
println("You've succeeded in $flips flip$plural")
}</lang>
}</lang>