annotate src/sim.tp @ 28:7a274d6026c8

Use built-in true and false.
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 19:33:35 -0700
parents a224dc43877f
children d9f1a063a466
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 {
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
2 eachbyte <- :string action {
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
3 strLen <- string byte_length:
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
4 index <- 0
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
5 while: {index < strLen} do: {
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
6 element <- (string byte: index)
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
7 action: index element
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
8 index <- index + 1
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
9 }
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
10 }
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
11
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
12 debugLog <- :str {
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
13 os write: 2 str
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
14 }
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
15
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
16 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
17 allid <- #[]
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
18 allobj <- #[]
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
19 new <- :idStr {
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
20 ret <- #{
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
21 id <- (idStr byte: 0)
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
22 str <- idStr
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
23 isrobot <- { false }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
24 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
25 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
26 allid append: (ret id)
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
27 ret
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
28 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
29 #{
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
30 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
31 if: id = ("R" byte: 0) { robot: } else: {
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
32 index <- 0
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
33 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
34 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
35 (allid get: index) != id
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
36 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
37 } do: {
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
38 index <- index + 1
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
39 }
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
40 if: index < (allid length) {
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
41 allobj get: index
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
42 } else: {
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
43 empty
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
44 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
45 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
46 }
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
47 wall <- new: "#"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
48 empty <- new: " "
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
49 earth <- new: "."
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
50 rock <- new: "*"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
51 lambda <- new: "\\"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
52 closedlift <- new: "L"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
53 openlift <- new: "O"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
54 newline <- new: "\n"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
55 robot <- {
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
56 #{
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
57 id <- ("R" byte: 0)
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
58 str <- "R"
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
59 isrobot <- { true }
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
60 heldBreath <- 0
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
61 x <- 0
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
62 y <- 0
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
63 move <- :cmd mine {
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
64 writeMove <- :xPrime yPrime {
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
65 mine setCell: xPrime yPrime self
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
66 mine setCell: x y empty
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
67 x <- xPrime
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
68 y <- yPrime
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
69 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
70 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
71 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
72 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
73 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
74 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
75 }
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
76 #{
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
77
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
78 cellTypes <- makeCellTypes:
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
79
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
80 state <- #{
6
86cdb799f950 unbarfed some things
William Morgan <bill@mrgn.org>
parents: 5
diff changeset
81 new <- :in_grid in_width in_height {
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
82 nextGrid <- #[]
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
83 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
84 endreached <- false
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
85 ret <- #{
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
86 grid <- in_grid
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
87 width <- in_width
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
88 height <- in_height
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
89 calcIndex <- :x y { x + y * width }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
90 calcX <- :index {index % width}
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
91 calcY <- :index {index / width}
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
92 setCell <- :x y val {
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
93 grid set: (calcIndex: x y) val
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
94 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
95 getCell <- :x y {
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
96 grid get: (calcIndex: x y)
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
97 }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
98 updatePos <- :obj Index {
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
99 obj x!: (calcX: Index)
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
100 obj y!: (calcY: Index)
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
101 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
102 water <- 0
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
103 flooding <- 0
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
104 waterproof <- 10
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
105 collected <- 0
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
106 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
107 ended <- {endreached}
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
108 doUpdate <- {
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
109 true
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
110 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
111 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
112 endreached <- roboCmd = "A"
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
113 robot move: roboCmd self
6
86cdb799f950 unbarfed some things
William Morgan <bill@mrgn.org>
parents: 5
diff changeset
114 moves <- moves + 1
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
115 doUpdate:
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
116 self
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
117 }
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
118 printGrid <- {
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
119 grid foreach: :index value {
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
120 os write: 2 (value str)
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
121 if: index % width = width - 1 {
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
122 os write: 2 "\n"
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
123 }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
124 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
125 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
126 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
127 foreach: in_grid :index el{
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
128 nextGrid append: el
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
129 if: (el isrobot) {
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
130 robot <- el
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
131 ret updatePos: robot index
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
132 } else: { true }
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
133 }
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
134 ret
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
135 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
136 fromStr <- :str {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
137 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
138 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
139 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
140 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
141 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
142 blank <- cellTypes empty
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
143 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
144 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
145 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
146 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
147 rows <- rows + 1
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
148 } 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
149 col <- col + 1
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
150 }
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
151 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
152 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
153 grid <- #[]
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
154 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
155 if: element = nl {
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
156 // 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
157 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
158 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
159 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
160 }
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
161 col <- 0
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
162 } 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
163 grid append: (cellTypes find: element)
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
164 col <- col + 1
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
165 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
166 }
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
167 new: grid maxCol rows
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
168 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
169 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
170
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
171 testMoves <- {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
172 myStep <- 0
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
173 {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
174 myStep <- myStep + 1
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
175 if: myStep > 5 {"A"} else: {"W"}
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
176 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
177 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
178
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
179 readFd <- :fd {
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
180 if: fd < 0 { "" } else: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
181 cur <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
182 part <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
183 while: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
184 part <- os read: fd 128
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
185 part != ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
186 } do: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
187 cur <- cur . part
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
188 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
189 cur
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
190 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
191 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
192
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
193 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
194 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
195 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
196 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
197 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
198 }
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
199
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
200 getMove <- {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
201 os read: 0 1
3
bb29dcd46cbf Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
202 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
203
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
204 main <- :args {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
205 if: (args length) < 2 {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
206 print: "usage: sim filename\n"
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
207 } else: {
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
208 verbose <- true
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
209 text <- readFile: (args get: 1)
14
26cfb964fe81 removed debug printing
William Morgan <bill@mrgn.org>
parents: 13
diff changeset
210 print: text
17
998ef2173f28 colse stdout file descriptor
William Morgan <bill@mrgn.org>
parents: 14
diff changeset
211 os close: 1
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
212 simState <- state fromStr: text
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
213 derp <- simState ended:
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
214 while: { if: (simState ended: ) {false} else: {true} } do: {
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
215 simState advance: (getMove: )
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
216 if: verbose {
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
217 simState printGrid
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
218 }
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
219 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
220 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
221 }
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
222
3
bb29dcd46cbf Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
223 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
224 }