added TextDisplay and GraphicsDisplay
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| package magic_squares | ||||
|  | ||||
| class MagicSquareSolver(initialGrid: Grid) { | ||||
| abstract class MagicSquareSolver(initialGrid: Grid) extends Displayable { | ||||
|   protected var _initial: Grid = initialGrid | ||||
|   protected val _size: Int = _initial.length | ||||
|   protected val SUM: Int = 15 | ||||
| @@ -28,6 +28,7 @@ class MagicSquareSolver(initialGrid: Grid) { | ||||
|   private def solveFrom(grid: Grid, x: Int, y: Int): Option[Grid] = { | ||||
|     if (DEBUG) println(s"Solving from $x, $y") | ||||
|     if (DEBUG) print(grid) | ||||
|     display(grid) | ||||
|     if (!isValid(grid)) { | ||||
|       if (DEBUG) println("  Grid is invalid") | ||||
|       return None | ||||
| @@ -111,7 +112,7 @@ object MagicSquareSolver { | ||||
|       Array(8, 0, 0), | ||||
|       Array(0, 0, 7), | ||||
|       Array(0, 9, 0) | ||||
|     )) | ||||
|     )) with TextDisplay | ||||
|     solver1.solve() | ||||
|     println() | ||||
|     /* | ||||
| @@ -124,7 +125,7 @@ object MagicSquareSolver { | ||||
|       Array(9, 0, 0), | ||||
|       Array(0, 0, 7), | ||||
|       Array(0, 8, 0) | ||||
|     )) | ||||
|     )) with TextDisplay | ||||
|     solver2.solve() | ||||
|     println() | ||||
|     /* | ||||
| @@ -135,7 +136,7 @@ object MagicSquareSolver { | ||||
|       Array(0, 0, 2), | ||||
|       Array(0, 5, 7), | ||||
|       Array(0, 0, 0) | ||||
|     )) | ||||
|     )) with GraphicsDisplay | ||||
|     solver3.solve() | ||||
|     /* | ||||
|     4,9,2 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user