KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > samples > solitaire > Configurationtest


1
2 package org.objectweb.jac.samples.solitaire;
3
4 import java.util.*;
5
6 public class Configuration {
7    public int nBalls ;
8    public byte[][] game ;
9    public Configuration parent ;
10
11    public Configuration(int nBalls, byte[][] game, Configuration parent){
12       this.nBalls = nBalls;
13       this.game = game;
14       this.parent = parent;
15    }
16    public String JavaDoc toString() {
17       return toString(game);
18    }
19    public String JavaDoc toString(byte[][] game) {
20       String JavaDoc result = "\n";
21       for(int i = 2 ; i<9 ;i++) {
22          for(int j = 2 ; j<9 ; j++) {
23             if (game[i][j] == 1)
24                result = result + "O";
25             if (game[i][j] == 0)
26                result = result + ".";
27             if (game[i][j] == 2)
28                result = result + " ";
29          }
30          result = result + "\n";
31       }
32       return result;
33    }
34
35      public boolean equals(Object JavaDoc entree) {
36       boolean result;
37       result = true;
38
39       //return super.equals( entree );
40

41       if ( entree == null ) return false;
42       if ( ! (entree instanceof Configuration) ) return false;
43       if ( ((Configuration)entree).game == null ) return false;
44
45       System.out.println("dans equals!!" + toString(game) + ((Configuration)entree).game );
46       System.out.println("dans equals!!" + toString(((Configuration)entree).game) + toString(game) + result);
47
48       for(int k = 0 ; k < 11 && result == true; k++){
49          for(int l = 0 ; l < 11 && result == true; l++){
50             if(((Configuration)entree).game[k][l] != this.game[k][l] )
51                result = false;}}
52       return result;
53    }
54      
55    public Vector createChildren () {
56       System.out.println( "fejffkfjeklj" );
57    
58       Vector result = new Vector();
59       for(int i = 2 ; i<9 ;i++) {
60          for(int j = 2 ; j<9 ; j++) {
61             System.out.print( "ij=" + i + "," + j + ":" + game[i][j] + " ");
62             if (game[i][j] == 0) {
63                /* System.out.println("vide pour " + i + ":" + j);
64                   System.out.println( this ); */

65
66                System.out.print( " (CAS 1 ) ");
67                System.out.print( game[i-2][j] + ":" + game[i-1][j]);
68                if (game[i-2][j] == 1 && game[i-1][j] == 1) {
69
70                                     byte[][] element = new byte[game.length][];
71                   for(int k = 0 ; k < game.length ; k++)
72                      element[k] = (byte[]) game[k].clone();
73
74                         
75                   element[i][j] = 1;
76                   element[i-2][j] = 0;
77                   element[i-1][j] = 0;
78
79                   /*byte[][] copy1 = new byte[element.length][];
80                   for(int k = 0 ; k < element.length ; k++){
81                      copy1[10 - k] = (byte[]) element[k].clone();}
82
83                   byte[][] copy2 = new byte[element.length][element.length];
84                   for(int k = 0 ; k < element.length ; k++)
85                      for(int l = 0 ; l < element.length ; l++){
86                         copy2[k][l] = element[l][k];}
87                     
88                   byte[][] copy3 = new byte[element.length][];
89                   for(int k = 0 ; k < element.length ; k++){
90                      copy3[10 - k] = (byte[]) copy2[k].clone();}
91                         
92                   byte[][] copy4 = new byte[element.length][element.length];
93                   for(int k = 0 ; k < element.length ; k++)
94                      for(int l = 0 ; l < element.length ; l++){
95                         copy4[k][l] = copy1[l][k];}
96                     
97                   byte[][] copy5 = new byte[element.length][];
98                   for(int k = 0 ; k < element.length ; k++){
99                      copy5[10 - k] = (byte[]) copy4[k].clone();}
100                 
101                   byte[][] copy6 = new byte[element.length][element.length];
102                   for(int k = 0 ; k < element.length ; k++)
103                      for(int l = 0 ; l < element.length ; l++){
104                         copy6[k][l] = copy5[l][k];}
105
106                   byte[][] copy7 = new byte[element.length][];
107                   for(int k = 0 ; k < element.length ; k++){
108                   copy7[10 - k] = (byte[]) copy6[k].clone();}*/

109
110                   /* System.out.println( toString(element) + "@@ " + toString(copy1) + "@@ " + toString(copy2) + "@@ " + toString(copy3) + "@@ " + toString(copy4) + "@@ " + toString(copy5) + "@@ " + toString(copy6) + "@@ " + toString(copy7)); */
111                   // if (!result.contains(new Configuration(nBalls - 1, element, this)) && !result.contains(new Configuration(nBalls - 1, copy1, this)) && !result.contains(new Configuration(nBalls - 1, copy2, this)) && !result.contains(new Configuration(nBalls - 1, copy3, this)) && !result.contains(new Configuration(nBalls - 1, copy4, this)) && !result.contains(new Configuration(nBalls - 1, copy5, this)) && !result.contains(new Configuration(nBalls - 1, copy6, this)) && !result.contains(new Configuration(nBalls - 1, copy7, this)))
112
result.add(new Configuration(nBalls - 1, element, this));
113                }
114
115                System.out.print( " (CAS 2 ) ");
116                System.out.print( game[i+2][j] + ":" + game[i+1][j] );
117                if (game[i+2][j] == 1 && game[i+1][j] == 1) {
118
119
120                   byte[][] element = new byte[game.length][];
121                   for(int k = 0 ; k < game.length ; k++)
122                      element[k] = (byte[]) game[k].clone();
123
124                   element[i][j] = 1;
125                   element[i+2][j] = 0;
126                   element[i+1][j] = 0;
127
128                   /* byte[][] copy1 = new byte[element.length][];
129                   for(int k = 0 ; k < element.length ; k++){
130                      copy1[10 - k] = (byte[]) element[k].clone();}
131
132                   byte[][] copy2 = new byte[element.length][element.length];
133                   for(int k = 0 ; k < element.length ; k++)
134                      for(int l = 0 ; l < element.length ; l++){
135                         copy2[k][l] = element[l][k];}
136                     
137                   byte[][] copy3 = new byte[element.length][];
138                   for(int k = 0 ; k < element.length ; k++){
139                      copy3[10 - k] = (byte[]) copy2[k].clone();}
140                         
141                   byte[][] copy4 = new byte[element.length][element.length];
142                   for(int k = 0 ; k < element.length ; k++)
143                      for(int l = 0 ; l < element.length ; l++){
144                         copy4[k][l] = copy1[l][k];}
145                     
146                   byte[][] copy5 = new byte[element.length][];
147                   for(int k = 0 ; k < element.length ; k++){
148                      copy5[10 - k] = (byte[]) copy4[k].clone();}
149                 
150                   byte[][] copy6 = new byte[element.length][element.length];
151                   for(int k = 0 ; k < element.length ; k++)
152                      for(int l = 0 ; l < element.length ; l++){
153                         copy6[k][l] = copy5[l][k];}
154
155                   byte[][] copy7 = new byte[element.length][];
156                   for(int k = 0 ; k < element.length ; k++){
157                   copy7[10 - k] = (byte[]) copy6[k].clone();} */

158
159                   /* System.out.println( element + "@" + copy1 + "@" + copy2 + "@" + copy3 + "@" + copy4 + "@" + copy5 + "@" + copy6 + "@" + copy7 + "@" + copy4[4]); */
160
161                   /* System.out.println(toString(element) + "@@ " + toString(copy1) + "@@ " + toString(copy2) + "@@ " + toString(copy3) + "@@ " + toString(copy4) + "@@ " + toString(copy5) + "@@ " + toString(copy6) + "@@ " + toString(copy7)); */
162                   // if (!result.contains(new Configuration(nBalls - 1, element, this)) && !result.contains(new Configuration(nBalls - 1, copy1, this)) && !result.contains(new Configuration(nBalls - 1, copy2, this)) && !result.contains(new Configuration(nBalls - 1, copy3, this)) && !result.contains(new Configuration(nBalls - 1, copy4, this)) && !result.contains(new Configuration(nBalls - 1, copy5, this)) && !result.contains(new Configuration(nBalls - 1, copy6, this)) && !result.contains(new Configuration(nBalls - 1, copy7, this)))
163
result.add(new Configuration(nBalls - 1, element, this));
164                }
165
166                System.out.print( " (CAS 3 ) ");
167                System.out.print( game[i][j-2] + ":" + game[i][j-1]);
168
169                if (game[i][j-2] == 1 && game[i][j-1] == 1) {
170
171                   System.out.print( " (CAS 3 ) ");
172
173                   byte[][] element = new byte[game.length][];
174                   for(int k = 0 ; k < game.length ; k++)
175                      element[k] = (byte[]) game[k].clone();
176
177                   element[i][j] = 1;
178                   element[i][j-2] = 0;
179                   element[i][j-1] = 0;
180
181                   /* byte[][] copy1 = new byte[element.length][];
182                   for(int k = 0 ; k < element.length ; k++){
183                      copy1[10 - k] = (byte[]) element[k].clone();}
184
185                   byte[][] copy2 = new byte[element.length][element.length];
186                   for(int k = 0 ; k < element.length ; k++)
187                      for(int l = 0 ; l < element.length ; l++){
188                         copy2[k][l] = element[l][k];}
189                     
190                   byte[][] copy3 = new byte[element.length][];
191                   for(int k = 0 ; k < element.length ; k++){
192                      copy3[10 - k] = (byte[]) copy2[k].clone();}
193                         
194                   byte[][] copy4 = new byte[element.length][element.length];
195                   for(int k = 0 ; k < element.length ; k++)
196                      for(int l = 0 ; l < element.length ; l++){
197                         copy4[k][l] = copy1[l][k];}
198                     
199                   byte[][] copy5 = new byte[element.length][];
200                   for(int k = 0 ; k < element.length ; k++){
201                      copy5[10 - k] = (byte[]) copy4[k].clone();}
202                 
203                   byte[][] copy6 = new byte[element.length][element.length];
204                   for(int k = 0 ; k < element.length ; k++)
205                      for(int l = 0 ; l < element.length ; l++){
206                         copy6[k][l] = copy5[l][k];}
207
208                   byte[][] copy7 = new byte[element.length][];
209                   for(int k = 0 ; k < element.length ; k++){
210                   copy7[10 - k] = (byte[]) copy6[k].clone();}*/

211
212
213                   /* System.out.println( toString(copy) + "@@ " + toString(copyy) + "@@ " + toString(copyyy) + "@@ " + toString(copyyyy)); */
214                   //if (!result.contains(new Configuration(nBalls - 1, element, this)) && !result.contains(new Configuration(nBalls - 1, copy1, this)) && !result.contains(new Configuration(nBalls - 1, copy2, this)) && !result.contains(new Configuration(nBalls - 1, copy3, this)) && !result.contains(new Configuration(nBalls - 1, copy4, this)) && !result.contains(new Configuration(nBalls - 1, copy5, this)) && !result.contains(new Configuration(nBalls - 1, copy6, this)) && !result.contains(new Configuration(nBalls - 1, copy7, this)))
215
result.add(new Configuration(nBalls - 1, element, this));
216                }
217
218                System.out.print( " (CAS 4 ) ");
219                System.out.print( game[i][j+2] + ":" + game[i][j+1] );
220
221                if (game[i][j+2] == 1 && game[i][j+1] == 1) {
222
223                   System.out.print( " (CAS 4 ) ");
224
225                   byte[][] element = new byte[game.length][];
226                   for(int k = 0 ; k < game.length ; k++)
227                      element[k] = (byte[]) game[k].clone();
228
229                   element[i][j] = 1;
230                   element[i][j+2] = 0;
231                   element[i][j+1] = 0;
232
233                   /* byte[][] copy1 = new byte[element.length][];
234                   for(int k = 0 ; k < element.length ; k++){
235                      copy1[10 - k] = (byte[]) element[k].clone();}
236
237                   byte[][] copy2 = new byte[element.length][element.length];
238                   for(int k = 0 ; k < element.length ; k++)
239                      for(int l = 0 ; l < element.length ; l++){
240                         copy2[k][l] = element[l][k];}
241                     
242                   byte[][] copy3 = new byte[element.length][];
243                   for(int k = 0 ; k < element.length ; k++){
244                      copy3[10 - k] = (byte[]) copy2[k].clone();}
245                         
246                   byte[][] copy4 = new byte[element.length][element.length];
247                   for(int k = 0 ; k < element.length ; k++)
248                      for(int l = 0 ; l < element.length ; l++){
249                         copy4[k][l] = copy1[l][k];}
250                     
251                   byte[][] copy5 = new byte[element.length][];
252                   for(int k = 0 ; k < element.length ; k++){
253                      copy5[10 - k] = (byte[]) copy4[k].clone();}
254                 
255                   byte[][] copy6 = new byte[element.length][element.length];
256                   for(int k = 0 ; k < element.length ; k++)
257                      for(int l = 0 ; l < element.length ; l++){
258                         copy6[k][l] = copy5[l][k];}
259
260                   byte[][] copy7 = new byte[element.length][];
261                   for(int k = 0 ; k < element.length ; k++){
262                   copy7[10 - k] = (byte[]) copy6[k].clone();}*/

263
264
265                         
266                   /* System.out.println( toString(copy) + "@@ " + toString(copyy) + "@@ " + toString(copyyy) + "@@ " + toString(copyyyy)); */
267                   //if (!result.contains(new Configuration(nBalls - 1, element, this)) && !result.contains(new Configuration(nBalls - 1, copy1, this)) && !result.contains(new Configuration(nBalls - 1, copy2, this)) && !result.contains(new Configuration(nBalls - 1, copy3, this)) && !result.contains(new Configuration(nBalls - 1, copy4, this)) && !result.contains(new Configuration(nBalls - 1, copy5, this)) && !result.contains(new Configuration(nBalls - 1, copy6, this)) && !result.contains(new Configuration(nBalls - 1, copy7, this)))
268
result.add(new Configuration(nBalls - 1, element, this));
269                }
270
271                System.out.println( "Fin " );
272
273             }
274          }
275       }
276       /* System.out.println( result); */
277       return result;
278    }
279
280 }
281
Popular Tags