Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[crypt.pl] hanoi game, legal move

  • Loading branch information...
commit 35435dc33a99f2da443f7786658aa648a7593ed6 1 parent 9c3e5f4
Carl Mäsak authored July 01, 2012

Showing 1 changed file with 33 additions and 0 deletions. Show diff stats Hide diff stats

  1. 33  crypt.pl
33  crypt.pl
... ...
@@ -0,0 +1,33 @@
  1
+use Test;
  2
+
  3
+role Event {
  4
+    method Str {
  5
+        sub event() { self.^name }
  6
+        sub name($attr) { $attr.name.substr(2) }
  7
+        sub value($attr) { $attr.get_value(self) }
  8
+
  9
+        "{event}[{map { ":{name $_}<{value $_}>" }, self.^attributes}]"
  10
+    }
  11
+}
  12
+
  13
+class DiskMoved does Event {
  14
+    has $.size;
  15
+    has $.from;
  16
+    has $.to;
  17
+}
  18
+
  19
+class HanoiGame {
  20
+    method move($from, $to) {
  21
+        DiskMoved.new(:size<tiny>, :$from, :$to);
  22
+    }
  23
+}
  24
+
  25
+multi MAIN('test', 'hanoi') {
  26
+    my $game = HanoiGame.new();
  27
+
  28
+    is $game.move('left', 'middle'),
  29
+       DiskMoved.new(:size<tiny>, :from<left>, :to<middle>),
  30
+       'legal move (+)';
  31
+
  32
+    done;
  33
+}

0 notes on commit 35435dc

Please sign in to comment.
Something went wrong with that request. Please try again.