Skip to content

Instantly share code, notes, and snippets.

Created June 17, 2009 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/131224 to your computer and use it in GitHub Desktop.
Save anonymous/131224 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl6
#
# AFAICT something in the commented out lines is causing the error
#
# ResizablePMCArray: Can't pop from an empty array!
# in Main (src/gen_setting.pm:0)
#
class Space {
has @.adjacent of Int is rw;
has $.occupant of Str is rw;
};
class Game {
has $.player is rw;
has %.board of Space is rw;
submethod BUILD {
$.player = 0;
my @adjacency = [
[ 1, 5, 6 ],
[ 1, 3, 8 ],
[ 2, 4, 10 ],
[ 3, 5, 12 ],
[ 1, 4, 14 ],
[ 1, 7, 15 ],
[ 6, 8, 16 ],
[ 2, 7, 9 ],
[ 8, 10, 17 ],
[ 3, 9, 11 ],
[ 10, 12, 18 ],
[ 4, 11, 13 ],
[ 12, 14, 19 ],
[ 5, 13, 15 ],
[ 6, 14, 20 ],
[ 7, 17, 20 ],
[ 9, 16, 18 ],
[ 10, 11, 17 ],
[ 13, 14, 20 ],
[ 15, 16, 19 ],
];
for 1 .. 20 {
%.board{$_ - 1} = Space.new(
adjacent => @adjacency[ $_ - 1 ],
occupant => '',
);
}
for < trap trap superbats superbats > -> $object {
%.board{ self.empty_space }.occupant = $object;
}
}
method debug {
for %.board.keys -> $i {
say
sprintf( '%2d ', $i )
# ,
# defined $.grid{$i}.occupant || 'empty'
# ,
# $i == self.player ?? ' [player] ' :: ''
# ,
;
}
return;
}
method empty_space {
my $rand;
{
$rand = ( 20.rand.int ) + 1;
# if defined %.board{$rand}.occupant || $.player == $rand {
# redo;
# }
}
return $rand;
}
}
my $g = Game.new;
$g.debug;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment