public class Configuration { private char[] grille; /* On veut que chaque case soit un x ou un o et que si elle est vide alors n la première case est 1 la deuxième 2, etc... */ public Configuration() { this.grille = new char[]{'n','n','n','n','n','n','n','n','n'}; } public boolean estLibre(int posGrille) { if (posGrille < 1 || posGrille > 9) { throw new IllegalArgumentException("La position doit être entre 1 et 9."); } return this.grille[posGrille - 1] == 'n'; } public void jouer(int position, char joueur) { if (position < 1 || position > 9) { throw new IllegalArgumentException("La position doit être entre 1 et 9."); } if (joueur != 'x' && joueur != 'o') { throw new IllegalArgumentException("Le joueur doit être 'x' ou 'o'."); } if (!estLibre(position)) { throw new IllegalArgumentException("Cette case est déjà occupée."); } this.grille[position - 1] = joueur; } public void afficherGrille() { for (int i = 0; i < 9; i++) { System.out.print(this.grille[i] + " "); if ((i + 1) % 3 == 0) { System.out.println(); } } } }