Mercurial > repos > icfp2012
comparison src/sim.tp @ 35:8e8903cc0997
Robot movement works now
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 15 Jul 2012 10:52:50 -0700 |
parents | ac0df071afe7 |
children | 814e3d482ad3 |
comparison
equal
deleted
inserted
replaced
34:ac0df071afe7 | 35:8e8903cc0997 |
---|---|
54 heldBreath <- 0 | 54 heldBreath <- 0 |
55 razors <- 0 | 55 razors <- 0 |
56 busted <- false | 56 busted <- false |
57 mine <- null | 57 mine <- null |
58 doCmd <- :cmd { | 58 doCmd <- :cmd { |
59 debugLog: "docmd\n" | |
60 action <- commands get: cmd | 59 action <- commands get: cmd |
61 debugLog: "fetched action\n" | |
62 action: | 60 action: |
63 } | 61 } |
64 move <- :xDelta yDelta { | 62 move <- :xDelta yDelta { |
65 xPrime <- x + xDelta | 63 xPrime <- x + xDelta |
66 yPrime <- y + yDelta | 64 yPrime <- y + yDelta |
72 y <- yPrime | 70 y <- yPrime |
73 } | 71 } |
74 | 72 |
75 navigable <- :cur { | 73 navigable <- :cur { |
76 // need "any" and "all" functions... | 74 // need "any" and "all" functions... |
77 if: cur eq empty {true} else: { | 75 if: (cur eq: empty) {true} else: { |
78 if: cur eq earth {true} else: { | 76 if: (cur eq: earth) {true} else: { |
79 if: cur eq lambda {true} else: { | 77 if: (cur eq: lambda) {true} else: { |
80 if: cur eq openLift {true} else: { | 78 if: (cur eq: openLift) {true} else: { |
81 false }}}} | 79 false }}}} |
82 } | 80 } |
83 | 81 |
84 consequenceOf <- :cur { | 82 consequenceOf <- :cur { |
85 if: cur = lambda {collected <- collected + 1} | 83 if: (cur eq: lambda) {collected <- collected + 1} |
86 if: cur = openLift {mine succeeded!: true} | 84 if: (cur eq: openLift) {mine succeeded!: true} |
87 } | 85 } |
88 | 86 |
89 destination <- mine getCell: xPrime yPrime | 87 destination <- mine getCell: xPrime yPrime |
90 debugLog: "destination is " . destination . "\n" | |
91 if: (destination navigable: ) { | 88 if: (destination navigable: ) { |
92 consequenceOf: destination | 89 consequenceOf: destination |
93 writeMove: | 90 writeMove: |
94 } else: { | 91 } else: { |
95 if: destination = rock { | 92 if: (destination eq: rock) { |
96 xPrimePrime <- xDelta * 2 + x | 93 xPrimePrime <- xDelta * 2 + x |
97 rockDestination <- mine getCell: xPrimePrime y | 94 rockDestination <- mine getCell: xPrimePrime y |
98 if: rockDestination = empty { | 95 if: (rockDestination eq: empty) { |
99 mine setCell: xPrimePrime y rock | 96 mine setCell: xPrimePrime y rock |
100 writeMove: | 97 writeMove: |
101 } | 98 } |
102 } | 99 } |
103 } | 100 } |
148 doUpdate <- { | 145 doUpdate <- { |
149 true | 146 true |
150 } | 147 } |
151 advance <- :roboCmd { | 148 advance <- :roboCmd { |
152 endreached <- roboCmd = "A" | 149 endreached <- roboCmd = "A" |
153 if: endreached { debugLog: "game over man\n" } else: { debugLog: "still going\n" } | 150 if: (not: endreached) { |
154 robot doCmd: roboCmd | 151 robot doCmd: roboCmd |
155 moves <- moves + 1 | 152 moves <- moves + 1 |
156 debugLog: "calling doUpdate" | 153 doUpdate: |
157 doUpdate: | 154 } |
158 self | 155 self |
159 } | 156 } |
160 printGrid <- { | 157 printGrid <- { |
161 cur <- (grid length) - width | 158 cur <- (grid length) - width |
162 col <- 0 | 159 col <- 0 |