Ciao a tutti!

Avrei bisogno di una mano con un programma Java(importante perchè domani avrei un esame che probabilmente sarà su questo programma).
Vi metto il Link con il testo:

http://homes.di.unimi.it/casiraghi/P...-16/domino.pdf

Il mio problema è sul Main Partita, non so come impostare la parte centrale.
Se riusciste a darmi una GRANDE mano ve ne sarei grato...

Metto quello che sono riuscito a fare...

TESSERA.JAVA
codice:
public class Tessera {

    int a;
    int b;

public Tessera ( int sinistro, int destro ) {






        a = sinistro;


        b = destro;






    }






    public int getSinistro() {






        return a;


    


    }






    public int getDestro() {






        return b;






    }






    public boolean contiene(int x) {






        if ( a == x || b == x ) {






            return true;






        }


        else {






            return false;






        }






    }






    public String toString() {






        return "["+a+","+b+"]";






    }


}
GIOCATORE.JAVA
codice:
import java.io.*;

import java.util.*;






public class Giocatore {






    String nome;


    ArrayList<Tessera> tessere = new ArrayList<Tessera>();






    public Giocatore( String n, ArrayList<Tessera> t ){






        nome = n;


        tessere = t;






    }






    public Tessera Estrai(int x) {






        boolean flag = false;


        Tessera giusta = null;






        for (int i=0; i<tessere.size(); i++) {






            if ( tessere.get(i).getSinistro() == x || tessere.get(i).getDestro() == x ){






                giusta = tessere.get(i);


                tessere.remove(i);


                flag = true;


                break;






            }


        }






        if (flag == false) {


    


            return null;






        }






        else {






            return giusta;






        }


    }






    public boolean finito() {






        if (tessere == null){






            return true;






        }


        else {






            return false;






        }


    }






    public Tessera prima() {






        Tessera giusta = null;






        giusta = tessere.get(0);


        tessere.remove(0);






        return giusta;






    }






    public String toString() {






        String stringa = nome + " ( ";






        for (int i = 0; i<tessere.size(); i++) {






            stringa = stringa + tessere.get(i).toString() + " ";






        }






        return stringa + ")";






    }


}
PARTITA.JAVA
codice:
import java.io.*;

import java.util.*;






public class Partita{


    public static void main( String args[] ) throws Exception {






        Scanner scanner = new Scanner( System.in );


        /*System.out.print( "Inserisci il numero delle Tessere: " );*/


        int d = scanner.nextInt();


        System.out.println(d);






        ArrayList<Tessera> t = new ArrayList<Tessera>();


        ArrayList<Tessera> t2 = new ArrayList<Tessera>();


        String n = "";


        String n2 = "";


        boolean flag = false;


        


        n = scanner.next();


        


        for (int i = 0; i<d; i++) {


                


            int sinistro = scanner.nextInt();


            int destro = scanner.nextInt();


            Tessera x = new Tessera(sinistro, destro);


            t.add(x);






        }






        Giocatore g1 = new Giocatore(n, t);


        System.out.println(g1.toString());






        n2 = scanner.next();






        for (int i = 0; i<d; i++) {


                


            int sinistro = scanner.nextInt();


            int destro = scanner.nextInt();


            Tessera x = new Tessera(sinistro, destro);


            t2.add(x);






        }






        Giocatore g2 = new Giocatore(n2, t2);


        System.out.println(g2.toString());


        System.out.println("");






        Tessera tavolo = g1.prima();


        int sinistratavolo = tavolo.getSinistro();


        int destratavolo = tavolo.getDestro();


        int mosse = 1;


        System.out.println("Mossa " + mosse + ": " + n + " estrae " + tavolo.toString());


        System.out.println(g1.toString());


        System.out.println(g2.toString());






        while (g1.finito() != true || g2.finito() != true || flag != true) {




            for (int i=0; i<n; i++) {


                if (n2(i).contiene(sinistratavolo)) {


                    sinistratavolo = n(i).getDestro();


                /*if ((tavolo = g2.Estrai(tavolo.getSinistro())) != null){






                mosse = mosse + 1;


                System.out.println("Mossa " + mosse + ": " + n2 + " estrae " + tavolo.toString());


                System.out.println(g1.toString());


                System.out.println(g2.toString());


            


            }


            else{ 






                if ((tavolo = g2.Estrai(tavolo.getDestro())) != null){


                


                    tavolo = g2.Estrai(tavolo.getDestro());


                    mosse = mosse + 1;


                    System.out.println("Mossa " + mosse + ": " + n2 + " estrae " + tavolo.toString());


                    System.out.println(g1.toString());


                    System.out.println(g2.toString());






                }


                else{






                    if ((tavolo = g1.Estrai(tavolo.getSinistro())) != null){


                


                        tavolo = g1.Estrai(tavolo.getSinistro());


                        mosse = mosse + 1;


                        System.out.println("Mossa " + mosse + ": " + n + " estrae " + tavolo.toString());


                        System.out.println(g1.toString());


                        System.out.println(g2.toString());






                    }


                    else{


                        


                        if ((tavolo = g2.Estrai(tavolo.getDestro())) != null) {






                        tavolo = g1.Estrai(tavolo.getDestro());


                        mosse = mosse + 1;


                        System.out.println("Mossa " + mosse + ": " + n + " estrae " + tavolo.toString());


                        System.out.println(g1.toString());


                        System.out.println(g2.toString());


        


                        }


                        else{






                            flag = true;


                        }


                    }


                }


            }


        }*/






        if (g1.finito() == true) {






            System.out.println("Vince " + n);






        }


        else{






            if (g2.finito() == true) {






                System.out.println("Vince " + n);






            }


            else{






                if (flag == true) {






                    System.out.println("Pareggio");


    


                }


            }


        }


        


        /*System.out.println( g1.toString() );


        System.out.println( g2.toString() );*/    






    }


}
Grazie e scusatemi per non aver lasciato tutti quegli spazi nel codice...