Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } |