Created
November 29, 2015 01:47
-
-
Save munchicken/4678fac95d48d4d2ec72 to your computer and use it in GitHub Desktop.
My Code vs Zombies submission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import math | |
# Save humans, destroy zombies! | |
class Person: | |
def __init__(self, id, x, y): | |
self.id = id | |
self.x = x | |
self.y = y | |
# game loop | |
while 1: | |
humans = [] | |
zombies = [] | |
fzombies = [] | |
h_dist = [] | |
z_dist = [] | |
fz_dist = [] | |
danger_dist = [] | |
danger_idxs = [] | |
x, y = [int(i) for i in raw_input().split()] | |
human_count = int(raw_input()) | |
for i in xrange(human_count): | |
human_id, human_x, human_y = [int(j) for j in raw_input().split()] | |
humans.append(Person(human_id, human_x, human_y)) | |
zombie_count = int(raw_input()) | |
for i in xrange(zombie_count): | |
zombie_id, zombie_x, zombie_y, zombie_xnext, zombie_ynext = [int(j) for j in raw_input().split()] | |
zombies.append(Person(zombie_id, zombie_x, zombie_y)) | |
fzombies.append(Person(zombie_id, zombie_xnext, zombie_ynext)) | |
# Write an action using print | |
# To debug: print >> sys.stderr, "Debug messages..." | |
# Your destination coordinates | |
# print "0 0" | |
#dist = math.hypot(x2-x1, y2-y1) | |
#for i in (humans): | |
#h_dist.append(math.hypot(i.x-x, i.y-y)) #dist from me | |
for i in (zombies): | |
z_dist.append(math.hypot(i.x-x, i.y-y)) #dist from me | |
for k in (z_dist): | |
if k == min(z_dist): | |
print >> sys.stderr, "moving to closest zombie" | |
move = Person(zombies[z_dist.index(k)].id, zombies[z_dist.index(k)].x, zombies[z_dist.index(k)].y) #move to closest zombie | |
for i in (fzombies): | |
for j in (humans): | |
danger_dist.append(math.hypot(i.x-j.x, i.y-j.y)) | |
danger_idxs.append(j) | |
h_dist.append(math.hypot(j.x-x, j.y-y)) | |
for i in (danger_dist): | |
#if (i < 800) and (h_dist[danger_dist.index(i)] <= 2000): | |
if (i < 1200): | |
print >> sys.stderr, "moving to human", danger_idxs[danger_dist.index(i)].id | |
#move = Person(danger_idxs[danger_dist.index(i)].id, danger_idxs[danger_dist.index(i)].x, danger_idxs[danger_dist.index(i)].y) | |
move = Person(danger_idxs[h_dist.index(min(h_dist))].id, danger_idxs[h_dist.index(min(h_dist))].x, danger_idxs[h_dist.index(min(h_dist))].y) | |
if (human_count == 1) or ((human_count == 2) and (min(danger_dist) < 400)): | |
if human_count == 2: | |
humans.reverse() | |
print >> sys.stderr, "moving to last human" | |
move = Person(humans[0].id, humans[0].x, humans[0].y) | |
print move.x, move.y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment