# -*- coding: utf-8 -*-


import api

from utils import _, Bataillon, Armee, target, dist
from utils import etat as e


def partie_debut():
    global armee
    armee = Armee()

fontaines = {(15, 0):target.LIBRE, (0, 15):target.LIBRE}
phase = 1

def phase_construction():
    e.update_construction()
    global phase

    targets = []
    for adv in e.adversaires:
        targets.extend([(dist((0,0), c.pos), c.pos) for c in api.tourelles_joueur(adv.di)])
    targets.sort(key=lambda a: a[0])
    i = 0
    while targets:
        i+=1
        armee.add(Bataillon(20, targets.pop()[1], armee))
        if i == 5:
            break
    armee.update_construction()


def phase_deplacement():
    e.update_deplacement()
    armee.update_deplacement()


def phase_tirs():
    e.update_tirs()


def phase_siege():
    e.update_siege()
    armee.update_siege()


def partie_fin():
    pass