wrote:
> <snip not-very-well-thought-out code>
Ya know, since the conditionals are identical for X and O, all you
really need to do is see if you match three-in-a-row, so the inside
loop is not really needed (ie, you don't need to check "is there XXX"
and then check "Is there OOO" - all you need to do is check if the
value of the first element is repeated two more times, and, if it is,
that value determines the winner). So you could instead do something
even more simple like this:
foreach my $group( [0,2,4],[5,7,9],[10,12,14],[0,7,14],[4,7,10] ) {
if ( (join '', @board[@$group]) eq $board[ $group->[0] ] x 3 ) {
print "Player $board[ $group->[0] ] Wins!\n";
}
}
--
http://DavidFilmer.com