Dommage.
Perso, j'ai fait un tableau unidimensionnel. Sa prend la case que le joueur sélectionne, et sa vérifie par exemple en diagonal (-4) (-1 pour la case à gauche). Ensuite, sa vérifie si la case (-4)*2 est aussi au joueur, sinon il vérifie si +4 est au joueur, si oui dans un des cas, sa retourne vrai.
Assez compliqué à expliquer, je te montre le code (en Java) (vas sur checkWin()) :
public class Morpion {
public static void main(String[] args) {
char[] table = {'1', '2', '3',
'4', '5', '6',
'7', '8', '9'};
char j1 = 'O', j2 = 'X';
boolean win = false, turn = false;
Scanner getKey = new Scanner(System.in);
String sKey;
int key, j;
System.out.println("C'est le tour du joueur 1");
while (win == false) {
drawTable(table);
sKey = getKey.next();
clearScreen();
if (isNumeric(sKey)) {
key = Integer.parseInt(sKey) - 1;
if (key > -1 && key < 9) {
if (! (table[key] == 'O' || table[key] == 'X')) {
turn = nextTurn(turn);
table[key] = turn?j1:j2;
win = checkWin(table, key, turn?j1:j2);
} else {
System.out.println("Cette case est déjà occupé !");
}
} else {
System.out.println("Votre nombre n'est pas dans le tableau !");
}
} else {
System.out.println("La valeur n'est pas numerique !");
}
j = turn?2:1;
if (!win) {
System.out.println("C'est le tour du joueur " + j);
}
}
drawTable(table);
j = turn?1:2;
System.out.println("Le joueur " + j + " à gagné !");
getKey.hasNext();
}
public static boolean checkWin(char[] table, int pos, char j) {
for (int d = -4; d < 5; d++) {
if (pos + d > -1 && pos + d < 9 && d != 0) {
if (table[pos + d] == j) {
if (pos + d * 2 > -1 && pos + d * 2 < 9) {
if (table[pos + d * 2] == j) {
return true;
}
} else if (pos - d > -1 && pos - d < 9) {
if (table[pos - d] == j) {
return true;
}
}
}
}
}
return false;
}
public static void drawTable(char[] table) {
System.out.println(String.valueOf(table[6]) + String.valueOf(table[7]) + String.valueOf(table[8]));
System.out.println(String.valueOf(table[3]) + String.valueOf(table[4]) + String.valueOf(table[5]));
System.out.println(String.valueOf(table[0]) + String.valueOf(table[1]) + String.valueOf(table[2]) + "\n");
}
public static void clearScreen() {
for (int y = 0; y < 25; y++)
System.out.println("\n");
}
public static boolean nextTurn(boolean turn) {
if (turn == true)
return false;
else
return true;
}
public static boolean isNumeric(String s) {
try {
Integer.parseInt(s);
return true;
} catch (NumberFormatException e) {
return false;
}
}
}