17

Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

Embed Size (px)

Citation preview

Page 1: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions
Page 2: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

Review of eight queens puzzle The interface Algorithm Solution display Extensions of eight queens problem Conclusion Reference

Page 3: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

The eight queens puzzle

Is the problem of putting eight chess queens on an 8×8 chessboard such that none of them is able to capture any other using the standard chess queen's moves. The queens must be placed in such a way that no two queens would be able to attack each other. Thus, a solution requires that no two queens share the same row, column, or diagonal.

The eight queens puzzle is an example of the more general n queens puzzle of placing n queens on an n×n chessboard, where solutions exist only for n = 1 and n ≥ 4.

Page 4: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions
Page 5: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

Java Java methods: main routine and

subroutine Find help online about java

programming Try to interpret existed java codes

about eight queens puzzle Make my own program

Page 6: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

An interface: a chess board with panels and buttons, which handles the mouse clicks, shows instantaneous result.

An algorithm “brain” that calculates each movement and solution.

Some supportive parts like counting queens numbers, drawing cells, checking occupation and so on.

Page 7: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

0 0 0 0 0 0 0 00 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 0

Page 8: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

0 1 0 1 0 1 0 00 0 1 1 1 0 0 01 1 1 2 1 1 1 10 0 1 1 1 0 0 00 1 0 1 0 1 0 01 0 0 1 0 0 1 00 0 0 1 0 0 0 10 0 0 1 0 0 0 0

Page 9: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

N 1 2 3 4 5 6 7 8 9 10 …

U 1 0 0 1 2 1 6 12 46 92 …

D 1 0 0 2 10 4 40 92 352 724 …

Solutions for N queens:

For eight queens, if each row is occupied by one queen only, there are 16,777,216 (8*8) possible combinations.

Page 10: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

1. Divide n by 12. Remember the remainder (n is 8 for the eight queens puzzle). 2. Write a list of the even numbers from 2 to n in order. 3. If the remainder is 3 or 9, move 2 to the end of the list. 4. Append the odd numbers from 1 to n in order, but, if the remainder is 8, switch pairs (i.e. 3, 1, 7, 5, 11, 9, …). 5. If the remainder is 2, switch the places of 1 and 3, then move 5 to the end of the list. 6. If the remainder is 3 or 9, move 1 and 3 to the end of the list. 7. Place the first-column queen in the row with the first number in the list, place the second-column queen in the row with the second number in the list, etc.

Page 12: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

LV probability algorithm The closed circle DNA algorithm

Page 13: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

http://www.physics.ubc.ca/~yanw123/p210/QueensApplet.html

Page 14: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

N queens on n×n board Using pieces other than queens on 8×8: 32

knights, 14 bishops, 16 kings or 8 rooks Board in other shapes instead of square Other than 2D, maybe 3D or higher

dimensions

Page 15: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

Recursion is a very effective way in solving logical problems that have no formulas, unless trying each possibility.

As a classical puzzle, “eight queens” is a good tool in methods exploration.

The “eight queens” model is just a special case of a series of puzzles.

Page 16: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions

“History” --Wikipediahttp://en.wikipedia.org/wiki/Eight_queens_puzzle

“Counting solutions ” --Wikipediahttp://en.wikipedia.org/wiki/Eight_queens_puzzle#Counting_solutions

“Recursive solution ” -- Wikipediahttp://en.wikipedia.org/wiki/Eight_queens_puzzle#An_animated_version_of_the_recursive_solution

“Related problems” -- Wikipediahttp://en.wikipedia.org/wiki/Eight_queens_puzzle#Related_problems

“Constructing a solution” --Wikipediahttp://en.wikipedia.org/wiki/Eight_queens_puzzle#Constructing_a_solution

“Eight queen problem: model of closed circle DNA algorithm of Eight Queens problem” – Tong Xiaojunhttp://www.cnki.com.cn/Article/CJFDTotal-JSGG200706002.htm

Page 17: Eight Queens Puzzle - jick. · PDF fileThe eight queens puzzle I s the problem of putting eight chess queens on ... 16 kings or 8 rooks ... maybe 3D or higher dimensions