annotate code/dotScanner.lm @ 85:f420fabd0e44 default tip

One last README change
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Jul 2014 04:42:24 -0700
parents 4251797af36b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
1c6d4f2642d0 Fist progress toward a simple recursive dot scanner bot
William Morgan <billjunk@mrgn.org>
parents:
diff changeset
1 #{
40
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
2 import: [
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
3 length
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
4 reverse
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
5 split:at
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
6 map
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
7 fold:with
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
8 filter
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
9 flatten
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
10 ] from: (module: "ll.lm")
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
11
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
12 import: [
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
13 makeTree:size
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
14 makeTree
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
15 get:fromTree:size
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
16 get:fromTree
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
17 treeMap:size
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
18 treeMap
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
19 tree:size:update:with
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
20 tree:update:with
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
21 tree:set:to
d5ccb66ae98b Move some basic library code out of dotScanner.lm into separate files now that import:from works
Michael Pavone <pavone@retrodev.com>
parents: 35
diff changeset
22 ] from: (module: "tree.lm")
26
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
23
46
d631e68a45d5 separated out grid functions for reuse inside gameState.lm
William Morgan <billjunk@mrgn.org>
parents: 40
diff changeset
24 import: [
d631e68a45d5 separated out grid functions for reuse inside gameState.lm
William Morgan <billjunk@mrgn.org>
parents: 40
diff changeset
25 grid:get
d631e68a45d5 separated out grid functions for reuse inside gameState.lm
William Morgan <billjunk@mrgn.org>
parents: 40
diff changeset
26 grid:update:with
d631e68a45d5 separated out grid functions for reuse inside gameState.lm
William Morgan <billjunk@mrgn.org>
parents: 40
diff changeset
27 grid:set:to
50
57a4bddadd46 added new helper functions to grids. more bugfixes to gameState.lm which compiles.
William Morgan <billjunk@mrgn.org>
parents: 46
diff changeset
28 gridMaxX
57a4bddadd46 added new helper functions to grids. more bugfixes to gameState.lm which compiles.
William Morgan <billjunk@mrgn.org>
parents: 46
diff changeset
29 gridMaxY
57a4bddadd46 added new helper functions to grids. more bugfixes to gameState.lm which compiles.
William Morgan <billjunk@mrgn.org>
parents: 46
diff changeset
30 gridArea
46
d631e68a45d5 separated out grid functions for reuse inside gameState.lm
William Morgan <billjunk@mrgn.org>
parents: 40
diff changeset
31 grid:inBounds?
d631e68a45d5 separated out grid functions for reuse inside gameState.lm
William Morgan <billjunk@mrgn.org>
parents: 40
diff changeset
32 calcPos
d631e68a45d5 separated out grid functions for reuse inside gameState.lm
William Morgan <billjunk@mrgn.org>
parents: 40
diff changeset
33 ] from: (module: "grid.lm")
24
37158acf31e5 Initial pass at scan loop
William Morgan <billjunk@mrgn.org>
parents: 12
diff changeset
34
26
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
35 visited <- 0
75
6df7f6372d29 Small tweak to dotScanner lambda man AI to ignore power pellets when it would be wasteful to eat them
Michael Pavone <pavone@retrodev.com>
parents: 50
diff changeset
36 badGhostCount <- 0
76
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
37 edibleGhosts <- 0
79
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
38 totalGhosts <- 0
28
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
39
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
40 advancer <- :continuations {
24
37158acf31e5 Initial pass at scan loop
William Morgan <billjunk@mrgn.org>
parents: 12
diff changeset
41 notdone <- 1
37158acf31e5 Initial pass at scan loop
William Morgan <billjunk@mrgn.org>
parents: 12
diff changeset
42 while: { notdone } do: {
28
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
43 if: (continuations isInteger?) {
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
44 notdone <- 0
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
45 } else: {
29
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
46 continuations <- fold: continuations [] with: :acc el{
28
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
47 ret <- acc
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
48 if: notdone {
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
49 ret <- el:
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
50 if: (ret isInteger?) {
31
3812bf35168d Simple AI seems to work now. Lots of debug junk needs to be removed though
Michael Pavone <pavone@retrodev.com>
parents: 30
diff changeset
51 ret <- acc
28
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
52 } else: {
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
53 if: (ret value) {
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
54 notdone <- 0
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
55 ret <- (ret tail)
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
56 } else: {
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
57 ret <- (ret tail) | acc
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
58 }
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
59 }
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
60 } else: {}
29
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
61 ret
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
62 }
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
63 if: notdone {
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
64 continuations <- flatten: continuations
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
65 } else: {}
24
37158acf31e5 Initial pass at scan loop
William Morgan <billjunk@mrgn.org>
parents: 12
diff changeset
66 }
37158acf31e5 Initial pass at scan loop
William Morgan <billjunk@mrgn.org>
parents: 12
diff changeset
67 }
28
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
68 continuations
26
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
69 }
79
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
70
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
71 target0 <- 2
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
72 target1 <- 3
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
73 target2 <- 4
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
74 target3 <- 7
26
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
75
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
76 makeContClos <- :grid myLoc path {
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
77 {
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
78 ret <- []
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
79 move <- 0
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
80 atpos <- 0
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
81 if: (grid: grid inBounds?: myLoc) {
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
82 if: (grid: visited get: myLoc) {
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
83 } else: {
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
84 atpos <- grid: grid get: myLoc
79
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
85 if: (atpos = target0) + (atpos = target1) + (atpos = target2) + (atpos = target3) {
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
86 //pellet, power pellet, fruit
26
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
87 ret <- #[1 (reverse: path)]
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
88 } else: {
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
89 visited <- grid: visited set: myLoc to: 1
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
90 if: atpos {
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
91 //empty space
26
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
92 move <- 0
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
93 while: { move < 4 } do: {
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
94 ret <- (makeContClos: grid (calcPos: move myLoc) move | path) | ret
29
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
95 move <- move + 1
26
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
96 }
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
97 ret <- #[0 ret]
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
98 } else: {}
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
99 }
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
100 }
28
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
101 } else: {
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
102 }
26
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
103 ret
4f7a421e77c6 Tag teaming the continuation function
William Morgan <billjunk@mrgn.org>
parents: 25
diff changeset
104 }
24
37158acf31e5 Initial pass at scan loop
William Morgan <billjunk@mrgn.org>
parents: 12
diff changeset
105 }
81
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
106
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
107 fruitX <- 0
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
108 fruitY <- 0
24
37158acf31e5 Initial pass at scan loop
William Morgan <billjunk@mrgn.org>
parents: 12
diff changeset
109
12
1c6d4f2642d0 Fist progress toward a simple recursive dot scanner bot
William Morgan <billjunk@mrgn.org>
parents:
diff changeset
110 step <- :myState world {
28
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
111 lmState <- (world tail) value
76
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
112 myVitality <- lmState value
23
5ded24518dc5 Add library functions from mike00.lm to dotScanner.lm. Add some code to process map state into a "grid" structure and make a version for visited state.
Michael Pavone <pavone@retrodev.com>
parents: 12
diff changeset
113 myLoc <- (lmState tail) value
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
114 ghostState <- ((world tail) tail) value
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
115 fruitState <- ((world tail) tail) tail
23
5ded24518dc5 Add library functions from mike00.lm to dotScanner.lm. Add some code to process map state into a "grid" structure and make a version for visited state.
Michael Pavone <pavone@retrodev.com>
parents: 12
diff changeset
116
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
117 grid <- makeTree: (map: (world value) :row {
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
118 makeTree: row
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
119 })
75
6df7f6372d29 Small tweak to dotScanner lambda man AI to ignore power pellets when it would be wasteful to eat them
Michael Pavone <pavone@retrodev.com>
parents: 50
diff changeset
120 badGhostCount <- 0
76
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
121 edibleGhosts <- 0
79
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
122 totalGhosts <- 0
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
123 grid <- fold: ghostState grid with: :acc ghost {
79
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
124 totalGhosts <- totalGhosts + 1
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
125 vitality <- ghost value
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
126 loc <- (ghost tail) value
35
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
127 dir <- (ghost tail) tail
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
128 nextloc <- 0
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
129 move <- 0
76
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
130 manHatDist <- 0
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
131 if: vitality = 1 {
76
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
132
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
133 if: (myLoc value) > (loc value) {
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
134 manHatDist <- (myLoc value) - (loc value)
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
135 } else: {
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
136 manHatDist <- (loc value) - (myLoc value)
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
137 }
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
138 if: (myLoc tail) > (loc tail) {
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
139 manHatDist <- manHatDist + (myLoc tail) - (loc tail)
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
140 } else: {
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
141 manHatDist <- manHatDist + (loc tail) - (myLoc tail)
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
142 }
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
143 if: myVitality > (manHatDist * 254) {
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
144 edibleGhosts <- edibleGhosts + 1
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
145 } else: {}
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
146 //mark fright mode ghosts
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
147 acc <- grid: acc set: loc to: 7
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
148 } else: {
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
149 if: vitality = 0 {
75
6df7f6372d29 Small tweak to dotScanner lambda man AI to ignore power pellets when it would be wasteful to eat them
Michael Pavone <pavone@retrodev.com>
parents: 50
diff changeset
150 badGhostCount <- badGhostCount + 1
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
151 //treat normal mode ghosts as a wall for now
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
152 acc <- grid: acc set: loc to: 0
35
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
153 while: { move < 4 } do: {
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
154 nextloc <- calcPos: move loc
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
155 if: (grid: acc inBounds?: nextloc) {
76
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
156 acc <- grid: acc update: nextloc with: :oldval {
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
157 if: oldval = 3 {
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
158 } else: {
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
159 oldval <- 0
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
160 }
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
161 oldval
47eb447a74cc Don't chase ghosts we can't catch
Michael Pavone <pavone@retrodev.com>
parents: 75
diff changeset
162 }
35
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
163 } else: {}
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
164 move <- move + 1
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
165 }
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
166 } else: {}
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
167 }
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
168 acc
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
169 }
79
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
170 //default behavior, target all yummy things
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
171 target0 <- 2
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
172 target1 <- 3
81
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
173 if: fruitState > 0 {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
174 //only target fruit when it is actually present
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
175 target2 <- 4
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
176 } else: {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
177 target2 <- 2
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
178 }
79
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
179 target3 <- 7
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
180 if: badGhostCount > 0 {
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
181 } else: {
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
182 if: totalGhosts > 0 {
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
183 //ignore power pellets when there are no ghosts in normal mode
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
184 target1 <- 2
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
185 if: edibleGhosts > 0 {
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
186 //ignore anything except edible ghosts when some are in range
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
187 target0 <- 7
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
188 target1 <- 7
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
189 target2 <- 7
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
190 } else: {}
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
191 } else: {}
dcfa97976071 Better handling of target selection
Michael Pavone <pavone@retrodev.com>
parents: 78
diff changeset
192 }
81
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
193 fruitDist <- 0
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
194 if: target2 = 4 {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
195 if: (myLoc value) > fruitX {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
196 fruitDist <- (myLoc value) - fruitX
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
197 } else: {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
198 fruitDist <- fruitX - (myLoc value)
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
199 }
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
200 if: (myLoc tail) > fruitY {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
201 fruitDist <- fruitDist + (myLoc tail) - fruitY
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
202 } else: {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
203 fruitDist <- fruitDist + fruitY - (myLoc tail)
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
204 }
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
205 if: fruitState > (fruitDist * 127) {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
206 //go straight for the fruit if we can make it in time
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
207 target0 <- 4
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
208 target1 <- 4
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
209 target2 <- 4
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
210 target3 <- 4
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
211 } else: {}
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
212 } else: {}
35
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
213 //make sure my location is marked clear even if there is a ghost nearby
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
214 grid <- grid: grid set: myLoc to: 1
28
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
215 visited <- treeMap: grid :row {
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
216 treeMap: row :el { 0 }
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
217 }
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
218 path <- advancer: [(makeContClos: grid myLoc [])]
35
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
219 if: (path isInteger?) {
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
220 print: 42
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
221 path <- [0]
8c26981aae8c Last fixes for lightning round version of dotScanner.lm
Michael Pavone <pavone@retrodev.com>
parents: 34
diff changeset
222 } else: {}
28
75c97fb80602 Tag team simple AI WIP
William Morgan <billjunk@mrgn.org>
parents: 26
diff changeset
223 #[0 (path value)]
12
1c6d4f2642d0 Fist progress toward a simple recursive dot scanner bot
William Morgan <billjunk@mrgn.org>
parents:
diff changeset
224 }
1c6d4f2642d0 Fist progress toward a simple recursive dot scanner bot
William Morgan <billjunk@mrgn.org>
parents:
diff changeset
225
30
3287eb6c25fe Sort of working in the game simulator!!!!!
William Morgan <billjunk@mrgn.org>
parents: 29
diff changeset
226 main <- :initWorld ghostCode {
81
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
227 grid <- (initWorld) value
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
228 fold: grid 0 with: :y row {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
229 fold: row 0 with: :x el {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
230 if: el = 4 {
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
231 fruitX <- x
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
232 fruitY <- y
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
233 } else: {}
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
234 x + 1
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
235 }
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
236 y + 1
4251797af36b Go straight for the fruit
Michael Pavone <pavone@retrodev.com>
parents: 79
diff changeset
237 }
30
3287eb6c25fe Sort of working in the game simulator!!!!!
William Morgan <billjunk@mrgn.org>
parents: 29
diff changeset
238 /*
29
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
239 print: (step: 0 #[
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
240 //grid
29
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
241 [
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
242 [0 0 0 0]
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
243 [0 2 2 0]
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
244 [0 1 0 0]
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
245 [0 0 0 0]
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
246 ]
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
247 //lmstate
29
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
248 #[0 #[1 2] 2 3 0]
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
249 //ghost state
29
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
250 []
34
968705fcb4c6 Initial stab at taking fruit and ghost state into account
Michael Pavone <pavone@retrodev.com>
parents: 32
diff changeset
251 //fruit state
29
5d1ac440b9db Seems to be working in CPU simulator. Need to remove debug crap
William Morgan <billjunk@mrgn.org>
parents: 28
diff changeset
252 0
30
3287eb6c25fe Sort of working in the game simulator!!!!!
William Morgan <billjunk@mrgn.org>
parents: 29
diff changeset
253 ]) */
23
5ded24518dc5 Add library functions from mike00.lm to dotScanner.lm. Add some code to process map state into a "grid" structure and make a version for visited state.
Michael Pavone <pavone@retrodev.com>
parents: 12
diff changeset
254 #[0 step]
12
1c6d4f2642d0 Fist progress toward a simple recursive dot scanner bot
William Morgan <billjunk@mrgn.org>
parents:
diff changeset
255 }
1c6d4f2642d0 Fist progress toward a simple recursive dot scanner bot
William Morgan <billjunk@mrgn.org>
parents:
diff changeset
256 }
1c6d4f2642d0 Fist progress toward a simple recursive dot scanner bot
William Morgan <billjunk@mrgn.org>
parents:
diff changeset
257
1c6d4f2642d0 Fist progress toward a simple recursive dot scanner bot
William Morgan <billjunk@mrgn.org>
parents:
diff changeset
258