annotate src/sim.tp @ 67:ff8d7b4499f5 default tip

Submission prep
author Mike Pavone <pavone@retrodev.com>
date Mon, 16 Jul 2012 04:48:50 -0700
parents aa822c683e28
children
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) }
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
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 }
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
62 navigable <- { false }
34
ac0df071afe7 Start debugging what bill was working on last night. Currently segfautls.
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
63 eq <- :other { id = (other id) }
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
64 collected <- 0
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
65 heldBreath <- 0
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
66 razors <- 0
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 {
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
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
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
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
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
86cdb799f950 unbarfed some things
William Morgan <bill@mrgn.org>
parents: 5
diff changeset
129 new <- :in_grid in_width in_height {
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
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
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
132 _ended <- false
52
b0d89ee419c1 Add maximum moves check
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
133 _maxmoves <- in_width * in_height
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
134 _heuristicValid <- false
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
135 _heuristic <- 0
55
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
136 getSafe <- :collection :index {
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
137 if: index >= 0 {
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
138 if: index < (collection length) {
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
139 collection get: index
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
140 } else: { (cellTypes wall) }
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
141 } else: { (cellTypes wall) }
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
142 }
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
143 _succeeded <- false
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
144 ret <- #{
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
145 grid <- in_grid
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
146 width <- in_width
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
147 height <- in_height
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
148 calcIndex <- :x y { x + y * width }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
149 calcX <- :index {index % width}
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
150 calcY <- :index {index / width}
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
151 getCell <- :x y {
55
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
152 grid getSafe: (calcIndex: x y)
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
153 }
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
154 setCell <- :x y val {
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
155 grid set: (calcIndex: x y) val
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
156 }
51
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
157 getNextCell <- :x y {
55
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
158 _nextGrid getSafe: (calcIndex: x y)
51
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
159 }
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
160 setNextCell <- :x y val {
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
161 _nextGrid set: (calcIndex: x y) val
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
162 }
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
163 validDest?:from <- :index :fromIndex {
55
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
164 cell <- (grid getSafe: index)
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
165 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
166 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
167 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
168 //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
169 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
170 rockdest <- index + diff
55
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
171 if: ((grid getSafe: rockdest) eq: (cellTypes empty)) {
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
172 //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
173 (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
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 }
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 }
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 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
180
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 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
182 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
183 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
184 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
185 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
186 }
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 here <- calcIndex: x y
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
189 cur <- #[(amove: here "A") (amove: here "W")]
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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 }
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
198 }
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
199 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
200 }
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
201 distanceFrom:to <- :x y celltype {
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
202 //debugLog: "calculating distance from " . x . ", " . y . " to " . celltype . "\n"
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
203 if: (celltype eq: (cellTypes closedLift)) {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
204 celltype navigable!: true
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
205 }
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
206 moves <- validMoves: x y
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
207 curdist <- 0
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
208 visited <- _nextGrid
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
209 foreach: grid :idx el {
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
210 visited set: idx false
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
211 }
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
212 notfound <- true
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
213 while: { if: notfound { (moves length) > 0 } } do: {
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
214 nextmoves <- #[]
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
215 curdist <- curdist + 1
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
216 //debugLog: "moves at distance " . curdist . "\n"
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
217 foreach: moves :idx move {
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
218 curpos <- move index
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
219 //debugLog: "" . move . " " . (grid get: curpos) . "\n"
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
220 if: (not: (visited get: curpos)) {
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
221 if: ((grid get: curpos) eq: celltype) {
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
222 notfound <- false
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
223 } else: {
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
224 visited set: curpos true
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
225 foreach: (validMoves: (calcX: curpos) (calcY: curpos)) :idx move {
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
226
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
227 nextmoves append: move
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
228 }
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
229 }
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
230 }
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
231 }
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
232 moves <- nextmoves
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
233 }
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
234 if: (celltype eq: (cellTypes closedLift)) {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
235 celltype navigable!: false
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
236 }
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
237 if: notfound {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
238 -1
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
239 } else: {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
240 curdist
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
241 }
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
242 }
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
243 getRobot <- { _robot }
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
244 updatePos <- :obj Index {
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
245 obj x!: (calcX: Index)
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
246 obj y!: (calcY: Index)
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
247 }
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
248 lambdaCount <- 0
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
249 water <- 0
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
250 flooding <- 0
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
251 waterproof <- 10
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
252 moves <- #[]
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
253 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
254 maxScore <- { score + (lambdaCount - (_robot collected)) * 25 + lambdaCount * 50 }
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
255 heuristic <- {
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
256 if: (not: _heuristicValid) {
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
257 dest <- if: (_robot collected) = lambdaCount {
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
258 dist <- (distanceFrom: (_robot x) (_robot y) to: (cellTypes openLift))
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
259 if: dist < 0 {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
260 //debugLog: "open lift unreachable\n"
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
261 _heuristic <- (_robot collected) * 50 - (moves length)
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
262 } else: {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
263 //debugLog: "open lift unreachable at distance" . dist . "\n"
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
264 _heuristic <- (_robot collected) * 75 - dist - (moves length)
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
265 }
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
266 } else: {
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
267 mult <- 0
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
268 liftdist <- (distanceFrom: (_robot x) (_robot y) to: (cellTypes closedLift))
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
269 if: liftdist < 0 {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
270 mult <- 50
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
271 } else: {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
272 mult <- 75
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
273 }
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
274 lambdadist <- (distanceFrom: (_robot x) (_robot y) to: (cellTypes lambda))
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
275 if: lambdadist < 0 {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
276 //debugLog: "lambda unreachable with lift multilier " . mult . "\n"
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
277 _heuristic <- score
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
278 } else: {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
279 //debugLog: "lambda reachable at distance " . lambdadist . " lift multilier " . mult . "\n"
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
280 _heuristic <- (_robot collected) * mult - lambdadist - (moves length)
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
281 }
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
282 }
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
283 //_heuristic <- (_robot collected) * 75 - (distanceFrom: (_robot x) (_robot y) to: (cellTypes openLift) - (moves length)
53
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
284 _heuristicValid <- true
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
285 }
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
286 _heuristic
fbeedb3aa239 Add heuristic for evaluating non-terminal states. Cull to 8 states based on heuristic rather than just a single one based on score.
Mike Pavone <pavone@retrodev.com>
parents: 52
diff changeset
287 }
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
288 addPoints <- :points { score <- score + points }
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
289 ended <- {_ended}
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
290 succeeded <- {_succeeded}
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
291 succeeded! <- {
48
365c83ea7658 merge and test
William Morgan <bill@mrgn.org>
parents: 47 46
diff changeset
292 _ended <- true
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
293 _succeeded <- true
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
294 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
295 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
296 doUpdate <- {
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
297 foreach: grid :index value {
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
298 nextValue <- value
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
299 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
300 x <- calcX: index
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
301 y <- calcY: index
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
302 below <- getCell: x (y - 1)
43
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
303 fallToSide <- :delta {
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
304 side <- getCell: (x + delta) y
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
305 belowSide <- getCell: (x + delta) (y - 1)
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
306 if: (side eq: (cellTypes empty)) {
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
307 if: (belowSide eq: (cellTypes empty)) {
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
308 setNextCell: (x + delta) (y - 1) value
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
309 nextValue <- (cellTypes empty)
43
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
310 true
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
311 } else: { false }
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
312 } else: { false }
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
313 }
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
314 if: (below eq: (cellTypes empty)) {
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
315 nextValue <- (cellTypes empty)
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
316 setNextCell: x (y - 1) value
43
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
317 } else: { if: (below eq: (cellTypes rock)) {
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
318 if: (not: (fallToSide: 1)) {fallToSide: -1}
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
319 } else: { if: (below eq: (cellTypes lambda)) {
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
320 fallToSide: 1
1f583d85c8ed rocks slide correctly now. rock movement is complete.
William Morgan <bill@mrgn.org>
parents: 42
diff changeset
321 }}} // end if
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
322 } else: {
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
323 if: (value eq: (cellTypes closedLift)) {
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
324 if: (_robot collected) = lambdaCount {
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
325 nextValue <- (cellTypes openLift)
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
326 }
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
327 }
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
328 }
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
329 _nextGrid set: index nextValue
40
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
330 }
51
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
331 }
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
332 checkForDeath <- {
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
333 robotsNewFace <- getNextCell: (_robot x) (_robot y) + 1
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
334 robotsFace <- getCell: (_robot x) (_robot y) + 1
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
335 if: (robotsNewFace eq: (cellTypes rock)) {
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
336 if: (not: (robotsFace eq: (cellTypes rock))) {
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
337 _ended <-true
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
338 }
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
339 }
51
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
340 }
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
341 swapGrids <- {
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
342 tmp <- grid
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
343 grid <- _nextGrid
186fce0c98ee robot can get crushed
William Morgan <bill@mrgn.org>
parents: 48
diff changeset
344 _nextGrid <- tmp
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
345 }
52
b0d89ee419c1 Add maximum moves check
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
346 abort <- {
b0d89ee419c1 Add maximum moves check
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
347 _ended <- true
b0d89ee419c1 Add maximum moves check
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
348 addPoints: (_robot collected) * 25
b0d89ee419c1 Add maximum moves check
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
349 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
350 advance <- :roboCmd {
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
351 if: roboCmd = "?" {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
352 os write: 2 "valid moves: "
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
353 valid <- validMoves: (_robot x) (_robot y)
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
354 foreach: valid :idx el {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
355 os write: 2 (el cmd)
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
356 }
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
357 os write: 2 "\n"
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
358 } else: {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
359 if: roboCmd = "h" {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
360 os write: 2 "heuristic: " . heuristic . "\n"
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
361 } else: {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
362 _heuristicValid <- false
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
363 if: roboCmd = "A" {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
364 moves append: roboCmd
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
365 abort
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
366 }
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
367
62
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
368 if: (not: _ended) {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
369 _robot doCmd: roboCmd
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
370 score <- score - 1
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
371 moves append: roboCmd
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
372 doUpdate:
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
373 checkForDeath:
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
374 swapGrids:
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
375 if: (moves length) >= _maxmoves {
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
376 abort
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
377 }
ff2b38518a58 Updated heuristic
Mike Pavone <pavone@retrodev.com>
parents: 60
diff changeset
378 }
52
b0d89ee419c1 Add maximum moves check
Mike Pavone <pavone@retrodev.com>
parents: 48
diff changeset
379 }
35
8e8903cc0997 Robot movement works now
Mike Pavone <pavone@retrodev.com>
parents: 34
diff changeset
380 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
381 self
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
382 }
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
383 printGrid <- {
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
384 cur <- (grid length) - width
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
385 col <- 0
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
386 while: {cur >= 0} do: {
55
b2e9e5ad3ad8 fixed array out of bounds errors. Test maps to proove it.
William Morgan <bill@mrgn.org>
parents: 51
diff changeset
387 os write: 2 ((grid getSafe: cur) string)
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
388 cur <- cur + 1
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
389 col <- col + 1
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
390 if: col = width {
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
391 col <- 0
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
392 cur <- cur - (width + width)
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
393 os write: 2 "\n"
23
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
394 }
75a005b210c5 almost got movement
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
395 }
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
396 os write: 2 "score: " . score . "\n"
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
397 os write: 2 "collected: " . (_robot collected) . "\n"
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
398 os write: 2 "moves: "
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
399 foreach: moves :idx m {
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
400 os write: 2 m
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
401 }
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
402 os write: 2 "\n"
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
403 }
67
ff8d7b4499f5 Submission prep
Mike Pavone <pavone@retrodev.com>
parents: 65
diff changeset
404 printMoves <- {
ff8d7b4499f5 Submission prep
Mike Pavone <pavone@retrodev.com>
parents: 65
diff changeset
405 foreach: moves :idx m {
ff8d7b4499f5 Submission prep
Mike Pavone <pavone@retrodev.com>
parents: 65
diff changeset
406 os write: 1 m
ff8d7b4499f5 Submission prep
Mike Pavone <pavone@retrodev.com>
parents: 65
diff changeset
407 }
ff8d7b4499f5 Submission prep
Mike Pavone <pavone@retrodev.com>
parents: 65
diff changeset
408 os write: 1 "\n"
ff8d7b4499f5 Submission prep
Mike Pavone <pavone@retrodev.com>
parents: 65
diff changeset
409 }
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
410 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
411 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
412 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
413 if: (el isrobot) {
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
414 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
415 } 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
416 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
417 }
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
418 }
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
419 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
420 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
421 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
422 myclone waterproof!: waterproof
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
423 movesclone <- #[]
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
424 foreach: moves :idx el {
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
425 movesclone append: el
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
426 }
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
427 myclone moves!: movesclone
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
428 myclone score!: score
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
429 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
430 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
431 }
60
7d4e51b4769a Add hashset based pruning
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
432 hash <- {
7d4e51b4769a Add hashset based pruning
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
433 value <- ((grid get: 0) id) * 128
7d4e51b4769a Add hashset based pruning
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
434 foreach: grid :idx el {
7d4e51b4769a Add hashset based pruning
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
435 value <- 1000003 * value + (el id)
7d4e51b4769a Add hashset based pruning
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
436 }
7d4e51b4769a Add hashset based pruning
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
437 //TODO add in any important state from outside grid
7d4e51b4769a Add hashset based pruning
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
438 value
7d4e51b4769a Add hashset based pruning
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
439 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
440 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
441 foreach: in_grid :index el{
47
ccaecf1d6425 correct reading and writing during update and test maps for verifying that.
William Morgan <bill@mrgn.org>
parents: 43
diff changeset
442 _nextGrid append: el
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
443 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
444 _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
445 _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
446 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
447 } else: {
f38437d22ebd success is possible. W implemented. Rock movement started but not finished.
William Morgan <bill@mrgn.org>
parents: 36
diff changeset
448 if: (el eq: (cellTypes lambda)) {
44
0c09730c173e Robot works on simple maps now
Mike Pavone <pavone@retrodev.com>
parents: 41
diff changeset
449 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
450 }
30
031d46ff76a9 minor clean up to use 'if' and 'not'
William Morgan <bill@mrgn.org>
parents: 29
diff changeset
451 }
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
452 }
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
453 ret
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
454 }
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
455
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
456 fromStr <- :str {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
457 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
458 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
459 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
460 blank <- cellTypes empty
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
461 lines <- #[]
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
462 curline <- #[]
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
463 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
464 if: element = nl {
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
465 col <- curline length
33
efa82c5e95c2 must commit, too late. does not compile.
William Morgan <bill@mrgn.org>
parents: 32
diff changeset
466 maxCol <- if: col > maxCol {col} else: {maxCol}
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
467 lines append: curline
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
468 curline <- #[]
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
469 } else: {
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
470 curline append: (cellTypes find: element)
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
471 }
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
472 }
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
473 grid <- #[]
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
474 cur <- (lines length) - 1
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
475 while: { cur >= 0 } do: {
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
476 curline <- (lines get: cur)
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
477 foreach: curline :idx el {
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
478 grid append: el
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
479 }
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
480 extra <- maxCol - (curline length)
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
481 while: { extra > 0 } do: {
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
482 grid append: blank
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
483 extra <- extra - 1
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
484 }
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
485 cur <- cur - 1
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
486 }
32
0a55ee387d69 Change grid order
Mike Pavone <pavone@retrodev.com>
parents: 31
diff changeset
487 new: grid maxCol (lines length)
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
488 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
489 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
490
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
491 readFd <- :fd {
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
492 if: fd < 0 { "" } else: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
493 cur <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
494 part <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
495 while: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
496 part <- os read: fd 128
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
497 part != ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
498 } do: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
499 cur <- cur . part
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
500 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
501 cur
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
502 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
503 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
504
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
505 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
506 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
507 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
508 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
509 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
510 }
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
511
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
512 getMove <- {
29
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
513 ret <- os read: 0 1
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
514 while: {ret = "\n"} do: {
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
515 ret <- os read: 0 1
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
516 }
d9f1a063a466 interactive mode works
William Morgan <bill@mrgn.org>
parents: 28
diff changeset
517 ret
3
bb29dcd46cbf Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
518 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
519
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
520 main <- :args {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
521 if: (args length) < 2 {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
522 print: "usage: sim filename\n"
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
523 } else: {
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
524 verbose <- true
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
525 text <- readFile: (args get: 1)
67
ff8d7b4499f5 Submission prep
Mike Pavone <pavone@retrodev.com>
parents: 65
diff changeset
526 os write: 1 text
ff8d7b4499f5 Submission prep
Mike Pavone <pavone@retrodev.com>
parents: 65
diff changeset
527 os close: 1
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
528 simState <- state fromStr: text
30
031d46ff76a9 minor clean up to use 'if' and 'not'
William Morgan <bill@mrgn.org>
parents: 29
diff changeset
529 while: { not: (simState ended: ) } do: {
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
530 simState advance: (getMove: )
25
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
531 if: verbose {
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
532 simState printGrid
a224dc43877f major progress! ...robot always moves down though
William Morgan <bill@mrgn.org>
parents: 24
diff changeset
533 }
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
534 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
535 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
536 }
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
537
3
bb29dcd46cbf Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
538 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
539 }