Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Position:
- def __init__(self, x, y):
- self.x, self.y = x, y
- self.radius = math.sqrt(self.x ** 2 + self.y ** 2)
- def dist(self, other):
- return math.sqrt((other.y - self.y) ** 2 + (other.x - self.x) ** 2)
- def __repr__(self):
- return f'{self.x} {self.y}'
- class Unit:
- def __init__(self, type, player, mass, radius, x, y, vx, vy):
- self.type = UnitType(type)
- self.player = player
- self.mass = mass
- self.radius = radius
- self.pos = Position(x, y)
- self.speed = Position(vx, vy)
- def move_to(self, unit) -> Tuple[int, int]:
- vx, vy = self.speed.x, self.speed.y
- if abs(vx) + abs(vy) < 10:
- x, y = unit.pos.x, unit.pos.y
- else:
- x, y = unit.pos.x - MINUS_V * vx, unit.pos.y - MINUS_V * vy
- return x, y
- def near(self, units) -> bool:
- for u in units:
- if self.dist(u) < u.radius + 10:
- return True
- return False
- def inside(self, units) -> bool:
- for u in units:
- if self.dist(u) < u.radius:
- return True
- return False
- def dist(self, other) -> int:
- return self.pos.dist(other.pos)
- def send_oil_to(self, target) -> Position:
- target_location = np.array([target.pos.x, target.pos.y])
- source_location = np.array([self.pos.x, self.pos.y])
- direction = target_location - source_location
- norm = np.linalg.norm(direction)
- vector = direction / norm
- _range = self.dist(target) - SKILL_RANGE + 1
- point = np.array([self.pos.x, self.pos.y]) + np.array([_range * vector[0], _range * vector[1]])
- return Position(*point)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement