Mercurial > repos > icfp2012
annotate src/sim.tp @ 25:a224dc43877f
major progress! ...robot always moves down though
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sat, 14 Jul 2012 19:05:56 -0700 |
parents | 8435bf0360f8 |
children | 7a274d6026c8 |
rev | line source |
---|---|
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
1 { |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
2 true <- #{ |
23 | 3 if <- :self trueblock { |
4 trueblock: | |
5 } | |
6 if:else <- :self trueblock :elseblock { | |
7 trueblock: | |
8 } | |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
9 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
10 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
11 false <- #{ |
23 | 12 if <- :self trueblock { |
13 self | |
14 } | |
15 if:else <- :self trueblock :elseblock { | |
16 elseblock: | |
17 } | |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
18 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
19 |
12 | 20 eachbyte <- :string action { |
21 strLen <- string byte_length: | |
22 index <- 0 | |
23 while: {index < strLen} do: { | |
24 element <- (string byte: index) | |
25 action: index element | |
26 index <- index + 1 | |
27 } | |
28 } | |
29 | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
30 debugLog <- :str { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
31 os write: 2 str |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
32 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
33 |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
34 makeCellTypes <- { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
35 allid <- #[] |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
36 allobj <- #[] |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
37 new <- :idStr { |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
38 ret <- #{ |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
39 id <- (idStr byte: 0) |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
40 str <- idStr |
10 | 41 isrobot <- { false } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
42 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
43 allobj append: ret |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
44 allid append: (ret id) |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
45 ret |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
46 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
47 #{ |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
48 find <- :id { |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
49 if: id = ("R" byte: 0) { robot: } else: { |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
50 index <- 0 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
51 while: { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
52 if: index < (allid length) { |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
53 (allid get: index) != id |
23 | 54 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
55 } do: { |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
56 index <- index + 1 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
57 } |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
58 if: index < (allid length) { |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
59 allobj get: index |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
60 } else: { |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
61 empty |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
62 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
63 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
64 } |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
65 wall <- new: "#" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
66 empty <- new: " " |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
67 earth <- new: "." |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
68 rock <- new: "*" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
69 lambda <- new: "\\" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
70 closedlift <- new: "L" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
71 openlift <- new: "O" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
72 newline <- new: "\n" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
73 robot <- { |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
74 #{ |
23 | 75 id <- ("R" byte: 0) |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
76 str <- "R" |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
77 isrobot <- { true } |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
78 heldBreath <- 0 |
23 | 79 x <- 0 |
80 y <- 0 | |
81 move <- :cmd mine { | |
82 writeMove <- :xPrime yPrime { | |
83 mine setCell: xPrime yPrime self | |
84 mine setCell: x y empty | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
85 x <- xPrime |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
86 y <- yPrime |
23 | 87 } |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
88 writeMove: x (y + 1) |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
89 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
90 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
91 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
92 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
93 } |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
94 ttrue <- true |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
95 tfalse <- false |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
96 #{ |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
97 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
98 // utilities |
12 | 99 true <- ttrue |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
100 |
12 | 101 false <- tfalse |
102 | |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
103 // end utilities |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
104 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
105 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
106 cellTypes <- makeCellTypes: |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
107 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
108 state <- #{ |
6 | 109 new <- :in_grid in_width in_height { |
10 | 110 nextGrid <- #[] |
111 robot <- false | |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
112 endreached <- false |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
113 ret <- #{ |
8 | 114 grid <- in_grid |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
115 width <- in_width |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
116 height <- in_height |
23 | 117 calcIndex <- :x y { x + y * width } |
118 calcX <- :index {index % width} | |
119 calcY <- :index {index / width} | |
10 | 120 setCell <- :x y val { |
23 | 121 grid set: (calcIndex: x y) val |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
122 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
123 getCell <- :x y { |
23 | 124 grid get: (calcIndex: x y) |
125 } | |
126 updatePos <- :obj Index { | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
127 obj x!: (calcX: Index) |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
128 obj y!: (calcY: Index) |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
129 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
130 water <- 0 |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
131 flooding <- 0 |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
132 waterproof <- 10 |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
133 collected <- 0 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
134 moves <- 0 |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
135 ended <- {endreached} |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
136 doUpdate <- { |
12 | 137 true |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
138 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
139 advance <- :roboCmd { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
140 endreached <- roboCmd = "A" |
23 | 141 robot move: roboCmd self |
6 | 142 moves <- moves + 1 |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
143 doUpdate: |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
144 self |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
145 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
146 printGrid <- { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
147 grid foreach: :index value { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
148 os write: 2 (value str) |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
149 if: index % width = width - 1 { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
150 os write: 2 "\n" |
23 | 151 } |
152 } | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
153 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
154 } |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
155 foreach: in_grid :index el{ |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
156 nextGrid append: el |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
157 if: (el isrobot) { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
158 robot <- el |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
159 ret updatePos: robot index |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
160 } else: { true } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
161 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
162 ret |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
163 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
164 fromStr <- :str { |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
165 strLen <- str byte_length: |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
166 maxCol <- 0 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
167 col <- 0 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
168 rows <- 0 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
169 nl <- (cellTypes newline) id |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
170 blank <- cellTypes empty |
12 | 171 eachbyte: str :index element { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
172 if: element = nl { |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
173 maxCol <- if: col > maxCol {col} else: {maxCol} |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
174 col <- 0 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
175 rows <- rows + 1 |
10 | 176 } else: { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
177 col <- col + 1 |
10 | 178 } |
179 } | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
180 col <- 0 |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
181 grid <- #[] |
12 | 182 eachbyte: str :index element { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
183 if: element = nl { |
10 | 184 // add spaces |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
185 while: { col < maxCol } do: { |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
186 grid append: blank |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
187 col <- col + 1 |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
188 } |
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
189 col <- 0 |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
190 } else: { |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
191 grid append: (cellTypes find: element) |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
192 col <- col + 1 |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
193 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
194 } |
13
c92633098f1d
simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents:
12
diff
changeset
|
195 new: grid maxCol rows |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
196 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
197 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
198 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
199 testMoves <- { |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
200 myStep <- 0 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
201 { |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
202 myStep <- myStep + 1 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
203 if: myStep > 5 {"A"} else: {"W"} |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
204 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
205 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
206 |
20
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
207 readFd <- :fd { |
8 | 208 if: fd < 0 { "" } else: { |
209 cur <- "" | |
210 part <- "" | |
211 while: { | |
212 part <- os read: fd 128 | |
213 part != "" | |
214 } do: { | |
215 cur <- cur . part | |
216 } | |
217 cur | |
218 } | |
219 } | |
220 | |
20
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
221 readFile <- :path { |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
222 fd <- os open: path (os O_RDONLY) |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
223 out <- readFd: fd |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
224 os close: fd |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
225 out |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
226 } |
50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
227 |
8 | 228 getMove <- { |
229 os read: 0 1 | |
3
bb29dcd46cbf
Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
230 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
231 |
8 | 232 main <- :args { |
233 if: (args length) < 2 { | |
234 print: "usage: sim filename\n" | |
235 } else: { | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
236 verbose <- true |
8 | 237 text <- readFile: (args get: 1) |
14 | 238 print: text |
17 | 239 os close: 1 |
8 | 240 simState <- state fromStr: text |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
241 derp <- simState ended: |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
242 while: { if: (simState ended: ) {false} else: {true} } do: { |
8 | 243 simState advance: (getMove: ) |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
244 if: verbose { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
245 simState printGrid |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
246 } |
8 | 247 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
248 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
249 } |
8 | 250 |
3
bb29dcd46cbf
Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
251 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
252 } |