I have not tried running this, or even looked at your code very carefully, but i wanted to make a suggestion regarding the format of your Legal.pm...
It seems like it might be a lot more readable (and probably reusable when defining hypothetical pieces) if you created named hash refrences for the two major classifications of move types: diagonally and horizontally. Then defined the legal attacks for the individual pieces based on those where appropriate (ie: bishop is an alias for the diagonal hash, rook is an alias for the horisontal hash, queen is a merge of both).
Alternatly (and the more i think about it, even better) you could impliment the set of legal attacks for a peice as a function ref instead of a hash ref -- where the function takes in a current location, and returns the list of legal atacks -- for simple pieces like the rook, pawn and king these functions are trivial. for things like bishop, and knight the math is a little more complicated, but still much shorter then your giant hashes. Once again the queen can be implimented by calling both the rook and bishop functions and unioning the results.
In reply to Re: "Attack" -- Find Solutions for N Non-Attacking Chess Pieces
by hossman
in thread "Attack" -- Find Solutions for N Non-Attacking Chess Pieces
by liverpole
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |