Skip to content

Commit bd3393f

Browse files
committed
Add GameSuccessEvaluator
1 parent 2a3537c commit bd3393f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.jayasuryat.minesweeperengine.controller.impl.handler
2+
3+
import android.util.Log
4+
import com.jayasuryat.minesweeperengine.model.cell.RawCell
5+
import com.jayasuryat.minesweeperengine.model.grid.Grid
6+
7+
internal class GameSuccessEvaluator {
8+
9+
fun isGameComplete(
10+
grid: Grid,
11+
): Boolean {
12+
13+
val totalCount = grid.gridSize.rows * grid.gridSize.columns
14+
val nonMineCellsCount = totalCount - grid.totalMines
15+
16+
val revealedCellsCount = grid.cells.flatten().count { it is RawCell.RevealedCell }
17+
Log.d("Im alive", "Im alive, (revealedCellsCount) $revealedCellsCount == $nonMineCellsCount (nonMineCellsCount)")
18+
return revealedCellsCount == nonMineCellsCount
19+
}
20+
}

0 commit comments

Comments
 (0)