このブログ内を検索可能

2024年6月26日水曜日

マジカルマインのシミュレーション(4) ペイアウト率及び全消し率

 再度以下のカードを用いてペイアウト率および全消し率を計算する。

1~25の順列25P7通りすべてのパターンをチェックすればよい…のだがなぜかメモリ不足でできないので、ランダムに番号を生成してそれを複数回行い近似値を得ることにした。

ただ、100回回すのに42秒かかるという事態。となると10000回試行するだけでも4200秒と1時間以上かかってしまう。これはさすがにプログラムがしょぼいか…。

とりあえず翌朝まで回してどうなるかみたいので、翌朝7時までは12時間つまり43200秒あるので、100000回くらい試行することはできそうであるからやってみる。

途中経過

600回試行→

宝箱獲得率左から24%、45%、30%、21%、15%、15%

ペイアウト率107%

全消し率0.3%

結論として若干良いカードらしいことが分かる。このカードが出続ければ徐々にメダルが増えていくという理論になる…が100%そんなことはない。



なお我が作った即席の荒いプログラムは以下。全然きれいではないが、とりあえず正しい結果を返しているのでまあそれなりに役には立つ。

numtomat[x_] := {1 + QuotientRemainder[x - 1, 6][[1]], 

  1 + QuotientRemainder[x - 1, 6][[2]]}; group = Table[Table[0, 6], 9];

pos[number_] := 

  For[j = 1, j <= 1, j++, return = {}; 

   For[i = 1, i <= 54, i++, 

    If[num[[numtomat[i][[1]], numtomat[i][[2]]]] == number, 

     return = Append[return, i]]]; Return[return]];

fall[number_] := 

  For[l = 1, l <= 1, l++, eraselist = {}; 

   If[pos[number] != {}, 

    erasegroup = 

     group[[numtomat[pos[number][[1]]][[1]], 

       numtomat[pos[number][[1]]][[2]]]]; 

    For[k = 1, k <= 54, k++, 

     If[erasegroup == group[[numtomat[k][[1]], numtomat[k][[2]]]], 

      eraselist = Append[eraselist, k]]]; Return[eraselist]]];

erase[list_] := 

  For[r = 1, r <= 1, r++, 

   For[i = 1, i <= Length[list], i++, 

    If[list != {}, 

     block[[numtomat[list[[i]]][[1]], numtomat[list[[i]]][[2]]]] = 0; 

     num[[numtomat[list[[i]]][[1]], numtomat[list[[i]]][[2]]]] = 0]; 

    group[[numtomat[list[[i]]][[1]], numtomat[list[[i]]][[2]]]] = 0]; 

   renzoku = Length[list]; retu = RandomInteger[{1, 6}]; 

   Which[renzoku == 7, odds[[retu]] += 0.5, renzoku == 8, 

    odds[[retu]] += 1.5, renzoku == 9, odds[[retu]] += 4, 

    renzoku == 10, odds[[retu]] += 4, renzoku == 11, 

    odds[[retu]] += 9, renzoku == 12, odds[[retu]] += 11.5, 

    renzoku == 13, odds[[retu]] += 14, renzoku >= 14, 

    odds[[retu]] += 5*renzoku - 51]];

haitouall = 0; kakutokuall = {0, 0, 0, 0, 0, 0};

zenkesi = 0; For[times = 1, times <= 100000, times++, 

 in = RandomChoice[Table[i, {i, 1, 25}], 8];

 block = {{3, 1, 1, 1, 2, 2}, {3, 1, 1, 1, 2, 2}, {3, 2, 2, 4, 2, 

    3}, {3, 1, 2, 4, 2, 3}, {3, 1, 2, 4, 3, 3}, {3, 1, 2, 3, 3, 

    2}, {1, 1, 3, 4, 2, 2}, {1, 3, 3, 4, 2, 2}, {3, 3, 4, 4, 4, 4}};

 num = {{0, 0, 20, 2, 0, 0}, {0, 0, 0, 17, 19, 11}, {4, 12, 0, 0, 0, 

    10}, {16, 0, 22, 9, 6, 0}, {0, 0, 21, 23, 8, 0}, {0, 0, 0, 0, 0, 

    3}, {14, 13, 15, 7, 0, 0}, {0, 0, 18, 0, 5, 25}, {24, 0, 1, 0, 0, 

    0}};

 group = Table[Table[0, 6], 9];

 treasure = {5, 2, 2, 2, 2, 5}; odds = {1, 1, 1, 1, 1, 1}; 

 For[lotta = 1, lotta <= 5, lotta++, groupcount = 0; 

  group = Table[Table[0, 6], 9]; For[i = 1, i <= 54, i++,

   If[group[[numtomat[i][[1]], numtomat[i][[2]]]] == 0 && 

      block[[numtomat[i][[1]], numtomat[i][[2]]]] != 0, 

     groupcount += 1; 

     group[[numtomat[i][[1]], numtomat[i][[2]]]] = groupcount;

     pre = post = 0; first = 0; 

     color = block[[numtomat[i][[1]], numtomat[i][[2]]]];

     While[pre != post || first == 0, first = 1;

       pre = Sum[Count[group[[l]], groupcount], {l, 1, 9}];

       For[j = 1, j <= 54, j++, 

        If[group[[numtomat[j][[1]], numtomat[j][[2]]]] == 0, 

         hidari = migi = ue = sita = {0, 0}; 

         If[numtomat[j][[2]] >= 2, 

          hidari = {numtomat[j][[1]], numtomat[j][[2]] - 1}];

         If[numtomat[j][[2]] <= 5, 

          migi = {numtomat[j][[1]], numtomat[j][[2]] + 1}];

         If[numtomat[j][[1]] >= 2, 

          ue = {numtomat[j][[1]] - 1, numtomat[j][[2]]}];

         If[numtomat[j][[1]] <= 8, 

          sita = {numtomat[j][[1]] + 1, numtomat[j][[2]]}];

         If[

          hidari != {0, 0} && 

           block[[hidari[[1]], hidari[[2]]]] == 

            block[[numtomat[j][[1]], numtomat[j][[2]]]] && 

           group[[hidari[[1]], hidari[[2]]]] > 0, 

          group[[numtomat[j][[1]], numtomat[j][[2]]]] = 

           group[[hidari[[1]], hidari[[2]]]]];

         If[

          ue != {0, 0} && 

           block[[ue[[1]], ue[[2]]]] == 

            block[[numtomat[j][[1]], numtomat[j][[2]]]] && 

           group[[ue[[1]], ue[[2]]]] > 0, 

          group[[numtomat[j][[1]], numtomat[j][[2]]]] = 

           group[[ue[[1]], ue[[2]]]]];

         If[

          migi != {0, 0} && 

           block[[migi[[1]], migi[[2]]]] == 

            block[[numtomat[j][[1]], numtomat[j][[2]]]] && 

           group[[migi[[1]], migi[[2]]]] > 0, 

          group[[numtomat[j][[1]], numtomat[j][[2]]]] = 

           group[[migi[[1]], migi[[2]]]]];

         If[

          sita != {0, 0} && 

           block[[sita[[1]], sita[[2]]]] == 

            block[[numtomat[j][[1]], numtomat[j][[2]]]] && 

           group[[sita[[1]], sita[[2]]]] > 0, 

          group[[numtomat[j][[1]], numtomat[j][[2]]]] = 

           group[[sita[[1]], sita[[2]]]]];]]; 

       groupall = 

        Sum[If[group[[numtomat[k]]] == groupcount, Return[1], 

          Return[0]], {k, 1, 54}]; 

       post = Sum[Count[group[[l]], groupcount], {l, 1, 9}];;]];];

  Which[lotta == 1, erase[fall[in[[1]]]]; erase[fall[in[[2]]]]; 

   erase[fall[in[[3]]]], lotta == 2, erase[fall[in[[4]]]]; 

   erase[fall[in[[5]]]], lotta == 3, erase[fall[in[[6]]]], lotta == 4,

    erase[fall[in[[7]]]], lotta == 5, erase[fall[in[[8]]]]]; 

  onemore = 1;

  

  While[onemore == 1, nonmovelist = Table[Table[0, 6], 9]; first = 0; 

   pre = 0; post = 0;

   

   While[pre != post || first == 0, first = 1; 

    pre = Sum[Count[nonmovelist[[l]], 1], {l, 1, 9}]; 

    For[m = 54, m >= 1, m--, 

     If[group[[numtomat[m][[1]], numtomat[m][[2]]]] != 0 && m >= 49, 

      nonmovelist[[numtomat[m][[1]], numtomat[m][[2]]]] = 1]; 

     If[group[[numtomat[m][[1]], numtomat[m][[2]]]] != 0 && 

       numtomat[m][[1]] <= 8 && 

       nonmovelist[[numtomat[m][[1]] + 1, numtomat[m][[2]]]] == 1 && 

       group[[numtomat[m][[1]], numtomat[m][[2]]]] == 

        group[[numtomat[m][[1]] + 1, numtomat[m][[2]]]], 

      nonmovelist[[numtomat[m][[1]], numtomat[m][[2]]]] = 1];

     If[group[[numtomat[m][[1]], numtomat[m][[2]]]] != 0 && 

       numtomat[m][[1]] >= 2 && 

       nonmovelist[[numtomat[m][[1]] - 1, numtomat[m][[2]]]] == 1 && 

       group[[numtomat[m][[1]], numtomat[m][[2]]]] == 

        group[[numtomat[m][[1]] - 1, numtomat[m][[2]]]], 

      nonmovelist[[numtomat[m][[1]], numtomat[m][[2]]]] = 1];

     If[group[[numtomat[m][[1]], numtomat[m][[2]]]] != 0 && 

       numtomat[m][[2]] >= 2 && 

       nonmovelist[[numtomat[m][[1]], numtomat[m][[2]] - 1]] == 1 && 

       group[[numtomat[m][[1]], numtomat[m][[2]]]] == 

        group[[numtomat[m][[1]], numtomat[m][[2]] - 1]], 

      nonmovelist[[numtomat[m][[1]], numtomat[m][[2]]]] = 1];

     If[group[[numtomat[m][[1]], numtomat[m][[2]]]] != 0 && 

       numtomat[m][[2]] <= 5 && 

       nonmovelist[[numtomat[m][[1]], numtomat[m][[2]] + 1]] == 1 && 

       group[[numtomat[m][[1]], numtomat[m][[2]]]] == 

        group[[numtomat[m][[1]], numtomat[m][[2]] + 1]], 

      nonmovelist[[numtomat[m][[1]], numtomat[m][[2]]]] = 1];

     If[group[[numtomat[m][[1]], numtomat[m][[2]]]] != 0 && 

       numtomat[m][[1]] <= 8 && 

       nonmovelist[[numtomat[m][[1]] + 1, numtomat[m][[2]]]] == 1, 

      nonmovelist[[numtomat[m][[1]], numtomat[m][[2]]]] = 1];

     

     ]; post = Sum[Count[nonmovelist[[l]], 1], {l, 1, 9}];]; 

   For[m = 54, m >= 1, m--, 

    If[nonmovelist[[numtomat[m][[1]], numtomat[m][[2]]]] == 0 && 

      group[[numtomat[m][[1]], numtomat[m][[2]]]] > 0, 

     block[[numtomat[m][[1]] + 1, numtomat[m][[2]]]] = 

      block[[numtomat[m][[1]], numtomat[m][[2]]]];

     group[[numtomat[m][[1]] + 1, numtomat[m][[2]]]] = 

      group[[numtomat[m][[1]], numtomat[m][[2]]]];

     num[[numtomat[m][[1]] + 1, numtomat[m][[2]]]] = 

      num[[numtomat[m][[1]], numtomat[m][[2]]]];

     block[[numtomat[m][[1]], numtomat[m][[2]]]] = 0;

     group[[numtomat[m][[1]], numtomat[m][[2]]]] = 0;

     num[[numtomat[m][[1]], numtomat[m][[2]]]] = 0]]; onemore = 0;

   For[s = 1, s <= 54, s++, 

    If[nonmovelist[[numtomat[s][[1]], numtomat[s][[2]]]] == 0 && 

      group[[numtomat[s][[1]], numtomat[s][[2]]]] > 0, 

     onemore = 1]]];];

 groupwin = Table[Table[0, 6], 9]; groupcount = 0;

 For[i = 1, i <= 54, i++,

  If[groupwin[[numtomat[i][[1]], numtomat[i][[2]]]] == 0, 

    groupcount += 1; 

    groupwin[[numtomat[i][[1]], numtomat[i][[2]]]] = groupcount;

    pre = post = 0; first = 0; 

    color = block[[numtomat[i][[1]], numtomat[i][[2]]]];

    While[pre != post || first == 0, first = 1;

      pre = Sum[Count[groupwin[[l]], groupcount], {l, 1, 9}];

      For[j = 1, j <= 54, j++, 

       If[groupwin[[numtomat[j][[1]], numtomat[j][[2]]]] == 0, 

        hidari = migi = ue = sita = {0, 0}; 

        If[numtomat[j][[2]] >= 2, 

         hidari = {numtomat[j][[1]], numtomat[j][[2]] - 1}];

        If[numtomat[j][[2]] <= 5, 

         migi = {numtomat[j][[1]], numtomat[j][[2]] + 1}];

        If[numtomat[j][[1]] >= 2, 

         ue = {numtomat[j][[1]] - 1, numtomat[j][[2]]}];

        If[numtomat[j][[1]] <= 8, 

         sita = {numtomat[j][[1]] + 1, numtomat[j][[2]]}];

        If[

         hidari != {0, 0} && 

          block[[hidari[[1]], hidari[[2]]]] == 

           block[[numtomat[j][[1]], numtomat[j][[2]]]] && 

          groupwin[[hidari[[1]], hidari[[2]]]] > 0, 

         groupwin[[numtomat[j][[1]], numtomat[j][[2]]]] = 

          groupwin[[hidari[[1]], hidari[[2]]]]];

        If[

         ue != {0, 0} && 

          block[[ue[[1]], ue[[2]]]] == 

           block[[numtomat[j][[1]], numtomat[j][[2]]]] && 

          groupwin[[ue[[1]], ue[[2]]]] > 0, 

         groupwin[[numtomat[j][[1]], numtomat[j][[2]]]] = 

          groupwin[[ue[[1]], ue[[2]]]]];

        If[

         migi != {0, 0} && 

          block[[migi[[1]], migi[[2]]]] == 

           block[[numtomat[j][[1]], numtomat[j][[2]]]] && 

          groupwin[[migi[[1]], migi[[2]]]] > 0, 

         groupwin[[numtomat[j][[1]], numtomat[j][[2]]]] = 

          groupwin[[migi[[1]], migi[[2]]]]];

        If[

         sita != {0, 0} && 

          block[[sita[[1]], sita[[2]]]] == 

           block[[numtomat[j][[1]], numtomat[j][[2]]]] && 

          groupwin[[sita[[1]], sita[[2]]]] > 0, 

         groupwin[[numtomat[j][[1]], numtomat[j][[2]]]] = 

          groupwin[[sita[[1]], sita[[2]]]]];]]; 

      groupall = 

       Sum[If[groupwin[[numtomat[k]]] == groupcount, Return[1], 

         Return[0]], {k, 1, 54}]; 

      post = Sum[Count[groupwin[[l]], groupcount], {l, 1, 9}];;]];];

 haitou = 0; kakutoku = {0, 0, 0, 0, 0, 0}; 

 For[i = 49, i <= 54, i++, flug = 0; 

  If[SubsetQ[

      groupwin[[1]], {groupwin[[numtomat[i][[1]], 

         numtomat[i][[2]]]]}] == True && 

    block[[numtomat[i][[1]], numtomat[i][[2]]]] == 0, 

   haitou += odds[[i - 48]]*treasure[[i - 48]]; 

   kakutoku[[i - 48]] = 1]]; 

 If[group == {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 

     0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 

     0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}, 

  zenkesi += 1]; kakutokuall += kakutoku; haitouall += haitou; 

 If[QuotientRemainder[times, 100][[2]] == 0, 

  Print[{times, N[kakutokuall/times], N[haitouall/times], 

    N[zenkesi/times]}]]]; Print[{N[kakutokuall/times], 

  N[haitouall/times], N[zenkesi/times]}]