Download the raw code.
# Adjacency matrix and chains and original board
class StonePairsGame {
has @.board;
has %.adj;
has @.chains;
method new ( $board_size ) {
my @board = ^$board_size;
my %adj;
my @chains = [ @board ];
for 0 ..^ @board.end -> $i {
%adj{$i}{$i+1} = 1;
}
self.bless( *, :@board, :%adj, :@chains );
}
}
my $N = $*IN.get or say 'aborted' and exit;
my $player1 = $*IN.get or say 'aborted' and exit;
my $board = StonePairsGame.new($N);
if $N == 2|3 and $player1 eq 'computer' {
say "computer takes 0,1\ncomputer wins";
}
elsif $N == 4 and $player1 eq 'computer' {
say 'computer takes 0,1';
$*IN.get eq '2,3' or busted();
say "human to move: 2,3\nhuman wins";
}
elsif $N == 4 and $player1 eq 'human' {
say 'human to move: 0,1,2,3';
$*IN.get eq '1,2' or busted();
say "computer takes 3,0\ncomputer wins";
}
else {
busted();
}
sub busted () {
die "
.)ssenhsiloof tnatsnoc dna(
.ycnetsisnoc hsiloof fo esnes a fo tuo dettimbus ylno si
,tset-esab eht etelpmoc ot staehc hcihw ,edoc sihT
.emit fo tuo nar dna ,noitnetta eud sti 4P nevig ton dah I
!em thguac uoY
".flip;
}
Aww. :-)
"Do as little as you need to, but no less." This is an example of "less".