-
Notifications
You must be signed in to change notification settings - Fork 0
/
chase_ai.py
45 lines (39 loc) · 1.33 KB
/
chase_ai.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from ai import AgarioAI
import random
class ChaserAI(AgarioAI):
def __init__(self, chase_after):
super().__init__()
self.chase_after = chase_after
self.in_random = False
self.last_random = ()
def get_chase_cord(self):
for player in self.other_players:
if player['name'] == self.chase_after:
return (player['x'], player['y'])
return None
def random_search(self):
tX = random.randrange(4000)
tY = random.randrange(4000)
return (tX, tY)
def check_random_target_reach(self):
return abs(self.last_random[0] - self.myX) < 2 \
and abs(self.last_random[1] - self.myY) < 2
def next_target(self):
chase = self.get_chase_cord()
if not chase:
if self.in_random:
if self.check_random_target_reach():
self.last_random = self.random_search()
else:
self.last_random = self.random_search()
self.in_random = True
return {
'x': self.last_random[0]-self.myX,
'y': self.last_random[1]-self.myY
}
else:
self.in_random = False
return {
'x': chase[0] - self.myX,
'y': chase[1] - self.myY
}