Java - Poner fila y columna a 0

 
Vista:

Poner fila y columna a 0

Publicado por angel (1 intervención) el 07/11/2010 15:41:12
ola necesito que si me pueden ayudar con ese codigo: la parte que no entiendo es este: cuando yo pongo fila y columna 0 el valor =0 entonces lo que hace que entra a ponerficha pero luego busca que si no hay un valor pone entonces 1 entonces quedaria asi:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
fila=0 y columna=0 el valor =0
ponerFichaOrdenador(){
luego entra en el if y queda asi
 
if (nTablero[n][m]==-1){
haora nTablero tiene almacenado
en la fila 0 y columna 0=el valor 0
en la fila 0 y columna 1= el valor 1
ahora es la parte que no entiendo cuando entra en la funcion min
y luego
la funcion min tiene la funcion max como se llama por si mismo como hace no se si puedan ponerme por medio de dibujos o por pseudocodigo se lo agradeceria mi correo es:matyac_24@hotmail.com yo soy programador pero no entiendo ese codigo
 
}
 
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
principal
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
public class TresEnRaya {
	private static int TAM=3;
    private static int nTablero[][]=new int[TAM][TAM];
 
    private static int nGanador=-1;
   // private static int nContar=0;
 
 
    public static void main(String[] args){
    	int fi=0;
    	int co=0;
     	empezarPartida();
    	pulsaBoton(fi,co);
 
 
    	//ponerFichaOrdenador();
 
	}
 
 
 
 
 
    /** Creates a new instance of TresEnRaya */
    public TresEnRaya() {
        empezarPartida();
      //  nContar=0;
    }
 
    public static int[][] getTablero(){
        return nTablero;
    }
 
    public static void empezarPartida(){
        for (int n=0;n<TAM;n++)
            for (int m=0;m<TAM;m++)
                nTablero[n][m]=-1;
        nGanador=-1;
    }
 
    public static void pulsaBoton(int n, int m){
        if (n>=0 && m>=0 && n<TAM && m<TAM && nTablero[n][m]==-1){
            if (nGanador==-1){
                nTablero[n][m]=0;
                nGanador = ganaPartida();
                ponerFichaOrdenador();
            }
        }
    }
 
    public static int ganaPartida(){
        if (nTablero[0][0] != -1 && nTablero[0][0] == nTablero[1][1]
                && nTablero[0][0] == nTablero[2][2])
            return nTablero[0][0];
        if (nTablero[0][2] != -1 && nTablero[0][2] == nTablero[1][1]
                && nTablero[0][2] == nTablero[2][0])
            return nTablero[0][2];
        for (int n=0;n<TAM;n++){
            if (nTablero[n][0] != -1 && nTablero[n][0] == nTablero[n][1]
                    && nTablero[n][0] == nTablero[n][2])
                return nTablero[n][0];
            if (nTablero[0][n] != -1 && nTablero[0][n] == nTablero[1][n]
                    && nTablero[0][n] == nTablero[2][n])
                return nTablero[0][n];
        }
        return -1;
    }
 
    public int getGanador(){
        return nGanador;
    }
 
    //Algoritmo minimax
    private static boolean tableroCompleto(){
        for (int n=0;n<TAM;n++)
            for (int m=0;m<TAM;m++)
                if (nTablero[n][m]==-1)
                    return false;
        return true;
    }
 
    private static boolean finPartida(){
        return tableroCompleto() || ganaPartida()!=-1;
    }
 
    private static void ponerFichaOrdenador(){
        if (!finPartida()){
            int f=0, c=0;
            int v=Integer.MIN_VALUE;
            int aux;
            for (int n=1;n<=1;n++){
                for (int m=1;m<=1;m++){
                    if (nTablero[n][m]==-1){//2if
                        nTablero[n][m]=1;
 
                        aux=min();
 
                        if (aux>v) {//1if
 
 
                            v=aux;
                            f=n;
                            c=m;
 
 
 
                 }//1if
                        nTablero[n][m]=-1;
                        }//if
 
                    }
                }
 
            nTablero[f][c]=1;
 
 
 
        }
 
 
        nGanador=ganaPartida();
    }
 
    private static int max(){
        if (finPartida()){
            if (ganaPartida()!=-1) return -1;
            else return 0;
        }
        int v=Integer.MIN_VALUE;
        int aux;
        for (int n=0;n<TAM;n++){
            for (int m=0;m<TAM;m++){
                if (nTablero[n][m]==-1){
 
 
                    nTablero[n][m]=1;
 
                    aux=min();
 
                   if (aux>v) v=aux;
 
 
                   nTablero[n][m]=-1;
 
                }
            }
        }
 
        return v;
    }
 
    private static int min(){
        if (finPartida()){
            if (ganaPartida()!=-1) return 1;
 
            else return 0;
        }
        int v=Integer.MAX_VALUE;
        int aux;
        for (int n=0;n<TAM;n++){
            for (int m=0;m<TAM;m++){
 
 
                if (nTablero[n][m]==-1){
 
 
                	nTablero[n][m]=0;
 
                	  aux=max();
 
                  if (aux<v) v=aux;
 
 
                    nTablero[n][m]=-1;
                }
            }
        }
 
        return v;
    }
 
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder