2016年10月15日星期六

Eight Queens Puzzle

The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens are able to attach each other. Each queen in the chess game is able to attach anything that's in its row, column or diagonal. The eight queens puzzle is an example of the more general n queens problem of placing n non-attacking queens on an n×chessboard that n is not 2 or 3.

Finding the solution may seem easy but it really costs a lot of troubles. So it is a good question for us to use computer science to solve this puzzle. It is  a good example of a problem which can be solved with a recursive algorithm. This puzzle is a tried-and-failed puzzle I believe. Placing one queen on the chessboard and then eliminate the row, column and diagonal's possibility  of putting  the next queen. Then put the next queen randomly in the rest of the position and repeat. If till the end there are no 8 queens on the chessboard, clean the chessboard and put the first queen on the chessboard randomly and repeat the previous process.
I believe that this puzzle can be solved with the combination of if and for loop. Combined with the function that we just learned, I believe that this can be a great project for us to practice.

没有评论:

发表评论