from time import*
from api import*
l=['VIDE','PLOMB','FER','CUIVRE','MERCURE','SOUFRE']
def el(a):
  global l
  return(l[a])

def nbel(a):
  global l
  for k in range(6):
    if(l[k]==a):
      return k

def DEBUT_TOUR():
  def autre():
    return 3-moi()
  etabli = [[[0]*6 for i in range(6)] for k in range(2)]
  zone_dim = [[[]] for i in range(6)] for k in range(2)]#liste id, type, liste de region=liste de couple
  def init_etabli():
    global etabli
    for id in range(2):
      for y in range(6):
        for x in range(6):
          etabli[id][y][x]=nbel[propriete_case((y,x),id+1)]
  def init_zone_dim():
    for id in range(1,3);
      deja_pris=[[False]*6 for k in range(6)]
      for y in range(6):
        for x in range(6):
          if(not(deja_pris[y][x]) and type_case((y,x),id)):
            def parcw(a,b):
              if(a>=0 and a<=5 and b>=0 and b<=5 and not(deja_pris[a][b])):
                deja_pris[a][b]=True
                zone_dim[id][nbel(type_case((a,b),id)))][-1].append((a,b))
                for zorglub in range(-1,2):
                  for zorglab in  range(-1+abs(zorglub),3-abs(zorglub),1+abs(zorglub)):
                    parcw(a+zorglub,b+zorglab)
            parcw(y,x)
            if(zone_dim[id][nbel(type_case((a,b),id)))]==[]):
  init_etabli()
  def placer_echantillo(pos):
    etabli[moi()][pos[0][1]][pos[0][0]] = nbel(echantillon_tour()[0])
    etabli[moi()][pos[1][1]][pos[1][0]] = nbel(echantillon_tour()[1])
    placer_echantillon(pos)
  def choisir_quoi_transmuter(nbtrans):
    def(trouver_faille):
      return 0

  def dern():
   def reccat():
    return 0
  def t_reg_pla(pos,id):#pos les deux cases a remplir
        placer_echantillon(pos[0],pos[1])
        zyr=taille_region(pos[id],moi())
        annuler()
        return zyr
  t=time()
  if(tour_actuel()<3):
    placer_echantillon((2,3),(3,3))
  if(True):
    if(tour_actuel()>2):
      m=0
      for k in placememts_possibles_echantillon(echantillon_tour(),moi()):
        m= max(m,t_reg_pla(k,0))
        m= max(m,t_reg_pla(k,1))
      for k in placememts_possibles_echantillon(echantillon_tour(),moi()):
        if(m==max(t_reg_pla(k,0),t_reg_pla(k,1))):
          placer_echantillon(k[0],k[1])
    if(element_propriete(echantillon_tour()[0])== TRANSMUTABLE_CATALYSEUR or element_propriete(echantillon_tour()[1])==TRANSMUTABLE_CATALYSEUR):
      donner_echantillon((MERCURE,SOUFRE))
    else:
      donner_echantillon((MERCURE,echantillon_tour()[0]))
  if(not(a_pose_echantillon)):
    if(placements_possible_echantillon()!=[]):
          placer_echantillon(placements_possible_echantillon()[0][0],placements_possible_echantillon()[0][1])
    else:
      aw=nbel(echantillon_tour())
      for y in range(6):
        for x in range(6):
          if(propriete_case((y,x),moi())==echantillon_tour[0]):
            transmuter((y,x))
            if(placements_possible_echantillon()!=[]):
              placer_echantillon(placements_possible_echantillon()[0][0],placements_possible_echantillon()[0][1])
            else:
              for y2 in range(6):
                for x2 in range(6):
                  if(propriete_case((y2,x2),moi())==echantillon_tour[1]):
                    transmuter((y2,x2))
                    placer_echantillon(placements_possible_echantillon()[0][0],placements_possible_echantillon()[0][1])
#  if(tour_actuel()==150):dern()
#  if(tour_actuel()==149):adern()
