<commit_before>var tilesWithoutMines,
    tilesWithoutMinesCounter;

function addEventListenersOnCanvas(tiles, settings) {
    $('canvas').on('click', {tiles: tiles, settings: settings}, onTileLeftClick).
        on('contextmenu', {tiles: tiles, settings: settings}, onTileRightClick);
}

function removeEventListenersFromCanvas() {
    $('canvas').off('click', onTileLeftClick).
        off('contextmenu', onTileRightClick);
}

function onTileLeftClick(event) {
    var tiles = event.data.tiles,
        settings = event.data.settings,
        tile;

    // To disable scroll click
    //if (event.button !== 1) {
        tile = getClickedTile(event, tiles, settings);
        if (tile && !tile.isVisited && !tile.hasMineFlag) {
            showBehindTile(tile, tiles, settings);
        }
    //}
}

function onTileRightClick(event) {
    var tiles = event.data.tiles,
        settings = event.data.settings,
        tile;

    // disable menu
    event.preventDefault();

    tile = getClickedTile(event, tiles, settings);
    if (tile && !tile.isVisited) {
        if (!tile.hasMineFlag) {
            tile.hasMineFlag = true;
            drawMineFlag(tile);
        }
        else {
            tile.hasMineFlag = false;
            drawSingleTile(tile, settings.tileSizeInPx, false);
        }
    }
}

function getClickedTile(event, tiles, settings) {
    var rect = canvas.getBoundingClientRect(),
        offsetX = event.clientX - rect.left,
        offsetY = event.clientY - rect.top,
        tile;

    // If the event is from mouse click is has offsetX.
    // If the event is from mobile phone it doesn't.
    if(event.offsetX) {
        tile = tiles.find(function (tile) {
            return tile.startXinPx < event.offsetX &&
                event.offsetX <= tile.startXinPx + settings.tileSizeInPx &&
                tile.startYinPx < event.offsetY &&
                event.offsetY <= tile.startYinPx + settings.tileSizeInPx;
        });
    }
    else {
        tile = tiles.find(function (tile) {
            return tile.startXinPx + settings.tileSizeInPx > offsetX &&
                tile.startYinPx + settings.tileSizeInPx > offsetY;
        });
    }

    return tile;
}

function showBehindTile(tile, tiles, settings) {
    if (tile.value === 0) {
        showAllTilesWithoutValue(tile.row, tile.col, tiles, settings);
    }
    else if (tile.value === '*') {
        gameOver(tiles, settings);
    }
    else {
        tile.isVisited = true;
        drawTileWithValue(tile, settings);<commit_msg>Finding tile when tapping has narrow range.<commit_after>var tilesWithoutMines,
    tilesWithoutMinesCounter;

function addEventListenersOnCanvas(tiles, settings) {
    $('canvas').on('click', {tiles: tiles, settings: settings}, onTileLeftClick).
        on('contextmenu', {tiles: tiles, settings: settings}, onTileRightClick);
}

function removeEventListenersFromCanvas() {
    $('canvas').off('click', onTileLeftClick).
        off('contextmenu', onTileRightClick);
}

function onTileLeftClick(event) {
    var tiles = event.data.tiles,
        settings = event.data.settings,
        tile;

    // To disable scroll click
    //if (event.button !== 1) {
        tile = getClickedTile(event, tiles, settings);
        if (tile && !tile.isVisited && !tile.hasMineFlag) {
            showBehindTile(tile, tiles, settings);
        }
    //}
}

function onTileRightClick(event) {
    var tiles = event.data.tiles,
        settings = event.data.settings,
        tile;

    // disable menu
    event.preventDefault();

    tile = getClickedTile(event, tiles, settings);
    if (tile && !tile.isVisited) {
        if (!tile.hasMineFlag) {
            tile.hasMineFlag = true;
            drawMineFlag(tile);
        }
        else {
            tile.hasMineFlag = false;
            drawSingleTile(tile, settings.tileSizeInPx, false);
        }
    }
}

function getClickedTile(event, tiles, settings) {
    var rect = canvas.getBoundingClientRect(),
        offsetX = event.clientX - rect.left,
        offsetY = event.clientY - rect.top,
        tile;

    // If the event is from mouse click is has offsetX.
    // Else the event is from mobile phone and it doesn't.
    if(event.offsetX) {
        tile = tiles.find(function (tile) {
            return tile.startXinPx < event.offsetX &&
                event.offsetX <= tile.startXinPx + settings.tileSizeInPx &&
                tile.startYinPx < event.offsetY &&
                event.offsetY <= tile.startYinPx + settings.tileSizeInPx;
        });
    }
    else {
        tile = tiles.find(function (tile) {
            return tile.startXinPx < offsetX &&
                offsetX <= tile.startXinPx + settings.tileSizeInPx &&
                tile.startYinPx < offsetY &&
                offsetY <= tile.startYinPx + settings.tileSizeInPx;
        });
    }

    return tile;
}

function showBehindTile(tile, tiles, settings) {
    if (tile.value === 0) {
        showAllTilesWithoutValue(tile.row, tile.col, tiles, settings);
    }
    else if (tile.value === '*') {
        gameOver(tiles, settings);
    }
    else {
        tile.isVisited = true;
        drawTileWithValue(tile, settings);
{'fraction_non_alphanumeric': 0.11943476577622919, 'fraction_numerical': 0.0007742934572202865, 'mean_word_length': 2.3143040410519564, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1713209', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1563, 'n_words': 332}