Project: HWS_Place Queens
Objectives: writing a complex program that includes: updating and printing a 2D table (printed table will have labelled rows and columns), error checking. Practice modularization by having to structure the program using
methods (reuse written methods to help you achieve new tasks - see recommended use of add queen to implement delete queen-). Good code alignment (for if/else, loops, and method definitions).
This program will maintain and print a chessboard that allows the user to place Queen pieces. The board will show the Queens and the row, column and diagonals the Queens will attack on.
implement the behavior shown in the sample run below. Make sure you align your code as it should be for each if-else, loop (for or while), method definition.
Code structure (a method to do the work for each user option):
. in main - implement a loop that displays the menu information and takes the user option and whatever other data is needed for that option. Next, implement the actions for each choice, using METHODS. DO NOT
write a big pile of code in main, but rather call other methods to do the work. Suggested method break-up is given below.
Note that since the same board must be used for as part of the actions for more than one option, the board object should be in main and passed as argument to other methods to work with it.
. a method to create and return a board of a given dimension.
. a method to print the board. (The board will be passed as an argument to this method. Same for the others.)
. a method to reset the board
. a method to add a queen on the board at a given row and column and show with a’ in each cell that it can attack. The row and column will be given as arguments, NOT read from the user.
i-lint, when you show mark (with 9the cells that are on the diagonal line of attack for a queen, it is easier to go ‘from the Q cell out then vice versa’:
. a method to count queens on the board
. a method to delete a queen from a specific row and column. In addition to the checks for valid board, valid row and valid column, this method should also check that there is a queen at the given position.
You cannot simply delete a queen from the existing board because it is not easy to know which ‘to remove and which to keep since another queen could be attaching on the same row as the one you are removing
(see sample run). Solve this by resetting the board and replacing the queens that should remain.
Take advantage of already implemented methods such as reset board and add queen. (Note how the add queen method can be reused here because the row and column are given as arguments as opposed lo read from
the user inside the method.)