I'm having trouble trying to figure out how to make the Eight Queens Problem where you have to insert eight queens in a 8 x 8 chess board so none of the queens are attacking each other. I'm sure I'll be using recursion and I doubt cheking the column, row and diagonals for avaibility is going to be hard, the problem is on how to make it go back and try a different row when the next queen can't be inserted in any row....maybe a for loop in the function from column 0 to column < board size...yeah, so when the for reaches the end it will return to the function and the for will try the next column.... ok I kinda have it, but how can I know when it finished? how can I make it continue searching for more solutions? not asking for the whole program here, just a couple of hints, maybe some one can point me to a good backtracking tutorial or something?



LinkBack URL
About LinkBacks



. Anyway to whoever it was, I tested the program before posting the code and it did finish, how? well you probably know by now or your post will still be here
, after the condition of the 8 queens is met ( count == BOARDSIZE ) it adds to the solutions counter and goes to try another space for the queen, eventually the very first loop would get to the end and just exit..... hopefully you get the idea of what I'm saying cause I don't plan on giving a better explanation
.