Props on taking on such an ambitious task to write an algorithm to solve all possible setups. It's definitely not an easy task but yours seems to work well enough. You may want to tweak the constraints a bit during the setup phase as I was able to build a layout that was impossible to solve. It's a pretty neat puzzle game you have there.