Once again I've become a perl beginner (do you ever stop?), except this time it's in perl6. Starting from ideas that I know well, I chose to redesign a portion of previous code of mine, in this case a chessboard. The first two classes went well (or at least worked, I know so little that I can't speak to their correctness…) but I'm stuck with the third. Here is the code:

#!/home/hsmyers/rakudo741/bin/perl6 # board.p6 - Beginnings of a PGN toolset. And place to start learning # Perl 6/Raku. use v6d; #!____________________________________________________________________ +_________ constant $size = 4; class Piece { my Str @namesOfPieces[$size] = < white-rook white-knight white-bishop white-queen >; my Str @abrevsOfPieces[$size] = < R N B Q K B N R >; my Str @symbolsOfPieces[$size] = < &#9814; &#9816; &#9815; &#9813; &#9812; &#9815; &#9816; &#9814 +; >; my Str @codeptsOfPieces[$size] = ( "\x2656", "\x2658", "\x2657", "\x2655", ); has Str $.name; has Str $.abrev; has Str $.symbol; has Uni $.codept; submethod BUILD( :$i ) { $!name = @namesOfPieces[$i]; $!abrev = @abrevsOfPieces[$i]; $!symbol = @symbolsOfPieces[$i]; $!codept = @codeptsOfPieces[$i].NFC; } } class Square { my Int @colors[$size] = < 1 0 1 0 1 0 1 0 >; my Str @names[$size] = < a1 b1 c1 d1 e1 f1 g1 h1 >; has Int $.color; has Int $.index; has Str $.name; has Piece $.piece; submethod BUILD( :$i ) { $!color = @colors[$i]; $!index = $i; $!name = @names[$i]; $!piece = Piece.new(:i($i)); } } class Board is Array { } my $p = Piece.new(:i(0)); $p.say; my $s = Square.new(:i(0)); $s.say; #!____________________________________________________________________ +_________ my @b := Board.new( Square.new(:i(0)), Square.new(:i(1)), Square.new(:i(2)) ); say @b; say @b.WHAT;

The Board class (empty as it is) is all that is left from my attempts so far. Amazingly (at least to me) it provides a degree of workability!. It has variously had a "new" and a "BUILD", neither provided a working solution. Obviously the current approach doesn't work considering that the actual count will be 64 and not 4.

My current notion is that I need to build an array of 64 Squares which in turn will create the needed pieces. I've tried to add to self with nothing working. Suggestions?

--hsm

"Never try to teach a pig to sing...it wastes your time and it annoys the pig."

In reply to [raku] How to use an object array in perl6 by hsmyers

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.