Commit 0c76fc92 authored by Trogno Lucas's avatar Trogno Lucas
Browse files

Algorithme d'attaque de l'IA

parent 5a0484e1
def attaque(M1,position):
case=2
while case==2 or case==1:
a=rd.randint(0,9)
b=rd.randint(0,9)
case=M1[a][b]
if M1[a][b]==2 or M1[a][b]==3:
case=2
while case==1 :
print("case attaquee :",a,b,"Touche !")
M1[a][b]=2
position[(a,b)]=position[(a,b)][0],2
elem=position[(a,b)][0]
#verifier si le bateau est coule
i=0
for cle in position.keys():
if position[cle][0]==elem and position[cle][1]==2:
i+=1
if i==elem.longueur:
coule=elem.nom+" coule!"
print(coule)
for cle in position.keys():
if position[cle][0]==elem:
M1[cle[0]][cle[1]]=3
position[cle]=position[cle][0],3
#verifier si le jeu est gagne
j=0
for cle in position.keys():
if position[cle][1]==3:
j+=1
if j==18:
message="jeu fini"
print('vous avez perdu')
break
possib=[]
if a-1>=0 :
possib.append(M1[a-1][b])
if a+1<=9:
possib.append(M1[a+1][b])
if b-1>=0:
possib.append(M1[a][b-1])
if b+1<=9:
possib.append(M1[a][b+1])
print(possib)
i=rd.randint(0,len(possib))
print(i)
case=possib[i-1]
a=case/10
b=case%10
if case==0 :
M1[a][b]=-1
print("case attaquee :",a,b,"Manque !")
message="jeu non fini"
L=[M1,message,position]
return L
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment