Update BombService

- L and T shapes will be considered as 4+
This commit is contained in:
2025-12-19 15:55:13 +08:00
parent aae09b5696
commit 73db75d40a
2 changed files with 24 additions and 4 deletions

View File

@@ -83,9 +83,9 @@ namespace Services
if (currentMatches == null || !currentMatches.Contains(pivotGem))
return;
// Only create a bomb if the pivot is part of a straight 4+ line of the SAME color.
int longestLine = GetLongestMatchedLineThroughPivot(pivot, pivotGem.MatchColor);
if (longestLine < 4)
// Create a bomb if it's a 4+ line OR an L/T shape (both horizontal and vertical >= 3)
bool isEligibleForBomb = IsEligibleForBomb(pivot, pivotGem.MatchColor);
if (!isEligibleForBomb)
return;
// Prevent duplicates for the same cell.
@@ -94,6 +94,24 @@ namespace Services
this.pendingBombSpawn = new BombSpawnRequest(pivot, pivotGem.MatchColor);
}
private bool IsEligibleForBomb(Vector2Int pivot, GemType color) {
int horizontal = 1 + CountSameColorInDirection(pivot, Vector2Int.left, color)
+ CountSameColorInDirection(pivot, Vector2Int.right, color);
int vertical = 1 + CountSameColorInDirection(pivot, Vector2Int.up, color)
+ CountSameColorInDirection(pivot, Vector2Int.down, color);
// Straight line of 4 or more
if (horizontal >= 4 || vertical >= 4)
return true;
// L or T shape: both directions have at least a 3-match intersecting at this pivot
if (horizontal >= 3 && vertical >= 3)
return true;
return false;
}
public async UniTask DetonateChainAsync(
IReadOnlyList<Vector2Int> initialBombs,

View File

@@ -24,7 +24,9 @@ namespace Services.Interfaces {
/// <param name="gemTypeToCheck">
/// Type of gem to check.
/// </param>
/// <returns></returns>
/// <returns>
/// True if there are matches, false otherwise.
/// </returns>
bool MatchesAt(Vector2Int positionToCheck, GemType gemTypeToCheck);
void FindAllMatches();
}