# Untitled

unknown
python
3 years ago
4.0 kB
1
Indexable
Never
```import sys
import math

class Unite:
def __init__(self, entity_id  , entity_type,x,y,vx, vy  ,state):
self.id = entity_id
self.type = entity_type
self.x = x
self.y = y
self.vx = vx
self.vy = vy
self.state = state

def distance(objet1,objet2):
x1=objet1.x
y1=objet1.y
x2=objet2.x
y2=objet2.y
d=((x2-x1)**2+(y2-y1)**2)**0.5
return d

def distancei(objet1,objet2):
x1=objet1.x+objet1.vx
y1=objet1.y+objet1.vy
x2=objet2.x+objet2.vx
y2=objet2.y+objet2.vy

d=((x2-x1)**2+(y2-y1)**2)**0.5
return d

def proche(objet,liste_objet):
objet0=liste_objet[0]
d0=distancei(objet,objet0)
for objet2 in liste_objet:
d=distancei(objet,objet2)
if d<d0:
d0=d
objet0=objet2
return objet0

def scalaire(objet1,objet2,but):
x1=objet1.x
y1=objet1.y
x2=objet2.x
y2=objet2.y
xbut=but.x
ybut=but.y
p= (x2-x1)*(xbut-x2)+(y2-y1)*(ybut-y2)
return p

def aligne(objet1,objet2,but):
if abs(distance(objet1,objet2)*distance(objet2,but)-scalaire(objet1,objet2,but))<100:
return True
else:
return False

def ordoneebut(objet1,objet2):
x1=objet1.x
y1=objet1.y
x2=objet2.x
y2=objet2.y
if x2-x1!=0:
ybord=(y2-y1)/(x2-x1)*(xbut-x1)+y2
else:
ybord=0
return ybord

def flip(objet,liste_objet):
for objet2 in liste_objet:
y=ordoneebut(objet,objet2)
if 2150<y<5350 and (objet2.x-objet.x)*(-1)**my_team_id>0 and distance(objet,objet2)>700:
return objet2
else:
return False

#def petrificus(objet):
#for objet2 in

# Grab Snaffles and try to throw them through the opponent's goal!
# Move towards a Snaffle and use your team id to determine where you need to throw it.

my_team_id = int(input())  # if 0 you need to score on the right of the map, if 1 you need to score on the left
xbut=16000*(1-my_team_id)
ybut=3750
# game loop
while True:
mywizards=[]
balls=[]
my_score, my_magic = [int(i) for i in input().split()]
opponent_score, opponent_magic = [int(i) for i in input().split()]
entities = int(input())  # number of entities still in game
for i in range(entities):
inputs = input().split()
entity_id = int(inputs[0])  # entity identifier
entity_type = inputs[1]  # "WIZARD", "OPPONENT_WIZARD" or "SNAFFLE" (or "BLUDGER" after first league)
x = int(inputs[2])  # position
y = int(inputs[3])  # position
vx = int(inputs[4])  # velocity
vy = int(inputs[5])  # velocity
state = int(inputs[6])  # 1 if the wizard is holding a Snaffle, 0 otherwise
objet = Unite(entity_id  , entity_type,x,y,vx, vy  ,state)
if entity_type == "WIZARD":
mywizards.append(objet)
elif entity_type == "SNAFFLE":
balls.append(objet)

for i in range(2):
sorcier=mywizards[i]

# Write an action using print

# To debug: print("Debug messages...", file=sys.stderr, flush=True)

# Edit this line to indicate the action for each wizard (0 ≤ thrust ≤ 150, 0 ≤ power ≤ 500)
# i.e.: "MOVE x y thrust" or "THROW x y power"
ballonp=proche(sorcier, balls)
ballon=flip(sorcier,balls)
if sorcier.state!=0:
print("THROW {} {} 500 tire".format(xbut,ybut))

elif ballon and my_magic>=20:
print("FLIPENDO {} flip".format(ballon.id))
my_magic-=20

elif (ballonp.x-sorcier.x)*(-1)**my_team_id<0 and my_magic>=15 :
print("ACCIO {} accio".format(ballonp.id))
my_magic-=15

else:
ballonp=proche(sorcier, balls)
print("MOVE {} {} 150 go".format(ballonp.x,ballonp.y))

```