import sys
from math import atan2, hypot, pi, cos, sin
from alryslib import *

if len(sys.argv) != 2:
    print('Usage: python.exe test.py input_file')
    sys.exit(1)

buffer = ''

try:
  with open(sys.argv[1], 'r') as f:
    buffer = f.read()
except IOError:
  print('Cannot open %s' % sys.argv[1])
  sys.exit(1)

steps = []
for e in buffer.split():
  try:
    steps.append(float(e))
  except:
    pass

position = [47.5, 43.5, 0]

index = 2

def mon_itineraire():
  global steps, position, index
  x, y = steps[index * 2:(index + 1) * 2]
  a = atan2(y - position[1], x - position[0]) * 180.0 / pi - position[2]
  l = hypot(x - position[0], y - position[1])
  a_droite(a)
  en_avant(l)
  position[2] += a
  position[0] += l * cos(position[2] * pi / 180.0)
  position[1] += l * sin(position[2] * pi / 180.0)
  index += 1
  return len(steps) >= (index + 1) * 2

print(aller_selon(mon_itineraire))
