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)) if (currentMatches == null || !currentMatches.Contains(pivotGem))
return; return;
// Only create a bomb if the pivot is part of a straight 4+ line of the SAME color. // Create a bomb if it's a 4+ line OR an L/T shape (both horizontal and vertical >= 3)
int longestLine = GetLongestMatchedLineThroughPivot(pivot, pivotGem.MatchColor); bool isEligibleForBomb = IsEligibleForBomb(pivot, pivotGem.MatchColor);
if (longestLine < 4) if (!isEligibleForBomb)
return; return;
// Prevent duplicates for the same cell. // Prevent duplicates for the same cell.
@@ -95,6 +95,24 @@ namespace Services
this.pendingBombSpawn = new BombSpawnRequest(pivot, pivotGem.MatchColor); 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( public async UniTask DetonateChainAsync(
IReadOnlyList<Vector2Int> initialBombs, IReadOnlyList<Vector2Int> initialBombs,
Func<Vector2Int, UniTask> destroyAtAsync, Func<Vector2Int, UniTask> destroyAtAsync,

View File

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