У меня в скрипте есть одна неточность. Когда зачёркивается 3 линии без "подковок", должен быть джекпот. Если зачеркивается 3 горизонтали хотя бы с 1 подковкой, то этот билет должен считаться как 3 линии. Пожалуйста, ничего больше не меняй, чтобы не сломать скрипт и алгоритм.
Также пропиши в скрипте джекпот - 10000 грн.
За 3 линии выигрыш 40% от призового фонда.
За 2 линии оставь без изменений и за 1 линию тоже.
<!DOCTYPE html>
<html lang="uk">
<head>
    <meta charset="UTF-8">
    <title>Лото Забава Симуляція</title>
    <style>
body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
}

.ticket {
    display: inline-block;
    margin: 10px;
    border: 2px solid #333;
    padding: 10px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
}

.field {
    display: grid;
    grid-template-columns: repeat(5, 40px);
    grid-gap: 5px;
    margin-bottom: 10px;
    border: 2px solid #ddd;
    padding: 5px;
    border-radius: 8px;
}

.cell {
    width: 40px;
    height: 40px;
    border: 1px solid #ccc;
    text-align: center;
    line-height: 40px;
    font-size: 16px;
    position: relative;
    border-radius: 5px;
    background-color: #f8f8f8;
}

.marked {
    background-color: #ffd700;
    color: #333;
    font-weight: bold;
}

.horseshoe {
    font-size: 24px;
    color: #e67e22;
}

#controls {
    margin: 20px;
}

#drawnNumbers {
    margin: 20px;
}

#results {
    margin: 20px;
}

#tickets {
    margin: 20px;
}

.button {
    padding: 10px 15px;
    margin: 5px;
    font-size: 16px;
    border: none;
    border-radius: 5px;
    background-color: #4CAF50;
    color: white;
    cursor: pointer;
}

#history {
    margin: 20px;
}

.completed-line {
    background-color: red !important;
    color: #fff;
}

#buyTicketsInput {
    width: 50px;
    padding: 5px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

#drawnCount {
    font-weight: bold;
}

#winningTickets {
    margin-top: 10px;
}

#info {
    margin: 20px;
    border: 1px solid #ccc;
    padding: 10px;
    border-radius: 5px;
    background-color: #f9f9f9;
}

#info p {
    margin: 5px 0;
}

#drawHistory li {
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #f9f9f9;
}
    </style>
</head>
<body>

<h1>Симуляція лотереї "Лото Забава"</h1>

<div id="controls">
    <label>Купити білети (20 грн за білет): </label>
    <input type="number" id="buyTicketsInput" value="1" min="1">
    <button class="button" onclick="buyTickets()">Купити</button>
    <button class="button" onclick="startNewDraw()">Почати новий розіграш</button>
    <button class="button" onclick="drawNextBall()">Дістати шар</button>
</div>

<div id="info">
    <p>Поточний тираж: <span id="currentDraw">1</span></p>
    <p>Кількість куплених білетів: <span id="ticketCount">0</span></p>
    <p>Загальний призовий фонд: <span id="prizeFund">0</span> грн</p>
</div>

<div id="drawnNumbers">
    <h3>Витягнуті номери (<span id="drawnCount">0</span> шарів):</h3>
    <div id="numbers"></div>
</div>

<div id="results">
    <h3>Результати:</h3>
    <p>Білетів з 1 лінією: <span id="oneLine">0</span> (виграш <span id="oneLinePrize">0</span> грн)</p>
    <p>Білетів з 2 лініями: <span id="twoLines">0</span> (виграш <span id="twoLinesPrize">0</span> грн на кожного)</p>
    <p>Білетів з 3 лініями: <span id="threeLines">0</span> (виграш <span id="threeLinesPrize">0</span> грн на кожного)</p>
    <p>Білетів з Джек-потом: <span id="jackpotWinners">0</span> (виграш 1,000,000 грн)</p>
    <div id="winningTickets"></div>
</div>

<div id="tickets">
    <h3>Ваші білети:</h3>
    <div id="ticketContainer"></div>
</div>

<div id="history">
    <h3>Історія розіграшів:</h3>
    <ul id="drawHistory"></ul>
</div>

<script>
    let currentDrawNumber = 1;
    let tickets = [];
    let drawnNumbers = [];
    let prizeFund = 0;
    const ticketPrice = 20;

    let oneLineWinners = new Set();
    let twoLineWinners = new Set();
    let threeLineWinners = new Set();
    let jackpotWinners = new Set();

    let drawHistory = [];

    let drawEnded = false;

    function buyTickets() {
        let quantityInput = document.getElementById('buyTicketsInput');
        let quantity = parseInt(quantityInput.value);
        if (isNaN(quantity) || quantity < 1) {
            alert('Введіть коректну кількість білетів.');
            return;
        }

        prizeFund += ticketPrice * quantity;
        document.getElementById('prizeFund').innerText = prizeFund;

        for (let i = 0; i < quantity; i++) {
            let ticket = generateTicket();
            tickets.push({
                fields: ticket,
                linesCompleted: 0,
                id: tickets.length // Unique identifier
            });
        }

        displayTickets();
        document.getElementById('ticketCount').innerText = tickets.length;
    }

    function generateTicket() {
        let ticket = [];
        for (let i = 0; i < 3; i++) {
            ticket.push(generateField());
        }
        return ticket;
    }

    function generateField() {
        let field = [];
        let ranges = [
            { min: 1, max: 15 },
            { min: 16, max: 30 },
            { min: 31, max: 45 },
            { min: 46, max: 60 },
            { min: 61, max: 75 },
        ];

        // Prepare empty 5x5 grid
        for (let i = 0; i < 5; i++) {
            field.push([null, null, null, null, null]);
        }

        // Fill columns
        for (let col = 0; col < 5; col++) {
            let columnNumbers = getUniqueRandomNumbers(5, ranges[col].min, ranges[col].max);
            for (let row = 0; row < 5; row++) {
                field[row][col] = columnNumbers[row];
            }
        }

        // Place two horseshoes in different rows (can't be in the same horizontal line)
        let horseshoeRows = getUniqueRandomNumbers(2, 0, 4);
        for (let i = 0; i < horseshoeRows.length; i++) {
            let row = horseshoeRows[i];
            let col;
            do {
                col = Math.floor(Math.random() * 5);
            } while (field[row][col] === '🔱'); // Ensure we don't overwrite a horseshoe
            field[row][col] = '🔱'; // Horseshoe symbol
        }

        return field;
    }

    function getUniqueRandomNumbers(count, min, max) {
        let numbers = [];
        while (numbers.length < count) {
            let num = Math.floor(Math.random() * (max - min + 1)) + min;
            if (!numbers.includes(num)) {
                numbers.push(num);
            }
        }
        return numbers;
    }

    function displayTickets() {
        let container = document.getElementById('ticketContainer');
        container.innerHTML = '';
        tickets.forEach((ticketObj, index) => {
            let ticket = ticketObj.fields;
            let ticketDiv = document.createElement('div');
            ticketDiv.classList.add('ticket');
            ticketDiv.setAttribute('data-ticket-id', ticketObj.id);
            let ticketHeader = document.createElement('h4');
            ticketHeader.innerText = 'Білет №' + (index + 1);
            ticketDiv.appendChild(ticketHeader);
            ticket.forEach((field, fieldIndex) => {
                let fieldDiv = document.createElement('div');
                fieldDiv.classList.add('field');
                fieldDiv.setAttribute('data-field-index', fieldIndex);
                field.forEach((row, rowIndex) => {
                    row.forEach((cell, colIndex) => {
                        let cellDiv = document.createElement('div');
                        cellDiv.classList.add('cell');
                        cellDiv.setAttribute('data-row', rowIndex);
                        cellDiv.setAttribute('data-col', colIndex);
                        if (cell === '🔱') {
                            cellDiv.innerHTML = '<span class="horseshoe">🔱</span>';
                        } else {
                            cellDiv.innerText = cell;
                            cellDiv.setAttribute('data-number', cell);
                        }
                        fieldDiv.appendChild(cellDiv);
                    });
                });
                ticketDiv.appendChild(fieldDiv);
            });
            container.appendChild(ticketDiv);
        });
    }

    function startNewDraw() {
        if (drawnNumbers.length > 0) {
            saveDrawHistory();
        }
        currentDrawNumber++;
        document.getElementById('currentDraw').innerText = currentDrawNumber;
        drawnNumbers = [];
        tickets = [];
        prizeFund = 0;
        oneLineWinners.clear();
        twoLineWinners.clear();
        threeLineWinners.clear();
        jackpotWinners.clear();
        document.getElementById('ticketCount').innerText = tickets.length;
        document.getElementById('prizeFund').innerText = prizeFund;
        document.getElementById('numbers').innerText = '';
        document.getElementById('drawnCount').innerText = '0';
        document.getElementById('oneLine').innerText = oneLineWinners.size;
        document.getElementById('twoLines').innerText = twoLineWinners.size;
        document.getElementById('threeLines').innerText = threeLineWinners.size;
        document.getElementById('jackpotWinners').innerText = jackpotWinners.size;
        document.getElementById('oneLinePrize').innerText = '0';
        document.getElementById('twoLinesPrize').innerText = '0';
        document.getElementById('threeLinesPrize').innerText = '0';
        document.getElementById('winningTickets').innerHTML = '';
        drawEnded = false;
        displayTickets();
    }

    function drawNextBall() {
        if (drawEnded) {
            alert('Розіграш завершено. Почніть новий тираж.');
            return;
        }
        if (drawnNumbers.length >= 75) {
            alert('Усі номери вже витягнуті.');
            return;
        }
        let number;
        do {
            number = Math.floor(Math.random() * 75) + 1;
        } while (drawnNumbers.includes(number));
        drawnNumbers.push(number);
        document.getElementById('numbers').innerText = drawnNumbers.join(', ');
        document.getElementById('drawnCount').innerText = drawnNumbers.length;
        markTickets(number);
        checkWinners();
    }

    function markTickets(number) {
        tickets.forEach((ticketObj) => {
            ticketObj.fields.forEach((field, fieldIndex) => {
                field.forEach((row, rowIndex) => {
                    row.forEach((cell, colIndex) => {
                        if (cell === number) {
                            // Mark the cell
                            let ticketDiv = document.querySelector(`.ticket[data-ticket-id="${ticketObj.id}"]`);
                            let fieldDiv = ticketDiv.querySelectorAll('.field')[fieldIndex];
                            let cellDivs = fieldDiv.querySelectorAll('.cell');
                            let cellDivIndex = rowIndex * 5 + colIndex;
                            let cellDiv = cellDivs[cellDivIndex];
                            cellDiv.classList.add('marked');
                        }
                    });
                });
            });
        });
    }

    function checkWinners() {
    oneLineWinners.clear();
    twoLineWinners.clear();
    threeLineWinners.clear();
    jackpotWinners.clear();

    tickets.forEach((ticketObj) => {
        let ticketId = ticketObj.id;
        let maxLinesCompleted = 0;
        let hasJackpot = false;

        ticketObj.fields.forEach((field, fieldIndex) => {
            let linesCompleted = checkFieldLines(field, ticketId, fieldIndex);
            if (linesCompleted > maxLinesCompleted) {
                maxLinesCompleted = linesCompleted;
            }
            if (isJackpot(field)) {
                hasJackpot = true;
            }
        });

        if (hasJackpot) {
            jackpotWinners.add(ticketId);
            addWinningTicket(ticketId + 1, 'Джекпот');
            drawEnded = true;
        } else if (maxLinesCompleted === 3) {
            threeLineWinners.add(ticketId);
            addWinningTicket(ticketId + 1, '3 лінії');
            drawEnded = true; // Заканчиваем розыгрыш, если билет имеет 3 линии в одном поле
        } else if (maxLinesCompleted === 2) {
            twoLineWinners.add(ticketId);
        } else if (maxLinesCompleted === 1) {
            oneLineWinners.add(ticketId);
        }
    });

    updatePrizes();
    updateResults();

    if (drawEnded) {
        alert('Розіграш завершено! Перевірте результати.');
    }
}

    function checkFieldLines(field, ticketId, fieldIndex) {
        let lines = 0;
        // Check only rows (horizontal lines)
        for (let i = 0; i < 5; i++) {
            let rowMarked = 0;
            for (let j = 0; j < 5; j++) {
                let cellValue = field[i][j];
                if (cellValue === '🔱') {
                    rowMarked++; // Horseshoe counts as a marked number
                } else if (isNumberMarked(cellValue)) {
                    rowMarked++;
                }
            }
            // Line is complete if 5 cells in row are marked (including horseshoes)
            if (rowMarked === 5) {
                lines++;
                highlightLine(ticketId, fieldIndex, 'row', i);
            }
        }
        return lines;
    }

    function isNumberMarked(number) {
        if (drawnNumbers.includes(number)) {
            return true;
        }
        return false;
    }

    function isJackpot(field) {
        // Jackpot is when all numbers are marked (excluding horseshoes)
        let allMarked = true;
        for (let i = 0; i < 5; i++) {
            for (let j = 0; j < 5; j++) {
                let cellValue = field[i][j];
                if (cellValue === '🔱') {
                    continue; // Skip horseshoes
                } else if (!isNumberMarked(cellValue)) {
                    allMarked = false;
                    break;
                }
            }
            if (!allMarked) break;
        }
        return allMarked;
    }

    function highlightLine(ticketId, fieldIndex, lineType, index) {
        let ticketDiv = document.querySelector(`.ticket[data-ticket-id="${ticketId}"]`);
        let fieldDiv = ticketDiv.querySelectorAll('.field')[fieldIndex];
        let cellDivs = fieldDiv.querySelectorAll('.cell');
        if (lineType === 'row') {
            for (let col = 0; col < 5; col++) {
                let cellIndex = index * 5 + col;
                let cellDiv = cellDivs[cellIndex];
                cellDiv.classList.add('completed-line');
            }
        }
    }

    function updatePrizes() {
        // For 1 line: prize is 24 UAH per winner
        let oneLinePrize = 24;
        document.getElementById('oneLinePrize').innerText = oneLinePrize;

        // For 2 lines: prize is 30% of prize fund divided among winners, but not less than 24 UAH each
        let totalTwoLinePrize = Math.max(prizeFund * 0.3, 24 * twoLineWinners.size);
        let twoLinePrizePerWinner = twoLineWinners.size > 0 ? (totalTwoLinePrize / twoLineWinners.size).toFixed(2) : 0;
        document.getElementById('twoLinesPrize').innerText = twoLinePrizePerWinner;

        // For 3 lines: prize is 190,000 UAH divided among winners
        let totalThreeLinePrize = 190000;
        let threeLinePrizePerWinner = threeLineWinners.size > 0 ? (totalThreeLinePrize / threeLineWinners.size).toFixed(2) : 0;
        document.getElementById('threeLinesPrize').innerText = threeLinePrizePerWinner;
    }

    function updateResults() {
        document.getElementById('oneLine').innerText = oneLineWinners.size;
        document.getElementById('twoLines').innerText = twoLineWinners.size;
        document.getElementById('threeLines').innerText = threeLineWinners.size;
        document.getElementById('jackpotWinners').innerText = jackpotWinners.size;
    }

    function addWinningTicket(ticketNumber, prizeCategory) {
        let winningTicketsDiv = document.getElementById('winningTickets');
        let ticketInfo = document.createElement('p');
        ticketInfo.innerText = `Білет №${ticketNumber} виграв: ${prizeCategory}`;
        winningTicketsDiv.appendChild(ticketInfo);
    }

    function saveDrawHistory() {
        let oneLinePrize = 24;
        let totalTwoLinePrize = Math.max(prizeFund * 0.3, 24 * twoLineWinners.size);
        let twoLinePrizePerWinner = twoLineWinners.size > 0 ? (totalTwoLinePrize / twoLineWinners.size).toFixed(2) : 0;
        let totalThreeLinePrize = 190000;
        let threeLinePrizePerWinner = threeLineWinners.size > 0 ? (totalThreeLinePrize / threeLineWinners.size).toFixed(2) : 0;

        let historyItem = {
            drawNumber: currentDrawNumber,
            drawnNumbers: [...drawnNumbers],
            winners: {
                oneLine: oneLineWinners.size,
                twoLines: twoLineWinners.size,
                threeLines: threeLineWinners.size,
                jackpot: jackpotWinners.size
            },
            prizes: {
                oneLine: oneLinePrize,
                twoLines: twoLinePrizePerWinner,
                threeLines: threeLinePrizePerWinner,
                jackpot: 1000000
            }
        };
        drawHistory.push(historyItem);
        updateDrawHistoryDisplay();
    }

    function updateDrawHistoryDisplay() {
        let historyDiv = document.getElementById('drawHistory');
        historyDiv.innerHTML = '';
        drawHistory.forEach((item) => {
            let listItem = document.createElement('li');
            listItem.innerHTML = `
                <strong>Тираж №${item.drawNumber}</strong><br>
                Номери (${item.drawnNumbers.length} шарів): ${item.drawnNumbers.join(', ')}<br>
                Переможці:<br>
                - 1 лінія: ${item.winners.oneLine} (виграш ${item.prizes.oneLine} грн)<br>
                - 2 лінії: ${item.winners.twoLines} (виграш ${item.prizes.twoLines} грн на кожного)<br>
                - 3 лінії: ${item.winners.threeLines} (виграш ${item.prizes.threeLines} грн на кожного)<br>
                - Джекпот: ${item.winners.jackpot} (виграш ${item.prizes.jackpot} грн)
            `;
            historyDiv.appendChild(listItem);
        });
    }
</script>

</body>
</html>