2048 Smart Auto Merge + Super Huge

2048 with huge tiles, new tiles as huge value, and smart auto merge

目前為 2025-12-06 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         2048 Smart Auto Merge + Super Huge
// @namespace    https://github.com/PatheticMustan/HackingGames
// @version      1.0
// @description  2048 with huge tiles, new tiles as huge value, and smart auto merge
// @author       PatheticMustan
// @match        https://2048game.com/*
// @icon         https://gabrielecirulli.github.io/2048/meta/og_image.png
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const MAX_VALUE = "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999";

    // Set initial board only once
    function setSuperHugeBoard() {
        if (!localStorage.getItem("hugeBoardSet")) {
            const gameState = {
                grid: {
                    size: 4,
                    cells: [
                        [{"position":{"x":0,"y":0},"value":MAX_VALUE},{"position":{"x":0,"y":1},"value":MAX_VALUE},{"position":{"x":0,"y":2},"value":MAX_VALUE},{"position":{"x":0,"y":3},"value":MAX_VALUE}],
                        [{"position":{"x":1,"y":0},"value":MAX_VALUE},{"position":{"x":1,"y":1},"value":MAX_VALUE},{"position":{"x":1,"y":2},"value":MAX_VALUE},{"position":{"x":1,"y":3},"value":MAX_VALUE}],
                        [{"position":{"x":2,"y":0},"value":MAX_VALUE},{"position":{"x":2,"y":1},"value":MAX_VALUE},{"position":{"x":2,"y":2},"value":MAX_VALUE},{"position":{"x":2,"y":3},"value":MAX_VALUE}],
                        [{"position":{"x":3,"y":0},"value":MAX_VALUE},{"position":{"x":3,"y":1},"value":MAX_VALUE},{"position":{"x":3,"y":2},"value":MAX_VALUE},{"position":{"x":3,"y":3},"value":MAX_VALUE}]
                    ]
                },
                score: MAX_VALUE,
                over: false,
                won: true,
                keepPlaying: true
            };
            localStorage.setItem("gameState", JSON.stringify(gameState));
            localStorage.setItem("hugeBoardSet", "true");
            location.reload();
        }
    }

    // Override tile spawn so all new tiles are MAX_VALUE
    function overrideTileSpawn() {
        const interval = setInterval(() => {
            if (window.game && game.grid) {
                clearInterval(interval);
                const originalInsertTile = game.grid.insertTile.bind(game.grid);
                game.grid.insertTile = function(tile) {
                    tile.value = MAX_VALUE;
                    originalInsertTile(tile);
                };
            }
        }, 100);
    }

    // Smart auto-merge: only moves that actually change the board
    function smartAutoMerge() {
        const moves = {37:'left', 38:'up', 39:'right', 40:'down'};

        setInterval(() => {
            if (!window.game || !game.grid) return;
            const currentGrid = game.grid.cells;

            for (let key in moves) {
                const clonedGrid = game.grid.clone();
                clonedGrid.prepareTiles();
                clonedGrid.move(moves[key]);
                if (!gridsEqual(clonedGrid.cells, currentGrid)) {
                    const event = new KeyboardEvent('keydown', { keyCode: parseInt(key), which: parseInt(key) });
                    document.dispatchEvent(event);
                    break; // make one move per interval
                }
            }
        }, 50); // fast interval for quick merging
    }

    function gridsEqual(a, b) {
        for (let y = 0; y < a.length; y++) {
            for (let x = 0; x < a[y].length; x++) {
                const valA = a[y][x] ? a[y][x].value : null;
                const valB = b[y][x] ? b[y][x].value : null;
                if (valA !== valB) return false;
            }
        }
        return true;
    }

    setSuperHugeBoard();
    setTimeout(overrideTileSpawn, 2000);
    setTimeout(smartAutoMerge, 3000);

})();