Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean hasChain(ArrayList<Domino> dominoes, int first, int second){//5,5
- boolean match = false;
- for(int i = 0; i < dominoes.size();i++){
- if((dominoes.get(i).first() == first && dominoes.get(i).second() == second) ||
- (dominoes.get(i).first() == second && dominoes.get(i).second() == first)){
- match = true;
- }
- }
- if (match){
- return match;
- }
- else {
- for(int i = 0;i<dominoes.size();i++){
- if(dominoes.get(i).first()==first){
- int other = dominoes.get(i).second();
- ArrayList<Domino> copy = new ArrayList<>();
- copy.addAll(dominoes);
- copy.remove(copy.get(i));
- if(hasChain(copy,other,second)){
- return true;
- }
- }
- else if(dominoes.get(i).second()==first){
- int other = dominoes.get(i).first();
- ArrayList<Domino> copy = new ArrayList<>();
- copy.addAll(dominoes);
- copy.remove(copy.get(i));
- if(hasChain(copy,other,second)){
- return true;
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment