Skip to content

Instantly share code, notes, and snippets.

@lrlucena
Last active November 18, 2017 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lrlucena/50f2275ffb278d660495140fd4005e06 to your computer and use it in GitHub Desktop.
Save lrlucena/50f2275ffb278d660495140fd4005e06 to your computer and use it in GitHub Desktop.
//------------ GENERATOR ------------------
def fill(px: Int, py: Int)(word: String): Unit = {
var (x, y) = ind(px, py)(word)
for ((c, i) <- word.zipWithIndex) {
matrix(x + px * i)(y + py * i) = c
}
}
def ind(px: Int, py: Int)(word: String): (Int, Int) = {
var x = randomN(0, Math.abs(word.size - matrix.size))
var y = randomN(0, matrix.size - 1)
var seq = 0 until word.length
seq.filter(i => matrix(x + i * px)(y + i * py) != empty).size match {
case 0 => return (x, y)
case _ => ind(px, py)(word)
}
}
val fillVert = fill(1, 0) _
val fillHorinz = fill(0, 1) _
val fillDiag = fill(1, 1) _
val fillTrans = fill(1, -1) _
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment