Et mise à jour : la méthode placerIA() qui permet de placer les bâteaux aléatoirement semble opérationnelle =)
public static void placerIA()
{
int a = 0;
int b = 0;
int c = 0;
int l1 = 0;
int c2 = 0;
int l3 = 0;
int c4 = 0;
int l = IHM.grille3.getRowCount();
int x = 0;
boolean x1 = false;
boolean x2 = false;
boolean x3 = false;
boolean x4 = false;
boolean verif = false;
do
{
do
{
a = (int)(Math.random()*(l-1)+1);
b = (int)(Math.random()*(l-1)+1);
}while(IHM.grille3.getValueAt(a, b)=="x");
IHM.placerBateau(IHM.grille3, "x", a, b);
for(int i = a+1; ia-longueur+1 ; i--)
{
if(i>0)
{
if(IHM.grille3.getValueAt(i, b) == "x")
{
x2 = true;
}
}
}
if(a-longueur+1 > 0 && IHM.grille3.getValueAt(a-longueur+1, b)!="x" && !x2)
{
IHM.placerBateau(IHM.grille3, "o", a-longueur+1 , b);
l1 = a - longueur + 1;
}
for(int i = b+1; ib-longueur+1 ; i--)
{
if(i>0)
{
if(IHM.grille3.getValueAt(a, i) == "x")
{
x4 = true;
}
}
}
if(b-longueur+1 > 0 && IHM.grille3.getValueAt(a, b-longueur+1)!="x" && !x4)
{
IHM.placerBateau(IHM.grille3, "o", a , b-longueur+1);
c4 = b - longueur + 1;
}
for(int i=1 ; i a-longueur ; k--)
{
IHM.placerBateau(IHM.grille3, "x", k, b);
}
x = 1;
}
if(c==2 && c2!=0)
{
for(int k = b+1 ; k < b+longueur ; k++)
{
IHM.placerBateau(IHM.grille3, "x", a, k);
}
x = 2;
}
if(c==3 && l3!=0)
{
for(int k = a+1 ; k < a+longueur ; k++)
{
IHM.placerBateau(IHM.grille3, "x", k, b);
}
x = 3;
}
if(c==4 && c4!=0)
{
for(int k = b-1 ; k > b-longueur ; k--)
{
IHM.placerBateau(IHM.grille3, "x", a, k);
}
x = 4;
}
}while(x == 0);
if(a+longueur-1 < IHM.grille3.getRowCount() && x!=3 && IHM.grille3.getValueAt(a+longueur-1, b)!= "x")
{
IHM.placerBateau(IHM.grille3, "", a+longueur-1 , b);
}
if(a-longueur+1 > 0 && x!=1 && IHM.grille3.getValueAt(a-longueur+1, b)!= "x")
{
IHM.placerBateau(IHM.grille3, "", a-longueur+1 , b);
}
if(b+longueur-1 < IHM.grille3.getColumnCount() && x!=2 && IHM.grille3.getValueAt(a, b+longueur-1)!= "x")
{
IHM.placerBateau(IHM.grille3, "", a , b+longueur-1);
}
if(b-longueur+1 > 0 && x!=4 && IHM.grille3.getValueAt(a, b-longueur+1)!= "x")
{
IHM.placerBateau(IHM.grille3, "", a , b-longueur+1);
}
}