Example #1
0
bool StateCondition_Threatened::IsSatisfied(GameState *state, bool canMove)
{
	if (MoveCondition_Threatened::checkingThreat)
        return false; // assume NOT threatened

	auto pieces = state->GetCurrentPlayer()->GetPiecesOnBoard();
	for (auto it = pieces.begin(); it != pieces.end(); it++)
	{
		Piece *piece = *it;
		if (!piece->TypeMatches(type))
            continue;
		
        MoveCondition_Threatened::checkingThreat = true;
        bool threatened = MoveCondition_Threatened::IsThreatened(state, piece->GetPosition());
        MoveCondition_Threatened::checkingThreat = false;
		
        if (threatened)
            return true;
    }

	return false;
}