import java.awt.Color;
import java.util.Enumeration;

public abstract class HostileWalker extends RandomWalker {
	//OVERVIEW: A HostileWalker will move if there are any unlike neighbors.

	private boolean inTurn;
	
	public boolean GetinTurn(){
		return inTurn;
	}
		
	public HostileWalker(){
		inTurn = false;
	}

	public Color getColor(){
		if(inTurn) {
			return Color.white;
		}
		else {
			return Color.yellow;
		}
	}

	private boolean lookatNeighbors() {
		Enumeration neighbors = getNeighbors();
		int uln = 0;
		int nbs = 0;
		while (neighbors.hasMoreElements()) {
			SimObject neighbor = (SimObject) neighbors.nextElement();
			if(someoneUnlike(neighbor) == true) {
				uln++;
			}
			if(someoneLike(neighbor) == true) {
				nbs++;
			}
		}
		if (uln>0){
			return true;
		}
		else if (nbs >1){
			return false;
		}
		else return true;
	}
	
	public abstract boolean someoneUnlike(Object neighbor);

	public abstract boolean someoneLike(Object neighbor);

	public void executeTurn () throws RuntimeException
	{
		synchronized (getGrid()) {
			if (lookatNeighbors() == true) {
				inTurn = true;
				super.executeTurn();
			}
		}
		inTurn = false;
	}
}