【发布时间】:2014-09-14 09:56:59
【问题描述】:
我正在尝试通过一项任务提高自己的概率,但无法弄清楚: 在西洋双陆棋游戏中,我有四行(动态)展示位置。
假设第 5、7、11、13 行。我正在扔动态数量的骰子。我试图找到每个游戏的概率。举个例子:
我掷了 4 个骰子,结果是 1,3,4,6
所以
我可以玩 5. row-1,3,4,6 骰子
我可以从 5. row-1,3,4 骰子和 7. row-6 骰子玩
我可以从 5. row-3,1 骰子、11. row-6 骰子和 13. row-4 骰子开始游戏 等等等等。
骰子必须是动态的,行必须是动态的,骰子可以像 1,3,4,6 或 6,1,4,3 或 3,1,6,4 一样混合播放。并且它必须计算在行上散布的骰子的不同变化的所有可能性。
我只是想计算玩无限骰子的西洋双陆棋的可能性。我试图用它来拥有一个可调整大小的可能移动类的方法,在这个类内部,有可调整大小的行类。在 rows 类中,有一个可调整大小的 List 移动变量。我为每个变化添加一个动作。这是非动态 4 骰子的代码。
public List<int> dice;
public List<int> places;
[System.Serializable]
public class arrayData
{
public List<arrayData2> places = new List<arrayData2>();
}
public List<arrayData> pos = new List<arrayData>();
[System.Serializable]
public class arrayData2
{
public List<int> moves = new List<int> {};
}
void Start()
{
vs();
}
void vs()
{
for (int i = 0; i < places.Count; i++)
{
for (int a = 0; a < dice.Count; a++)
{
for (int b = 0; b < dice.Count; b++)
{
for (int c = 0; c < dice.Count; c++)
{
for (int d = 0; d < dice.Count; d++)
{
if (a == b || a == c || a == d || b == c || b == d || c == d)
{
continue;
}
pos.Add(new arrayData());
for (int s = 0; s < places.Count; s++)
{
pos[pos.Count - 1].places.Add(new arrayData2());
}
pos[pos.Count - 1].places[i].moves.Add(dice[a]);
pos[pos.Count - 1].places[i].moves.Add(dice[b]);
pos[pos.Count - 1].places[i].moves.Add(dice[c]);
pos[pos.Count - 1].places[i].moves.Add(dice[d]);
}
}
}
}
}
}
我想不通的:
-首先,我尝试使其成为递归循环,但我无法弄清楚结构
-其次,输出为我提供了行之间分布变化的缺失值:它给出了这样的值:5. row-1,3,4,6 骰子,但没有这样的值:5. row-3,1骰子和第 11 行第 6 行骰子和第 13 行第 4 行骰子
我知道这是一个很大的问题,但任何指出错误或正确方向的人都会非常感激。
谢谢
【问题讨论】:
-
顺便说一下 dice 的单数和复数形式是 .... dice... 没有像 dice 这样的词
-
@PaulZahra Singular for dice is die,如果你想挑剔的话。
-
@MarcusWigert 怕不是老家伙...很多个月以前它曾经是,但现在在现代英语中它是 Dice...oxforddictionaries.com/definition/english/dice
标签: c# loops recursion nested permutation