Presentation is loading. Please wait.

Presentation is loading. Please wait.

N Queen Puzzle https://en.wikipedia.org/wiki/Eight_queens_puzzle Backtracking Algorithm 1. Starting from first row, loop through all the positions in this.

Similar presentations


Presentation on theme: "N Queen Puzzle https://en.wikipedia.org/wiki/Eight_queens_puzzle Backtracking Algorithm 1. Starting from first row, loop through all the positions in this."— Presentation transcript:

1 N Queen Puzzle https://en.wikipedia.org/wiki/Eight_queens_puzzle Backtracking Algorithm 1. Starting from first row, loop through all the positions in this row, if could find a safe position, mark it and move forward to next row. 2. If you can a safe position in the next row, keep moving forward. If this finally leads to a solution, save it. Otherwise transverse back to previous row to look for other possible safe positions 3. Repeat until we have looped through all positions type Board struct { field [][]int} type Boards []Board http://www.geeksforgeeks.org/backtracking-set-3-n-queen-problem/ Shuo Zhao shuozhao@andrew.cmu.edu

2 Independent Solutions N=4 Independent Solutions N=4 Solutions N=5, 6, 7, 8 Solutions N123456789 Ind.10012161246 All10021044092352 https://en.wikipedia.org/wiki/Eight_queens_puzzle

3 Nonstandard Board ShapestandardcolumnDonut Attacking conditionsx=i; y=j; abs(x-i)=abs(j-y) x=i; y=j; abs(x-i)=abs(j-y) abs(x-i)=abs(j+n-y) abs(x-i)=abs(j-n-y) x=i; y=j; abs(x-i)=abs(j-y) abs(x-i)=abs(j+n-y) abs(x-i)=abs(j-n-y) abs(x+n-i)=abs(j-y) abs(x-n-i)=abs(j-y) Higher Dimensional Board (3d as example) abs(x-i)=abs(y-j)=abs(z-k) (3dimensional diagonal) if x=i (yz plane): y=j; z=k; (1dimensional); abs(y-j)=abs(z-k) (2dimensional) if y=i (xz plane): x=i; z=k; (1dimensional); abs(x-i)=abs(z-k) (2dimensional) if z=k (xy plane): y=j; x=i; (1dimensional); abs(y-j)=abs(x-i) (2dimensional) if x!=i&& y!=i&& z!=k (xyz space): abs(x-i)=abs(y-j)=abs(z-k) (3dimensional) Jeremiah Barr and Shrisha Rao, Department of Computer Science, Mount Mercy College, IA 52402 http://www.micsymposium.org/mics _2004/Barr.pdf N=4


Download ppt "N Queen Puzzle https://en.wikipedia.org/wiki/Eight_queens_puzzle Backtracking Algorithm 1. Starting from first row, loop through all the positions in this."

Similar presentations


Ads by Google