implemented grid of size n

This commit is contained in:
Louis Heredero 2024-04-23 14:59:32 +02:00
parent 7141534e9f
commit 9d6b1f767e
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 12 additions and 3 deletions

View File

@ -48,6 +48,6 @@ trait GraphicsDisplay extends Displayable {
}
}
}
win.syncGameLogic(5)
win.syncGameLogic(60)
}
}

View File

@ -3,7 +3,7 @@ package magic_squares
abstract class MagicSquareSolver(initialGrid: Grid) extends Displayable {
protected var _initial: Grid = initialGrid
protected val _size: Int = _initial.length
protected val SUM: Int = 15
protected val SUM: Int = _size * (_size * _size + 1) / 2
protected val DEBUG: Boolean = false
protected def print(grid: Grid): Unit = {
@ -38,7 +38,7 @@ abstract class MagicSquareSolver(initialGrid: Grid) extends Displayable {
return Some(grid)
}
var values: Array[Int] = Array(_initial(y)(x))
if (values(0) == 0) values = (1 to 9).toArray
if (values(0) == 0) values = (1 to _size * _size).toArray
if (DEBUG) println(s" Values to test: " + values.mkString("[", ", ", "]"))
val newGrid: Grid = copy(grid)
@ -143,5 +143,14 @@ object MagicSquareSolver {
3,5,7
8,1,6
*/
val solver4: MagicSquareSolver = new MagicSquareSolver(Array(
Array(11, 0, 0, 20, 3),
Array(4, 12, 0, 0, 16),
Array(0, 5, 13, 21, 9),
Array(10, 0, 0, 14, 22),
Array(23, 6, 19, 2, 0),
)) with GraphicsDisplay
solver4.solve()
}
}