8 -Queen_Puzzle_Problem_Presentation.ppt

rg1712781 12 views 40 slides Sep 11, 2024
Slide 1
Slide 1 of 40
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40

About This Presentation

This presentation explains the 8 puzzle problem.


Slide Content

8-Queens Puzzle

Basic Rules
The board: a matrix of size N X N.
In standard chess: N = 8.

Basic Rules
The queen - moves horizontally, vertically, or
diagonally.

The queen - moves horizontally, vertically, or
diagonally.
Can attack any piece on its way.
Basic Rules

The queen - moves horizontally, vertically, or
diagonally.
Can attack any piece on its way.
Basic Rules

Basic Rules
Two queens threaten each other if they are on
the same vertical, horizontal, or diagonal line.

Basic Rules
Two queens threaten each other if they are on
the same vertical, horizontal, or diagonal line.

8-Queens puzzle
Place 8 queens on the board such that
no two queens are threatening each other.

S
tep-by-step Algorithm
1 .Initialize the board: Create an 8x8 chessboard and initialze
all positions to 0(empty).
2 .Recursive function :
Base case- If the current row is 8(all queens have been
placed), return true (solution found) .
Iterative loop –
For each column in the next row;
Check validity:
i. If the current position is safe (no queen attack),place a
queen there .
ii. Recursively call the function for the next row.
iii. If the recursive call returns true (solution found),return true.
iv. Remove the queen from the current position(backtracking).
If no valid position is found in the current row, return false(no
solution) .

Recu
rsive (non-OOP) solution

8-Queens puzzle
Place 8 queens on the board such that
no two queens are threatening each other.

Place a queen at a non-threatened cell.

Place a queen at a non-threatened cell.

Place a queen at a non-threatened cell.

Place a queen at a non-threatened cell.

Place a queen at a non-threatened cell.

Place a queen at a non-threatened cell.

Place a queen at a non-threatened cell.

Place a queen at a non-threatened cell.

Backtrack.

Backtrack.

Place a queen at a non-threatened cell.

Place a queen at a non-threatened cell.

Place a queen at a non-threatened cell.
Backtrack…

• Each queen is an autonomous agent!
Main ideas
• Queens are added to the board from left to right.
• A queen tries to find a safe position in its column.
• If no safe position is found,
then the queen asks its neighbors to advance to
the next legal position.
(In which no two neighbors threaten each other.)
• Each queen has its own fixed column.

A queen places itself at a safe position in its column.

A queen places itself at a safe position in its column.

A queen places itself at a safe position in its column.

A queen places itself at a safe position in its column.

A queen places itself at a safe position in its column.

No safe position for queen 6 at column 6.
Asks neighbor (queen 5) to change position.

No safe position for queen 6 at column 6.
Asks neighbor (queen 5) to change position.

Queen 5 is at the last row.
Asks neighbor (queen 4) to change position.

A queen places itself at a safe position in its column.

A queen places itself at a safe position in its column.

A queen places itself at a safe position in its column.

A queen places itself at a safe position in its column.

No safe position for queen 8 at column 8.
Proceed the search in a similar way…