solitaire: flatten FreeCell auto-move target returns for detekt (#owner-report)
- Commit
21331e5d3f760eb5bdad1cb25dc74fc56f91621a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-12 20:56 UTC (23 days ago)
- Parents
eba1bda
Context: :games:solitaire:detekt must be green for this branch, and SolitaireFreeCellOps.kt (touched by the free-cell drop guard earlier in the branch) carried a pre-existing ReturnCount finding on main: resolveFreeCellAutoMoveTarget had 8 return statements (limit 6). Change: compute the three candidate destinations (foundation for a single card, then a viable tableau column, then an empty free cell for a single card off a column) as values and pick the first in the same priority order with one `when`. Pure and order-preserving, so tap-to-move in FreeCell resolves exactly the same targets. User-visible effect: none. Verification: :games:solitaire:detekt clean; FreeCell tap-to-move tests (SolitaireFlightTest, SolitaireMovesTest, SpiderPyramidOpsTest) pass in :games:solitaire:testDevUnitTest.
Diff
games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.kt
diff --git a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.kt b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.ktindex d6ec206461..fd81010a11 100644--- a/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.kt+++ b/games/solitaire/src/main/java/com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.kt@@ -236,25 +236,28 @@ internal fun SolitaireViewModel.freeCellAutoMoveImpl(sourceId: String) { * handler. */ internal fun SolitaireViewModel.resolveFreeCellAutoMoveTarget(sourceId: String): String? {- val state = uiStateInternal.value.freeCell ?: return null- if (state.isWon) return null+ val state = uiStateInternal.value.freeCell?.takeUnless { it.isWon } ?: return null val cards = draggedCards(sourceId)- if (cards.isEmpty()) return null- val origin = freeCellMoveOrigin(sourceId) ?: return null- if (cards.size == SINGLE_CARD) {- for (fi in state.foundations.indices) {- if (canPlaceOnFoundation(cards.first(), state.foundations[fi], fi)) return "foundation_$fi"- }+ val origin = freeCellMoveOrigin(sourceId)+ if (cards.isEmpty() || origin == null) return null+ val single = cards.size == SINGLE_CARD+ val foundation = if (single) {+ state.foundations.indices.firstOrNull { fi -> canPlaceOnFoundation(cards.first(), state.foundations[fi], fi) }+ } else {+ null }- state.tableauPiles.indices.firstOrNull { toCol ->+ val column = state.tableauPiles.indices.firstOrNull { toCol -> toCol != origin.fromCol && isViableTableauTarget(state, cards, origin, toCol)- }?.let { return "tableau_$it" }+ } // Empty free cell — last resort for a single card off a tableau column.- if (cards.size == SINGLE_CARD && origin.fromCol != null) {- val emptyCell = state.freeCells.indexOfFirst { it == null }- if (emptyCell >= 0) return "freecell_$emptyCell"+ val cell = state.freeCells.indexOfFirst { it == null }+ .takeIf { it >= 0 && single && origin.fromCol != null }+ return when {+ foundation != null -> "foundation_$foundation"+ column != null -> "tableau_$column"+ cell != null -> "freecell_$cell"+ else -> null }- return null } private data class FreeCellMoveOrigin(val fromCol: Int?, val fromIdx: Int, val fromCell: Int?)