-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCode_vs_Zombie.py
More file actions
77 lines (62 loc) · 2.17 KB
/
Code_vs_Zombie.py
File metadata and controls
77 lines (62 loc) · 2.17 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import sys
import math
# Save humans, destroy zombies!
class Human(object):
def __init__(self, id, x, y):
self.id = id
self.x = x
self.y = y
class Zombie(object):
def __init__(self, id, x, y, nx, ny):
self.id = id
self.x = x
self.y = y
self.nx = nx
self.ny = ny
def get_distance(x1, y1, x2, y2):
return math.sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
# game loop
while True:
human_array = []
zombie_array = []
x, y = [int(i) for i in input().split()]
human_count = int(input())
for i in range(human_count):
human_id, human_x, human_y = [int(j) for j in input().split()]
human_array.append(Human(human_id, human_x, human_y))
zombie_count = int(input())
for i in range(zombie_count):
zombie_id, zombie_x, zombie_y, zombie_xnext, zombie_ynext = [int(j) for j in input().split()]
zombie_array.append(Zombie(zombie_id, zombie_x, zombie_y, zombie_xnext, zombie_ynext))
min_dist = sys.maxsize - 1
for human in human_array:
closing_zombie = None
closest_zombie_dist = sys.maxsize - 1
for zombie in zombie_array:
zdist = get_distance(human.x, human.y, zombie.x, zombie.y)
if closest_zombie_dist > zdist:
closest_zombie_dist = zdist
closing_zombie = zombie
if closest_zombie_dist < min_dist:
dist = get_distance(x, y, human.x, human.y)
if closest_zombie_dist / 400.0 >= (max(dist - 2000, 0)) / 1000.0:
location = (closing_zombie.x, closing_zombie.y)
min_dist = closest_zombie_dist
pzombie = True
for z in zombie_array:
for h in human_array:
if get_distance(h.x, h.y, z.x, z.y) < get_distance(x, y, z.x, z.y):
pzombie = False
break
if not pzombie:
break
if pzombie:
center_x = 0
center_y = 0
for z in zombie_array:
center_x += z.x
center_y += z.y
center_x /= len(zombie_array)
center_y /= len(zombie_array)
location = (int(center_x), int(center_y))
print("%s %s" % location)