comparison code/dotScanner.lm @ 79:dcfa97976071

Better handling of target selection
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Jul 2014 03:24:21 -0700
parents 3b8a277decfa
children 4251797af36b
comparison
equal deleted inserted replaced
78:3b8a277decfa 79:dcfa97976071
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 edibleGhosts <- 0
38 totalGhosts <- 0
38 39
39 advancer <- :continuations { 40 advancer <- :continuations {
40 notdone <- 1 41 notdone <- 1
41 while: { notdone } do: { 42 while: { notdone } do: {
42 if: (continuations isInteger?) { 43 if: (continuations isInteger?) {
64 } else: {} 65 } else: {}
65 } 66 }
66 } 67 }
67 continuations 68 continuations
68 } 69 }
70
71 target0 <- 2
72 target1 <- 3
73 target2 <- 4
74 target3 <- 7
69 75
70 makeContClos <- :grid myLoc path { 76 makeContClos <- :grid myLoc path {
71 { 77 {
72 ret <- [] 78 ret <- []
73 move <- 0 79 move <- 0
74 atpos <- 0 80 atpos <- 0
75 if: (grid: grid inBounds?: myLoc) { 81 if: (grid: grid inBounds?: myLoc) {
76 if: (grid: visited get: myLoc) { 82 if: (grid: visited get: myLoc) {
77 } else: { 83 } else: {
78 atpos <- grid: grid get: myLoc 84 atpos <- grid: grid get: myLoc
79 if: badGhostCount > 0 { 85 if: (atpos = target0) + (atpos = target1) + (atpos = target2) + (atpos = target3) {
80 } else: {
81 //treat power pellets as empty space when there are no ghosts in normal mode
82 if: (atpos = 3) {
83 atpos <- 1
84 } else: {
85 if: edibleGhosts > 0 {
86 if: (atpos = 2) {
87 atpos <- 1
88 } else: {}
89 } else: {}
90 }
91 }
92 if: (atpos = 2) + (atpos = 3) + (atpos = 4) + (atpos = 7) {
93 //pellet, power pellet, fruit 86 //pellet, power pellet, fruit
94 ret <- #[1 (reverse: path)] 87 ret <- #[1 (reverse: path)]
95 } else: { 88 } else: {
96 visited <- grid: visited set: myLoc to: 1 89 visited <- grid: visited set: myLoc to: 1
97 if: atpos { 90 if: atpos {
131 } 124 }
132 makeTree: row 125 makeTree: row
133 }) 126 })
134 badGhostCount <- 0 127 badGhostCount <- 0
135 edibleGhosts <- 0 128 edibleGhosts <- 0
129 totalGhosts <- 0
136 grid <- fold: ghostState grid with: :acc ghost { 130 grid <- fold: ghostState grid with: :acc ghost {
131 totalGhosts <- totalGhosts + 1
137 vitality <- ghost value 132 vitality <- ghost value
138 loc <- (ghost tail) value 133 loc <- (ghost tail) value
139 dir <- (ghost tail) tail 134 dir <- (ghost tail) tail
140 nextloc <- 0 135 nextloc <- 0
141 move <- 0 136 move <- 0
176 move <- move + 1 171 move <- move + 1
177 } 172 }
178 } else: {} 173 } else: {}
179 } 174 }
180 acc 175 acc
176 }
177 //default behavior, target all yummy things
178 target0 <- 2
179 target1 <- 3
180 target2 <- 4
181 target3 <- 7
182 if: badGhostCount > 0 {
183 } else: {
184 if: totalGhosts > 0 {
185 //ignore power pellets when there are no ghosts in normal mode
186 target1 <- 2
187 if: edibleGhosts > 0 {
188 //ignore anything except edible ghosts when some are in range
189 target0 <- 7
190 target1 <- 7
191 target2 <- 7
192 } else: {}
193 } else: {}
181 } 194 }
182 //make sure my location is marked clear even if there is a ghost nearby 195 //make sure my location is marked clear even if there is a ghost nearby
183 grid <- grid: grid set: myLoc to: 1 196 grid <- grid: grid set: myLoc to: 1
184 visited <- treeMap: grid :row { 197 visited <- treeMap: grid :row {
185 treeMap: row :el { 0 } 198 treeMap: row :el { 0 }