Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from dataclasses import dataclass, field
- from enum import Enum
- from numpy import array, linalg
- def idebug(*args):
- return
- print(*args, file=sys.stderr, flush=True)
- def debug(*args):
- # return
- print(*args, file=sys.stderr, flush=True)
- # Units in Wood 3
- class UnitType(Enum):
- REAPER = 0
- # DESTROYER = 1
- # DOOF = 2
- # TANKER = 3
- WRECK = 4
- @dataclass
- class Unit:
- id: int
- type: UnitType
- player: int
- mass: int
- radius: int
- x: int
- y: int
- vx: int
- vy: int
- location: array = field(init=False)
- velocity: array = field(init=False)
- speed: int = field(init=False)
- def __post_init__(self):
- self.location = array([self.x, self.y], dtype=float)
- self.velocity = array([self.vx, self.vy], dtype=float)
- self.speed = linalg.norm(self.velocity)
- def dist(self, other):
- return linalg.norm(self.location - other.location)
- def __repr__(self):
- return f'{self.player} {self.type} {self.location} {self.velocity} {self.mass} {self.radius}'
- @dataclass
- class Wreck(Unit):
- water: int
- def __repr__(self):
- return f'{self.type} #{self.id} has {self.water} water'
- # game loop
- while True:
- my_score = int(input())
- idebug(my_score)
- enemy_score_1 = int(input())
- idebug(enemy_score_1)
- enemy_score_2 = int(input())
- idebug(enemy_score_2)
- my_rage = int(input())
- idebug(my_rage)
- enemy_rage_1 = int(input())
- idebug(enemy_rage_1)
- enemy_rage_2 = int(input())
- idebug(enemy_rage_2)
- unit_count = int(input())
- idebug(unit_count)
- units = []
- wrecks = []
- for i in range(unit_count):
- line = input()
- idebug(line)
- inputs = line.split()
- unit_id = int(inputs[0])
- unit_type = int(inputs[1])
- player = int(inputs[2])
- mass = float(inputs[3])
- radius = int(inputs[4])
- x = int(inputs[5])
- y = int(inputs[6])
- vx = int(inputs[7])
- vy = int(inputs[8])
- extra = int(inputs[9])
- extra_2 = int(inputs[10])
- # debug(f'unit type = {unit_type}')
- if unit_type == UnitType.WRECK.value:
- 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))
- else:
- units.append(Unit(id=unit_id, type=UnitType(unit_type), player=player, mass=mass, radius=radius, x=x, y=y, vx=vx, vy=vy))
- my_reaper: Unit = [u for u in units if u.player == 0][0]
- target: Wreck = min(wrecks, key=lambda w: w.dist(my_reaper))
- x, y = target.location
- thrust = 300
- print(f'{round(x)} {round(y)} {thrust}')
- print('WAIT')
- print('WAIT')
Add Comment
Please, Sign In to add comment