SlideShare a Scribd company logo
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.
Step-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)
.
Recursive (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.
8 -Queen_Puzzle_Problem_Presentation.ppt
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…
8 -Queen_Puzzle_Problem_Presentation.ppt

More Related Content

PPTX
N queen puzzle
PDF
N queens problem
PPTX
The N-Queens problemdskksnjfnskjdfnsjnddjsdnjs
PDF
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
PDF
Ht3313461349
PPTX
8-Queens Problem.pptx
PPTX
8 QUEENS PROBLEM.pptx
PPTX
AI problem solving.pptx
N queen puzzle
N queens problem
The N-Queens problemdskksnjfnskjdfnsjnddjsdnjs
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
Ht3313461349
8-Queens Problem.pptx
8 QUEENS PROBLEM.pptx
AI problem solving.pptx

Similar to 8 -Queen_Puzzle_Problem_Presentation.ppt (20)

PPTX
8queensproblemusingbacktracking-120903114053-phpapp01.pptx
PPTX
N queen problem
PPTX
Backtracking Basics.pptx
PDF
8 Queens Problemyjjffhhhgfghhhfhhggghjgg
PPTX
Solution of N Queens Problem genetic algorithm
PDF
need help with this java lab please read below and follow the steps.pdf
KEY
groovy & grails - lecture 8
PPTX
Water jug problem ai part 6
PPTX
8 queens problem using ga
PPTX
N-queens.pptx
PPTX
Chessboard Puzzles Part 2 - Independence
PPTX
8 queen problem
PDF
N Queens problem
PPTX
Chessboard Puzzles Part 1 - Domination
PDF
# Imports# Include your imports here, if any are used. import.pdf
PDF
Algorithm Performance For Chessboard Separation Problems
PPTX
PPT
ma project
DOCX
A detailed lesson plan in Chess
PDF
Ai lecture 10(unit02)
8queensproblemusingbacktracking-120903114053-phpapp01.pptx
N queen problem
Backtracking Basics.pptx
8 Queens Problemyjjffhhhgfghhhfhhggghjgg
Solution of N Queens Problem genetic algorithm
need help with this java lab please read below and follow the steps.pdf
groovy & grails - lecture 8
Water jug problem ai part 6
8 queens problem using ga
N-queens.pptx
Chessboard Puzzles Part 2 - Independence
8 queen problem
N Queens problem
Chessboard Puzzles Part 1 - Domination
# Imports# Include your imports here, if any are used. import.pdf
Algorithm Performance For Chessboard Separation Problems
ma project
A detailed lesson plan in Chess
Ai lecture 10(unit02)
Ad

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Spectroscopy.pptx food analysis technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
Teaching material agriculture food technology
PDF
Approach and Philosophy of On baking technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)
sap open course for s4hana steps from ECC to s4
Spectroscopy.pptx food analysis technology
Building Integrated photovoltaic BIPV_UPV.pdf
cuic standard and advanced reporting.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Teaching material agriculture food technology
Approach and Philosophy of On baking technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
The Rise and Fall of 3GPP – Time for a Sabbatical?
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Empathic Computing: Creating Shared Understanding
Cloud computing and distributed systems.
Ad

8 -Queen_Puzzle_Problem_Presentation.ppt

  • 2. Basic Rules The board: a matrix of size N X N. In standard chess: N = 8.
  • 3. Basic Rules The queen - moves horizontally, vertically, or diagonally.
  • 4. The queen - moves horizontally, vertically, or diagonally. Can attack any piece on its way. Basic Rules
  • 5. The queen - moves horizontally, vertically, or diagonally. Can attack any piece on its way. Basic Rules
  • 6. Basic Rules Two queens threaten each other if they are on the same vertical, horizontal, or diagonal line.
  • 7. Basic Rules Two queens threaten each other if they are on the same vertical, horizontal, or diagonal line.
  • 8. 8-Queens puzzle Place 8 queens on the board such that no two queens are threatening each other.
  • 9. Step-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) .
  • 11. 8-Queens puzzle Place 8 queens on the board such that no two queens are threatening each other.
  • 12. Place a queen at a non-threatened cell.
  • 13. Place a queen at a non-threatened cell.
  • 14. Place a queen at a non-threatened cell.
  • 15. Place a queen at a non-threatened cell.
  • 16. Place a queen at a non-threatened cell.
  • 17. Place a queen at a non-threatened cell.
  • 18. Place a queen at a non-threatened cell.
  • 19. Place a queen at a non-threatened cell.
  • 22. Place a queen at a non-threatened cell.
  • 23. Place a queen at a non-threatened cell.
  • 24. Place a queen at a non-threatened cell. Backtrack…
  • 25. • 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.
  • 26. A queen places itself at a safe position in its column.
  • 27. A queen places itself at a safe position in its column.
  • 28. A queen places itself at a safe position in its column.
  • 29. A queen places itself at a safe position in its column.
  • 30. A queen places itself at a safe position in its column.
  • 31. No safe position for queen 6 at column 6. Asks neighbor (queen 5) to change position.
  • 32. No safe position for queen 6 at column 6. Asks neighbor (queen 5) to change position.
  • 33. Queen 5 is at the last row. Asks neighbor (queen 4) to change position.
  • 35. A queen places itself at a safe position in its column.
  • 36. A queen places itself at a safe position in its column.
  • 37. A queen places itself at a safe position in its column.
  • 38. A queen places itself at a safe position in its column.
  • 39. No safe position for queen 8 at column 8. Proceed the search in a similar way…