Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.71 KB | None | 0 0
  1. import sys
  2. import math
  3. # Auto-generated code below aims at helping you parse
  4. # the standard input according to the problem statement.
  5. class ship:
  6.     def __init__(self, x, y , arg1, arg2, arg3, arg4, entityid):
  7.         self.x = int(x)
  8.         self.y = int(y)
  9.         self.arg1 = arg_1
  10.         self.arg2 = arg_2
  11.         self.arg3 = arg_3
  12.         self.arg4 = arg_4
  13.         self.entityid = entity_id
  14.        
  15. class barrel:
  16.     def __init__(self, x, y):
  17.         self.x = int(x)
  18.         self.y = int(y)
  19.        
  20. class mine:
  21.     def __init__(self, x, y):
  22.         self.x = int(x)
  23.         self.y = int(y)
  24.  
  25. class cannonball:
  26.     def __init__(self, x, y):
  27.         self.x = int(x)
  28.         self.y = int(y)
  29.  
  30.        
  31. def distance(ship,anything):
  32.     return ((ship.x - anything.x)**2 + (ship.y - anything.y)**2)
  33.        
  34.  
  35.  
  36. def shoot(m,e):
  37.      if e.arg2 == 0:
  38.         print("FIRE {} {}".format(e.x, e.y))
  39.      elif distance(m,e) <= 25 and (e.arg2 == 1):
  40.         if e.arg1 == 0:
  41.             if e.x + 2 > 20:
  42.                 print("FIRE {} {}".format(20 , e.y))
  43.             else:
  44.                 print("FIRE {} {}".format(e.x  + 3 , e.y))
  45.         elif e.arg1 == 1:
  46.             if e.y - 2 < 0:
  47.                 print("FIRE {} {}".format(e.x + 1, 0))
  48.             else:
  49.                 print("FIRE {} {}".format(e.x + 1 , e.y - 2))
  50.         elif e.arg1 == 2:
  51.              if e.y - 2 < 0:
  52.                 print("FIRE {} {}".format(e.x - 1 , 0))
  53.              else:
  54.                 print("FIRE {} {}".format(e.x - 1 , e.y - 2))
  55.         elif e.arg1 == 3:
  56.             if e.x - 2 < 0:
  57.                 print("FIRE {} {}".format(0 , e.y))
  58.             else:
  59.                 print("FIRE {} {}".format(e.x  - 3 , e.y))
  60.         elif e.arg1 == 4:
  61.             if e.y + 2 > 22:
  62.                 print("FIRE {} {}".format(e.x - 1 , 22))
  63.             else:
  64.                 print("FIRE {} {}".format(e.x - 1 , e.y + 2))
  65.         elif e.arg1 == 5:
  66.             if e.y + 2 > 22:
  67.                 print("FIRE {} {}".format(e.x + 1, 22))
  68.             else:
  69.                 print("FIRE {} {}".format(e.x + 1 , e.y + 2))
  70.      elif distance(m,e) <= 64 and (e.arg2 == 1):
  71.         if e.arg1 == 0:
  72.             if e.x + 4 > 20:
  73.                 print("FIRE {} {}".format(20 , e.y))
  74.             else:
  75.                 print("FIRE {} {}".format(e.x  + 4 , e.y))
  76.                
  77.         elif e.arg1 == 1:
  78.             if e.y - 4 < 0:
  79.                 print("FIRE {} {}".format(e.x + 2 , 0))
  80.             else:
  81.                 print("FIRE {} {}".format(e.x + 2 , e.y - 4))
  82.         elif e.arg1 == 2:
  83.              if e.y - 3 < 0:
  84.                 print("FIRE {} {}".format(e.x - 2 , 0))
  85.              else:
  86.                 print("FIRE {} {}".format(e.x - 2 , e.y - 4))
  87.         elif e.arg1 == 3:
  88.             if e.x - 4 < 0:
  89.                 print("FIRE {} {}".format(0 , e.y))
  90.             else:
  91.                 print("FIRE {} {}".format(e.x  - 4 , e.y))
  92.         elif e.arg1 == 4:
  93.             if e.y + 3 > 22:
  94.                 print("FIRE {} {}".format(e.x - 2, 22))
  95.             else:
  96.                 print("FIRE {} {}".format(e.x - 2 , e.y + 4))
  97.         elif e.arg1 == 5:
  98.             if e.y + 3 > 22:
  99.                 print("FIRE {} {}".format(e.x + 2 , 22))
  100.             else:
  101.                 print("FIRE {} {}".format(e.x + 2 , e.y + 4))
  102.      elif distance(m, e) <= 100 and (e.arg2 == 1):
  103.         if e.arg1 == 0:
  104.             if e.x + 5 > 20:
  105.                 print("FIRE {} {}".format(20 , e.y))
  106.             else:
  107.                 print("FIRE {} {}".format(e.x  + 4 , e.y))
  108.                
  109.         elif e.arg1 == 1:
  110.             if e.y - 5 < 0:
  111.                 print("FIRE {} {}".format(e.x + 2 , 0))
  112.             else:
  113.                 print("FIRE {} {}".format(e.x + 2 , e.y - 4))
  114.         elif e.arg1 == 2:
  115.              if e.y - 5 < 0:
  116.                 print("FIRE {} {}".format(e.x - 2 , 0))
  117.              else:
  118.                 print("FIRE {} {}".format(e.x - 2 , e.y - 4))
  119.         elif e.arg1 == 3:
  120.             if e.x - 5 < 0:
  121.                 print("FIRE {} {}".format(0 , e.y))
  122.             else:
  123.                 print("FIRE {} {}".format(e.x  - 4 , e.y))
  124.         elif e.arg1 == 4:
  125.             if e.y + 5 > 22:
  126.                 print("FIRE {} {}".format(e.x - 2 , 22))
  127.             else:
  128.                 print("FIRE {} {}".format(e.x - 2 , e.y + 4))
  129.         elif e.arg1 == 5:
  130.             if e.y + 5 > 22:
  131.                 print("FIRE {} {}".format(e.x + 2 , 22))
  132.             else:
  133.                 print("FIRE {} {}".format(e.x + 2 , e.y + 4))
  134.      elif distance(m, e) <= 25 and (e.arg2 == 2):
  135.         if es.arg1 == 0:
  136.             print("FIRE {} {}".format(e.x + 4 , e.y))
  137.         elif e.arg1 == 1:
  138.             print("FIRE {} {}".format(e.x + 2 , e.y - 4))
  139.         elif e.arg1 == 2:
  140.             print("FIRE {} {}".format(e.x - 2 , e.y - 4))
  141.         elif e.arg1 == 3:
  142.             print("FIRE {} {}".format(e.x - 4 , e.y))
  143.         elif e.arg1 == 4:
  144.             print("FIRE {} {}".format(e.x - 2 , e.y + 4))
  145.         elif e.arg1 == 5:
  146.             print("FIRE {} {}".format(e.x + 2 , e.y + 4))
  147.        
  148.      elif distance(m, e) <= 64 and (e.arg2 == 2):
  149.         if es.arg1 == 0:
  150.             print("FIRE {} {}".format(e.x + 7 , e.y))
  151.         elif e.arg1 == 1:
  152.             print("FIRE {} {}".format(e.x + 4 , e.y - 7))
  153.         elif e.arg1 == 2:
  154.             print("FIRE {} {}".format(e.x - 4 , e.y - 7))
  155.         elif e.arg1 == 3:
  156.             print("FIRE {} {}".format(e.x - 7 , e.y))
  157.         elif e.arg1 == 4:
  158.             print("FIRE {} {}".format(e.x - 4 , e.y + 7))
  159.         elif e.arg1 == 5:
  160.             print("FIRE {} {}".format(e.x + 4 , e.y + 7))
  161.      elif distance(m, e) <= 100 and (e.arg2 == 2):
  162.         if e.arg1 == 0:
  163.             print("FIRE {} {}".format(e.x + 8 , e.y))
  164.         elif e.arg1 == 1:
  165.             print("FIRE {} {}".format(e.x + 5 , e.y - 8))
  166.         elif e.arg1 == 2:
  167.             print("FIRE {} {}".format(e.x - 5 , e.y - 8))
  168.         elif e.arg1 == 3:
  169.             print("FIRE {} {}".format(e.x - 8 , e.y))
  170.         elif e.arg1 == 4:
  171.             print("FIRE {} {}".format(e.x - 5 , e.y + 8))
  172.         elif e.arg1 == 5:
  173.             print("FIRE {} {}".format(e.x + 5 , e.y + 8))
  174.    
  175.  
  176.  
  177.            
  178.            
  179.  
  180.  
  181. # game loop
  182. while True:
  183.     my_ship_count = int(input())  # the number of remaining ships
  184.     entity_count = int(input())  # the number of entities (e.g. ships, mines or cannonballs)
  185.     barrels = []#lista z beczkami
  186.     myships = []
  187.     mines = []
  188.     enemyships = []
  189.     cannonballs = []
  190.     forbidden = []
  191.    
  192.    
  193.     for i in range(entity_count):
  194.         entity_id, entity_type, x, y, arg_1, arg_2, arg_3, arg_4 = input().split()
  195.         entity_id = int(entity_id)
  196.         x = int(x)
  197.         y = int(y)
  198.         arg_1 = int(arg_1)
  199.         arg_2 = int(arg_2)
  200.         arg_3 = int(arg_3)
  201.         arg_4 = int(arg_4)
  202.         if entity_type == "BARREL":
  203.             b = barrel(x,y)
  204.             barrels.append(b)
  205.         elif entity_type == "SHIP":
  206.             if arg_4 == 1:
  207.                 myship = ship(x, y , arg_1, arg_2, arg_3, arg_4, entity_id)
  208.                 myships.append(myship)
  209.             else:
  210.                 enemyship = ship(x, y , arg_1, arg_2, arg_3, arg_4, entity_id)
  211.                 enemyships.append(enemyship)
  212.         elif entity_type == "MINE":
  213.             tmp = mine(x,y)
  214.             mines.append(tmp)
  215.        
  216.        
  217.         elif entity_type == "CANNONBALL":
  218.             c = cannonball(x,y)
  219.             cannonballs.append(c)
  220.        
  221.         myships = list(sorted(myships, key = lambda x: x.entityid))
  222.        
  223.  
  224.    
  225.    
  226.            
  227.     for m in myships:
  228.         if m.arg2 != 2:
  229.             speedcond = True
  230.         else:
  231.             speedcond = False
  232.         if m.arg2 == 0:
  233.             mcond = True
  234.         else:
  235.             mcond = False
  236.         for e in enemyships:
  237.             if distance(m, e) <= 100:
  238.                 scond = True
  239.             else:
  240.                 scond = False
  241.         if cannonballs:
  242.             for c in cannonballs:
  243.                 if distance(m,c) <= 15:
  244.                     ccond = True
  245.                 else:
  246.                     ccond = False
  247.         elif not cannonballs:
  248.             ccond = False
  249.         if mines:
  250.             for mi in mines:
  251.                 if (distance(m, mi) >= 25) and (distance (m, mi) <= 100) and (m not in forbidden):
  252.                     micond = True
  253.                 else:
  254.                     micond = False
  255.         elif not mines:
  256.             micond = False
  257.        
  258.        
  259.        
  260.        
  261.        
  262.        
  263.        
  264.         if mcond and barrels and (not scond) and (not micond):
  265.             t = min(barrels, key = lambda x: distance(m, x))
  266.             print("MOVE {} {}".format(t.x, t.y))
  267.            
  268.         elif mcond and scond:
  269.             t = min(enemyships, key = lambda x : distance(m , x))
  270.             if distance(m , t) < 16:
  271.                 shoot(m,t)
  272.             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]):
  273.                 print("PORT")
  274.             else:
  275.                 print("FASTER")
  276.            
  277.            
  278.         elif scond and (not micond):
  279.             t = min(enemyships, key = lambda x: distance(m, x))
  280.             if (not ccond) or distance(m, t) < 16:
  281.                 shoot(m,t)
  282.             else:
  283.                 print("FASTER")
  284.        
  285.         elif scond and micond:
  286.             t = min(enemyships, key = lambda x: distance(m, x))
  287.             if (not ccond) or distance(m, t) < 16:
  288.                 shoot(m,t)
  289.             elif (not ccond) or distance(m, t) > 16:
  290.                 t = min(mines, key = lambda x: distance(m,x))
  291.                 print("FIRE {} {}".format(t.x, t.y))
  292.             else:
  293.                 print("FASTER")
  294.            
  295.                
  296.  
  297.                
  298.         elif mcond and (not barrels) and (not scond):
  299.             t = min(enemyships, key = lambda x: distance(m, x))
  300.             print("MOVE {} {}".format(t.x, t.y))
  301.        
  302.         elif mcond and (not barrels) and scond:
  303.             t = min(enemyships, key = lambda x: distance(m, x))
  304.             print("FIRE {} {}".format(t.x, t.y))
  305.        
  306.            
  307.                
  308.        
  309.                
  310.        
  311.        
  312.  
  313.         elif micond:
  314.             t = min(mines, key = lambda x: distance(m,x))
  315.             print("FIRE {} {}".format(t.x,t.y))
  316.             forbidden.append(t)
  317.  
  318.                
  319.         elif barrels and (not mcond):
  320.             t = min(barrels, key = lambda x: distance(m, x))
  321.             print("MOVE {} {}".format(t.x, t.y))
  322.            
  323.         else:
  324.             t = min(enemyships, key = lambda x: distance(m,x))
  325.             print("MOVE {} {}".format(t.x, t.y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement