dragonchild

I refactored your refactor to work in Pugs. It's a little hackish in parts, but it does work :)

I committed it to svn http://svn.openfoundry.org/pugs/examples/games/tic_tac_toe.p6 and added some POD so as to give credit where credit is due.

#!/usr/bin/pugs use v6; sub print_board ( @b ) { my $count = 0; for (@b) -> $x { print "$x\t"; print "\n" unless ++$count % 3; } } my @g = ('.') xx 9; print_board( @g ); my %player = ('X','Player 1','O','Player 2'); my %entered; my $choice = any (1 .. 9); my $player = 'X'; while (grep { $_ eq '.' } @g) { say %player{$player} ~ " Enter the Position [1-9]:"; my $in = =$IN; unless ($in == $choice) { say "Please enter a value within 1-9"; } else { my $idx = $in - 1; if (%entered.exists($idx)) { say "Element already entered at $in"; } else { @g[$idx] = $player; %entered{$idx}++; for ( [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ], [ 0, 3, 6 ], [ 1, 4, 7 ], [ 2, 5, 8 ], [ 0, 4, 8 ], [ 2, 4, 6 ] ) -> $c { if (@g[$c[0]] ne '.' && @g[$c[0]] eq @g[$c[1]] eq @g[$ +c[2]]) { print_board( @g ); say " " ~ %player{$player} ~ " Wins \n"; exit(); } } print_board( @g ); $player = $player eq 'X' ?? 'O' :: 'X'; } } } =pod =head1 NAME tic_tac_toe.p6 - Tic-Tac-Toe =head1 DESCRIPTION This is a perl6 implementation of the classic Tic-Tac-Toe game. =head1 AUTHORS mkirank L<http://www.perlmonks.org/index.pl?node_id=451261> rob kinyon L<http://www.perlmonks.org/index.pl?node_id=451302> stevan little, E<lt>stevan@iinteractive.comE<gt> =cut
BTW - if either of you want commit access, just ask :)

-stvn

In reply to Re^2: Pugs Tic Tac by stvn
in thread Pugs Tic Tac by mkirank

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.