annotate src/sim.tp @ 43:1f583d85c8ed

rocks slide correctly now. rock movement is complete.
author William Morgan <bill@mrgn.org>
date Sun, 15 Jul 2012 16:45:42 -0700
parents 21b14768ea00
children 5d2e59cbbc7c ccaecf1d6425
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 {
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
2 null <- #{}
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
3
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
4 eachbyte <- :string action {
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
5 strLen <- string byte_length:
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
6 index <- 0
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
7 while: {index < strLen} do: {
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
8 element <- (string byte: index)
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
9 action: index element
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
10 index <- index + 1
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
11 }
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
12 }
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
13
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
14 debugLog <- :str {
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
15 os write: 2 str
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
16 }
39
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
17
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
18 abs <- :val {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
19 if: val < 0 { 0 - val } else: { val }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
20 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
21
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
22 makeCellTypes <- {
31
f7a1daaec925 Use dictionary
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
23 typedict <- dict linear
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
24 new <- :idStr {
36
814e3d482ad3 Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
25 cannav <- if: idStr = " " {true} else: {
814e3d482ad3 Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
26 if: idStr = "." {true} else: {
814e3d482ad3 Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
27 if: idStr = "\\" {true} else: {
814e3d482ad3 Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
28 if: idStr = "O" {true} else: {
814e3d482ad3 Make navigable a property of the cell type so I can use it in lifter
Mike Pavone <pavone@retrodev.com>
parents: 35
diff changeset
29 false }}}}
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
30 ret <- #{
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
31 id <- (idStr byte: 0)
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
32 string <- idStr
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
33 isrobot <- { false }
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
34 eq <- :other { id = (other id) }
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
35 navigable <- { cannav }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
36 }
31
f7a1daaec925 Use dictionary
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
37 typedict set: (ret id) ret
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
38 ret
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
39 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
40 #{
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
41 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
42 if: id = ("R" byte: 0) { robot: } else: {
31
f7a1daaec925 Use dictionary
Mike Pavone <pavone@retrodev.com>
parents: 30
diff changeset
43 typedict get: id withDefault: empty
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
44 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
45 }
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
46 wall <- new: "#"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
47 empty <- new: " "
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
48 earth <- new: "."
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
49 rock <- new: "*"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
50 lambda <- new: "\\"
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
51 closedLift <- new: "L"
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
52 openLift <- new: "O"
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
53 newline <- new: "\n"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
54 robot <- {
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
55 commands <- dict linear
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
56 ret <- #{
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
57 id <- ("R" byte: 0)
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
58 string <- "R"
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
59 x <- 0
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
60 y <- 0
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
61 isrobot <- { true }
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
62 eq <- :other { id = (other id) }
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
63 collected <- 0
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
64 heldBreath <- 0
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
65 razors <- 0
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
66 busted <- false
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
67 mine <- null
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
68 doCmd <- :cmd {
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
69 action <- commands get: cmd withDefault: { null }
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
70 action:
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
71 }
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
72 move <- :xDelta yDelta {
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
73 xPrime <- x + xDelta
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
74 yPrime <- y + yDelta
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
75
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
76 writeMove <- {
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
77 mine setCell: xPrime yPrime self
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
78 mine setCell: x y empty
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
79 x <- xPrime
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
80 y <- yPrime
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
81 }
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
82
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
83 consequenceOf <- :cur {
35
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
84 if: (cur eq: lambda) {collected <- collected + 1}
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
85 if: (cur eq: openLift) {mine succeeded!: true}
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
86 }
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
87
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
88 destination <- mine getCell: xPrime yPrime
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
89 if: (destination navigable: ) {
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
90 consequenceOf: destination
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
91 writeMove:
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
92 } else: {
35
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
93 if: (destination eq: rock) {
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
94 xPrimePrime <- xDelta * 2 + x
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
95 rockDestination <- mine getCell: xPrimePrime y
35
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
96 if: (rockDestination eq: empty) {
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
97 mine setCell: xPrimePrime y rock
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
98 writeMove:
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
99 }
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
100 }
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
101 }
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
102
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
103 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
104 }
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
105 commands set: "L" {ret move: (-1) 0 }
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
106 commands set: "R" {ret move: 1 0 }
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
107 commands set: "U" {ret move: 0 1 }
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
108 commands set: "D" {ret move: 0 (-1) }
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
109 //commands set: "A" {mine ended!: true}
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
110 ret
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
111 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
112 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
113 }
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
114 #{
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
115
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
116 cellTypes <- makeCellTypes:
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
117
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
118 state <- #{
6
86cdb799f950 unbarfed some things
William Morgan <bill@mrgn.org>
parents: 5
diff changeset
119 new <- :in_grid in_width in_height {
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
120 nextGrid <- #[]
39
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
121 _robot <- null
13
c92633098f1d simulator now properly parses map and accepts input until A is sent to it over stdin
Mike Pavone <pavone@retrodev.com>
parents: 12
diff changeset
122 endreached <- false
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
123 _lambdaCount <- 0
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
124 _succeeded <- false
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
125 ret <- #{
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
126 grid <- in_grid
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
127 width <- in_width
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
128 height <- in_height
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
129 calcIndex <- :x y { x + y * width }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
130 calcX <- :index {index % width}
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
131 calcY <- :index {index / width}
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
132 setCell <- :x y val {
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
133 grid set: (calcIndex: x y) val
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
134 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
135 getCell <- :x y {
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
136 grid get: (calcIndex: x y)
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
137 }
39
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
138 validDest?:from <- :index :fromIndex {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
139 cell <- (grid get: index)
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
140 if: (cell navigable) {true} else: {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
141 if: (cell eq: (cellTypes rock)) {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
142 diff <- index - fromIndex
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
143 //make sure movement was horizontal
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
144 if: (abs: diff) = 1 {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
145 rockdest <- index + diff
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
146 if: ((grid get: rockdest) eq: (cellTypes empty)) {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
147 //make sure rock destination doesn't wrap
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
148 (calcY: rockdest) = (calcY: index)
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
149 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
150 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
151 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
152 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
153 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
154 validMoves <- :x y {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
155
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
156 amove <- :idx name {#{
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
157 index <- idx
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
158 cmd <- name
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
159 string <- {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
160 name . "(" . idx . ")"
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
161 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
162 }}
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
163 here <- calcIndex: x y
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
164 //TODO: Add wait move when rocks are in motion
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
165 //(amove: here "W")
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
166 cur <- #[(amove: here "A")]
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
167 up <- amove: (calcIndex: x y + 1) "U"
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
168 down <- amove: (calcIndex: x y - 1) "D"
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
169 left <- amove: (calcIndex: x - 1 y) "L"
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
170 right <- amove: (calcIndex: x + 1 y) "R"
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
171 foreach: #[up down left right] :idx el {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
172 if: (validDest?: (el index) from: here) {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
173 cur append: el
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
174 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
175 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
176 cur
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
177 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
178 getRobot <- { _robot }
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
179 updatePos <- :obj Index {
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
180 obj x!: (calcX: Index)
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
181 obj y!: (calcY: Index)
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
182 }
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
183 lambdaCount <- {_lambdaCount}
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
184 water <- 0
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
185 flooding <- 0
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
186 waterproof <- 10
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
187 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
188 ended <- {endreached}
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
189 succeeded <- {_succeeded}
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
190 succeeded! <- :newval {
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
191 endreached <- newval
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
192 _succeeded <- newval
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
193 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
194 doUpdate <- {
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
195 foreach: grid :index value {
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
196 if: (value eq: (cellTypes rock)) {
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
197 x <- calcX: index
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
198 y <- calcY: index
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
199 below <- getCell: x (y - 1)
43
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
200 fallToSide <- :delta {
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
201 side <- getCell: (x + delta) y
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
202 belowSide <- getCell: (x + delta) (y - 1)
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
203 if: (side eq: (cellTypes empty)) {
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
204 if: (belowSide eq: (cellTypes empty)) {
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
205 setCell: (x + delta) (y - 1) value
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
206 setCell: x y (cellTypes empty)
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
207 true
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
208 } else: { false }
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
209 } else: { false }
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
210 }
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
211 if: (below eq: (cellTypes empty)) {
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
212 setCell: x y (cellTypes empty)
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
213 setCell: x (y - 1) value
43
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
214 } else: { if: (below eq: (cellTypes rock)) {
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
215 if: (not: (fallToSide: 1)) {fallToSide: -1}
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
216 } else: { if: (below eq: (cellTypes lambda)) {
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
217 fallToSide: 1
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
218 }}} // end if
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
219 } else: {
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
220 if: (value eq: (cellTypes closedLift)) {
41
20327ae2120b merged.
William Morgan <bill@mrgn.org>
parents: 40 39
diff changeset
221 if: (_robot collected) = _lambdaCount {
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
222 grid set: index (cellTypes openLift)
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
223 }
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
224 }
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
225 }
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
226 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
227 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
228 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
229 endreached <- roboCmd = "A"
35
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
230 if: (not: endreached) {
39
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
231 _robot doCmd: roboCmd
35
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
232 moves <- moves + 1
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
233 doUpdate:
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
234 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
235 self
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
236 }
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
237 printGrid <- {
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
238 cur <- (grid length) - width
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
239 col <- 0
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
240 while: {cur >= 0} do: {
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
241 os write: 2 ((grid get: cur) string)
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
242 cur <- cur + 1
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
243 col <- col + 1
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
244 if: col = width {
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
245 col <- 0
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
246 cur <- cur - (width + width)
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
247 os write: 2 "\n"
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
248 }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
249 }
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
250 }
39
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
251 clone <- {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
252 cgrid <- #[]
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
253 foreach: grid :idx el {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
254 if: (el isrobot) {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
255 cgrid append: (cellTypes robot)
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
256 } else: {
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
257 cgrid append: el
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
258 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
259 }
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
260 myclone <- state new: cgrid width height
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
261 myclone water!: water
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
262 myclone flooding!: flooding
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
263 myclone waterproof!: waterproof
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
264 myclone moves!: moves
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
265 myclone
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
266 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
267 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
268 foreach: in_grid :index el{
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
269 nextGrid append: el
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
270 if: (el isrobot) {
39
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
271 _robot <- el
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
272 _robot mine!: ret
9bccdb3ac979 Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
Mike Pavone <pavone@retrodev.com>
parents: 36
diff changeset
273 ret updatePos: _robot index
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
274 } else: {
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
275 if: (el eq: (cellTypes lambda)) {
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
276 _lambdaCount <- _lambdaCount + 1
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
277 }
30
031d46ff76a9 minor clean up to use 'if' and 'not'
William Morgan <bill@mrgn.org>
parents: 29
diff changeset
278 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
279 }
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
280 ret
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
281 }
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
282
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
283 fromStr <- :str {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
284 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
285 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
286 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
287 blank <- cellTypes empty
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
288 lines <- #[]
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
289 curline <- #[]
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
290 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
291 if: element = nl {
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
292 col <- curline length
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
293 maxCol <- if: col > maxCol {col} else: {maxCol}
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
294 lines append: curline
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
295 curline <- #[]
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
296 } else: {
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
297 curline append: (cellTypes find: element)
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
298 }
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
299 }
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
300 grid <- #[]
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
301 cur <- (lines length) - 1
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
302 while: { cur >= 0 } do: {
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
303 curline <- (lines get: cur)
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
304 foreach: curline :idx el {
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
305 grid append: el
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
306 }
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
307 extra <- maxCol - (curline length)
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
308 while: { extra > 0 } do: {
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
309 grid append: blank
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
310 extra <- extra - 1
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
311 }
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
312 cur <- cur - 1
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
313 }
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
314 new: grid maxCol (lines length)
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
315 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
316 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
317
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
318 readFd <- :fd {
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
319 if: fd < 0 { "" } else: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
320 cur <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
321 part <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
322 while: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
323 part <- os read: fd 128
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
324 part != ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
325 } do: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
326 cur <- cur . part
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
327 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
328 cur
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
329 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
330 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
331
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
332 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
333 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
334 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
335 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
336 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
337 }
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
338
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
339 getMove <- {
29
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
340 ret <- os read: 0 1
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
341 while: {ret = "\n"} do: {
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
342 ret <- os read: 0 1
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
343 }
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
344 ret
3
bb29dcd46cbf Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
345 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
346
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
347 main <- :args {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
348 if: (args length) < 2 {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
349 print: "usage: sim filename\n"
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
350 } else: {
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
351 verbose <- true
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
352 text <- readFile: (args get: 1)
14
26cfb964fe81 removed debug printing
William Morgan <bill@mrgn.org>
parents: 13
diff changeset
353 print: text
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
354 //os close: 1
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
355 simState <- state fromStr: text
30
031d46ff76a9 minor clean up to use 'if' and 'not'
William Morgan <bill@mrgn.org>
parents: 29
diff changeset
356 while: { not: (simState ended: ) } do: {
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
357 simState advance: (getMove: )
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
358 if: verbose {
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
359 simState printGrid
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
360 }
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
361 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
362 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
363 }
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
364
3
bb29dcd46cbf Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
365 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
366 }