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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.