Lecture 14

Then backtrack to column 1 then go down in column 1 q

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1. +Q++ Q+++ ++++ ++++ illegal 15 illegal illegal Are there other solutions? There must be, due to summetry: Q Q 3 ill steps + +++ Q+++ + +++ + Q++ ++Q+ Q+++ ++++ +Q++ ++QQ Q+++ ++++ +Q++ ill I placed 4 queens on a 4x4 board. Problem solved. ++Q+ Q++Q ++++ +Q++ ill ++Q+ Q+++ +++Q +Q++ legal 16 The program is long and complicated. It certainly does not fit onto one screen. It moves from one row to the next row with a while loop. However, it moves from one column to the next column by recursion. This is done as follows: We can continue the program to find this and other solutions. Q Q 17 18 void PlaceNextQueen (int Column, boardtypes &Board, boolean &Done) { .............. .............. PlaceNextQueen(Column+1, Board, Done); } Please study the program in your textbook. Good exercise: Try to write the FUNCTION Attack which is used in the book, but not explained. Attack(Board, Row, Column) returns TRUE if on the board there is any queen that can attack the field in row Row and column Column. 19 20...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online