Mercurial > repos > icfp2012
comparison src/sim.tp @ 40:f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sun, 15 Jul 2012 14:35:56 -0700 |
parents | 814e3d482ad3 |
children | 20327ae2120b |
comparison
equal
deleted
inserted
replaced
37:2dc785f67327 | 40:f38437d22ebd |
---|---|
26 ret <- #{ | 26 ret <- #{ |
27 id <- (idStr byte: 0) | 27 id <- (idStr byte: 0) |
28 string <- idStr | 28 string <- idStr |
29 isrobot <- { false } | 29 isrobot <- { false } |
30 eq <- :other { id = (other id) } | 30 eq <- :other { id = (other id) } |
31 navigable <- { cannav } | 31 navigable <- { cannav } |
32 } | 32 } |
33 typedict set: (ret id) ret | 33 typedict set: (ret id) ret |
34 ret | 34 ret |
35 } | 35 } |
36 #{ | 36 #{ |
60 heldBreath <- 0 | 60 heldBreath <- 0 |
61 razors <- 0 | 61 razors <- 0 |
62 busted <- false | 62 busted <- false |
63 mine <- null | 63 mine <- null |
64 doCmd <- :cmd { | 64 doCmd <- :cmd { |
65 action <- commands get: cmd | 65 action <- commands get: cmd withDefault: { null } |
66 action: | 66 action: |
67 } | 67 } |
68 move <- :xDelta yDelta { | 68 move <- :xDelta yDelta { |
69 xPrime <- x + xDelta | 69 xPrime <- x + xDelta |
70 yPrime <- y + yDelta | 70 yPrime <- y + yDelta |
114 state <- #{ | 114 state <- #{ |
115 new <- :in_grid in_width in_height { | 115 new <- :in_grid in_width in_height { |
116 nextGrid <- #[] | 116 nextGrid <- #[] |
117 robot <- null | 117 robot <- null |
118 endreached <- false | 118 endreached <- false |
119 _lambdaCount <- 0 | |
120 _succeeded <- false | |
119 ret <- #{ | 121 ret <- #{ |
120 grid <- in_grid | 122 grid <- in_grid |
121 width <- in_width | 123 width <- in_width |
122 height <- in_height | 124 height <- in_height |
123 calcIndex <- :x y { x + y * width } | 125 calcIndex <- :x y { x + y * width } |
131 } | 133 } |
132 updatePos <- :obj Index { | 134 updatePos <- :obj Index { |
133 obj x!: (calcX: Index) | 135 obj x!: (calcX: Index) |
134 obj y!: (calcY: Index) | 136 obj y!: (calcY: Index) |
135 } | 137 } |
138 lambdaCount <- {_lambdaCount} | |
136 water <- 0 | 139 water <- 0 |
137 flooding <- 0 | 140 flooding <- 0 |
138 waterproof <- 10 | 141 waterproof <- 10 |
139 moves <- 0 | 142 moves <- 0 |
140 ended <- {endreached} | 143 ended <- {endreached} |
141 succeeded <- false | 144 succeeded <- {_succeeded} |
145 succeeded! <- :newval { | |
146 endreached <- newval | |
147 _succeeded <- newval | |
148 } | |
142 doUpdate <- { | 149 doUpdate <- { |
143 true | 150 foreach: grid :index value { |
151 if: (value eq: (cellTypes rock)) { | |
152 x <- calcX: index | |
153 y <- calcY: index | |
154 below <- getCell: x (y - 1) | |
155 if: (below eq: (cellTypes empty)) { | |
156 setCell: x y (cellTypes empty) | |
157 setCell: x (y - 1) value | |
158 } | |
159 } else: { | |
160 if: (value eq: (cellTypes closedLift)) { | |
161 if: (robot collected) = _lambdaCount { | |
162 grid set: index (cellTypes openLift) | |
163 } | |
164 } | |
165 } | |
166 } | |
144 } | 167 } |
145 advance <- :roboCmd { | 168 advance <- :roboCmd { |
146 endreached <- roboCmd = "A" | 169 endreached <- roboCmd = "A" |
147 if: (not: endreached) { | 170 if: (not: endreached) { |
148 robot doCmd: roboCmd | 171 robot doCmd: roboCmd |
170 nextGrid append: el | 193 nextGrid append: el |
171 if: (el isrobot) { | 194 if: (el isrobot) { |
172 robot <- el | 195 robot <- el |
173 robot mine!: ret | 196 robot mine!: ret |
174 ret updatePos: robot index | 197 ret updatePos: robot index |
198 } else: { | |
199 if: (el eq: (cellTypes lambda)) { | |
200 _lambdaCount <- _lambdaCount + 1 | |
201 } | |
175 } | 202 } |
176 | 203 |
177 | 204 |
178 // adding a 'new' method to robot and doing this instead | 205 // adding a 'new' method to robot and doing this instead |
179 // wolud allow me to treat robots and other cellTypes equaly | 206 // wolud allow me to treat robots and other cellTypes equaly |