Solving Draught Puzzle - Step 2

◀ Solving Draught Puzzle - Step 1▶ Solving Draught Puzzle - Step 3
Amazon Let’s apply the 2nd step of the Four-Step Programming Model to solve the Draught puzzle!

Four Step Programming Model: Step 2
We need variables to store attributes of the board and the pieces, including the total number of the pieces, the maximum number of orientations of a piece, the maximum number of rows a piece occupies, the maximum number of columns a piece occupies, the width of the board, and the height of the board.

I need a clock_t object to keep track of time; I need a char[][] to represent the board; I need another char[][] to store temporary piece; I need an ifstream object to open and read a file. The following is a list of variables I need:
const int numPieces = 13;
const int numTrans = 8; const int numRows = 5; const int numCols = 5; const int boardWidth = 10; const int boardHeight = 10; clock_t start = clock(); char board[boardHeight][boardWidth]; char tempcc[numRows][numCols]; ifstream fin;
I make the attributes of the board and the pieces constants because their values shouldn’t change throughout the program. In refining the skeleton, I realize that in order to not store repeated orientations, I need to be able to see if a particular orientation is already stored.

I create a little structure that contains a two-dimensional array to represent an orientation of a piece:
struct array {
	char acc[numRows][numCols];
And I created the following functions:
bool sameArray(array a, char cc[numRows][numCols]) {
- return true if the contents of a are identical to cc; return false otherwise
bool repeated(vector<array> va, char cc[numRows][numCols]) {
- return true if cc exists in va; return false otherwise
} void arrayInit(array & ar, char cc[numRows][numCols]) { - make the contents of ar equal to cc }
Let's look at the next step!
◀ Solving Draught Puzzle - Step 1▶ Solving Draught Puzzle - Step 3

Questions? Let me know!