Using Probabilistic Graphical Models to Solve NP-complete Puzzle Problems