package org.puc.rio.inf1636.hglm.war.objective;

import org.puc.rio.inf1636.hglm.war.model.Continent;
import org.puc.rio.inf1636.hglm.war.model.Map;
import org.puc.rio.inf1636.hglm.war.model.Player;
import org.puc.rio.inf1636.hglm.war.model.Territory;

public class ConquerTwoSpecifiedContinentsAndAThirdObjective extends WarObjective {


Continent targetContinent1;
Continent targetContinent2;
	public ConquerTwoSpecifiedContinentsAndAThirdObjective(String description, Continent c1, Continent c2) {
		super("Conquistar na totalidade a "+ c1.toString() + ", " + c2.toString() + " e um terceiro");
		this.targetContinent1=c1;
		this.targetContinent2=c2;
	}

	@Override
	public
	boolean checkVictory(Map m, Player p) {
		for(Continent c : Continent.values()) { //for each continent
			int tCont =0;
			int pCont =0;
			for(Territory t : m.getTerritoriesByContinent(c)) {
				if(c.equals(targetContinent1) || c.equals(targetContinent2)){
					if(!t.getOwner().equals(p)) {
						return false; //Player fails in specified
					}
				}
				else { // unspecified continent
					tCont++;
					if(t.getOwner().equals(p)){
						pCont++;
					}
					if(tCont==pCont) { //Player conquered unspecified Territory
						return true;
					}
				}
			}
		}
		return false;
	}

}

@@ -711,16 +711,75 @@
 er p) %7B%0A
+%09%09int chosenContinents=0;%0A%09%09boolean flagUnspecified=false;%0A
 %09%09for(Co
@@ -930,69 +930,17 @@
 %09%09%09%09
-if(c.equals(targetContinent1) %7C%7C c.equals(targetContinent2))%7B
+%09tCont++;
 %0A%09%09%09
@@ -948,9 +948,8 @@
 %09if(
-!
 t.ge
@@ -971,17 +971,16 @@
 (p))
- 
 %7B%0A%09%09%09%09%09%09
 retu
@@ -979,162 +979,195 @@
 %09%09%09%09
-return false; //Player fails in specified%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%09else %7B // unspecified continent%0A%09%09%09%09%09tCont++;%0A%09%09%09%09%09if(t.getOwner().equals(p
+pCont++;%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09if(tCont==pCont) %7B //Player conquered unspecified Territory%0A%09%09%09%09if(c.equals(this.targetContinent1) %7C%7C c.equals(this.targetContinent2
 ))
+ 
 %7B%0A%09%09%09%09%09
-%09pCont
+chosenContinents
 ++;%0A
-%09
 %09%09%09%09
@@ -1176,89 +1176,42 @@
 %09%09%09%09
-%09if(tCont==pCont) %7B //Player conquered unspecified Territory%0A%09%09%09%09%09%09return 
+else %7B%0A%09%09%09%09%09flagUnspecified=
 true;%0A
-%09
 %09%09%09%09
@@ -1219,15 +1219,13 @@
 %0A%09%09%09
-%09
 %7D%0A%09%09%09
-%7D
 %0A%09%09%7D
@@ -1235,20 +1235,54 @@
 return f
-alse
+lagUnspecified && chosenContinents %3E=2
 ;%0A%09%7D%0A%0A%7D%0A

corrected algorithm for this objective