Package com.abhyudayasharma.tictactoe
Class MagicSquare
- java.lang.Object
-
- com.abhyudayasharma.tictactoe.MagicSquare
-
class MagicSquare extends java.lang.Object
Generates a magic square of odd size.- Author:
- Kabir Kanha Arora
-
-
Field Summary
Fields Modifier and Type Field Description private static int
expectedSum
private int
mainCnt
private int[][]
matrix
-
Constructor Summary
Constructors Modifier Constructor Description private
MagicSquare(int n)
Private constructor for the Magic square.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static int
getExpectedSum()
Returns the expected sum of every diagonal, row and column of the Magic Square.(package private) static int[][]
getMagicSquare(int n)
Calculates and returns a new magic square object.private void
placeNextOdd(int r, int c, int[][] matrix, int n, int max)
Recursive method for placing digits in the magic square.
-
-
-
Method Detail
-
getExpectedSum
static int getExpectedSum()
Returns the expected sum of every diagonal, row and column of the Magic Square.- Returns:
- the expected sum of every diagonal, row and column of the Magic Square.
-
getMagicSquare
static int[][] getMagicSquare(int n)
Calculates and returns a new magic square object. The objects produced by this methods are isomorphic to one another but are not eht same objects.- Parameters:
n
- the size of the magic square to be generated. Even values do not produce expected results.- Returns:
- a new magic square
-
placeNextOdd
private void placeNextOdd(int r, int c, int[][] matrix, int n, int max)
Recursive method for placing digits in the magic square.- Parameters:
r
- the row indexc
- the column indexmatrix
- matrix that will eventually become a magic squaren
- the size of the magic square to be constructedmax
- the maximum possible value in the magic square.
-
-