Advertisement
Fallstar

Resol.java

May 16th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package Taquin;
  2. import java.util.*;
  3. public class Resol{
  4.  
  5.  
  6.     //Attributs
  7.     private IJeu t;
  8.     private ArrayList<IJeu> sol;
  9.    
  10.    
  11.     //Constructeurs
  12.  
  13.     public Resol(IJeu t){
  14.         this.t = t;
  15.     }
  16.    
  17.    
  18.     //Mรฉthodes
  19.    
  20.    
  21.    
  22.    
  23.        
  24.        
  25.        
  26.     /**
  27.     *Ajoute ร  sol la liste des positions qui mรจne ร  la solution.
  28.     *
  29.     */
  30.        
  31.         public void solve() {
  32.         ArrayList<Couple<IJeu>> front = new ArrayList<Couple<IJeu>>();
  33.         ArrayList<IJeu> vus = new ArrayList<IJeu>();
  34.        
  35.         Couple<IJeu> found = null;
  36.  
  37.         Couple<IJeu> start = new Couple<IJeu>(t, null);
  38.         start.ajoutSiNecessaireEtMaJ(front, start.getT().generer_fils(), vus);
  39.        
  40.         ArrayList<Couple<IJeu>> clonefront;
  41.         while (found == null && front.size()>0) {
  42.             for (Couple<IJeu> c : front) {
  43.                 if (c.getT().estGagnant()) {
  44.                     found = c;
  45.                     break;
  46.                 }
  47.             }
  48.             clonefront = new ArrayList<Couple<IJeu>>(front);
  49.             front.clear();
  50.             for (Couple<IJeu> c : clonefront) {
  51.                 c.ajoutSiNecessaireEtMaJ(front, c.getT().generer_fils(), vus);
  52.             }
  53.             System.out.println(vus.size());
  54.         }
  55.             this.sol = found.remonte();
  56.     }
  57.        
  58.        
  59.     public void printSolution(){
  60.         System.out.println(this.sol);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement