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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
3 if <- :self trueblock {
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
4 trueblock:
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
5 }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
6 if:else <- :self trueblock :elseblock {
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
7 trueblock:
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
12 if <- :self trueblock {
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
13 self
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
14 }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
15 if:else <- :self trueblock :elseblock {
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
16 elseblock:
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
20 eachbyte <- :string action {
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
21 strLen <- string byte_length:
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
22 index <- 0
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
23 while: {index < strLen} do: {
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
24 element <- (string byte: index)
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
25 action: index element
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
26 index <- index + 1
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
27 }
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
28 }
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
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
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
79 x <- 0
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
80 y <- 0
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
81 move <- :cmd mine {
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
82 writeMove <- :xPrime yPrime {
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
83 mine setCell: xPrime yPrime self
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
99 true <- ttrue
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
100
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
101 false <- tfalse
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
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
86cdb799f950 unbarfed some things
William Morgan <bill@mrgn.org>
parents: 5
diff changeset
109 new <- :in_grid in_width in_height {
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
110 nextGrid <- #[]
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
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
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
117 calcIndex <- :x y { x + y * width }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
118 calcX <- :index {index % width}
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
119 calcY <- :index {index / width}
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
120 setCell <- :x y val {
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
124 grid get: (calcIndex: x y)
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
125 }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
141 robot move: roboCmd self
6
86cdb799f950 unbarfed some things
William Morgan <bill@mrgn.org>
parents: 5
diff changeset
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
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
151 }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
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
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
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
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
178 }
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
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
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
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
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
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
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
208 if: fd < 0 { "" } else: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
209 cur <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
210 part <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
211 while: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
212 part <- os read: fd 128
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
213 part != ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
214 } do: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
215 cur <- cur . part
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
216 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
217 cur
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
218 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
219 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
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
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
228 getMove <- {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
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
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
232 main <- :args {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
233 if: (args length) < 2 {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
234 print: "usage: sim filename\n"
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
235 } else: {
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
236 verbose <- true
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
237 text <- readFile: (args get: 1)
14
26cfb964fe81 removed debug printing
William Morgan <bill@mrgn.org>
parents: 13
diff changeset
238 print: text
17
998ef2173f28 colse stdout file descriptor
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
239 os close: 1
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
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
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
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
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
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
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
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 }