comparison code/dotScanner.lm @ 76:47eb447a74cc

Don't chase ghosts we can't catch
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Jul 2014 02:57:56 -0700
parents 6df7f6372d29
children 41f16c010717
comparison
equal deleted inserted replaced
75:6df7f6372d29 76:47eb447a74cc
32 calcPos 32 calcPos
33 ] from: (module: "grid.lm") 33 ] from: (module: "grid.lm")
34 34
35 visited <- 0 35 visited <- 0
36 badGhostCount <- 0 36 badGhostCount <- 0
37 edibleGhosts <- 0
37 38
38 advancer <- :continuations { 39 advancer <- :continuations {
39 notdone <- 1 40 notdone <- 1
40 while: { notdone } do: { 41 while: { notdone } do: {
41 if: (continuations isInteger?) { 42 if: (continuations isInteger?) {
78 if: badGhostCount > 0 { 79 if: badGhostCount > 0 {
79 } else: { 80 } else: {
80 //treat power pellets as empty space when there are no ghosts in normal mode 81 //treat power pellets as empty space when there are no ghosts in normal mode
81 if: (atpos = 3) { 82 if: (atpos = 3) {
82 atpos <- 1 83 atpos <- 1
83 } else: {} 84 } else: {
85 if: edibleGhosts > 0 {
86 if: (atpos = 2) {
87 atpos <- 1
88 } else: {}
89 } else: {}
90 }
84 } 91 }
85 if: (atpos = 2) + (atpos = 3) + (atpos = 4) { 92 if: (atpos = 2) + (atpos = 3) + (atpos = 4) + (atpos = 7) {
86 //pellet, power pellet, fruit 93 //pellet, power pellet, fruit
87 ret <- #[1 (reverse: path)] 94 ret <- #[1 (reverse: path)]
88 } else: { 95 } else: {
89 visited <- grid: visited set: myLoc to: 1 96 visited <- grid: visited set: myLoc to: 1
90 if: atpos { 97 if: atpos {
104 } 111 }
105 } 112 }
106 113
107 step <- :myState world { 114 step <- :myState world {
108 lmState <- (world tail) value 115 lmState <- (world tail) value
116 myVitality <- lmState value
109 myLoc <- (lmState tail) value 117 myLoc <- (lmState tail) value
110 ghostState <- ((world tail) tail) value 118 ghostState <- ((world tail) tail) value
111 fruitState <- ((world tail) tail) tail 119 fruitState <- ((world tail) tail) tail
112 120
113 grid <- makeTree: (map: (world value) :row { 121 grid <- makeTree: (map: (world value) :row {
122 } 130 }
123 } 131 }
124 makeTree: row 132 makeTree: row
125 }) 133 })
126 badGhostCount <- 0 134 badGhostCount <- 0
135 edibleGhosts <- 0
127 grid <- fold: ghostState grid with: :acc ghost { 136 grid <- fold: ghostState grid with: :acc ghost {
128 vitality <- ghost value 137 vitality <- ghost value
129 loc <- (ghost tail) value 138 loc <- (ghost tail) value
130 dir <- (ghost tail) tail 139 dir <- (ghost tail) tail
131 nextloc <- 0 140 nextloc <- 0
132 move <- 0 141 move <- 0
142 manHatDist <- 0
133 if: vitality = 1 { 143 if: vitality = 1 {
134 //treat fright mode ghosts as a pellet for now 144
135 acc <- grid: acc set: loc to: 2 145 if: (myLoc value) > (loc value) {
146 manHatDist <- (myLoc value) - (loc value)
147 } else: {
148 manHatDist <- (loc value) - (myLoc value)
149 }
150 if: (myLoc tail) > (loc tail) {
151 manHatDist <- manHatDist + (myLoc tail) - (loc tail)
152 } else: {
153 manHatDist <- manHatDist + (loc tail) - (myLoc tail)
154 }
155 if: myVitality > (manHatDist * 254) {
156 edibleGhosts <- edibleGhosts + 1
157 } else: {}
158 //mark fright mode ghosts
159 acc <- grid: acc set: loc to: 7
136 } else: { 160 } else: {
137 if: vitality = 0 { 161 if: vitality = 0 {
138 badGhostCount <- badGhostCount + 1 162 badGhostCount <- badGhostCount + 1
139 //treat normal mode ghosts as a wall for now 163 //treat normal mode ghosts as a wall for now
140 acc <- grid: acc set: loc to: 0 164 acc <- grid: acc set: loc to: 0
141 while: { move < 4 } do: { 165 while: { move < 4 } do: {
142 nextloc <- calcPos: move loc 166 nextloc <- calcPos: move loc
143 if: (grid: acc inBounds?: nextloc) { 167 if: (grid: acc inBounds?: nextloc) {
144 acc <- grid: acc set: nextloc to: 0 168 acc <- grid: acc update: nextloc with: :oldval {
169 if: oldval = 3 {
170 } else: {
171 oldval <- 0
172 }
173 oldval
174 }
145 } else: {} 175 } else: {}
146 move <- move + 1 176 move <- move + 1
147 } 177 }
148 } else: {} 178 } else: {}
149 } 179 }