Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[crypt.pl] hanoi game, legal move

  • Loading branch information...
commit 35435dc33a99f2da443f7786658aa648a7593ed6 1 parent 9c3e5f4
Carl Mäsak authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 crypt.pl
33 crypt.pl
View
@@ -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;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.