Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import math
- # Auto-generated code below aims at helping you parse
- # the standard input according to the problem statement.
- class ship:
- def __init__(self, x, y , arg1, arg2, arg3, arg4, entityid):
- self.x = int(x)
- self.y = int(y)
- self.arg1 = arg_1
- self.arg2 = arg_2
- self.arg3 = arg_3
- self.arg4 = arg_4
- self.entityid = entity_id
- class barrel:
- def __init__(self, x, y):
- self.x = int(x)
- self.y = int(y)
- class mine:
- def __init__(self, x, y):
- self.x = int(x)
- self.y = int(y)
- class cannonball:
- def __init__(self, x, y):
- self.x = int(x)
- self.y = int(y)
- def distance(ship,anything):
- return ((ship.x - anything.x)**2 + (ship.y - anything.y)**2)
- def shoot(m,e):
- if e.arg2 == 0:
- print("FIRE {} {}".format(e.x, e.y))
- elif distance(m,e) <= 25 and (e.arg2 == 1):
- if e.arg1 == 0:
- if e.x + 2 > 20:
- print("FIRE {} {}".format(20 , e.y))
- else:
- print("FIRE {} {}".format(e.x + 3 , e.y))
- elif e.arg1 == 1:
- if e.y - 2 < 0:
- print("FIRE {} {}".format(e.x + 1, 0))
- else:
- print("FIRE {} {}".format(e.x + 1 , e.y - 2))
- elif e.arg1 == 2:
- if e.y - 2 < 0:
- print("FIRE {} {}".format(e.x - 1 , 0))
- else:
- print("FIRE {} {}".format(e.x - 1 , e.y - 2))
- elif e.arg1 == 3:
- if e.x - 2 < 0:
- print("FIRE {} {}".format(0 , e.y))
- else:
- print("FIRE {} {}".format(e.x - 3 , e.y))
- elif e.arg1 == 4:
- if e.y + 2 > 22:
- print("FIRE {} {}".format(e.x - 1 , 22))
- else:
- print("FIRE {} {}".format(e.x - 1 , e.y + 2))
- elif e.arg1 == 5:
- if e.y + 2 > 22:
- print("FIRE {} {}".format(e.x + 1, 22))
- else:
- print("FIRE {} {}".format(e.x + 1 , e.y + 2))
- elif distance(m,e) <= 64 and (e.arg2 == 1):
- if e.arg1 == 0:
- if e.x + 4 > 20:
- print("FIRE {} {}".format(20 , e.y))
- else:
- print("FIRE {} {}".format(e.x + 4 , e.y))
- elif e.arg1 == 1:
- if e.y - 4 < 0:
- print("FIRE {} {}".format(e.x + 2 , 0))
- else:
- print("FIRE {} {}".format(e.x + 2 , e.y - 4))
- elif e.arg1 == 2:
- if e.y - 3 < 0:
- print("FIRE {} {}".format(e.x - 2 , 0))
- else:
- print("FIRE {} {}".format(e.x - 2 , e.y - 4))
- elif e.arg1 == 3:
- if e.x - 4 < 0:
- print("FIRE {} {}".format(0 , e.y))
- else:
- print("FIRE {} {}".format(e.x - 4 , e.y))
- elif e.arg1 == 4:
- if e.y + 3 > 22:
- print("FIRE {} {}".format(e.x - 2, 22))
- else:
- print("FIRE {} {}".format(e.x - 2 , e.y + 4))
- elif e.arg1 == 5:
- if e.y + 3 > 22:
- print("FIRE {} {}".format(e.x + 2 , 22))
- else:
- print("FIRE {} {}".format(e.x + 2 , e.y + 4))
- elif distance(m, e) <= 100 and (e.arg2 == 1):
- if e.arg1 == 0:
- if e.x + 5 > 20:
- print("FIRE {} {}".format(20 , e.y))
- else:
- print("FIRE {} {}".format(e.x + 4 , e.y))
- elif e.arg1 == 1:
- if e.y - 5 < 0:
- print("FIRE {} {}".format(e.x + 2 , 0))
- else:
- print("FIRE {} {}".format(e.x + 2 , e.y - 4))
- elif e.arg1 == 2:
- if e.y - 5 < 0:
- print("FIRE {} {}".format(e.x - 2 , 0))
- else:
- print("FIRE {} {}".format(e.x - 2 , e.y - 4))
- elif e.arg1 == 3:
- if e.x - 5 < 0:
- print("FIRE {} {}".format(0 , e.y))
- else:
- print("FIRE {} {}".format(e.x - 4 , e.y))
- elif e.arg1 == 4:
- if e.y + 5 > 22:
- print("FIRE {} {}".format(e.x - 2 , 22))
- else:
- print("FIRE {} {}".format(e.x - 2 , e.y + 4))
- elif e.arg1 == 5:
- if e.y + 5 > 22:
- print("FIRE {} {}".format(e.x + 2 , 22))
- else:
- print("FIRE {} {}".format(e.x + 2 , e.y + 4))
- elif distance(m, e) <= 25 and (e.arg2 == 2):
- if es.arg1 == 0:
- print("FIRE {} {}".format(e.x + 4 , e.y))
- elif e.arg1 == 1:
- print("FIRE {} {}".format(e.x + 2 , e.y - 4))
- elif e.arg1 == 2:
- print("FIRE {} {}".format(e.x - 2 , e.y - 4))
- elif e.arg1 == 3:
- print("FIRE {} {}".format(e.x - 4 , e.y))
- elif e.arg1 == 4:
- print("FIRE {} {}".format(e.x - 2 , e.y + 4))
- elif e.arg1 == 5:
- print("FIRE {} {}".format(e.x + 2 , e.y + 4))
- elif distance(m, e) <= 64 and (e.arg2 == 2):
- if es.arg1 == 0:
- print("FIRE {} {}".format(e.x + 7 , e.y))
- elif e.arg1 == 1:
- print("FIRE {} {}".format(e.x + 4 , e.y - 7))
- elif e.arg1 == 2:
- print("FIRE {} {}".format(e.x - 4 , e.y - 7))
- elif e.arg1 == 3:
- print("FIRE {} {}".format(e.x - 7 , e.y))
- elif e.arg1 == 4:
- print("FIRE {} {}".format(e.x - 4 , e.y + 7))
- elif e.arg1 == 5:
- print("FIRE {} {}".format(e.x + 4 , e.y + 7))
- elif distance(m, e) <= 100 and (e.arg2 == 2):
- if e.arg1 == 0:
- print("FIRE {} {}".format(e.x + 8 , e.y))
- elif e.arg1 == 1:
- print("FIRE {} {}".format(e.x + 5 , e.y - 8))
- elif e.arg1 == 2:
- print("FIRE {} {}".format(e.x - 5 , e.y - 8))
- elif e.arg1 == 3:
- print("FIRE {} {}".format(e.x - 8 , e.y))
- elif e.arg1 == 4:
- print("FIRE {} {}".format(e.x - 5 , e.y + 8))
- elif e.arg1 == 5:
- print("FIRE {} {}".format(e.x + 5 , e.y + 8))
- # game loop
- while True:
- my_ship_count = int(input()) # the number of remaining ships
- entity_count = int(input()) # the number of entities (e.g. ships, mines or cannonballs)
- barrels = []#lista z beczkami
- myships = []
- mines = []
- enemyships = []
- cannonballs = []
- forbidden = []
- for i in range(entity_count):
- entity_id, entity_type, x, y, arg_1, arg_2, arg_3, arg_4 = input().split()
- entity_id = int(entity_id)
- x = int(x)
- y = int(y)
- arg_1 = int(arg_1)
- arg_2 = int(arg_2)
- arg_3 = int(arg_3)
- arg_4 = int(arg_4)
- if entity_type == "BARREL":
- b = barrel(x,y)
- barrels.append(b)
- elif entity_type == "SHIP":
- if arg_4 == 1:
- myship = ship(x, y , arg_1, arg_2, arg_3, arg_4, entity_id)
- myships.append(myship)
- else:
- enemyship = ship(x, y , arg_1, arg_2, arg_3, arg_4, entity_id)
- enemyships.append(enemyship)
- elif entity_type == "MINE":
- tmp = mine(x,y)
- mines.append(tmp)
- elif entity_type == "CANNONBALL":
- c = cannonball(x,y)
- cannonballs.append(c)
- myships = list(sorted(myships, key = lambda x: x.entityid))
- for m in myships:
- if m.arg2 != 2:
- speedcond = True
- else:
- speedcond = False
- if m.arg2 == 0:
- mcond = True
- else:
- mcond = False
- for e in enemyships:
- if distance(m, e) <= 100:
- scond = True
- else:
- scond = False
- if cannonballs:
- for c in cannonballs:
- if distance(m,c) <= 15:
- ccond = True
- else:
- ccond = False
- elif not cannonballs:
- ccond = False
- if mines:
- for mi in mines:
- if (distance(m, mi) >= 25) and (distance (m, mi) <= 100) and (m not in forbidden):
- micond = True
- else:
- micond = False
- elif not mines:
- micond = False
- if mcond and barrels and (not scond) and (not micond):
- t = min(barrels, key = lambda x: distance(m, x))
- print("MOVE {} {}".format(t.x, t.y))
- elif mcond and scond:
- t = min(enemyships, key = lambda x : distance(m , x))
- if distance(m , t) < 16:
- shoot(m,t)
- elif (m.x == 0 and m.arg1 in [2,3,4]) or (m.x == 22 and m.arg1 in [0,1,5]) or (m.y == 0 and m.arg1 in [1,2]) or (m.y == 20 and m.arg1 in [4,5]):
- print("PORT")
- else:
- print("FASTER")
- elif scond and (not micond):
- t = min(enemyships, key = lambda x: distance(m, x))
- if (not ccond) or distance(m, t) < 16:
- shoot(m,t)
- else:
- print("FASTER")
- elif scond and micond:
- t = min(enemyships, key = lambda x: distance(m, x))
- if (not ccond) or distance(m, t) < 16:
- shoot(m,t)
- elif (not ccond) or distance(m, t) > 16:
- t = min(mines, key = lambda x: distance(m,x))
- print("FIRE {} {}".format(t.x, t.y))
- else:
- print("FASTER")
- elif mcond and (not barrels) and (not scond):
- t = min(enemyships, key = lambda x: distance(m, x))
- print("MOVE {} {}".format(t.x, t.y))
- elif mcond and (not barrels) and scond:
- t = min(enemyships, key = lambda x: distance(m, x))
- print("FIRE {} {}".format(t.x, t.y))
- elif micond:
- t = min(mines, key = lambda x: distance(m,x))
- print("FIRE {} {}".format(t.x,t.y))
- forbidden.append(t)
- elif barrels and (not mcond):
- t = min(barrels, key = lambda x: distance(m, x))
- print("MOVE {} {}".format(t.x, t.y))
- else:
- t = min(enemyships, key = lambda x: distance(m,x))
- print("MOVE {} {}".format(t.x, t.y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement