2017-08-10 111 views
0

我想知道这个模拟器是否可以正常工作,因为我不认为这些是合乎逻辑的答案,但也不能捕捉到错误。加倍游戏模拟

我写了一个模拟器随后的比赛(鉴于一副扑克牌和1分)找到最优策略(什么是经销商最大的牌继续游戏)

1. Dealer picks a card and shows it to you(Dealer can't pick Joker) 
2. You decide whether to play or no 
3.1. If you don't play you get current points and finish game 
3.2. If you play you pick a Card 
3.2.1. If your card is higher you get double points and go back to step 1 
3.2.2. If your and dealer's cards are equal you go back to step 1 
3.2.3. If dealer's card is higher you lose all points and finish 

仿真结果表明赢系数以显示这些数字,这对我来说是非常可疑的。我预计它会增长到1.5到7,然后回到1.

(First-Win/number of simulations,Second-最大牌经销商可以为你继续游戏)

1 -1 
1.0853817 0 
1.1872532 1 
1.3126581 2 
1.4672619 3 
1.6704736 4 
1.9485809 5 
2.2674231 6 
2.9993735 7 
3.5692085 8 
4.3581477 9 
4.0109722 10 
2.3629856 11 
0 12 

这里的C#代码:

using System; 

namespace Codeforces 
{ 
    class Program 
    { 
    static int[] k = new int[54]; 

    static Random rand = new Random(); 

    static long Doubling(int i, long f) 
    { 
     int d = rand.Next(52); 

     if (k[d] > i) return f; 

     int ch = d; 
     while (ch == d) ch = rand.Next(54); 

     if (k[d] > k[ch]) return 0; 

     if (k[d] == k[ch]) return Doubling(i, f); 

     return Doubling(i, f * 2); 
    } 

    static void Main(string[] args) 
    { 
     for (int i = 0; i < 54; i++) k[i] = i/4; 

     for (int i = -1; i < 13; i++) 
     { 
      long sum = 0; 
      for (int j = 0; j < 1e7; j++) 
      { 
       sum += Doubling(i, 1); 
      } 

      Console.WriteLine(sum/1.0e7 + " " + i); 
     } 
    } 
} 

}

+2

那么最新的问题或问题? –

+0

对不起忘了补充,我想知道这个模拟器是否正常工作 – luka25

+0

您的意思是“挑选”(您选择卡的地方)还是“绘制”(随机分配的地方)? –

回答

1

我不是一个C#程序员,但它看起来像你的基本方法主要是正确的。我会建议使用循环而不是递归。

您的问题描述对于jokers的价值以及是否经销商在绘制时丢弃了jokers或是否神奇只是不会吸引它们而模糊—如果我正确地读取了您的代码,您似乎已经去掉了后者。

看起来,实现递归的方式在每次玩游戏之后都会隐式地替换牌中的牌,而不是玩牌。

当我用另一种语言独立实现这一点时,我得到了类似的结果。在我看来,你的直觉是错误的。

+0

谢谢,我也发现它是正确的。 – luka25