comparison src/sim.tp @ 34:ac0df071afe7

Start debugging what bill was working on last night. Currently segfautls.
author Mike Pavone <pavone@retrodev.com>
date Sun, 15 Jul 2012 10:30:40 -0700
parents efa82c5e95c2
children 8e8903cc0997
comparison
equal deleted inserted replaced
33:efa82c5e95c2 34:ac0df071afe7
18 makeCellTypes <- { 18 makeCellTypes <- {
19 typedict <- dict linear 19 typedict <- dict linear
20 new <- :idStr { 20 new <- :idStr {
21 ret <- #{ 21 ret <- #{
22 id <- (idStr byte: 0) 22 id <- (idStr byte: 0)
23 str <- idStr 23 string <- idStr
24 isrobot <- { false } 24 isrobot <- { false }
25 eq <- :other { id = (other id) }
25 } 26 }
26 typedict set: (ret id) ret 27 typedict set: (ret id) ret
27 ret 28 ret
28 } 29 }
29 #{ 30 #{
39 lambda <- new: "\\" 40 lambda <- new: "\\"
40 closedLift <- new: "L" 41 closedLift <- new: "L"
41 openLift <- new: "O" 42 openLift <- new: "O"
42 newline <- new: "\n" 43 newline <- new: "\n"
43 robot <- { 44 robot <- {
45 commands <- dict linear
44 ret <- #{ 46 ret <- #{
45 id <- ("R" byte: 0) 47 id <- ("R" byte: 0)
46 str <- "R" 48 string <- "R"
47 x <- 0 49 x <- 0
48 y <- 0 50 y <- 0
49 isrobot <- { true } 51 isrobot <- { true }
52 eq <- :other { id = (other id) }
50 collected <- 0 53 collected <- 0
51 heldBreath <- 0 54 heldBreath <- 0
52 razors <- 0 55 razors <- 0
53 busted <- false 56 busted <- false
54 mine <- null 57 mine <- null
55 doCmd <- :cmd { 58 doCmd <- :cmd {
59 debugLog: "docmd\n"
56 action <- commands get: cmd 60 action <- commands get: cmd
61 debugLog: "fetched action\n"
57 action: 62 action:
58 } 63 }
59 move <- :xDelta yDelta { 64 move <- :xDelta yDelta {
60 xPrime <- x + xDelta 65 xPrime <- x + xDelta
61 yPrime <- y + yDelta 66 yPrime <- y + yDelta
65 mine setCell: x y empty 70 mine setCell: x y empty
66 x <- xPrime 71 x <- xPrime
67 y <- yPrime 72 y <- yPrime
68 } 73 }
69 74
70 navigable <- { 75 navigable <- :cur {
71 // need "any" and "all" functions... 76 // need "any" and "all" functions...
72 if: self = empty {true} else: { 77 if: cur eq empty {true} else: {
73 if: self = earth {true} else: { 78 if: cur eq earth {true} else: {
74 if: self = lambda {true} else: { 79 if: cur eq lambda {true} else: {
75 if: self = openLift {true} else: { 80 if: cur eq openLift {true} else: {
76 false }}}} 81 false }}}}
77 } 82 }
78 83
79 consequenceOf <- { 84 consequenceOf <- :cur {
80 if: self = lambda {collected <- collected + 1} 85 if: cur = lambda {collected <- collected + 1}
81 if: self = openLift {mine succeeded!: true} 86 if: cur = openLift {mine succeeded!: true}
82 } 87 }
83 88
84 destination <- mine getCell: xPrime yPrime 89 destination <- mine getCell: xPrime yPrime
85 90 debugLog: "destination is " . destination . "\n"
86 if: (destination navigable: ) { 91 if: (destination navigable: ) {
87 consequenceOf: destination 92 consequenceOf: destination
88 writeMove: 93 writeMove:
89 } else: { 94 } else: {
90 if: destination = rock { 95 if: destination = rock {
97 } 102 }
98 } 103 }
99 104
100 } 105 }
101 } 106 }
102 commands <- dict linear 107 commands set: "L" {ret move: (-1) 0 }
103 commands set: "L" {move: -1 0 } 108 commands set: "R" {ret move: 1 0 }
104 commands set: "R" {move: 1 0 } 109 commands set: "U" {ret move: 0 1 }
105 commands set: "U" {move: 0 1 } 110 commands set: "D" {ret move: 0 (-1) }
106 commands set: "D" {move: 0 -1 }
107 //commands set: "A" {mine ended!: true} 111 //commands set: "A" {mine ended!: true}
108 ret 112 ret
109 } 113 }
110 } 114 }
111 } 115 }
144 doUpdate <- { 148 doUpdate <- {
145 true 149 true
146 } 150 }
147 advance <- :roboCmd { 151 advance <- :roboCmd {
148 endreached <- roboCmd = "A" 152 endreached <- roboCmd = "A"
149 robot doCmd: roboCmd inMine: self 153 if: endreached { debugLog: "game over man\n" } else: { debugLog: "still going\n" }
154 robot doCmd: roboCmd
150 moves <- moves + 1 155 moves <- moves + 1
156 debugLog: "calling doUpdate"
151 doUpdate: 157 doUpdate:
152 self 158 self
153 } 159 }
154 printGrid <- { 160 printGrid <- {
155 cur <- (grid length) - width 161 cur <- (grid length) - width
156 col <- 0 162 col <- 0
157 while: {cur >= 0} do: { 163 while: {cur >= 0} do: {
158 os write: 2 ((grid get: cur) str) 164 os write: 2 ((grid get: cur) string)
159 cur <- cur + 1 165 cur <- cur + 1
160 col <- col + 1 166 col <- col + 1
161 if: col = width { 167 if: col = width {
162 col <- 0 168 col <- 0
163 cur <- cur - (width + width) 169 cur <- cur - (width + width)
262 print: "usage: sim filename\n" 268 print: "usage: sim filename\n"
263 } else: { 269 } else: {
264 verbose <- true 270 verbose <- true
265 text <- readFile: (args get: 1) 271 text <- readFile: (args get: 1)
266 print: text 272 print: text
267 os close: 1 273 //os close: 1
268 simState <- state fromStr: text 274 simState <- state fromStr: text
269 while: { not: (simState ended: ) } do: { 275 while: { not: (simState ended: ) } do: {
270 simState advance: (getMove: ) 276 simState advance: (getMove: )
271 if: verbose { 277 if: verbose {
272 simState printGrid 278 simState printGrid