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