Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] more hanoi DWIM

* Understood a few more hanoi commands
* Parsed putting the tiny disk back as 'put_thing_on', not 'move'
* Draw the hanoi state when putting the tiny disk back
  • Loading branch information...
commit e67c6b00aee6042606eee62662a20096f5e6a5b5 1 parent 3aadbbf
Carl Mäsak authored July 30, 2012

Showing 1 changed file with 22 additions and 8 deletions. Show diff stats Hide diff stats

  1. 30  bin/crypt
30  bin/crypt
@@ -1490,6 +1490,7 @@ multi MAIN() {
1490 1490
     }
1491 1491
 
1492 1492
     my @all_events;
  1493
+    my $player_has_tiny_disk = False;
1493 1494
 
1494 1495
     loop {
1495 1496
         my $command = prompt('> ');
@@ -1585,7 +1586,7 @@ inventory";
1585 1586
                     $
1586 1587
                 }
1587 1588
                 regex verb { \w+ [\h+ \w+]?? <?{ $/ eq any @verbs }> }
1588  
-                regex noun { \w+ [\h+ 'disk']? }
  1589
+                regex noun { \w+ [\h+ ['disk'|'rod']]? }
1589 1590
                 regex prep { 'in' | 'on' }
1590 1591
             }
1591 1592
 
@@ -1606,21 +1607,23 @@ inventory";
1606 1607
             }
1607 1608
 
1608 1609
             when /^ :s [move|put] [the]?
1609  
-                    $<disk>=[tiny||small||medium||large||huge]
1610  
-                    disk [on|to] [the]?
  1610
+                    $<disk>=[[tiny||small||medium||large||huge] disk]
  1611
+                    [on|to] [the]?
1611 1612
                     $<target>=[left||middle||right]
1612  
-                    rod $/ {
  1613
+                    [rod]? $/ {
1613 1614
 
1614  
-                $verb = 'move';
1615  
-                @args = ~$<disk>, ~$<target>;
  1615
+                unless $<disk> eq 'tiny disk' && $player_has_tiny_disk {
  1616
+                    $verb = 'move';
  1617
+                    @args = ~$<disk>, ~$<target>;
  1618
+                }
1616 1619
                 proceed;
1617 1620
             }
1618 1621
 
1619 1622
             when /^ :s [move|put] [the]?
1620 1623
                     $<source>=[left||middle||right]
1621  
-                    disk [on|to] [the]?
  1624
+                    [disk|rod] [on|to] [the]?
1622 1625
                     $<target>=[left||middle||right]
1623  
-                    rod $/ {
  1626
+                    [rod]? $/ {
1624 1627
 
1625 1628
                 $verb = 'move';
1626 1629
                 @args = ~$<source>, ~$<target>;
@@ -1680,6 +1683,9 @@ inventory";
1680 1683
                     }
1681 1684
                     when Adventure::PlayerTook {
1682 1685
                         say "You take the {.thing}.";
  1686
+                        if .thing eq 'tiny disk' {
  1687
+                            $player_has_tiny_disk = True;
  1688
+                        }
1683 1689
                     }
1684 1690
                     when Adventure::PlayerDropped {
1685 1691
                         say "You drop the {.thing} on the ground.";
@@ -1690,6 +1696,14 @@ inventory";
1690 1696
                     when Adventure::PlayerPutIn {
1691 1697
                         say "You put the {.thing} in the {.in}.";
1692 1698
                     }
  1699
+                    when Adventure::PlayerPutOn {
  1700
+                        say "You put the {.thing} on the {.on}.";
  1701
+                        if .thing eq 'tiny disk' {
  1702
+                            $player_has_tiny_disk = False;
  1703
+                            print_hanoi_game(@all_events);
  1704
+                            say "";
  1705
+                        }
  1706
+                    }
1693 1707
                     when Adventure::GameRemarked {
1694 1708
                         say %descriptions{"remark:{.remark}"};
1695 1709
                     }

0 notes on commit e67c6b0

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