attakth_ia2.py

Created by mathieu-croslacoste

Created on September 15, 2025

14.3 KB

Attakth_ia compressed, doesn’t work on emulatpr.


from kandinsky import fill_rect as F,draw_string as D
from ion import keydown as K
from random import randint as R
from time import sleep as S
W=range
MechDat={#21 machines possibles
"Bondisseur":(1,"F","B",1,1,4,3),
"Brouteur":(1,"F","LR",1,1,2,4),
#"Long-nez":(1,"F","B",2,1,2,5),
"Pillard":(1,"F","B",2,1,3,5),
"Tunnelier":(1,"F","B",2,1,2,4),
"Charognarde":(2,"F","B",3,2,2,5),
"Corne-filante":(2,"F","LR",2,2,2,5),
#"Corne-sabre":(2,"F","LR",2,2,2,5),
"Coureuse":(2,"F","B",2,2,3,4),
#"Etincelle":(2,"B","F",2,3,3,5),
"Fouisseur":(2,"F","B",2,1,3,4),
#"Hautes-pattes":(2,"F","B",1,2,4,6),
#"Laboureur":(2,"F","B",2,1,2,5),
"Razoptere":(2,"F","B",2,3,2,6),
#"Tunnelier pisteur":(2,"F","B",2,1,2,4),
"Aile-d'Helion":(3,"B","F",3,2,3,7),
#"Carapateur":(3,"F","B",3,3,2,7),
#"Cracheur boursoufle":(3,"F","BLR",3,2,2,7),
"Galop-griffe":(3,"F","B",3,2,2,8),
#"Grande-bouche":(3,"F","B",3,2,2,7),
"Testudien":(3,"FR","B",2,1,2,7),
#"Veilleur rouge":(3,"LR","F",2,2,2,5),
#"Galop-griffe elemental":(4,"F","B",3,2,2,8),
#"Grimpeur":(4,"F","B",3,1,3,8),
"Gyrodorse":(4,"FLR","B",3,2,3,5),
"Ravageur":(4,"F","B",2,2,2,9),
"Traqueur":(4,"F","B",4,2,3,5),
#"Frappe-defense":(5,"F","B",3,2,2,10),
#"Galop-griffe supreme":(5,"FLR","B",3,1,2,8),
#"Mastodonte":(5,"F","LR",3,2,2,10),
"Vulpivol":(5,"F","B",3,3,2,9),
#"Brise-roc":(6,"LR","B",3,2,3,9),
"Brisevague":(6,"LR","B",4,3,2,10),
#"Carapeste":(6,"BLR","F",3,3,2,10),
#"Gueule-d'orage":(6,"BF","LR",3,2,3,10),
"Oiseau-tempete":(6,"F","B",3,3,3,9),
#"Griffes de feu":(7,"F","B",4,2,3,10),
#"Griffes de gel":(7,"LR","F",4,2,2,10),
"Grilleuse":(8,"F","B",4,2,2,12),
"Rampant":(9,"F","B",4,3,2,12),
"Massacrepine":(10,"F","LR",4,1,2,15)}
icones={
"pow":('2#','$%,%$#',"$'('$#",'%%*%%#','%$$$($$$%#','($&$(#','+$)#','*$*#',')$+#','($&$(#',"'$($'#",'&$*$&#','$%,%$#','$%,%$#','2#'),
"ran":('*$*#','($$$$$(#','&%%$%%&#',"%$'$'$%#",'%$,$%#','$$.$$#','*$*#',"#'%&%'#",'*$*#','$$.$$#','%$,$%#',"%$'$'$%#",'&%%$%%&#','($$$$$(#','*$*#'),
"spe":('*$*#',')&)#','(%$%(#','($&$(#','*$*#','%%&$&%%#',"$%'$'%$#",'#%%*%%#',"$%'$'%$#",'%%&$&%%#','*$*#','($&$(#','(%$%(#',')&)#','*$*#'),
"hps":("&'$'&#","%$'$'$%#",'$$%%&%%$$#',"#$%'$'%$#",'#$$.$$#','#$$.$$#','#$$.$$#','#$%,%$#','$$%*%$$#','%$%(%$%#','&$%&%$&#',"'$%$%$'#",'($&$(#',')$$$)#','*$*#')}
im=(('#&###','#$$$#','#$$$#','#$$$#','#&###'),('$$$#','#%$#','$$$#','$$$#','#&###'),('#&###','%$#','#&###','#$%#','#&###'),('#&###','%$#','#&###','%$#','#&###'),('#$$$#','#$$$#','#&###','%$#','%$#'),('#&###','#$%#','#&###','%$#','#&###'),('#&###','#$%#','#&###','#$$$#','#&###'),('#&###','%$#','$$$#','#$%#','#$%#'),('#&###','#$$$#','#&###','#$$$#','#&###'),('#&###','#$$$#','#&###','%$#','#&###'))
Pal=("brown","cyan",(150,255,50),"g","grey",(220,220,220))
class Mech:
 def __init__(s,name,x,y,rot=0):s.name,s.moved,s.atkd,s.x,s.y,s.rotA=name,0,0,x,y,rot;s.PV,s.Armr,s.Weak,s.Pow,s.Ran,s.Move,s.Hp=MechDat[name]
 def upPos(s,x,y,rot=0):s.x,s.y,s.rotA=x,y,rot
def CS(c="w"):F(0,0,320,222,c)
def Dess(str,X,Y,c,bg="w"):
 CurX=X
 for char in str:
  if char!='\n':D(char,CurX,Y,c,bg);CurX+=8
  else:CurX,Y=X,Y+16
def Cur(x,y,c):
 for k in(0,1):F(x,y+25*k,8,1,c);F(x+18,y+25*k,8,1,c);F(x+25*k,y+18,1,8,c);F(x+25*k,y,1,8,c)
def EffCur(xA=0,yA=0,xB=7,yB=7):
 for i in W(xA,xB+1):
  for j in W(yA,yB+1):Cur(Xc+25*i,Yc+25*j,"k")
 F(0,0,320,19,bg);F(0,0,116,60,bg)
def AffHp(mech,dmg=0,simul=0,atkOnArmr=0,atkOnWeak=0):
 dmg=max(1,dmg);leftHp,Xa,Ya=max(0,mech.Hp-dmg*simul),mech.x,mech.y
 if simul:F(Xc+5+25*Xa-7*(dmg>9),Yc+3+25*Ya,8+7*(dmg>9)+8,12,"r");Im(-dmg,Xc+6+25*Xa-7*(dmg>9),Yc+4+25*Ya,"w","r",2)
 else:Aff(mech,1,0)
 Pow=Map[Ya][Xa]+mech.Pow+simul*(atkOnArmr-atkOnWeak);F(Xc+1+25*Xa,Yc+18+25*Ya,5+4*(Pow<0),7,"rb"[mech in PlHand]);Im(Pow,Xc+2+25*Xa,Yc+19+25*Ya,("w",(100,200,255),"pink")[atkOnArmr+2*atkOnWeak],"rb"[mech in PlHand]);F(Xc+20+25*Xa-4*(leftHp>9),Yc+18+25*Ya,5+4*(leftHp>9),7,"rb"[mech in PlHand]);Im(leftHp,Xc+21+25*Xa-4*(leftHp>9),Yc+19+25*Ya,"w","rb"[mech in PlHand])
def Aff(mechId,dMech=1,dHp=1):
 Xa,Ya=mechId.x,mechId.y;F(119+25*Xa,20+25*Ya,24,24,Pal[Map[Ya][Xa]+2])
 if dMech:
  Dess(mechId.name[0:2],Xc+25*Xa+4,Yc+25*Ya+4,"k",Pal[Map[Ya][Xa]+2]);FArmr(Xc+25*Xa+5,Yc+25*Ya+5,mechId.name,mechId.rotA)
  if dHp:AffHp(mechId)
def FArmr(x,y,card,rot=0):
 clrs=[((200,)*3,("r",(50,200,255))[l in MechDat[card][1]])[l in"".join(MechDat[card][1:3])]for l in"FLB"]
 for k in(-1,0,1):F((x+7+2*k,x+18-2*k**2,x+7-2*k,x-3+2*k**2)[rot],(y-4+2*k**2,y+7+2*k,y+18-2*k**2,y+7-2*k)[rot],2,2,clrs[0])
 for k in(0,1,2):F((x-4,x+4,x+18,x+4)[rot-k],(y+4,y-4,y+4,y+18)[rot-k],(2,8)[rot%2-k%2],(8,2)[rot%2-k%2],(clrs[1+k%2],(100,200,255))[card=="Testudien"and k==2])
def Im(truc,x,y,c="b",bg="w",z=1):
 l=(1,len(str(truc)))[len(str(truc))<3]
 for el in W(l):
  if str(truc)[el]=="-":F(x,y+2*z,z*3,z,c)
  else:
   if len(str(truc))<3:motif=im[int(str(truc)[el])]
   else:motif=icones[truc]
   for lig in W(len(motif)):
    elt,rang=motif[lig],0
    for pos in W(0,len(elt)-1,2):
     for k in(0,1):F(x+z*rang+z*4*el,y+z*lig,z*(ord(elt[pos+k])-35),z,(bg,c)[k]);rang+=ord(elt[pos+k])-35
def Cadre(X=5,Y=105,c="brown"):
 for k in(0,1):F(X-4,Y-20+97*k,116,3,c);F(X-5+115*k,Y-19,3,98,c)
def CardId(card,mech=None,X=198,Y=28,c="brown"):
 F(X-2,Y-17,112,94,"k");Dess(str((card,card.split(" ")[0])[len(card)>14]),X-3,Y-15,"y","k")
 if len(card)>14:Dess(str(card.split(" ")[1]),X-3,Y+1,"y","k")
 Cadre(X,Y,c);Dess("PV",X+47,Y+20,"y","k")
 for l in W(20):F(X+89-l,Y+39-l,2*l,1,"y")
 Dess(str(MechDat[card][0]),X+84-4*(MechDat[card][0]>9),Y+20,"brown","y");FArmr(X+15,Y+30,card);F(X,Y+55,108,18,"brown")
 for k in W(4):
  Im(("pow","ran","spe","hps")[k],X+25*k,Y+57,"w","brown")
  if k==3 and mech:Im(mech.Hp,X+92,Y+60,"w","brown",2)
  else:Im(MechDat[card][k+3],X+17+25*k,Y+60,"w","brown",2)
def Card(X,Y):
 for mech in PlHand+AdvHand:
  if (X,Y)==(mech.x,mech.y):CardId(mech.name,mech,5,105,"rb"[mech in PlHand])
def Main(mechList):
 X,Y,mechList2=25,80,sorted(set(mechList));F(5,108,224,114,"w")
 for k in W(len(mechList2)):Dess(str(mechList.count(mechList2[k]))+"x"+mechList2[k],X+2,Y+28+16*k,"g");Im(MechDat[mechList2[k]][0],X-6,Y+32+16*k,"brown","y",2)
 Dess("PMP "+str(sum([MechDat[mechList[k]][0]for k in W(len(mechList))]))+"/10",X,Y-15,"r","w");S(.2)
mechAtkable,atkOnArmr,atkOnWeak,actMech,usedMech,score=None,0,0,None,set(),[0,0]
def ORI(actMech):
 Dess("SHIFT/ALPHA Tourner",110,1,c,bg)
 if K(13)|K(12):
  actMech.rotA=(actMech.rotA+K(13)-K(12))%4
  if mechAtkable:Aff(mechAtkable)
  Aff(actMech);S(.1)
def EmpLibr(X,Y):return 1-any((X,Y)==(mech.x,mech.y)for mech in PlHand+AdvHand)
def PlcPiece(choix):
 X,Y,chgX,chgY=4,7,-1,0
 for i in W(8):
  for j in(6,7):Cur(Xc+25*i,Yc+25*j,"y")
 while(K(52)and Y in(6,7)and EmpLibr(X,Y)and(Map[Y][X]!=-2))^1:
  if chgX|chgY:CardId(chosenMech[choix],None,5,105,c="b");Cur(Xc+25*X,Yc+25*Y,"ky"[Y in(6,7)]);X,Y=(X+chgX)%8,(Y+chgY)%8;Cur(Xc+25*X,Yc+25*Y,"r");Card(X,Y);S(.2)
  chgX,chgY=K(3)-K(0),K(2)-K(1)
 PlHand.append(Mech(chosenMech[choix],X,Y,0))
 while K(52):0
 Cur(Xc+25*X,Yc+25*Y,"k");Aff(PlHand[-1]);EffCur(0,6,7,7)
def Scores():
 Dess("Scores",5,65,"purple",bg)
 for j in(0,1):Dess(str(score[j]),70+20*j,65,"rb"[j],bg)
def Des(mech):
 score[mech in AdvHand]+=mech.PV;Scores();(AdvHand,PlHand)[mech in PlHand].remove(mech);Aff(mech,0)
 while max(score)>=7:Dess("Fin de partie ! Victoire du joueur "+("bleu","rouge")[score[0]>=7],40,1,"br"[score[0]>=7],bg)
def AtkableMech(actMech):
 mechAtkable=None
 for k in W(1,actMech.Ran+1):
  mechAtkable=[mech for mech in(PlHand,AdvHand)[actMech in PlHand]if(mech.x,mech.y)==(actMech.x+k*(2-actMech.rotA)*(actMech.rotA%2),actMech.y+k*(1-actMech.rotA)*(actMech.rotA%2-1))]
  if mechAtkable:return mechAtkable[0]
 return mechAtkable
def SimulAtk(mechAtkable,actMech,aff=1):
 atkSide="BRFL"[(mechAtkable.rotA-actMech.rotA)%4];atkOnWeak,atkOnArmr=(atkSide in mechAtkable.Weak,atkSide in mechAtkable.Armr);dmg=max(1,actMech.Pow+Map[actMech.y][actMech.x]-mechAtkable.Pow-Map[mechAtkable.y][mechAtkable.x]+atkOnWeak-atkOnArmr)
 if aff:Aff(mechAtkable,1,0);AffHp(mechAtkable,dmg,1,atkOnArmr,atkOnWeak)
 return dmg
def possDesti(mech,aff=0):
 DestiPoss=[(mech.x,mech.y)]
 for i in W(mech.Move):
  N=len(DestiPoss)
  for k in W(N):
   (Xp,Yp)=DestiPoss[k]
   if i==0 or Map[Yp][Xp]!=-1:
    for(dx,dy)in((-1,0),(0,1),(1,0),(0,-1)):
     if 0<=Xp+dx<=7 and 0<=Yp+dy<=7:
      if Map[Yp+dy][Xp+dx]!=-2:
        DestiPoss.append((Xp+dx,Yp+dy))
        if aff:Cur(Xc+25*(Xp+dx),Yc+25*(Yp+dy),"y")
 return DestiPoss
def DeplSmpl(actMech):
 global usedMech,mechAtkable,atkOnArmr,atkOnWeak,X,Y;X0,Y0,rot0,chgX,chgY=actMech.x,actMech.y,actMech.rotA,0,0
 while K(52)and atkngPl:0
 DestiPoss=possDesti(actMech,1)
 while((K(52)|K(4))and(X,Y)!=(X0,Y0)and(X,Y)in DestiPoss and len([mech for mech in PlHand+AdvHand if(mech.x,mech.y)==(X,Y)])==1)^1:
  if chgX|chgY:
   nX,nY=min(7,max(0,X+chgX)),min(7,max(0,Y+chgY))
   if(chgX|chgY)and((nX,nY)!=(X,Y))and(nX,nY)in DestiPoss:
    Aff(actMech,0);actMech.x,actMech.y=nX,nY
    if 1-EmpLibr(X,Y):Aff([mech for mech in PlHand+AdvHand if(mech.x,mech.y)==(X,Y)][0])
    X,Y,atkOnArmr,atkOnWeak=nX,nY,0,0;Aff(actMech)
    if mechAtkable:Aff(mechAtkable);AffHp(mechAtkable,0,0)
   S(.1)
  ORI(actMech);mechAtkable=AtkableMech(actMech)
  if mechAtkable and abs(X-X0)+abs(Y-Y0)<=actMech.Move:SimulAtk(mechAtkable,actMech)
  chgX,chgY=K(3)-K(0),K(2)-K(1)
  if K(17):
   Aff(actMech,0);actMech.upPos(X0,Y0,rot0);Aff(actMech)
   if 1-EmpLibr(X,Y):Aff([mech for mech in PlHand+AdvHand if(mech.x,mech.y)==(X,Y)][0])
   if mechAtkable:AffHp(mechAtkable)
   EffCur();return 0
 while K(52):0
 usedMech.add(actMech)
 if mechAtkable:AffHp(mechAtkable)
 AffHp(actMech);EffCur();return 1
def AtkSmpl(actMech):
 global usedMech,mechAtkable,atkOnArmr,atkOnWeak
 while K(4)and atkngPl:0
 X0,Y0,rot0=actMech.x,actMech.y,actMech.rotA
 for i in W(8):
  for j in W(8):Cur(Xc+25*i,Yc+25*j,"kr"[abs(X0-i)+abs(Y0-j)<=actMech.Ran])
 while 1:
  ORI(actMech);mechAtkable=AtkableMech(actMech)
  if mechAtkable:
   SimulAtk(mechAtkable,actMech)
   if K(4)or 1-atkngPl:
    EffCur();dmg=SimulAtk(mechAtkable,actMech);mechAtkable.Hp-=dmg;Aff(mechAtkable,mechAtkable.Hp>0)
    while K(4):0
    usedMech.add(actMech)
    if mechAtkable.Hp<=0:Des(mechAtkable)
    return 1
  if K(17):
   actMech.rotA=rot0;Aff(actMech)
   if mechAtkable:AffHp(mechAtkable)
   while K(17):0
   EffCur();return 0
def Tour(j):
 global usedMech,mechAtkable,atkOnArmr,atkOnWeak,Xa,Ya,X,Y,PlHand,AdvHand;usedMech,X,chgX,chgY,tour,mechMode=set(),X+1,-1,0,1,(len(j)==1);Scores()
 while 1:
  if len([mech for mech in usedMech if mech.moved])==2 or(mechMode and j[0].moved):
   Dess("HOME Fin du tour "+"12"[tour-1]*mechMode,5,1,c,bg)
   if K(6)|K(16):
    EffCur()
    if(mechMode and tour==2)or 1-mechMode:break
    elif mechMode and tour==1:tour,actMech.moved,actMech.atkd=2,0,0
  if chgX|chgY:
   Cur(Xc+25*X,Yc+25*Y,"k");X,Y=(X+chgX)%8,(Y+chgY)%8;F(3,88,112,94,"k")
   if EmpLibr(X,Y):Cadre();F(40,95,40,40,Pal[Map[Y][X]+2]);Dess(str(("Gouffre","Marais","Prairie","Foret","Colline","Montagne")[Map[Y][X]+2])+"\nPuissance  "+str(Map[Y][X]),5,142,"w","k");Im("pow",79,160,"w","brown")
   else:Card(X,Y)
   EffCur();S(.2)
  Cur(Xc+25*X,Yc+25*Y,"r");chgX,chgY=K(3)-K(0),K(2)-K(1)
  if(X,Y)in[(mech.x,mech.y)for mech in j]:
   actMech=[mech for mech in j if(mech.x,mech.y)==(X,Y)][0]
   if 2>len(usedMech)or actMech in usedMech:
    X0,Y0,rot0=actMech.x,actMech.y,actMech.rotA
    if 1-actMech.moved:
     Dess("EXE Deplacer",5,21,c,bg)
     if K(52):actMech.moved=DeplSmpl(actMech)
    if 1-actMech.atkd:
     Dess("OK Attaquer",5,41,c,bg)
     if K(4):actMech.atkd=AtkSmpl(actMech)
Xc,Yc,X,Y,X0,Y0,rot0,bg,atkngPl,PlHand,AdvHand=118,19,4,7,0,0,0,(220,220,160),0,[],[]
CS()
Dess("ATTAKTH",130,15,"g")
Dess("      Mode\n\n\n  Joueur vs IA\n\n\nValider avec EXE",95,58,"purple")
for k in(0,1):F(60,40+k*147,200,1,"b")
while 1-K(52):0
while K(52):0
Map=[[R(0,2)+R(1-i,1)for k in W(8)]for i in W(4)]
Map+=[[Map[3-i][7-k]for k in W(8)] for i in W(4)]
MechAdv=["Galop-griffe","Tunnelier","Brisevague"]
CS()
mechList=sorted([mech for mech in MechDat.keys()])
Dess("Choisir les pieces\n  du joueur bleu",20,12,"b")
chosenMech,rang,chg,Nb_PMP=[],1,-1,0
Dess("PMP "+str(Nb_PMP)+"/10",25,65,"r","w")
selMech=mechList[rang+chg]
while(K(52)and 7<=Nb_PMP<=10)^1:
 if chg:rang=(rang+chg)%len(mechList);selMech=mechList[rang];CardId(selMech,c="b");S(.2)
 Nb_PMP=sum([MechDat[chosenMech[k]][0]for k in W(len(chosenMech))])
 if K(2):
  if chosenMech.count(selMech)<4 and Nb_PMP<=10-MechDat[selMech][0]:chosenMech.append(selMech);Main(chosenMech)
 if K(1):
  if selMech in chosenMech:chosenMech.remove(selMech);Main(chosenMech)
 chg=K(3)-K(0)
while K(52):0
CS(bg)
for i in W(8):
 for j in W(len(Map[i])):F(Xc+1+25*j,Yc+1+25*i,24,24,Pal[Map[i][j]+2])
for i in W(9):F(118+25*i,19,1,25*8,"k");F(118,19+25*i,25*8,1,"k")
for choix in W(max(len(chosenMech),len(MechAdv))):
 if choix<len(chosenMech):PlcPiece(choix)
 if choix<len(MechAdv):AdvHand.append(Mech(MechAdv[choix],2+choix,R(0,1),2));Aff(AdvHand[-1])#eviter le cas du gouffre
atkngPl=R(0,1)
while 1:
 atkngPl=1-atkngPl;c=((150,0,0),"b")[atkngPl]
 for mech in AdvHand+PlHand:mech.moved,mech.atkd,mech.Pow=0,0,MechDat[mech.name][3]*((mech in AdvHand,mech in PlHand)[atkngPl]);AffHp(mech)
 if atkngPl:Tour(PlHand)
 else:#IA joue
  mechMode,usedMech=(len(AdvHand)==1),set()
  for passe in(0,1):
   bstAtk=[0,None,0,0,0]
   for mech in AdvHand:
    if(mechMode or mech not in usedMech)and len(usedMech)<2:
     X0,Y0,rot0=mech.x,mech.y,mech.rotA;DestiPoss=[(X,Y)for(X,Y)in possDesti(mech)if EmpLibr(X,Y)and(X,Y)!=(X0,Y0)]
     for(Xd,Yd)in DestiPoss:
      for Ori in W(4):
       mech.upPos(Xd,Yd,Ori);cible=AtkableMech(mech)
       if cible: 
        dmg=SimulAtk(cible,mech,0)
        if dmg>bstAtk[0]and(mechMode or mech not in usedMech)and len(usedMech)<2:bstAtk=[dmg,cible,mech,Xd,Yd,Ori]
     mech.upPos(X0,Y0,rot0)
   if bstAtk[0]>0 and len(usedMech)<2:
    dmg,cible,mech,Xd,Yd,ori=bstAtk
    if mechMode or mech not in usedMech:
     #possDesti(mech,1);S(1)
     Aff(mech,0);mech.upPos(Xd,Yd,ori);Aff(mech);S(.7)
     #EffCur()
     SimulAtk(cible,mech);S(.7);AtkSmpl(mech);usedMech.add(mech)
     #S(1)
  while len(usedMech)<2:
   if mechMode and len(usedMech)==1:usedMech.add(0)
   for alt in W(3,-2,-1):
    for mech in AdvHand:
     X0,Y0,rot0=mech.x,mech.y,mech.rotA
     for(Xa,Ya)in((X,Y)for(X,Y)in possDesti(mech)if EmpLibr(X,Y)and(X,Y)!=(X0,Y0)):
      if Map[Ya][Xa]==alt and len(usedMech)<2 and(mechMode or mech not in usedMech):
       #possDesti(mech,1)
       Aff(mech,0);mech.upPos(Xa,Ya,rot0);Aff(mech);usedMech.add(mech);S(1)
       #EffCur()
       break
      else:mech.upPos(X0,Y0,rot0)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.