Advertisement
Guest User

Untitled

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