next up previous
Next: About this document ...

1#1
1#1
Introduction to
Object Oriented Programming 2E
Timothy A. Budd
1#1
Chapter 5
1#1
A Case Study : Eight Queens

Statement of the Problem

Problem - how to place eight queens on a chessboard so that no two queens can attack each other:


2#2

OOP Approach

More than just solving the problem, we want to solve the problem in an OOP manner.

Observations

Here are a few observations we can make concerning this problem:

Pointers

We can make each queen point to the next on the left, then send messages only to the rightmost queen. Each queen will in turn send messages only to the neighbor it points to.


3#3

CRC Card for Queen


4#4

CRC Card for Queen - Backside


5#5

Initialization

Initialization will set each queen to point to neighbor, and set column value. C++ version is shown:


6#6

Finding First Solution

Finding first solution, in pseudo-code:


7#7

Finding Next Solution


8#8

Test or Advance


9#9

Can Attack


10#10

The Last Queen

Two approaches to handling the leftmost queen -

Both versions are described in text.

Final Analysis



 
next up previous
Next: About this document ...
ChandraKanth Modem
1/27/1999