huiguo 发表于 3 天前

【异界方块】roll到黑白不一定是好运?——本次活动概率计算小脚本

本帖最后由 huiguo 于 2026-6-10 22:37 编辑

刷到了咸鱼鱼老师的帖子【异界方块】R语言计算本次活动概率,启发于
感兴趣的同学可以让AI跑一下发1贴和2贴的概率是多少,我就摸鱼去了
也就是说已经 Roll 到了一个方块,或者已经 Roll 到了两个方块,那后面继续 Roll 的时候,自己最终拿到几等奖的概率可以算出来的
比如:1.只 Roll 到第一个方块时,想知道后面两次 Roll 完之后,一等奖、二等奖、三等奖分别有多大概率2.已经 Roll 到两个方块时,想知道最后一次 Roll 完之后,最终会变成几等奖3.三次都 Roll 完后,也可以直接判断最终奖项然后找了一下 G 老师,于是本帖就这么诞生了{:4_86:}
脚本的功能很简单:
在安装脚本后,在输入框里依次第一次,第二次、第三次 Roll 到的方块颜色,它会根据当前已经 Roll 到的结果,自动计算最终获得一等奖、二等奖、三等奖的概率
https://i.postimg.cc/nz9265hj/tu-pian.png如果什么都不输入,它就会计算得奖的总概率https://i.postimg.cc/GpbYrfh3/tu-pian.png如果只输入第一次 Roll 的颜色,它就会计算剩下两次 Roll 后的最终得奖的概率https://i.postimg.cc/c4qB2XY4/tu-pian.png如果输入第一次和第二次 Roll 的颜色,它就会计算最后一次 Roll 后的最终得奖的概率https://i.postimg.cc/nLssHtby/tu-pian.png如果三次都输入了,它就会直接告诉你最终是几等奖奖项判断规则按照:一等奖 > 二等奖 > 三等奖也就是说,如果某个结果同时满足多个奖项条件,就按更高奖项来算脚本代码如下:// ==UserScript==
// @Name         方块 Roll 奖项概率计算器
// @namespace    https://tampermonkey.net/
// @version      1.0
// @description输入已 Roll 到的方块颜色,计算最终获得一等奖、二等奖、三等奖的概率
// @author       huiguo
// @Match      https://www.gamemale.com/*
// @grant      none
// ==/UserScript==

(function () {
    'use strict';

    // ==============================
    // 方块概率配置
    // ==============================
    const cubeProb = {
      "金色": 0.01,
      "黑色": 0.04,
      "白色": 0.04,
      "绿色": 0.13,
      "蓝色": 0.13,
      "粉色": 0.13,
      "橙色": 0.13,
      "红色": 0.13,
      "紫色": 0.13,
      "青色": 0.13
    };

    const colors = Object.keys(cubeProb);

    // ==============================
    // 创建悬浮面板
    // ==============================
    const panel = document.createElement("div");
    panel.id = "roll-calc-panel";
    panel.innerHTML = `
      <div id="roll-calc-header">
            <span>方块 Roll 概率计算器</span>
            <button id="roll-calc-toggle">-</button>
      </div>

      <div id="roll-calc-body">
            <label>第一次 Roll</label>
            <select id="roll1">
                <option value="">未输入</option>
            </select>

            <label>第二次 Roll</label>
            <select id="roll2">
                <option value="">未输入</option>
            </select>

            <label>第三次 Roll</label>
            <select id="roll3">
                <option value="">未输入</option>
            </select>

            <button id="roll-calc-btn">计算概率</button>
            <button id="roll-reset-btn">重置</button>

            <div id="roll-result">
                请按顺序输入已 Roll 到的颜色。
            </div>
      </div>
    `;

    document.body.appendChild(panel);

    // ==============================
    // 添加样式
    // ==============================
    const style = document.createElement("style");
    style.textContent = `
      #roll-calc-panel {
            position: fixed;
            right: 20px;
            bottom: 20px;
            width: 310px;
            background: #ffffff;
            color: #222;
            border-radius: 14px;
            box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
            z-index: 999999;
            font-family: "Microsoft YaHei", Arial, sans-serif;
            overflow: hidden;
            border: 1px solid #ddd;
      }

      #roll-calc-header {
            background: #4a6cf7;
            color: white;
            padding: 10px 12px;
            font-size: 15px;
            font-weight: bold;
            display: flex;
            justify-content: space-between;
            align-items: center;
            cursor: move;
            user-select: none;
      }

      #roll-calc-toggle {
            background: white;
            color: #4a6cf7;
            border: none;
            border-radius: 6px;
            width: 26px;
            height: 24px;
            font-size: 16px;
            cursor: pointer;
            font-weight: bold;
      }

      #roll-calc-body {
            padding: 14px;
      }

      #roll-calc-body label {
            display: block;
            margin-top: 9px;
            margin-bottom: 4px;
            font-size: 14px;
            font-weight: bold;
      }

      #roll-calc-body select {
            width: 100%;
            padding: 7px;
            border-radius: 8px;
            border: 1px solid #ccc;
            font-size: 14px;
            background: white;
            color: #222;
      }

      #roll-calc-btn,
      #roll-reset-btn {
            width: 100%;
            margin-top: 10px;
            padding: 9px;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            cursor: pointer;
      }

      #roll-calc-btn {
            background: #4a6cf7;
            color: white;
      }

      #roll-reset-btn {
            background: #eeeeee;
            color: #333;
      }

      #roll-calc-btn:hover {
            background: #3454d1;
      }

      #roll-reset-btn:hover {
            background: #dddddd;
      }

      #roll-result {
            margin-top: 12px;
            padding: 10px;
            background: #f0f3ff;
            border-radius: 10px;
            font-size: 13px;
            line-height: 1.7;
            max-height: 220px;
            overflow-y: auto;
      }

      .roll-warning {
            color: #c0392b;
            font-weight: bold;
      }

      .roll-prize {
            color: #4a6cf7;
            font-weight: bold;
      }
    `;

    document.head.appendChild(style);

    // ==============================
    // 初始化下拉框
    // ==============================
    function initSelects() {
      const selects = [
            document.getElementById("roll1"),
            document.getElementById("roll2"),
            document.getElementById("roll3")
      ];

      selects.forEach(select => {
            colors.forEach(color => {
                const option = document.createElement("option");
                option.value = color;
                option.textContent = color + "方块";
                select.appendChild(option);
            });
      });
    }

    initSelects();

    // ==============================
    // 判断最终奖项
    // 优先级:一等奖 > 二等奖 > 三等奖
    // ==============================
    function judgePrize(rolls) {
      const counts = {};

      rolls.forEach(color => {
            counts = (counts || 0) + 1;
      });

      const uniqueColors = Object.keys(counts);
      const countValues = Object.values(counts);

      // 一等奖:只要有金色
      if (rolls.includes("金色")) {
            return "一等奖";
      }

      // 一等奖:三个颜色相同
      if (uniqueColors.length === 1) {
            return "一等奖";
      }

      // 二等奖:两个相同 + 一个不同
      if (countValues.includes(2)) {
            return "二等奖";
      }

      // 二等奖:黑色 + 白色 + 其他颜色
      if (
            rolls.includes("黑色") &&
            rolls.includes("白色") &&
            uniqueColors.length === 3
      ) {
            return "二等奖";
      }

      // 三等奖:三个不同颜色
      if (uniqueColors.length === 3) {
            return "三等奖";
      }

      return "未中奖";
    }

    // ==============================
    // 枚举剩余 Roll 的所有可能
    // ==============================
    function enumerateRolls(currentRolls, remainingCount, currentProb, resultProb) {
      if (remainingCount === 0) {
            const prize = judgePrize(currentRolls);
            resultProb += currentProb;
            return;
      }

      colors.forEach(color => {
            enumerateRolls(
                [...currentRolls, color],
                remainingCount - 1,
                currentProb * cubeProb,
                resultProb
            );
      });
    }

    // ==============================
    // 计算概率
    // ==============================
    function calculate() {
      const r1 = document.getElementById("roll1").value;
      const r2 = document.getElementById("roll2").value;
      const r3 = document.getElementById("roll3").value;

      const resultBox = document.getElementById("roll-result");
      const inputs = ;

      if (!r1 && (r2 || r3)) {
            resultBox.innerHTML = `
                <span class="roll-warning">
                  请按顺序输入:必须先输入第一次 Roll 的颜色。
                </span>
            `;
            return;
      }

      if (!r2 && r3) {
            resultBox.innerHTML = `
                <span class="roll-warning">
                  请按顺序输入:必须先输入第二次 Roll 的颜色。
                </span>
            `;
            return;
      }

      const knownRolls = inputs.filter(x => x !== "");
      const remainingCount = 3 - knownRolls.length;


      const resultProb = {
            "一等奖": 0,
            "二等奖": 0,
            "三等奖": 0,
            "未中奖": 0
      };

      enumerateRolls(knownRolls, remainingCount, 1, resultProb);

      const first = (resultProb["一等奖"] * 100).toFixed(2);
      const second = (resultProb["二等奖"] * 100).toFixed(2);
      const third = (resultProb["三等奖"] * 100).toFixed(2);
      const none = (resultProb["未中奖"] * 100).toFixed(2);

      const inputText = knownRolls
            .map((c, i) => `第 ${i + 1} 次:${c}方块`)
            .join("<br>");

      if (remainingCount === 0) {
            const prize = judgePrize(knownRolls);

            resultBox.innerHTML = `
                <strong>你已经输入了三次 Roll 结果:</strong><br>
                ${inputText}<br><br>
                最终结果:<span class="roll-prize">${prize}</span>
            `;
      } else {
            resultBox.innerHTML = `
                <strong>当前已知结果:</strong><br>
                ${inputText}<br><br>

                剩余还要 Roll <strong>${remainingCount}</strong> 次。<br><br>

                最终获得 <strong>一等奖</strong> 的概率:${first}%<br>
                最终获得 <strong>二等奖</strong> 的概率:${second}%<br>
                最终获得 <strong>三等奖</strong> 的概率:${third}%<br>
                最终 <strong>未中奖</strong> 的概率:${none}%
            `;
      }
    }

    // ==============================
    // 重置
    // ==============================
    function reset() {
      document.getElementById("roll1").value = "";
      document.getElementById("roll2").value = "";
      document.getElementById("roll3").value = "";
      document.getElementById("roll-result").innerHTML =
            "请按顺序输入已 Roll 到的颜色。";
    }

    document.getElementById("roll-calc-btn").addEventListener("click", calculate);
    document.getElementById("roll-reset-btn").addEventListener("click", reset);

    // ==============================
    // 收起 / 展开
    // ==============================
    const toggleBtn = document.getElementById("roll-calc-toggle");
    const body = document.getElementById("roll-calc-body");

    toggleBtn.addEventListener("click", function () {
      if (body.style.display === "none") {
            body.style.display = "block";
            toggleBtn.textContent = "-";
      } else {
            body.style.display = "none";
            toggleBtn.textContent = "+";
      }
    });

    // ==============================
    // 面板拖拽
    // ==============================
    const header = document.getElementById("roll-calc-header");

    let isDragging = false;
    let offsetX = 0;
    let offsetY = 0;

    header.addEventListener("mousedown", function (e) {
      isDragging = true;

      const rect = panel.getBoundingClientRect();
      offsetX = e.clientX - rect.left;
      offsetY = e.clientY - rect.top;

      panel.style.right = "auto";
      panel.style.bottom = "auto";
      panel.style.left = rect.left + "px";
      panel.style.top = rect.top + "px";
    });

    document.addEventListener("mousemove", function (e) {
      if (!isDragging) return;

      panel.style.left = e.clientX - offsetX + "px";
      panel.style.top = e.clientY - offsetY + "px";
    });

    document.addEventListener("mouseup", function () {
      isDragging = false;
    });

})();




https://i.postimg.cc/7hp4MjQb/ping-mu-jie-tu-2026-06-10-220635.png比较有意思(并不)的是,算完之后可以发现
Roll 到黑色方块和白色方块,运气反而可能更背一点,得奖概率比 Roll 到其他普通颜色还要低{:6_189:}一开始我还以为黑色和白色是特殊组合,roll 到的话应该会更容易拿奖一点,结果实际算下来并不是这样{:4_100:}
因为黑色和白色本身概率只有 4%,而普通颜色有 13%,所以虽然它们有“黑 + 白 + 其他”的二等奖特殊规则,但单独 Roll 到黑色或者白色的时候,后续能凑出好结果的整体概率反而不一定占优
(我不行了我第一帖就 roll 到了一个黑色的{:6_180:}
目前脚本主要是为了方便这个帖子适合还没把这三个活动帖发完的坛友(比如我一周三帖,还是太难了{:6_164:},想看“已经 Roll 到某个颜色后,后面还能拿几等奖”,可以试试这个小工具,不用自己算惹
(https://www.gamemale.com/static/image/smiley/revocreate/05.gif最后许愿一下本帖金方块来黑方块来白方块来https://www.gamemale.com/static/image/smiley/revocreate/05.gif)




商人弗霖 发表于 3 天前

商人弗霖打开异界的百宝袋,袋口微光一闪,一枚【粉色方块】轻巧地蹦了出来。

刀火 发表于 3 天前

我第一下就是黑色,当时就算了下,发现还不如普通颜色,最后果然拿了三等奖{:6_164:}

aaawwwww 发表于 3 天前

晕了,还挺好奇这次活动我到底能拿到什么奖惹

PUCK 发表于 3 天前

其他颜色成双是两次百分之13,黑白明显要小很多

crino66666 发表于 3 天前

确实,当初看到二等奖条件就觉得一黑一白这概率比直接出金还低

是KUMAyo 发表于 3 天前

因为黑和白色自身的概率还是偏低的,如果黑和白色和其他颜色均分概率再加上黑白色能够触发二等奖的话,那先出黑或者白更有可能中二等奖呢,因为多了一个中奖的组合~{:6_190:}

娱乐法师火布偶 发表于 3 天前

确实不要黑白会更有利一点,不过这个活动是完全看脸的,拿到也没办法

Burry 发表于 3 天前

主要是黑跟白概率都很小,而且要都有才能发挥作用。确实挺难的。

solyluna007 发表于 3 天前

不管是什么概率,结果都是注定的,小精灵我们来了

伊犁鼠兔吃雪莲 发表于 3 天前

黑白配是经典配色,但要凑齐概率也不高,
正在酝酿帖子内容,看看积累的素材够不够出三篇的,来个二等奖不算太贪心吧

谢谢下一个 发表于 3 天前

反正我已经到手一枚灵魂向勋章了,就等明年这时候兑换果克了

雨停了我就回来 发表于 3 天前

看来第一次roll到黑白很大概率会变成三等奖额

克莱因蓝 发表于 3 天前

https://img.gamemale.com/album/202508/27/154618wt52fzit25qb9aaf.jpg这种看脸的活动对我来说就是默认三等了 中奖绝缘体

小蓝龙泷泽 发表于 3 天前

因为本来出黑白概率就会更低,出了一个的话想二等就只能赌同黑同白,想再赌其他颜色双色的概率就少了

Qxia1010 发表于 3 天前

确实抽到黑白像是最下签惹,5%还是太低了,高一点的话反而可以期待下三骰全是黑白的情况

野生阿努厨 发表于 3 天前

同样是中了黑白陷阱的朋友,是的我们没救了{:6_164:}

一只随行 发表于 3 天前

确实roll到黑/白后,后续要继续roll出黑/白或者继续roll两个其他同色才能组成二等奖以上的组合,概率应该是更低的{:6_190:}

Adam123456 发表于 3 天前

roll到黑白那真的背啊,话说原来黑白的概率跟其他的颜色不一样啊,我还以为就金色概率低

spcialguy 发表于 前天 00:01

到最后还是看运气的,这个也只是安慰自己罢了,我怎么挣扎,最后还是一个小精灵。:'(
页: [1] 2 3
查看完整版本: 【异界方块】roll到黑白不一定是好运?——本次活动概率计算小脚本