Commit fc85ae53 authored by Trogno Lucas's avatar Trogno Lucas
Browse files

Grille de l'IA

parent 0c76fc92
#IA
import numpy as np
import random as rd
from bateau import Bateau
from bateau import f
M2=np.zeros([10,10])
M1=np.zeros([10,10])
porte_avion=Bateau("porte avion",5)
croiseur=Bateau("croiseur",4)
contre_torpilleur=Bateau("contre torpilleur",3)
sous_marin=Bateau("sous-marin",3)
torpilleur=Bateau("torpilleur",2)
bateaux=[porte_avion, croiseur, contre_torpilleur, sous_marin, torpilleur]
posit={}
print('ça marche')
#constituer sa grille
def grilleIA() :
for elem in bateaux:
k=rd.randint(0,9)
l=rd.randint(0,9)
if M2[k][l]!=0:
while M2[k][l]!=0:
k=rd.randint(0,9)
l=rd.randint(0,9)
print(k,l)
possibilites=[]
a,b,c,d=0,0,0,0
for case in range(0,elem.longueur):
#horizontal a gauche
if k-elem.longueur<-1 or M2[k-case][l]!=0:
a+=1
#horizontal a droite
if k+elem.longueur>10 or M2[k+case][l]!=0:
b+=1
#vertical en haut
if l-elem.longueur<-1 or M2[k][l-case]!=0:
c+=1
#vertical en bas
if l+elem.longueur>10 or M2[k][l+case]!=0:
d+=1
if a==0:
possibilites.append(chr(64+k-elem.longueur+2)+ str(l+1))
if b==0:
possibilites.append(chr(64+k+elem.longueur)+str(l+1))
if c==0:
possibilites.append(chr(k+65) +str(l-elem.longueur+2))
if d==0:
possibilites.append(chr(k+65) +str(l+elem.longueur))
poss=''
for possi in possibilites:
poss+=possi+', '
poss=poss[:-2]
print(possibilites)
i=rd.randint(0,len(possibilites)-1)
queue=possibilites[i]
print(chr(k+65),l+1)
m=f(queue[0])-1
n=int(queue[1])-1
if len(queue)==3:
n=9
if k==m:
for i in range(min(l,n),max(l,n)+1):
M2[k][i]=1
posit[(k,i)]=elem,1
if l==n:
for i in range(min(k,m),max(k,m)+1):
M2[i][l]=1
posit[(i,l)]=elem,1
return M2
\ No newline at end of file
Markdown is supported
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