Mercurial > repos > icfp2014
comparison code/ghost2.gq @ 73:91e7a30a9e27
Unsuccessful attempt at improving ghost performance with a wingman ghost
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Jul 2014 00:42:45 -0700 |
parents | |
children | 10a75a37c0fa |
comparison
equal
deleted
inserted
replaced
72:a2a5d80abaa0 | 73:91e7a30a9e27 |
---|---|
1 #{ | |
2 up <- 0 | |
3 right <- 1 | |
4 down <- 2 | |
5 left <- 3 | |
6 myIdx <- (me: ) | |
7 lastX <- 0 | |
8 lastY <- 0 | |
9 myX <- 0 | |
10 myY <- 0 | |
11 | |
12 getDirX <- :dir startX { | |
13 if: dir = right { | |
14 startX <- startX + 1 | |
15 } else: { | |
16 if: dir = left { | |
17 startX <- startX - 1 | |
18 } | |
19 } | |
20 startX | |
21 } | |
22 | |
23 getDirY <- :dir startY { | |
24 if: dir = up { | |
25 startY <- startY - 1 | |
26 } else: { | |
27 if: dir = down { | |
28 startY <- startY + 1 | |
29 } | |
30 } | |
31 startY | |
32 } | |
33 | |
34 /* | |
35 opDir <- :dir { | |
36 (dir + 2) and: 3 | |
37 } | |
38 */ | |
39 | |
40 goTowardsX:Y <- :targetX targetY { | |
41 myVit <- ghostStatus: myIdx | |
42 myDir <- direction | |
43 | |
44 | |
45 firstChoice <- 0 | |
46 secondChoice <- 0 | |
47 | |
48 if: myX > targetX { | |
49 //ghost is to the right of target | |
50 if: myY > targetY { | |
51 //ghost is below target | |
52 if: (myX - targetX) > (myY - targetY) { | |
53 //target is more left than up | |
54 firstChoice <- left | |
55 secondChoice <- up | |
56 } else: { | |
57 firstChoice <- up | |
58 secondChoice <- left | |
59 } | |
60 } else: { | |
61 //ghost is above or directly to the right of target | |
62 if: (myX - targetX) > (targetY - myY) { | |
63 //target is more left than down | |
64 firstChoice <- left | |
65 secondChoice <- down | |
66 } else: { | |
67 //target is more down than left | |
68 firstChoice <- down | |
69 secondChoice <- left | |
70 } | |
71 } | |
72 } else: { | |
73 //ghost is to the left of or directly above/below target | |
74 if: myY > targetY { | |
75 //ghost is below target | |
76 if: (targetX - myX) > (myY - targetY) { | |
77 //target is more right than up | |
78 firstChoice <- right | |
79 secondChoice <- up | |
80 } else: { | |
81 firstChoice <- up | |
82 secondChoice <- right | |
83 } | |
84 } else: { | |
85 //ghost is above or directly to the left of target | |
86 if: (targetX - myX) > (targetY - myY) { | |
87 //target is more right than down | |
88 firstChoice <- right | |
89 secondChoice <- down | |
90 } else: { | |
91 //target is more down than right | |
92 firstChoice <- down | |
93 secondChoice <- right | |
94 } | |
95 } | |
96 } | |
97 if: myVit = 1 { | |
98 //currently in fright mode, try to run away | |
99 firstChoice <- (firstChoice + 2) and: 3 //opDir: firstChoice | |
100 secondChoice <- (secondChoice + 2) and: 3 //opDir: secondChoice | |
101 } | |
102 | |
103 | |
104 | |
105 tmp <- 0 | |
106 i <- 0 | |
107 fail <- 0 | |
108 while: { i < 3} do: { | |
109 targetX <- getDirX: firstChoice myX | |
110 targetY <- getDirY: firstChoice myY | |
111 | |
112 if: (mapContentsAt: targetX targetY) - 1 > 4 { | |
113 //first choice is a wall or ghost start pos | |
114 tmp <- firstChoice | |
115 firstChoice <- secondChoice | |
116 secondChoice <- (firstChoice + 2) and: 3 //opDir: firstChoice | |
117 i <- i + 1 | |
118 } else: { | |
119 if: firstChoice = ( (myDir + 2) and: 3 /*opDir: myDir*/) { | |
120 //first choice is backwards | |
121 tmp <- firstChoice | |
122 firstChoice <- secondChoice | |
123 secondChoice <- (firstChoice + 2) and: 3 //opDir: firstChoice | |
124 i <- i + 1 | |
125 } else: { | |
126 i <- 3 | |
127 } | |
128 } | |
129 } | |
130 direction!: firstChoice | |
131 | |
132 0 | |
133 } | |
134 | |
135 //"wingman" - tries to surround lambda man | |
136 //position two cells ahead of his current position | |
137 main <- { | |
138 lmX <- lambdamanPos: | |
139 lmY <- yCoord | |
140 myX <- ghostPos: myIdx | |
141 myY <- yCoord | |
142 diffX <- 0 | |
143 diffY <- 0 | |
144 | |
145 if: notFirst? = 1 { | |
146 diffX <- lmX - lastX | |
147 diffY <- lmY - lastY | |
148 } | |
149 lastX <- lmX | |
150 lastY <- lmY | |
151 | |
152 distX <- myX - lmX | |
153 if: distX < 0 { | |
154 distX <- 0 - distX | |
155 } | |
156 distY <- myY - lmY | |
157 if: distY < 0 { | |
158 distY <- 0 - distX | |
159 } | |
160 dist <- distX + distY | |
161 if: dist < 8 { | |
162 diffX <- 0 | |
163 diffY <- 0 | |
164 } | |
165 | |
166 lmX <- (lmX + diffY) + diffY | |
167 lmY <- (lmY + diffX) + diffX | |
168 | |
169 goTowardsX: lmX Y: lmY | |
170 | |
171 } | |
172 } |