mkirank has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
I have successfully written my first perl 6 code :-)
Please feel free to make changes and then someone with commit access can put it to the pugs/examples/games directory
I have successfully written my first perl 6 code :-)
Please feel free to make changes and then someone with commit access can put it to the pugs/examples/games directory
#!/usr/bin/pugs use v6; my @g = ('.') xx 9; my $cnt = 0; for (@g)->$x { print "$x \t"; print "\n" if ( !( ++$cnt % 3 ) ); } my $player; my %player = ('X','Player 1','O','Player 2'); my %entered; my $choice = any (1 .. 9); my $tmp = 0; while ($tmp < 9) { $player = ( $tmp % 2 ) ?? 'O' :: 'X'; say %player{$player} ," Enter the Position [1-9]:"; my $in = =$IN; if (!$in ~~ rx:perl5/[1-9]/) { say " Please enter digits from 1-9 \n"; eval 'next'; } if ($in == $choice) { $in --; if (%entered.exists($in)) { say "Element already entered at $in"; eval 'next'; } %entered{$in} ++; $tmp ++; } else { say "Please enter a value within 1-9"; $tmp --; eval 'next'; } @g[$in] = $player; 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 (join ('',@g[@c]) ~~ rx:perl5/([XO])\1\1/) { say " %player{$player} Wins \n"; exit; } } for (@g) { print $_; print "\n" if ( !( ++ $cnt % 3 ) ); } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pugs Tic Tac
by stvn (Monsignor) on Apr 25, 2005 at 16:36 UTC | |
Re: Pugs Tic Tac
by dragonchild (Archbishop) on Apr 25, 2005 at 19:01 UTC | |
by stvn (Monsignor) on Apr 25, 2005 at 21:15 UTC | |
Re: Pugs Tic Tac
by eric256 (Parson) on Apr 25, 2005 at 18:11 UTC | |
by revdiablo (Prior) on Apr 25, 2005 at 18:29 UTC | |
by gaal (Parson) on Apr 25, 2005 at 19:59 UTC | |
by bmann (Priest) on Apr 25, 2005 at 18:33 UTC | |
by eric256 (Parson) on Apr 25, 2005 at 20:37 UTC | |
by revdiablo (Prior) on Apr 25, 2005 at 21:30 UTC | |
Re: Pugs Tic Tac
by jacques (Priest) on Apr 25, 2005 at 17:00 UTC | |
by revdiablo (Prior) on Apr 25, 2005 at 17:18 UTC | |
by japhy (Canon) on Apr 25, 2005 at 17:31 UTC | |
by revdiablo (Prior) on Apr 25, 2005 at 18:23 UTC | |
by QM (Parson) on Apr 26, 2005 at 02:25 UTC | |
by japhy (Canon) on Apr 25, 2005 at 20:04 UTC | |
by cog (Parson) on Apr 25, 2005 at 19:33 UTC | |
by bpphillips (Friar) on Apr 25, 2005 at 19:42 UTC | |
by cog (Parson) on Apr 25, 2005 at 20:14 UTC | |
by revdiablo (Prior) on Apr 25, 2005 at 20:03 UTC | |
Re: Pugs Tic Tac
by stvn (Monsignor) on Apr 26, 2005 at 03:45 UTC |
Back to
Seekers of Perl Wisdom