function checkWinCondition()

in src/gemini_95/index.ts [1429:1471]


    function checkWinCondition() {
        if (minesweeperGameOver) return;

        let revealedCount = 0;
        let correctlyFlaggedMines = 0;

        for (let r = 0; r < minesweeperGridSize.rows; r++) {
            for (let c = 0; c < minesweeperGridSize.cols; c++) {
                const cell = grid[r][c];
                if (cell.isRevealed && !cell.isMine) {
                    revealedCount++;
                }
                if (cell.isFlagged && cell.isMine) {
                    correctlyFlaggedMines++;
                }
            }
        }

        const totalNonMineCells = (minesweeperGridSize.rows * minesweeperGridSize.cols) - minesweeperMineCount;
        const allNonMinesRevealed = revealedCount === totalNonMineCells;
        const allMinesFlagged = correctlyFlaggedMines === minesweeperMineCount && minesweeperFlagsPlaced === minesweeperMineCount;

        if (allNonMinesRevealed || allMinesFlagged) {
            console.log("Game Won!");
            minesweeperGameOver = true;
            if (minesweeperTimerInterval) {
                clearInterval(minesweeperTimerInterval);
                minesweeperTimerInterval = null;
            }
            resetButton.textContent = '😎';
            // Optionally auto-flag remaining mines if won by revealing
            if (allNonMinesRevealed) {
                 grid.forEach(row => row.forEach(cell => {
                     if (cell.isMine && !cell.isFlagged) {
                         cell.isFlagged = true;
                         cell.element.textContent = '🚩';
                         minesweeperFlagsPlaced++;
                     }
                 }));
                 updateFlagCount();
            }
        }
    }