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 toString() { 17 return toString(game); 18 } 19 public String toString(byte[][] game) { 20 String 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 entree) { 36 boolean result; 37 result = true; 38 39 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 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 109 110 111 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 158 159 160 161 162 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 211 212 213 214 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 263 264 265 266 267 result.add(new Configuration(nBalls - 1, element, this)); 269 } 270 271 System.out.println( "Fin " ); 272 273 } 274 } 275 } 276 277 return result; 278 } 279 280 } 281 | Popular Tags |