Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I could do the idea of having the boolean in one element and having the int in the following. Frankly though, I find it easier to manage and think about if I could have them both the boolean and the int in the same element. Reasoning for this, is I will have to have the system calculate different locations in a later portion of the code, and to just find a single element via very simple arithmetic is trivial, compared to doing a similar calculation, but then having to worry considering the next element, which will in essence throw off my calculation.

What I mean by this is I have several subroutines that currently depend on a simple calculation, in this case, lets take an example of placing a queen on D6, well with my two-dimensional array, I will completely block out the vertical and the horizontal columns, but what about the diagonals? well by doing a simple addition or subtraction of 1 to the factor being used in this case (in this case its actually two factors, the D which is equal to 4, and another that 6) With this, I could do a simple subtraction on one and addition on the other or two additions or two subtractions until I run out of possible squares. In our example, to resolve the upper left portion of the diagonal, we would do a double subtraction of 1 until one of the two arrays runs out of elements, and so on. This is why I want to have both of these values in the same element, since if they happen to be in the following element, I can no longer use the method described above to calculate all the squares being threatened by that queen that has been placed, in this case at D6, since as I go in one direction, I may be accessing either the boolean or the int, and I can't be sure without modifying the math used. It is just easier in this case to have them both in the same element if possible. The only other solution which could be used, is to create two two-dimensional arrays, and while that would work, I feel it would be a waste of resources that could be easily avoided.

A rough diagram of the board setup with the Q being the queen and the x's being the squares under attack, has been created below.

1 2 3 4 5 6 7 8 A | | |x| | |x| | | B | | | |x| |x| |x| C | | | | |x|x|x| | D |x|x|x|x|x|Q|x|x| E | | | | |x|x|x| | F | | | |x| |x| |x| G | | |x| | |x| | | H | |x| | | |x| | |

In reply to Re^3: Creating a unique variable type (an object) by tfredett
in thread Creating a unique variable type by tfredett

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (4)
    As of 2018-06-23 05:12 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (125 votes). Check out past polls.