Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[crypt.pl] cannot remove covered disks

This exception takes precedence over the 'forbidden disk removal' one.
  • Loading branch information...
commit b6edc9c5658bd095128b7ccde640a020abc6a697 1 parent 94cf486
Carl Mäsak authored July 01, 2012

Showing 1 changed file with 17 additions and 2 deletions. Show diff stats Hide diff stats

  1. 19  crypt.pl
19  crypt.pl
@@ -139,15 +139,20 @@
139 139
 
140 140
     method remove($disk) {
141 141
         my $size = $disk.words[0];
142  
-        die X::Hanoi::ForbiddenDiskRemoval.new(:$disk)
143  
-            unless $size eq 'tiny';
144 142
         my $source;
145 143
         for %!state -> ( :key($rod), :value(@disks) ) {
146 144
             if $disk eq any(@disks) {
  145
+                sub smaller_disks {
  146
+                    grep { %size_of{$_} < %size_of{$disk} }, @disks;
  147
+                }
  148
+                die X::Hanoi::CoveredDisk.new(:$disk, :covered_by(smaller_disks))
  149
+                    unless @disks[*-1] eq $disk;
147 150
                 $source = $rod;
148 151
                 last;
149 152
             }
150 153
         }
  154
+        die X::Hanoi::ForbiddenDiskRemoval.new(:$disk)
  155
+            unless $size eq 'tiny';
151 156
         my @events = Hanoi::DiskRemoved.new(:$size, :$source);
152 157
         self!apply($_) for @events;
153 158
         return @events;
@@ -348,6 +353,16 @@ (&code, $ex_type, $message, &followup?)
348 353
                    'Removing the small disk is forbidden',
349 354
                    '.message attribute';
350 355
             };
  356
+
  357
+        throws_exception
  358
+            { $game.remove('medium disk') },
  359
+            X::Hanoi::CoveredDisk,
  360
+            'removing a disk (-) the disk is covered',
  361
+            {
  362
+                is .disk, 'medium disk', '.disk attribute';
  363
+                is .covered_by, ['small disk'],
  364
+                    '.covered_by attribute';
  365
+            };
351 366
     }
352 367
 
353 368
     done;

0 notes on commit b6edc9c

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