Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[crypt.pl] adding a disk

  • Loading branch information...
commit 89ce1449010437126f1dea47b90a5c88420df0bf 1 parent 00629f1
@masak authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 crypt.pl
View
16 crypt.pl
@@ -27,6 +27,11 @@
has $.source;
}
+class Hanoi::DiskAdded does Event {
+ has $.size;
+ has $.target;
+}
+
class X::Hanoi::LargerOnSmaller is Exception {
has $.larger;
has $.smaller;
@@ -143,6 +148,13 @@
return @events;
}
+ method add($disk, $target) {
+ my $size = $disk.words[0];
+ my @events = Hanoi::DiskAdded.new(:$size, :$target);
+ self!apply($_) for @events;
+ return @events;
+ }
+
# The method will throw X::Hanoi::CoveredDisk if the disk is not topmost,
# or X::Hanoi::DiskHasBeenRemoved if the disk isn't found on any rod.
method !rod_with_disk($disk, $action) {
@@ -417,6 +429,10 @@ (&code, $ex_type, $message, &followup?)
'Cannot move the tiny disk because it has been removed',
'.message attribute';
};
+
+ is $game.add('tiny disk', 'left'),
+ Hanoi::DiskAdded.new(:size<tiny>, :target<left>),
+ 'adding a disk (+)';
}
done;
Please sign in to comment.
Something went wrong with that request. Please try again.