Mercurial > repos > icfp2012
comparison src/sim.tp @ 23:75a005b210c5
almost got movement
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sat, 14 Jul 2012 14:38:21 -0700 |
parents | 998ef2173f28 |
children | 8435bf0360f8 |
comparison
equal
deleted
inserted
replaced
18:883ae0c1b7f6 | 23:75a005b210c5 |
---|---|
1 { | 1 { |
2 true <- #{ | 2 true <- #{ |
3 if:else <- :self trueblock :elseblock { | 3 if <- :self trueblock { |
4 trueblock: | 4 trueblock: |
5 } | 5 } |
6 if:else <- :self trueblock :elseblock { | |
7 trueblock: | |
8 } | |
6 } | 9 } |
7 | 10 |
8 false <- #{ | 11 false <- #{ |
9 if:else <- :self trueblock :elseblock { | 12 if <- :self trueblock { |
10 elseblock: | 13 self |
11 } | 14 } |
15 if:else <- :self trueblock :elseblock { | |
16 elseblock: | |
17 } | |
12 } | 18 } |
13 | 19 |
14 eachbyte <- :string action { | 20 eachbyte <- :string action { |
15 strLen <- string byte_length: | 21 strLen <- string byte_length: |
16 index <- 0 | 22 index <- 0 |
38 if: id = ("R" byte: 0) { robot: } else: { | 44 if: id = ("R" byte: 0) { robot: } else: { |
39 index <- 0 | 45 index <- 0 |
40 while: { | 46 while: { |
41 if: index < (allid length) { | 47 if: index < (allid length) { |
42 (allid get: index) != id | 48 (allid get: index) != id |
43 } else: {false} | 49 } |
44 } do: { | 50 } do: { |
45 index <- index + 1 | 51 index <- index + 1 |
46 } | 52 } |
47 if: index < (allid length) { | 53 if: index < (allid length) { |
48 allobj get: index | 54 allobj get: index |
59 closedlift <- new: "L" | 65 closedlift <- new: "L" |
60 openlift <- new: "O" | 66 openlift <- new: "O" |
61 newline <- new: "\n" | 67 newline <- new: "\n" |
62 robot <- { | 68 robot <- { |
63 #{ | 69 #{ |
64 id <- ("R" byte: 0) | 70 id <- ("R" byte: 0) |
65 isrobot <- { true } | 71 isrobot <- { true } |
66 heldBreath <- 0 | 72 heldBreath <- 0 |
67 move <- :cmd { | 73 x <- 0 |
68 cmd | 74 y <- 0 |
75 move <- :cmd mine { | |
76 writeMove <- :xPrime yPrime { | |
77 mine setCell: xPrime yPrime self | |
78 mine setCell: x y empty | |
79 x!: xPrime | |
80 y!: yPrime | |
81 } | |
82 writeMove: x (y - 1) | |
69 } | 83 } |
70 } | 84 } |
71 } | 85 } |
72 } | 86 } |
73 } | 87 } |
91 robot <- false | 105 robot <- false |
92 endreached <- false | 106 endreached <- false |
93 foreach: in_grid :index el{ | 107 foreach: in_grid :index el{ |
94 nextGrid append: el | 108 nextGrid append: el |
95 if: (el isrobot) { | 109 if: (el isrobot) { |
96 robot <- el | 110 robot <- el |
111 updatePos: robot index | |
97 } else: { true } | 112 } else: { true } |
98 } | 113 } |
99 #{ | 114 #{ |
100 grid <- in_grid | 115 grid <- in_grid |
101 width <- in_width | 116 width <- in_width |
102 height <- in_height | 117 height <- in_height |
103 address <- :x y { x + y * width } | 118 calcIndex <- :x y { x + y * width } |
119 calcX <- :index {index % width} | |
120 calcY <- :index {index / width} | |
104 setCell <- :x y val { | 121 setCell <- :x y val { |
105 grid set: (address: x y) val | 122 grid set: (calcIndex: x y) val |
106 } | 123 } |
107 getCell <- :x y { | 124 getCell <- :x y { |
108 grid get: (address: x y) | 125 grid get: (calcIndex: x y) |
126 } | |
127 updatePos <- :obj Index { | |
128 obj x! (calcX: Index) | |
129 obj y! (calcY: Index) | |
109 } | 130 } |
110 water <- 0 | 131 water <- 0 |
111 flooding <- 0 | 132 flooding <- 0 |
112 waterproof <- 10 | 133 waterproof <- 10 |
113 collected <- 0 | 134 collected <- 0 |
116 doUpdate <- { | 137 doUpdate <- { |
117 true | 138 true |
118 } | 139 } |
119 advance <- :roboCmd { | 140 advance <- :roboCmd { |
120 endreached <- roboCmd = "A" | 141 endreached <- roboCmd = "A" |
121 robot move: roboCmd | 142 robot move: roboCmd self |
122 moves <- moves + 1 | 143 moves <- moves + 1 |
123 doUpdate: | 144 doUpdate: |
145 if: debugToStdErr { | |
146 grid foreach: :index value { | |
147 os write: 2 (string: (value id)) | |
148 } | |
149 } | |
124 self | 150 self |
125 } | 151 } |
126 | 152 |
127 } | 153 } |
128 } | 154 } |
188 | 214 |
189 getMove <- { | 215 getMove <- { |
190 os read: 0 1 | 216 os read: 0 1 |
191 } | 217 } |
192 | 218 |
219 debugToStdErr <- true | |
193 main <- :args { | 220 main <- :args { |
194 if: (args length) < 2 { | 221 if: (args length) < 2 { |
195 print: "usage: sim filename\n" | 222 print: "usage: sim filename\n" |
196 } else: { | 223 } else: { |
197 text <- readFile: (args get: 1) | 224 text <- readFile: (args get: 1) |