Last active
August 29, 2015 14:03
-
-
Save ajrouvoet/7e7b423d744d6d884502 to your computer and use it in GitHub Desktop.
Minesweeper board init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.Random | |
object Main { | |
type Board = List[List[Int]] | |
def main(argv: Array[String]) = { | |
val size: (Int, Int) = (80, 80) | |
val bombs = 250 | |
print_board(setup_board(size, bombs)) | |
} | |
def print_board(board: Board) = | |
for( | |
row <- board | |
) print_row(row) | |
def print_row(row: List[Int]) = { | |
for( | |
col <- row | |
) { | |
if(col == 1) | |
print("X") | |
else | |
print(".") | |
} | |
println() | |
} | |
def setup_board(size: (Int, Int), k: Int): Board = { | |
val ones: List[Int] = Array.fill(k)(1).toList | |
val zeros: List[Int] = Array.fill(size._1 * size._2 - k)(0).toList | |
val random_pos: List[Int] = Random.shuffle( | |
ones ++ zeros | |
) | |
random_pos.grouped(size._1).toList | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment