KickJava   Java API By Example, From Geeks To Geeks.

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


1
2 package org.objectweb.jac.samples.solitaire;
3
4 import java.util.*;
5
6 public class Run{
7     public static void main(String JavaDoc[] args) {
8         byte[][] game = new byte[][] {
9             new byte[] {2,2,2,2,2,2,2,2,2,2,2} ,
10             new byte[] {2,2,2,2,2,2,2,2,2,2,2} ,
11             new byte[] {2,2,2,2,0,0,0,2,2,2,2} ,
12             new byte[] {2,2,2,2,0,1,0,2,2,2,2} ,
13             new byte[] {2,2,0,0,1,1,1,0,0,2,2} ,
14             new byte[] {2,2,0,1,1,0,1,1,0,2,2} ,
15             new byte[] {2,2,0,0,1,1,1,0,0,2,2} ,
16             new byte[] {2,2,2,2,0,1,0,2,2,2,2} ,
17             new byte[] {2,2,2,2,0,0,0,2,2,2,2} ,
18             new byte[] {2,2,2,2,2,2,2,2,2,2,2} ,
19             new byte[] {2,2,2,2,2,2,2,2,2,2,2}
20         } ;
21         
22         int x = 0;
23         Vector current = new Vector();
24         current.add( new Configuration(32,game,null) );
25         Vector next = new Vector();
26         boolean finish = true;
27         do { x = x+1;
28             System.out.println( "Next step for :" );
29             //System.out.println( current );
30
for ( int i=0; i < current.size(); i++ ) {
31                 Vector children = new Vector();
32                 children = ((Configuration)current.get(i)).createChildren();
33                 
34                 for (int j=0; j < children.size(); j++) {
35                     
36                     byte[][] element = new byte[11][];
37                         for(int k = 0 ; k < 11 ; k++)
38                         element[k] = (byte[]) ((Configuration)children.get(j)).game[k].clone();
39                     
40                     byte[][] copy1 = new byte[element.length][];
41                     for(int k = 0 ; k < element.length ; k++){
42                     copy1[10 - k] = (byte[]) element[k].clone();}
43
44                     byte[][] copy2 = new byte[element.length][element.length];
45                     for(int k = 0 ; k < element.length ; k++)
46                         for(int l = 0 ; l < element.length ; l++){
47                         copy2[k][l] = element[l][k];}
48                     
49                     byte[][] copy3 = new byte[element.length][];
50                     for(int k = 0 ; k < element.length ; k++){
51                     copy3[10 - k] = (byte[]) copy2[k].clone();}
52                         
53                     byte[][] copy4 = new byte[element.length][element.length];
54                     for(int k = 0 ; k < element.length ; k++)
55                         for(int l = 0 ; l < element.length ; l++){
56                         copy4[k][l] = copy1[l][k];}
57                     
58                     byte[][] copy5 = new byte[element.length][];
59                     for(int k = 0 ; k < element.length ; k++){
60                     copy5[10 - k] = (byte[]) copy4[k].clone();}
61                     
62                     byte[][] copy6 = new byte[element.length][element.length];
63                     for(int k = 0 ; k < element.length ; k++)
64                         for(int l = 0 ; l < element.length ; l++){
65                         copy6[k][l] = copy5[l][k];}
66
67                     byte[][] copy7 = new byte[element.length][];
68                     for(int k = 0 ; k < element.length ; k++){
69                     copy7[10 - k] = (byte[]) copy6[k].clone();}
70                     
71                     
72           /* if (!next.contains(new Configuration(0, element, (Configuration)current.get(i)))
73                      && ((!copy1.equals(element)) && !next.contains(new Configuration(0, copy1, (Configuration)current.get(i))))
74                      && ((!copy2.equals(element)) && (!copy2.equals(copy1)) && !next.contains(new Configuration(0, copy2, (Configuration)current.get(i))))
75                      && ((!copy3.equals(element)) && (!copy3.equals(copy1)) && (!copy3.equals(copy2)) && !next.contains(new Configuration(0, copy3, (Configuration)current.get(i))))
76                      && ((!copy4.equals(element)) && (!copy4.equals(copy1)) && (!copy4.equals(copy2)) && (!copy4.equals(copy3)) && !next.contains(new Configuration(0, copy4, (Configuration)current.get(i))))
77                      && ((!copy5.equals(element)) && (!copy5.equals(copy1)) && (!copy5.equals(copy2)) && (!copy5.equals(copy3)) && (!copy5.equals(copy4)) && !next.contains(new Configuration(0, copy5, (Configuration)current.get(i))))
78                      && ((!copy6.equals(element)) && (!copy6.equals(copy1)) && (!copy6.equals(copy2)) && (!copy6.equals(copy3)) && (!copy6.equals(copy4)) && (!copy6.equals(copy5)) && !next.contains(new Configuration(0, copy6, (Configuration)current.get(i))))
79                      && ((!copy6.equals(element)) && (!copy7.equals(copy1)) && (!copy7.equals(copy2)) && (!copy7.equals(copy3)) && (!copy7.equals(copy4)) && (!copy7.equals(copy5))&& (!copy7.equals(copy6)) && !next.contains(new Configuration(0, copy7, (Configuration)current.get(i)))) )*/

80         /* System.out.println(Configuration.toString(element) + Configuration.toString(copy1) + Configuration.toString(copy2) + Configuration.toString(copy3) + Configuration.toString(copy4) + Configuration.toString(copy5) + Configuration.toString(copy6) + Configuration.toString(copy7) ); */
81         next.add ( children.get(j) );
82                     } }System.out.println( "taille : " + next.size() );
83
84             finish = true;
85             
86             if (next.size() > 0) {
87                 current = next;
88                 finish = false;
89             }
90             next = new Vector();
91             } while ( finish == false );
92     Configuration affichage = new Configuration(0, game , null);
93         
94         for (int b=0; b < current.size(); b++) {
95             affichage = (Configuration)current.get(b);
96             System.out.println("--------------------------------------------------" );
97             for ( int a=0; a < x; a++ ) {
98             System.out.println( affichage );
99             affichage = affichage.parent;
100             }
101     }
102
103 }
104
105 }
106
Popular Tags