File tree Expand file tree Collapse file tree 3 files changed +404
-0
lines changed 
data/scenarios/Challenges Expand file tree Collapse file tree 3 files changed +404
-0
lines changed Original file line number Diff line number Diff line change 1+ def  goDir =  \f .  \r . 
2+   let  d  =  fst  r  in 
3+   if  (d  ==  down ) {
4+     grapesHere <-  ishere  " grapes" 
5+     if  grapesHere {
6+         grab ; return  ()
7+     } {};
8+     return  ();
9+   } {
10+     turn  d ;
11+ 
12+     // An obstruction might arise after 
13+     // navigation direction is determined 
14+     // but before we move. 
15+     try  {
16+       move ;
17+     } {};
18+     f ;
19+   }
20+   end ;
21+ 
22+ def  followRoute =  \item . 
23+     nextDir <-  path  (inL ()) (inR item );
24+     case  nextDir return  $  goDir $  followRoute item ;
25+     end ;
26+ 
27+ def  getGrapes = 
28+     let  targetItem =  " grapes" in 
29+     emperorHasThem <-  has  targetItem;
30+     if  emperorHasThem {
31+         say  " Tally ho!" 
32+     } {
33+         grapesDropped <-  as  base  {
34+             baseHasThem <-  has  targetItem;
35+             return  $  not  baseHasThem;
36+         };
37+ 
38+         if  grapesDropped {
39+             followRoute targetItem;
40+         } {
41+             wait  10 ;
42+             getGrapes;
43+         };
44+     }
45+     end ;
46+ 
47+ def  avoidSides = 
48+ 
49+     toLeft <-  scan  back ;
50+     case  toLeft return  (\_ . 
51+         turn  right ;
52+     );
53+ 
54+     toRight <-  scan  back ;
55+     case  toRight return  (\_ . 
56+         turn  left ;
57+     );
58+ 
59+     behind  <-  scan  back ;
60+     case  behind  return  (\_ . 
61+         isBlocked <-  blocked ;
62+         if  isBlocked {} {move ;}
63+     );
64+     
65+     watch  forward ;
66+     watch  back ;
67+     watch  left ;
68+     watch  right ;
69+     wait  1000 ;
70+     end ;
71+ 
72+ def  go  = 
73+     getGrapes;
74+     avoidSides;
75+     go ;
76+     end ;
77+ 
78+ go ;
Original file line number Diff line number Diff line change 1+ def  doN =  \n .  \f .  if  (n  >  0 ) {f ; doN (n  -  1 ) f } {}; end ;
2+ 
3+ def  intersperse  =  \n .  \f2 .  \f1 .  if  (n  >  0 ) {
4+         f1 ;
5+         if  (n  >  1 ) {
6+             f2 ;
7+         } {};
8+         intersperse  (n  -  1 ) f2  f1 ;
9+     } {};
10+     end ;
11+ 
12+ def  shiftRightForPush = 
13+     turn  back ;
14+     move ;
15+     turn  left ;
16+     move ;
17+     turn  left ;
18+     end ;
19+ 
20+ /* 
21+ Precondition: 
22+ Positioned behind the wall, facing it, on the leftmost cell. 
23+ */ 
24+ def  pushWall = 
25+     intersperse  3  shiftRightForPush push ;
26+     end ;
27+ 
28+ def  moveToBackWall = 
29+     turn  back ;
30+     doN 5  move ;
31+     turn  right ;
32+     doN 2  move ;
33+     turn  right ;
34+     end ;
35+ 
36+ def  moveRightSide = 
37+     turn  right ;
38+     push ;
39+     turn  right ;
40+     move ;
41+     turn  left ;
42+     move ;
43+     turn  left ;
44+     doN 5  push ;
45+     turn  right ;
46+     move ;
47+     turn  left ;
48+     move ;
49+     turn  left ;
50+     push ;
51+     end ;
52+ 
53+ def  moveLeftSide = 
54+     doN 4  move ;
55+     turn  left ;
56+     doN 5  move ;
57+     turn  right ;
58+     push ;
59+     turn  left ;
60+     move ;
61+     turn  right ;
62+     move ;
63+     turn  right ;
64+     doN 5  push ;
65+     turn  left ;
66+     move ;
67+     turn  right ;
68+     move ;
69+     turn  right ;
70+     push ;
71+     end ;
72+ 
73+ def  initialSetup = 
74+     turn  south ;
75+     doN 3  move ;
76+     turn  right ;
77+     move ;
78+     turn  right ;
79+     end ;
80+ 
81+ def  waitUntilGrapesGrabbed = 
82+     itemHere <-  scan  forward ;
83+     case  itemHere return  (\_ . 
84+         watch  forward ;
85+         wait  1000 ;
86+         waitUntilGrapesGrabbed;
87+     );
88+     end ;
89+ 
90+ def  placeGrapes = 
91+ 
92+     doN 4  move ;
93+     place  " grapes" 
94+     turn  back ;
95+     move ;
96+     doN 2  push ;
97+     turn  back ;
98+     doN 2  move ;
99+     waitUntilGrapesGrabbed;
100+ 
101+     turn  back ;
102+     doN 4  move ;
103+     turn  back ;
104+     doN 2  push ;
105+     end ;
106+ 
107+ def  go  = 
108+     placeGrapes;
109+ 
110+     // initialSetup; 
111+     // pushWall; 
112+     // moveToBackWall; 
113+     // pushWall; 
114+     // moveRightSide; 
115+     // moveLeftSide; 
116+     end ;
117+ 
118+ go ;
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments