Commit 29cdf1637f43af9aaa1a7167257d3dc8d84d1ea8

Authored by Trogno Lucas
1 parent 2c14a99b

programme d'attaque de l'IA

Showing 1 changed file with 33 additions and 27 deletions   Show diff stats
IAattaque.py
  1 +
  2 +import numpy as np
  3 +import random as rd
  4 +import builtins
  5 +from IA import position
  6 +
  7 +def f(c):
  8 + return ord(c)-ord("A")+1
  9 +
1 10 def attaque(M1,position):
  11 + a=-1
  12 + b=-1
2 13 case=2
3 14 while case==2 or case==1:
4   - a=rd.randint(0,9)
5   - b=rd.randint(0,9)
  15 + for i in range(10):
  16 + for j in range(10):
  17 + if M1[i][j]==2:
  18 + pos=[]
  19 + if i!=0:
  20 + pos.append(M1[i-1][j])
  21 + if i!=9:
  22 + pos.append(M1[i+1][j])
  23 + if j!=0:
  24 + pos.append(M1[i][j-1])
  25 + if j!=9:
  26 + pos.append(M1[i][j+1])
  27 + k=rd.randint(0,len(pos))
  28 + case=pos[k-1]
  29 + a=case/10
  30 + b=case%10
  31 + if a==-1 and b==-1:
  32 + a=rd.randint(0,9)
  33 + b=rd.randint(0,9)
6 34 case=M1[a][b]
7   - if M1[a][b]==2 or M1[a][b]==3:
  35 + if M1[a][b]==2 or M1[a][b]==3 or M1[a][b]==-1:
8 36 case=2
  37 + continue
9 38 while case==1 :
10 39 print("case attaquee :",a,b,"Touche !")
11 40 M1[a][b]=2
12   - position[(a,b)]=position[(a,b)][0],2
  41 + position[(a,b)]=position[(a,b)][0],2
13 42 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 43 possib=[]
38 44 if a-1>=0 :
39 45 possib.append(M1[a-1][b])
... ...