Package Phase1
Class Search
java.lang.Object
Phase1.Search
public class Search
extends java.lang.Object
Class starting the execution of the main program
-
Field Summary
Fields Modifier and Type Field Description static int
area
It holds the value of the area of the grid (horizontal size * vertical size)static int
chosenAlgorithm
A flag that holds the value that corresponds to the algorithm used to solve the puzzlestatic boolean
flag
Flag checking if a solution has already been foundstatic int
horizontalGridSize
It holds the value of the horizontal size of the gridstatic char[]
input
Input values for the search() methodstatic boolean
lpdone
Flag checking if the Phase1.LandingPage and Phase1.ChoosePieces classes have already been terminated.static java.util.ArrayList<java.lang.String>
solArr
static java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>>
solRows
static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>
supMat
static java.util.ArrayList<java.lang.String>
tempArr
static UI
ui
Static Phase1.UI class to display the boardstatic int
verticalGridSize
It holds the value of the vertical size of the grid -
Constructor Summary
Constructors Constructor Description Search()
-
Method Summary
Modifier and Type Method Description static int[][]
addPiece(int[][] field, int[][] piece, int pieceID, int x, int y)
Adds a pentomino to the position on the field (overriding current board at that position) - non-burte-force methodstatic int
algorithmX(java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> matrix, int row, int col, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> suppMat)
Takes the possibilities matrix and outputs a solution for that matrixstatic int
algorithmX(java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> matrix, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> suppMat)
Turns the pentomino problem into an exact cover problem and solves it by iterating over the matrix of possible position of any pentominostatic java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>>
buildMatrix(int[][] field)
Builds the matrixstatic void
createWindow()
A method responsible for creating the window with the game solver, that is being displayed after all settings are inputted by the userstatic void
deleteColumn(int index, java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> m)
static void
deleteRow(int index, java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> m)
static void
main(java.lang.String[] args)
Main function.static void
search()
Helper function that starts the solving process with the user-chosen algorithmstatic void
wipeField(int[][] field)
-
Field Details
-
horizontalGridSize
public static int horizontalGridSizeIt holds the value of the horizontal size of the grid -
verticalGridSize
public static int verticalGridSizeIt holds the value of the vertical size of the grid -
area
public static int areaIt holds the value of the area of the grid (horizontal size * vertical size) -
input
public static char[] inputInput values for the search() method -
supMat
public static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> supMat -
solRows
public static java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> solRows -
tempArr
public static java.util.ArrayList<java.lang.String> tempArr -
solArr
public static java.util.ArrayList<java.lang.String> solArr -
ui
Static Phase1.UI class to display the board -
flag
public static boolean flagFlag checking if a solution has already been found -
chosenAlgorithm
public static int chosenAlgorithmA flag that holds the value that corresponds to the algorithm used to solve the puzzle -
lpdone
public static boolean lpdoneFlag checking if the Phase1.LandingPage and Phase1.ChoosePieces classes have already been terminated.
Until it is the case, the Phase1.Search class waits for their termination.
-
-
Constructor Details
-
Search
public Search()
-
-
Method Details
-
createWindow
public static void createWindow()A method responsible for creating the window with the game solver, that is being displayed after all settings are inputted by the user -
search
public static void search()Helper function that starts the solving process with the user-chosen algorithm -
addPiece
public static int[][] addPiece(int[][] field, int[][] piece, int pieceID, int x, int y)Adds a pentomino to the position on the field (overriding current board at that position) - non-burte-force method- Parameters:
field
- the field to put the game piece onpiece
- array holding the currently considered piece's statepieceID
- the ID of piece currently looked atx
- helper variable keeping track of the position in the field arrayy
- helper variable keeping track of the position in the field array
-
algorithmX
public static int algorithmX(java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> matrix, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> suppMat)Turns the pentomino problem into an exact cover problem and solves it by iterating over the matrix of possible position of any pentomino -
algorithmX
public static int algorithmX(java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> matrix, int row, int col, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> suppMat)Takes the possibilities matrix and outputs a solution for that matrix- Parameters:
matrix
- the possibilities matrixrow
- currently considered rowcol
- currently considered columnsuppMat
- support matrix- Returns:
- integer
-
deleteRow
public static void deleteRow(int index, java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> m)- Parameters:
index
- : index of the row to be deletedm
- : the array to delete the row from
-
deleteColumn
public static void deleteColumn(int index, java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> m)- Parameters:
index
- : index of the column to be deletedm
- : the array to delete the column from
-
wipeField
public static void wipeField(int[][] field) -
buildMatrix
public static java.util.ArrayList<java.util.ArrayList<java.lang.Boolean>> buildMatrix(int[][] field)Builds the matrix- Parameters:
field
- : the field to build the base matrix for- Returns:
- matrix with all possible placements of all chosen pentominoes
-
main
public static void main(java.lang.String[] args)Main function. Needs to be executed to start any algorithm- Parameters:
args
- default parameter, not used by the program
-