Min Conflicts
Your friend bets you can't put 8 queens on a board without any one of them threating the other. Well, we can't let you loose now, can we!!! So let's discuss how to help you win this bet. How about we randomnly try all the combinations. We are surely to hit the solution. After many tries... Well this is kinda tiring. Have you reached for solution, well I haven't, seems like this approach of ours was a failure. As any logical person would have pointed out that this approach is really bad , there are around 4,426,165,368 possible arrangements of eight queens on the board, surely some of them would give the right answer but the probability of them would be very less.
Back-tracking
How about rather than randomnly placing the queens let place them one at a time. Keep the first queen at first position, the second queen at any safe position on the next row and so one.
After a few placement, now you see there is no place left to place the next queen. What to do now?
Let's backtrack!!!. Go back to the previous state where there were no queens interescting and shift that queen to any other safe position. Now try to place the queen that earlier possed a problem. Any progress, if yes Congrats we can proceed further. If no, well the next step is simple, backtrack to the previous safe queen, shift it's position, then the one ahead of it and so on. This process is long but still much efficient than the randomly searching for a solution.
Logic really helps!!!, doesn't it.
Still you can't show-off to your friend.
Let's look at another way, that will surely blow his mind.
Min-Conflicts
As the name suggest we'll try to minimize the conflicts between different queens, one at a time and do it over and over untill we reach the solution. So place the 8 queens randomly on the board. It's a mess, well lets apply the logic. Select the Queen having maximum conflicts and place it at the square where it will have the minimum conflicts. By doing so you have reduced the number of total conflicts on the board. Our approach is simple, keep doing this untill we have reduced the total conflicts all the way to 0. Do the first step and repeat the process over and over. After a few step you will reach the solution. Boast to your friend !!! This method is so efficient that even million queen problems can be solved under 60 steps( ofcourse by fast computers.)Random Function Board
Random-Conflicts
- Selected Column:
- Conflicts Per Row:
- Min-Conflicts:
- New Row Selected:
- Previous Row:
Min-Coflict Function Board
Min-Conflicts
- Selected Column:
- Conflicts Per Row:
- Min-Conflicts:
- New Row Selected:
- Previous Row: