7 use Moose::Autobox::Undef;
9 use autobox UNDEF => 'Moose::Autobox::Undef';
11 sub ARRAY::print_board {
16 print("\n") unless ((++$count) % 3);
20 my $g = [ ('.') x 9 ];
24 my $players = { 'X' => 'Player 1', 'O' => 'Player 2' };
26 my $player_character = [ 'X', 'O' ]->any;
29 my $choice = [ 1 .. 9 ]->any;
32 while ($g->all == '.') {
35 print($players->{$player} . " Enter the Position [1-9]: ");
38 unless ($in == $choice) {
39 print "\n\tPlease enter a value within 1-9\n\n";
44 if ($entered->exists($idx)) {
45 print "\n\tElement already entered at $in\n";
56 [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ],
57 [ 0, 3, 6 ], [ 1, 4, 7 ], [ 2, 5, 8 ],
58 [ 0, 4, 8 ], [ 2, 4, 6 ],
61 #my @row = @{$g}[$_->[0], $_->[1], $_->[2]];
65 #(($row->all == 'X') || ($row->all == 'O'))&& warn "Wow, this worked";
67 if ( ( $players->exists($g->[$_->[0]]) &&
68 $players->exists($g->[$_->[1]]) &&
69 $players->exists($g->[$_->[2]]) )
71 ( ( $g->[$_->[0]] eq $g->[$_->[1]] ) &&
72 ( $g->[$_->[1]] eq $g->[$_->[2]] ) ) )
74 print("\n\t$players->{$player} Wins\n");
79 $player = $player eq 'X' ? 'O' : 'X';
87 tic_tac_toe.p6 - Tic-Tac-Toe
91 This is a Moose::Autobox port of a perl6 implementation
92 of the classic Tic-Tac-Toe game.
94 This uses a modified version of the one Rob Kinyon created
95 L<http://www.perlmonks.org/index.pl?node_id=451302>.
99 mkirank L<http://www.perlmonks.org/index.pl?node_id=451261>
101 Rob Kinyon L<http://www.perlmonks.org/index.pl?node_id=451302>
103 Stevan Little, E<lt>stevan@iinteractive.comE<gt>