Mercurial > repos > icfp2012
annotate src/sim.tp @ 45:9f1ca5ba2684
Discard entries for which we can easily tell that it will be impossible for them to be better than the current best. This allows us to terminate when we cannot solve the map
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 15 Jul 2012 17:26:25 -0700 |
parents | 0c09730c173e |
children | 5d2e59cbbc7c |
rev | line source |
---|---|
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
1 { |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
2 null <- #{} |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
3 |
12 | 4 eachbyte <- :string action { |
5 strLen <- string byte_length: | |
6 index <- 0 | |
7 while: {index < strLen} do: { | |
8 element <- (string byte: index) | |
9 action: index element | |
10 index <- index + 1 | |
11 } | |
12 } | |
13 | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
14 debugLog <- :str { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
15 os write: 2 str |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
16 } |
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 | 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 | 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 | 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 | 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 | 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 | 59 x <- 0 |
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 | 77 mine setCell: xPrime yPrime self |
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 | 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 { |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
84 if: (cur eq: lambda) { |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
85 collected <- collected + 1 |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
86 mine addPoints: 25 |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
87 } |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
88 if: (cur eq: openLift) {mine succeeded!} |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
89 } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
90 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
91 destination <- mine getCell: xPrime yPrime |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
92 if: (destination navigable: ) { |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
93 consequenceOf: destination |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
94 writeMove: |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
95 } else: { |
35 | 96 if: (destination eq: rock) { |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
97 xPrimePrime <- xDelta * 2 + x |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
98 rockDestination <- mine getCell: xPrimePrime y |
35 | 99 if: (rockDestination eq: empty) { |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
100 mine setCell: xPrimePrime y rock |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
101 writeMove: |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
102 } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
103 } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
104 } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
105 |
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
|
106 } |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
107 clone <- { |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
108 myclone <- robot |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
109 myclone collected!: collected |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
110 myclone heldBreath!: heldBreath |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
111 myclone razors!: razors |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
112 myclone |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
113 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
114 } |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 //commands set: "A" {mine ended!: true} |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
120 ret |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
121 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
122 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
123 } |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
124 #{ |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
125 |
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
126 cellTypes <- makeCellTypes: |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
127 |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
128 state <- #{ |
6 | 129 new <- :in_grid in_width in_height { |
10 | 130 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
|
131 _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
|
132 endreached <- false |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
133 |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
134 _succeeded <- false |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
135 ret <- #{ |
8 | 136 grid <- in_grid |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
137 width <- in_width |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
138 height <- in_height |
23 | 139 calcIndex <- :x y { x + y * width } |
140 calcX <- :index {index % width} | |
141 calcY <- :index {index / width} | |
10 | 142 setCell <- :x y val { |
23 | 143 grid set: (calcIndex: x y) val |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
144 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
145 getCell <- :x y { |
23 | 146 grid get: (calcIndex: x y) |
147 } | |
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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 //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
|
154 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
|
155 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
|
156 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
|
157 //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
|
158 (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
|
159 } |
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 } |
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 } |
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 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
|
165 |
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 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 } |
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 }} |
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 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
|
174 //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
|
175 //(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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 } |
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
|
185 } |
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
|
186 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
|
187 } |
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
|
188 getRobot <- { _robot } |
23 | 189 updatePos <- :obj Index { |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
190 obj x!: (calcX: Index) |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
191 obj y!: (calcY: Index) |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
192 } |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
193 lambdaCount <- 0 |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
194 water <- 0 |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
195 flooding <- 0 |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
196 waterproof <- 10 |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
197 moves <- #[] |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
198 score <- 0 |
45
9f1ca5ba2684
Discard entries for which we can easily tell that it will be impossible for them to be better than the current best. This allows us to terminate when we cannot solve the map
Mike Pavone <pavone@retrodev.com>
parents:
44
diff
changeset
|
199 maxScore <- { score + (lambdaCount - (_robot collected)) * 25 + lambdaCount * 50 } |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
200 addPoints <- :points { score <- score + points } |
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
|
201 ended <- {endreached} |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
202 succeeded <- {_succeeded} |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
203 succeeded! <- { |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
204 endreached <- true |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
205 _succeeded <- true |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
206 addPoints: lambdaCount * 50 |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
207 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
208 doUpdate <- { |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
209 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
|
210 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
|
211 x <- calcX: index |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
212 y <- calcY: index |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
213 below <- getCell: x (y - 1) |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
214 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
|
215 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
|
216 setCell: x (y - 1) value |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
217 } |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
218 } else: { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
219 if: (value eq: (cellTypes closedLift)) { |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
220 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
|
221 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
|
222 } |
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 } |
7
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
226 } |
1bd46f854dbb
progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents:
6
diff
changeset
|
227 advance <- :roboCmd { |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
228 if: roboCmd = "A" { |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
229 endreached <- true |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
230 moves append: roboCmd |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
231 addPoints: (_robot collected) * 25 |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
232 } |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
233 |
35 | 234 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
|
235 _robot doCmd: roboCmd |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
236 score <- score - 1 |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
237 moves append: roboCmd |
35 | 238 doUpdate: |
239 } | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
240 self |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
241 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
242 printGrid <- { |
32 | 243 cur <- (grid length) - width |
244 col <- 0 | |
245 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
|
246 os write: 2 ((grid get: cur) string) |
32 | 247 cur <- cur + 1 |
248 col <- col + 1 | |
249 if: col = width { | |
250 col <- 0 | |
251 cur <- cur - (width + width) | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
252 os write: 2 "\n" |
23 | 253 } |
254 } | |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
255 os write: 2 "score: " . score . "\n" |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
256 os write: 2 "collected: " . (_robot collected) . "\n" |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
257 os write: 2 "moves: " |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
258 foreach: moves :idx m { |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
259 os write: 2 m |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
260 } |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
261 os write: 2 "\n" |
32 | 262 } |
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
|
263 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
|
264 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
|
265 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
|
266 if: (el isrobot) { |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
267 cgrid append: (el clone) |
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
|
268 } 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
|
269 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
|
270 } |
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 } |
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 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
|
273 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
|
274 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
|
275 myclone waterproof!: waterproof |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
276 movesclone <- #[] |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
277 foreach: moves :idx el { |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
278 movesclone append: el |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
279 } |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
280 myclone moves!: movesclone |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
281 myclone score!: score |
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
282 myclone lambdaCount!: lambdaCount |
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
|
283 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
|
284 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
285 } |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
286 foreach: in_grid :index el{ |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
287 nextGrid append: el |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
288 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
|
289 _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
|
290 _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
|
291 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
|
292 } else: { |
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
293 if: (el eq: (cellTypes lambda)) { |
44
0c09730c173e
Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents:
41
diff
changeset
|
294 ret lambdaCount!: (ret lambdaCount) + 1 |
40
f38437d22ebd
success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents:
36
diff
changeset
|
295 } |
30
031d46ff76a9
minor clean up to use 'if' and 'not'
William Morgan <bill@mrgn.org>
parents:
29
diff
changeset
|
296 } |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
297 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
298 |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
299 // adding a 'new' method to robot and doing this instead |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
300 // wolud allow me to treat robots and other cellTypes equaly |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
301 // particularly for adding methods or state to other cellTypess. |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
302 // |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
303 // if: (el = (cellTypes robot)) { |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
304 // robot <- el new: |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
305 // (ret grid) set: index robot |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
306 // robot mine!: ret |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
307 // ret updatePos: robot index |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
308 // nextGrid append: el |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
309 // } else: { |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
310 // nextGrid append: el |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
311 // } |
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
312 |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
313 } |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
314 ret |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
315 } |
32 | 316 |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
317 fromStr <- :str { |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 blank <- cellTypes empty |
32 | 322 lines <- #[] |
323 curline <- #[] | |
12 | 324 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
|
325 if: element = nl { |
32 | 326 col <- curline length |
33
efa82c5e95c2
must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents:
32
diff
changeset
|
327 maxCol <- if: col > maxCol {col} else: {maxCol} |
32 | 328 lines append: curline |
329 curline <- #[] | |
10 | 330 } else: { |
32 | 331 curline append: (cellTypes find: element) |
10 | 332 } |
333 } | |
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
|
334 grid <- #[] |
32 | 335 cur <- (lines length) - 1 |
336 while: { cur >= 0 } do: { | |
337 curline <- (lines get: cur) | |
338 foreach: curline :idx el { | |
339 grid append: el | |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
340 } |
32 | 341 extra <- maxCol - (curline length) |
342 while: { extra > 0 } do: { | |
343 grid append: blank | |
344 extra <- extra - 1 | |
345 } | |
346 cur <- cur - 1 | |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
347 } |
32 | 348 new: grid maxCol (lines length) |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
349 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
350 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
351 |
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
|
352 readFd <- :fd { |
8 | 353 if: fd < 0 { "" } else: { |
354 cur <- "" | |
355 part <- "" | |
356 while: { | |
357 part <- os read: fd 128 | |
358 part != "" | |
359 } do: { | |
360 cur <- cur . part | |
361 } | |
362 cur | |
363 } | |
364 } | |
365 | |
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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 } |
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
|
372 |
8 | 373 getMove <- { |
29 | 374 ret <- os read: 0 1 |
375 while: {ret = "\n"} do: { | |
376 ret <- os read: 0 1 | |
377 } | |
378 ret | |
3
bb29dcd46cbf
Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
379 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
380 |
8 | 381 main <- :args { |
382 if: (args length) < 2 { | |
383 print: "usage: sim filename\n" | |
384 } else: { | |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
385 verbose <- true |
8 | 386 text <- readFile: (args get: 1) |
14 | 387 print: text |
34
ac0df071afe7
Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
388 //os close: 1 |
8 | 389 simState <- state fromStr: text |
30
031d46ff76a9
minor clean up to use 'if' and 'not'
William Morgan <bill@mrgn.org>
parents:
29
diff
changeset
|
390 while: { not: (simState ended: ) } do: { |
8 | 391 simState advance: (getMove: ) |
25
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
392 if: verbose { |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
393 simState printGrid |
a224dc43877f
major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents:
24
diff
changeset
|
394 } |
8 | 395 } |
5
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
396 } |
be946b2a2cbc
initial barf into simulator file
William Morgan <bill@mrgn.org>
parents:
3
diff
changeset
|
397 } |
8 | 398 |
3
bb29dcd46cbf
Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
399 } |
11
f28e465e9ee6
tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents:
10
diff
changeset
|
400 } |