Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[crypt.pl] hanoi game, legal move
  • Loading branch information
Carl Masak committed Jul 1, 2012
1 parent 9c3e5f4 commit 35435dc
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions crypt.pl
@@ -0,0 +1,33 @@
use Test;

role Event {
method Str {
sub event() { self.^name }
sub name($attr) { $attr.name.substr(2) }
sub value($attr) { $attr.get_value(self) }

"{event}[{map { ":{name $_}<{value $_}>" }, self.^attributes}]"
}
}

class DiskMoved does Event {
has $.size;
has $.from;
has $.to;
}

class HanoiGame {
method move($from, $to) {
DiskMoved.new(:size<tiny>, :$from, :$to);
}
}

multi MAIN('test', 'hanoi') {
my $game = HanoiGame.new();

is $game.move('left', 'middle'),
DiskMoved.new(:size<tiny>, :from<left>, :to<middle>),
'legal move (+)';

done;
}

0 comments on commit 35435dc

Please sign in to comment.