Last active
November 18, 2017 14:44
-
-
Save lrlucena/50f2275ffb278d660495140fd4005e06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//------------ 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