annotate src/sim.tp @ 31:f7a1daaec925

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