Authored by Trogno Lucas
1 parent 5a0484e1

### Algorithme d'attaque de l'IA

Showing 1 changed file with 57 additions and 0 deletions
IAattaque.py 0 → 100644

 ... ... @@ -0,0 +1,57 @@ 1 +def attaque(M1,position): 2 + case=2 3 + while case==2 or case==1: 4 + a=rd.randint(0,9) 5 + b=rd.randint(0,9) 6 + case=M1[a][b] 7 + if M1[a][b]==2 or M1[a][b]==3: 8 + case=2 9 + while case==1 : 10 + print("case attaquee :",a,b,"Touche !") 11 + M1[a][b]=2 12 + position[(a,b)]=position[(a,b)][0],2 13 + elem=position[(a,b)][0] 14 + 15 + #verifier si le bateau est coule 16 + i=0 17 + for cle in position.keys(): 18 + if position[cle][0]==elem and position[cle][1]==2: 19 + i+=1 20 + if i==elem.longueur: 21 + coule=elem.nom+" coule!" 22 + print(coule) 23 + for cle in position.keys(): 24 + if position[cle][0]==elem: 25 + M1[cle[0]][cle[1]]=3 26 + position[cle]=position[cle][0],3 27 + #verifier si le jeu est gagne 28 + j=0 29 + for cle in position.keys(): 30 + if position[cle][1]==3: 31 + j+=1 32 + if j==18: 33 + message="jeu fini" 34 + print('vous avez perdu') 35 + break 36 + 37 + possib=[] 38 + if a-1>=0 : 39 + possib.append(M1[a-1][b]) 40 + if a+1<=9: 41 + possib.append(M1[a+1][b]) 42 + if b-1>=0: 43 + possib.append(M1[a][b-1]) 44 + if b+1<=9: 45 + possib.append(M1[a][b+1]) 46 + print(possib) 47 + i=rd.randint(0,len(possib)) 48 + print(i) 49 + case=possib[i-1] 50 + a=case/10 51 + b=case%10 52 + if case==0 : 53 + M1[a][b]=-1 54 + print("case attaquee :",a,b,"Manque !") 55 + message="jeu non fini" 56 + L=[M1,message,position] 57 + return L 0 58 \ No newline at end of file ... ...