Mercurial > repos > icfp2012
comparison src/sim.tp @ 12:6ef6dc8ab95e
Get simulator compiling
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sat, 14 Jul 2012 03:07:02 -0700 |
parents | f28e465e9ee6 |
children | c92633098f1d |
comparison
equal
deleted
inserted
replaced
11:f28e465e9ee6 | 12:6ef6dc8ab95e |
---|---|
7 | 7 |
8 false <- #{ | 8 false <- #{ |
9 if:else <- :self trueblock :elseblock { | 9 if:else <- :self trueblock :elseblock { |
10 elseblock: | 10 elseblock: |
11 } | 11 } |
12 } | |
13 | |
14 eachbyte <- :string action { | |
15 strLen <- string byte_length: | |
16 index <- 0 | |
17 while: {index < strLen} do: { | |
18 element <- (string byte: index) | |
19 action: index element | |
20 index <- index + 1 | |
21 } | |
12 } | 22 } |
13 | 23 |
14 makeCellTypes <- { | 24 makeCellTypes <- { |
15 allstr <- #[] | 25 allstr <- #[] |
16 allobj <- #[] | 26 allobj <- #[] |
23 allstr append: idstr | 33 allstr append: idstr |
24 ret | 34 ret |
25 } | 35 } |
26 #{ | 36 #{ |
27 find <- :idstr { | 37 find <- :idstr { |
28 if: idstr = "R" { robot } else: { | 38 if: idstr = "R" { robot: } else: { |
29 index <- 0 | 39 index <- 0 |
30 while: { | 40 while: { |
31 if: index < (allstr length) { | 41 if: index < (allstr length) { |
32 (allstr get: index) != idstr | 42 (allstr get: index) != idstr |
33 } else: {false} | 43 } else: {false} |
61 ttrue <- true | 71 ttrue <- true |
62 tfalse <- false | 72 tfalse <- false |
63 #{ | 73 #{ |
64 | 74 |
65 // utilities | 75 // utilities |
66 true <- {ttrue} | 76 true <- ttrue |
67 | 77 |
68 false <- {tfalse} | 78 false <- tfalse |
69 | 79 |
70 foreach <- :string action { | |
71 strLen <- string byte_length: | |
72 index <- 0 | |
73 while: {index < strLen} do: { | |
74 element <- (string byte: index) | |
75 action: index element | |
76 index <- index + 1 | |
77 } | |
78 } | |
79 // end utilities | 80 // end utilities |
80 | 81 |
81 | 82 |
82 cellTypes <- makeCellTypes: | 83 cellTypes <- makeCellTypes: |
83 | 84 |
104 flooding <- 0 | 105 flooding <- 0 |
105 waterproof <- 10 | 106 waterproof <- 10 |
106 collected <- 0 | 107 collected <- 0 |
107 moves <- 0 | 108 moves <- 0 |
108 ended <- false | 109 ended <- false |
109 doMove <- :roboMove { | |
110 | |
111 robo <- doMove r | |
112 nexty <- doMove y | |
113 ended <- roboMove = "A" | |
114 } | |
115 doUpdate <- { | 110 doUpdate <- { |
116 updateCell <- :x y { | 111 true |
117 //if | |
118 } | |
119 } | 112 } |
120 advance <- :roboCmd { | 113 advance <- :roboCmd { |
114 ended <- roboCmd = "A" | |
121 robot move: roboCmd | 115 robot move: roboCmd |
122 moves <- moves + 1 | 116 moves <- moves + 1 |
123 doUpdate: | 117 doUpdate: |
124 self | 118 self |
125 } | 119 } |
129 fromStr <- :str { | 123 fromStr <- :str { |
130 | 124 |
131 strLen <- str byte_length: | 125 strLen <- str byte_length: |
132 maxRow <- 0 | 126 maxRow <- 0 |
133 curRow <- 0 | 127 curRow <- 0 |
134 foreach: str :index element { | 128 eachbyte: str :index element { |
135 if: element = ((cellTypes newline) id) { | 129 if: element = ((cellTypes newline) id) { |
136 maxRow <- if: curRow > maxRow {curRow} else: {maxRow} | 130 maxRow <- if: curRow > maxRow {curRow} else: {maxRow} |
137 curRow <- 0 | 131 curRow <- 0 |
138 } else: { | 132 } else: { |
139 curRow <- curRow + 1 | 133 curRow <- curRow + 1 |
140 } | 134 } |
141 } | 135 } |
142 | 136 |
143 foreach: str :index element { | 137 eachbyte: str :index element { |
144 if: element = ((cellTypes newline) id) { | 138 if: element = ((cellTypes newline) id) { |
145 // add spaces | 139 // add spaces |
146 curRow <- 0 | 140 curRow <- 0 |
147 } else: { | 141 } else: { |
148 curRow = curRow + 1 | 142 curRow = curRow + 1 |