One method of solving a CSP is to keep a set that initially contains all of the variables. On each iteration you choose a variable from the set and remove all values in its domain that are impossible given the constraints containing the variable and the domains of the other variables in those constraints. Then you add all of those other variables to the set because they are now restricted more than before. You keep doing the above until you get stuck (which may or may not happen). You then start guessing. There are a bunch of heuristics about how you should choose which variable to guess (eg the variable with the smallest domain). Once you have made your guess, you then add all of the variables back to the set. If you find out the puzzle is impossible, you backtrack to the last guess you made. I believe there are ways you can determine which guess was the problem and immediately backtrack to there.