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