import javax.lang.model.util.ElementScanner6; import java.util.Scanner; public class Tateti{ char[][] tateti={{' ',' ',' '},{' ',' ',' '},{' ',' ',' '}}; public Tateti(){ } public static int convertirInt(char a){ if(a=='1'||a=='2'||a=='3'){ return ((Character.getNumericValue(a))-1); }else{ return -1; } } public static int convertirChar(char a){ if(a=='A'){ return 0; }else if(a=='B'){ return 1; }else if(a=='C'){ return 2; }else{ return -1; } } public int setJugada(int a,int b,char j){ if(tateti[a][b]==' '){ tateti[a][b]=j; return 1; }else{ return 0; } } public int verificaJugada(){ int CF[]=new int[3]; int CC[]=new int[3]; int CDI=0,CDD=0,gano=0; for(int i=0;i<3;i++){ for(int j=0;j<2;j++){ if(tateti[i][j]==tateti[i][j+1] && Character.compare(tateti[i][j],' ')!=0 && Character.compare(tateti[i][j+1],' ')!=0){ CF[i]++; } if(tateti[j+1][i]==tateti[j][i] && Character.compare(tateti[j+1][i],' ')!=0 && Character.compare(tateti[j][i],' ')!=0){ CC[i]++; } } } if(CF[0]==2){ System.out.println("A1-A2-A3"); gano=1; }else if(CF[1]==2){ System.out.println("B1-B2-B3"); gano=1; }else if(CF[2]==2){ System.out.println("C1-A2-A3"); gano=1; }else if(CC[0]==2){ System.out.println("A1-B1-C1"); gano=1; }else if(CC[1]==2){ System.out.println("A2-B2-C2"); gano=1; }else if(CC[2]==2){ System.out.println("A3-B3-C3"); gano=1; }else if(tateti[0][0]==tateti[1][1] &&tateti[0][0]==tateti[2][2]&& Character.compare(tateti[0][0],' ')!=0 && Character.compare(tateti[1][1],' ')!=0){ System.out.println("A1-B2-C3"); gano=1; }else if(tateti[0][2]==tateti[1][1] && tateti[2][0]==tateti[1][1]&& Character.compare(tateti[0][2],' ')!=0 && Character.compare(tateti[1][1],' ')!=0){ System.out.println("A3-B2-C1"); gano=1; } return gano; } public void imprimirTablero(){ for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ System.out.print("| "+tateti[i][j]+" |"); } System.out.println(); } } /*public static void main(String[] args) { Tateti t=new Tateti(); int gano=0; int jugadaValida=0; Scanner scanner=new Scanner(System.in); String jugada; int I1; int I2; char caracter; for(int i=0;i<9;i++){ jugadaValida=0; if(i%2==0){ caracter='X'; }else{ caracter='O'; } while(jugadaValida==0){ System.out.println("Ingrese la jugada:"); jugada=scanner.nextLine(); I1=convertirChar(jugada.charAt(0)); // System.out.println(I1); I2= convertirInt(jugada.charAt(1)); // System.out.println(I2); if(I1==-1||I2==-1){ System.out.println("Jugada Invalida"); }else{ if(t.setJugada(I1,I2,caracter)==0){ System.out.println("Jugada Invalida"); }else{ t.imprimirTablero(); gano=t.verificaJugada(); jugadaValida=1; } } } if(gano==1){ System.out.println("Gano"); break; } } }*/ }