philRG

MM Starter (for Remi. only :-))

Apr 17th, 2022 (edited)
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.77 KB | None | 0 0
  1. import sys
  2. from dataclasses import dataclass, field
  3. from enum import Enum
  4.  
  5. from numpy import array, linalg
  6.  
  7.  
  8. def idebug(*args):
  9.     return
  10.     print(*args, file=sys.stderr, flush=True)
  11.  
  12.  
  13. def debug(*args):
  14.     # return
  15.     print(*args, file=sys.stderr, flush=True)
  16.  
  17.  
  18. # Units in Wood 3
  19. class UnitType(Enum):
  20.     REAPER = 0
  21.     # DESTROYER = 1
  22.     # DOOF = 2
  23.     # TANKER = 3
  24.     WRECK = 4
  25.  
  26.  
  27. @dataclass
  28. class Unit:
  29.     id: int
  30.     type: UnitType
  31.     player: int
  32.     mass: int
  33.     radius: int
  34.     x: int
  35.     y: int
  36.     vx: int
  37.     vy: int
  38.     location: array = field(init=False)
  39.     velocity: array = field(init=False)
  40.     speed: int = field(init=False)
  41.  
  42.     def __post_init__(self):
  43.         self.location = array([self.x, self.y], dtype=float)
  44.         self.velocity = array([self.vx, self.vy], dtype=float)
  45.         self.speed = linalg.norm(self.velocity)
  46.  
  47.     def dist(self, other):
  48.         return linalg.norm(self.location - other.location)
  49.  
  50.     def __repr__(self):
  51.         return f'{self.player} {self.type} {self.location} {self.velocity} {self.mass} {self.radius}'
  52.  
  53.  
  54. @dataclass
  55. class Wreck(Unit):
  56.     water: int
  57.  
  58.     def __repr__(self):
  59.         return f'{self.type} #{self.id} has {self.water} water'
  60.  
  61.  
  62. # game loop
  63. while True:
  64.     my_score = int(input())
  65.     idebug(my_score)
  66.     enemy_score_1 = int(input())
  67.     idebug(enemy_score_1)
  68.     enemy_score_2 = int(input())
  69.     idebug(enemy_score_2)
  70.     my_rage = int(input())
  71.     idebug(my_rage)
  72.     enemy_rage_1 = int(input())
  73.     idebug(enemy_rage_1)
  74.     enemy_rage_2 = int(input())
  75.     idebug(enemy_rage_2)
  76.  
  77.     unit_count = int(input())
  78.     idebug(unit_count)
  79.     units = []
  80.     wrecks = []
  81.     for i in range(unit_count):
  82.         line = input()
  83.         idebug(line)
  84.         inputs = line.split()
  85.         unit_id = int(inputs[0])
  86.         unit_type = int(inputs[1])
  87.         player = int(inputs[2])
  88.         mass = float(inputs[3])
  89.         radius = int(inputs[4])
  90.         x = int(inputs[5])
  91.         y = int(inputs[6])
  92.         vx = int(inputs[7])
  93.         vy = int(inputs[8])
  94.         extra = int(inputs[9])
  95.         extra_2 = int(inputs[10])
  96.         # debug(f'unit type = {unit_type}')
  97.         if unit_type == UnitType.WRECK.value:
  98.             wrecks.append(Wreck(id=unit_id, type=UnitType.WRECK, player=player, mass=mass, radius=radius, x=x, y=y, vx=vx, vy=vy, water=extra))
  99.         else:
  100.             units.append(Unit(id=unit_id, type=UnitType(unit_type), player=player, mass=mass, radius=radius, x=x, y=y, vx=vx, vy=vy))
  101.  
  102.     my_reaper: Unit = [u for u in units if u.player == 0][0]
  103.     target: Wreck = min(wrecks, key=lambda w: w.dist(my_reaper))
  104.  
  105.     x, y = target.location
  106.  
  107.     thrust = 300
  108.     print(f'{round(x)} {round(y)} {thrust}')
  109.  
  110.     print('WAIT')
  111.     print('WAIT')
  112.  
Add Comment
Please, Sign In to add comment