Question
Using MatLab: 1. Begin the code using a variable that defines the board size we will create an 8x8 board by initializing a matrix that
Using MatLab:
1. Begin the code using a variable that defines the board size we will create an 8x8 board by initializing a matrix that is size 8x8 using the zeros command. From here forward, we are going to use the symbol 0 to indicate a space that is unoccupied on the board.
2. Write code that will randomly place pieces on the board. Specifically, iterate through every available space on the board and randomly place a 0, 1, or 2; these will correspond to open spaces, a red piece, and a black piece, respectively. Remember that checkers only involves light or dark spaces, so make sure you have scheme for valid placement (i.e. that only places pieces on one color).
a. Use the randi command to generate random integers of 0, 1 and 2.
3. Now, randomly select any space on the board (occupied or not) and place a red king there. Well use the number 3 to designate the king.
a. Make sure that your code is capable of placing the king on any suitable space. Do not hard code a specific space or limit it in any other way.
4. After placing the king, employ a series of if statements that will check for available moves. For each direction, print out text that describes the available move(s).
5. Advanced features (add in at least 1):
a. Add in advanced move detection. This could include items such as available double jumps (or higher order than that!), or bad move detection such as if your king will be vulnerable after making a particular move.
b. Add advanced display features. Matlab has powerful plotting features and image display/modification capabilities. The above algorithm displays the board in the most simple form possible, but try to augment it to be more visually appealing.
c. Ask for user input. Prompt the user which of the available moves they would like to make, and then execute that move and re-display the board in its new form.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started