bool StateCondition_TurnsSinceLastCapture::IsSatisfied(GameState *state, bool canMove) { if (state->GetTurnNumber() <= number) return false; GameState *checkState = state->GetPreviousState(); int stepsBack = -1; while (checkState != 0 && stepsBack <= number) { stepsBack++; Move *move = checkState->GetSubsequentMove(); checkState = checkState->GetPreviousState(); // check the actual captured piece(s), instead of the moved piece auto capturedPieces = move->GetAllCaptures(); for (auto it = capturedPieces->begin(); it != capturedPieces->end(); it++) { Piece *piece = *it; if (owner != Player::Any && state->GetCurrentPlayer()->GetRelationship(piece->GetOwner()) != owner) continue; if (!piece->TypeMatches(type)) continue; delete capturedPieces; return ResolveComparison(comparison, stepsBack, number); } delete capturedPieces; } return false; }
bool StateCondition_TurnsSinceLastMove::IsSatisfied(GameState *state, bool canMove) { if (state->GetTurnNumber() <= number) return false; GameState *checkState = state->GetPreviousState(); int stepsBack = -1; while (checkState != 0 && stepsBack <= number) { stepsBack++; Move *move = checkState->GetSubsequentMove(); checkState = checkState->GetPreviousState(); if (owner != Player::Any && state->GetCurrentPlayer()->GetRelationship(move->GetPlayer()) != owner) continue; if (!move->GetPiece()->TypeMatches(type)) continue; return ResolveComparison(comparison, stepsBack, number); } return false; }