Well, let me explain why I didn't choose any of those methods for implementing the data structure.

I implemented the data structure before anything else, including the original Eight Queens Problem, and one of my foremost priorities for it was speed.  That would rule out function references; if you're trying to make things as fast as possible, you can't make each legal move a function call.

As far as why I didn't define things in terms of diagonals versus horizontal/vertical moves:  the data structure needed to contain AoA for each square for each piece rather than simply an array, and the reason for that was, when calculating the directions for a piece such as a bishop, rook or queen, you have to stop as soon as you hit another piece (if the piece is of the opposite color, it can be captured, of course).  Besides which, pawns, knights and kings wouldn't follow those same rules, so what would be the point?

When I created the data structure, I *did* actually calculate the rook moves and bishop moves first, and then just "added" them together to get the queen.

So I hope you understand my reasoning.  Maybe if you try running the program, you'll see why optimizing for speed was my primary goal.


@ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"

In reply to Re^2: "Attack" -- Find Solutions for N Non-Attacking Chess Pieces by liverpole
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.