Solving Draught Puzzle - Step 3◀ Solving Draught Puzzle - Step 2▶ Solving Draught Puzzle - Step 4 Amazon
et’s apply the 3rd step of the Four-Step Programming Model to solve the Draught puzzle!
Four Step Programming Model: Step 3
: Elements of board and tempcc can be accessed via , so make sure their indices do not go out of bounds. Pay close attention to the conditions of flow control statements.
: The attributes of the board and the pieces are constants because their values shouldn’t change after initialized. start will be assigned a value once the program starts finding a solution, and won’t be altered.
The most troublesome variable is board. In the recursive function that attempts to solve the draught puzzle, board’s contents will be constantly changed. In the event that its contents need to be altered in order for us to obtain some critical information, we can copy its contents to a temporary array and have the temporary array do that.
tempcc, as its name suggests, is a temporary storage for a piece. One thing you should note is that you should initialize an array’s contents after you declare the array; it’s good practice.
: I make the attributes of the board and the pieces global constants because their values should not change throughout the program and are needed by many functions. I am tempted to also make start and board global, but right now I am not sure yet. The remaining variables stay local for now.
Let's look at the next step!◀ Solving Draught Puzzle - Step 2▶ Solving Draught Puzzle - Step 4