Mercurial > repos > icfp2012
annotate 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 |
rev | line source |
---|---|
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
1 { |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
2 null <- #{} |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
3 |
12 | 4 eachbyte <- :string action { |
5 strLen <- string byte_length: | |
6 index <- 0 | |
7 while: {index < strLen} do: { | |
8 element <- (string byte: index) | |
9 action: index element | |
10 index <- index + 1 | |
11 } | |
12 } | |
13 | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
14 debugLog <- :str { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
15 os write: 2 str |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
16 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
17 |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
18 makeCellTypes <- { |
31 | 19 typedict <- dict linear |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
20 new <- :idStr { |
36
814e3d482ad3
Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
21 cannav <- if: idStr = " " {true} else: { |
814e3d482ad3
Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
22 if: idStr = "." {true} else: { |
814e3d482ad3
Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
23 if: idStr = "\\" {true} else: { |
814e3d482ad3
Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
24 if: idStr = "O" {true} else: { |
814e3d482ad3
Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents:
35
diff
changeset
|
25 false }}}} |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
26 ret <- #{ |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
27 id <- (idStr byte: 0) |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
28 string <- idStr |
10 | 29 isrobot <- { false } |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
30 eq <- :other { id = (other id) } |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
31 navigable <- { cannav } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
32 } |
31 | 33 typedict set: (ret id) ret |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
34 ret |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
35 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
36 #{ |
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
|
37 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
|
38 if: id = ("R" byte: 0) { robot: } else: { |
31 | 39 typedict get: id withDefault: empty |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
40 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
41 } |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
42 wall <- new: "#" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
43 empty <- new: " " |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
44 earth <- new: "." |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
45 rock <- new: "*" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
46 lambda <- new: "\\" |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
47 closedLift <- new: "L" |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
48 openLift <- new: "O" |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
49 newline <- new: "\n" |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
50 robot <- { |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
51 commands <- dict linear |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
52 ret <- #{ |
23 | 53 id <- ("R" byte: 0) |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
54 string <- "R" |
23 | 55 x <- 0 |
56 y <- 0 | |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
57 isrobot <- { true } |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
58 eq <- :other { id = (other id) } |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
59 collected <- 0 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
60 heldBreath <- 0 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
61 razors <- 0 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
62 busted <- false |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
63 mine <- null |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
64 doCmd <- :cmd { |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
65 action <- commands get: cmd withDefault: { null } |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
66 action: |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
67 } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
68 move <- :xDelta yDelta { |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
69 xPrime <- x + xDelta |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
70 yPrime <- y + yDelta |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
71 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
72 writeMove <- { |
23 | 73 mine setCell: xPrime yPrime self |
74 mine setCell: x y empty | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
75 x <- xPrime |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
76 y <- yPrime |
23 | 77 } |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
78 |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
79 consequenceOf <- :cur { |
35 | 80 if: (cur eq: lambda) {collected <- collected + 1} |
81 if: (cur eq: openLift) {mine succeeded!: true} | |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
82 } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
83 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
84 destination <- mine getCell: xPrime yPrime |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
85 if: (destination navigable: ) { |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
86 consequenceOf: destination |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
87 writeMove: |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
88 } else: { |
35 | 89 if: (destination eq: rock) { |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
90 xPrimePrime <- xDelta * 2 + x |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
91 rockDestination <- mine getCell: xPrimePrime y |
35 | 92 if: (rockDestination eq: empty) { |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
93 mine setCell: xPrimePrime y rock |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
94 writeMove: |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
95 } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
96 } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
97 } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
98 |
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
|
99 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
100 } |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
101 commands set: "L" {ret move: (-1) 0 } |
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
102 commands set: "R" {ret move: 1 0 } |
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
103 commands set: "U" {ret move: 0 1 } |
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
104 commands set: "D" {ret move: 0 (-1) } |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
105 //commands set: "A" {mine ended!: true} |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
106 ret |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
107 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
108 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
109 } |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
110 #{ |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
111 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
112 cellTypes <- makeCellTypes: |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
113 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
114 state <- #{ |
6 | 115 new <- :in_grid in_width in_height { |
10 | 116 nextGrid <- #[] |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
117 robot <- null |
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
|
118 endreached <- false |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
119 _lambdaCount <- 0 |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
120 _succeeded <- false |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
121 ret <- #{ |
8 | 122 grid <- in_grid |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
123 width <- in_width |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
124 height <- in_height |
23 | 125 calcIndex <- :x y { x + y * width } |
126 calcX <- :index {index % width} | |
127 calcY <- :index {index / width} | |
10 | 128 setCell <- :x y val { |
23 | 129 grid set: (calcIndex: x y) val |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
130 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
131 getCell <- :x y { |
23 | 132 grid get: (calcIndex: x y) |
133 } | |
134 updatePos <- :obj Index { | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
135 obj x!: (calcX: Index) |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
136 obj y!: (calcY: Index) |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
137 } |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
138 lambdaCount <- {_lambdaCount} |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
139 water <- 0 |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
140 flooding <- 0 |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
141 waterproof <- 10 |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
142 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
|
143 ended <- {endreached} |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
144 succeeded <- {_succeeded} |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
145 succeeded! <- :newval { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
146 endreached <- newval |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
147 _succeeded <- newval |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
148 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
149 doUpdate <- { |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
150 foreach: grid :index value { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
151 if: (value eq: (cellTypes rock)) { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
152 x <- calcX: index |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
153 y <- calcY: index |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
154 below <- getCell: x (y - 1) |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
155 if: (below eq: (cellTypes empty)) { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
156 setCell: x y (cellTypes empty) |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
157 setCell: x (y - 1) value |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
158 } |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
159 } else: { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
160 if: (value eq: (cellTypes closedLift)) { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
161 if: (robot collected) = _lambdaCount { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
162 grid set: index (cellTypes openLift) |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
163 } |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
164 } |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
165 } |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
166 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
167 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
168 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
|
169 endreached <- roboCmd = "A" |
35 | 170 if: (not: endreached) { |
171 robot doCmd: roboCmd | |
172 moves <- moves + 1 | |
173 doUpdate: | |
174 } | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
175 self |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
176 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
177 printGrid <- { |
32 | 178 cur <- (grid length) - width |
179 col <- 0 | |
180 while: {cur >= 0} do: { | |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
181 os write: 2 ((grid get: cur) string) |
32 | 182 cur <- cur + 1 |
183 col <- col + 1 | |
184 if: col = width { | |
185 col <- 0 | |
186 cur <- cur - (width + width) | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
187 os write: 2 "\n" |
23 | 188 } |
189 } | |
32 | 190 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
191 } |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
192 foreach: in_grid :index el{ |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
193 nextGrid append: el |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
194 if: (el isrobot) { |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
195 robot <- el |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
196 robot mine!: ret |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
197 ret updatePos: robot index |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
198 } else: { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
199 if: (el eq: (cellTypes lambda)) { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
200 _lambdaCount <- _lambdaCount + 1 |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
201 } |
30
031d46ff76a9
minor clean up to use 'if' and 'not'
William Morgan <bill@mrgn.org>
parents:
29
diff
changeset
|
202 } |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
203 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
204 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
205 // adding a 'new' method to robot and doing this instead |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
206 // wolud allow me to treat robots and other cellTypes equaly |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
207 // particularly for adding methods or state to other cellTypess. |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
208 // |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
209 // if: (el = (cellTypes robot)) { |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
210 // robot <- el new: |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
211 // (ret grid) set: index robot |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
212 // robot mine!: ret |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
213 // ret updatePos: robot index |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
214 // nextGrid append: el |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
215 // } else: { |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
216 // nextGrid append: el |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
217 // } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
218 |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
219 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
220 ret |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
221 } |
32 | 222 |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
223 fromStr <- :str { |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 blank <- cellTypes empty |
32 | 228 lines <- #[] |
229 curline <- #[] | |
12 | 230 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
|
231 if: element = nl { |
32 | 232 col <- curline length |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
233 maxCol <- if: col > maxCol {col} else: {maxCol} |
32 | 234 lines append: curline |
235 curline <- #[] | |
10 | 236 } else: { |
32 | 237 curline append: (cellTypes find: element) |
10 | 238 } |
239 } | |
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
|
240 grid <- #[] |
32 | 241 cur <- (lines length) - 1 |
242 while: { cur >= 0 } do: { | |
243 curline <- (lines get: cur) | |
244 foreach: curline :idx el { | |
245 grid append: el | |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
246 } |
32 | 247 extra <- maxCol - (curline length) |
248 while: { extra > 0 } do: { | |
249 grid append: blank | |
250 extra <- extra - 1 | |
251 } | |
252 cur <- cur - 1 | |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
253 } |
32 | 254 new: grid maxCol (lines length) |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
255 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
256 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
257 |
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
|
258 readFd <- :fd { |
8 | 259 if: fd < 0 { "" } else: { |
260 cur <- "" | |
261 part <- "" | |
262 while: { | |
263 part <- os read: fd 128 | |
264 part != "" | |
265 } do: { | |
266 cur <- cur . part | |
267 } | |
268 cur | |
269 } | |
270 } | |
271 | |
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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 } |
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
|
278 |
8 | 279 getMove <- { |
29 | 280 ret <- os read: 0 1 |
281 while: {ret = "\n"} do: { | |
282 ret <- os read: 0 1 | |
283 } | |
284 ret | |
3
bb29dcd46cbf
Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
285 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
286 |
8 | 287 main <- :args { |
288 if: (args length) < 2 { | |
289 print: "usage: sim filename\n" | |
290 } else: { | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
291 verbose <- true |
8 | 292 text <- readFile: (args get: 1) |
14 | 293 print: text |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
294 //os close: 1 |
8 | 295 simState <- state fromStr: text |
30
031d46ff76a9
minor clean up to use 'if' and 'not'
William Morgan <bill@mrgn.org>
parents:
29
diff
changeset
|
296 while: { not: (simState ended: ) } do: { |
8 | 297 simState advance: (getMove: ) |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
298 if: verbose { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
299 simState printGrid |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
300 } |
8 | 301 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
302 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
303 } |
8 | 304 |
3
bb29dcd46cbf
Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
305 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
306 } |