|
CMPU 102 - Assignment 4 NQueens Problem |
Assigned: Mon, Feb. 25 Due (by
|
In this assignment you will:
isUnderAttack() Summary:
We have provided the GUI and most of the recursive backtracking
solution to the NQueens problem--a more general version of the Eight
Queens problem presented in section 6.1 of the text (p. 294). You
will complete the implementation of NQueens by providing the missing
code for method isUnderAttack() in class NQueensGame.
In
this class we've provided the code for everything but the isUnderAttack() method. You shouldn't change any other code in the class; just provide the missing code for this method. You should study the placeQueens() method to understand how it works, and what it expects of isUnderAttack() when it invokes this method.
We would have asked you to implement the placeQueens() method,
but the book pretty much gives the solution away. To make it a little
more interesting, we've enhanced the code to find random solutions,
rather than the same solution each time. You should test your solution
by running the program from the GUI many times, visually verifying the
solutions on the chess board.
To determine if a queen is under attack, your isUnderAttack() method should
check all prior columns to verify there is no queen in the same row, or
along one of the diagonals, of where the queen is being placed in the
current column. One more stipulation: you must implement this method
recursively--no loops. We recommend you consider using three recursive
helper methods, one to check each possible threat direction. While
there is some thought involved in how you accomplish this task, you
should find this week's assignment to be very straight-forward.
From a terminal window, type the following commands:
cdcd cs102submit102 NQueens