【发布时间】:2021-01-05 20:43:22
【问题描述】:
我想用替换进行置换,但如果符号不在列表中,则跳过。 目前该实现不依赖于 PayDistribution。 它仅使用符号列表。 所以,如果我发送 (A,B,C) 的 symbolList 和 3 的 windowWidth,我会得到:
A,A,A
A,A,B
A,A,C
A,B,A
A,B,B
...
C,C,C
但如果我有一个 PayDistribution:
符号:第一个到第三个位置
答:1 1 1
B:1 1 0
C:1 1 1
如果 B 不会位于第三位,那么我不想包含 B 位于第三位的任何排列:
例如 A,A,B 不应该存在。
我只想让它跳转下一个有效条目。 似乎我可以在 GetCombinations 函数中添加一个检查来执行此操作,但我不确定如何。 真的希望通过跳过来加快速度。使用大型符号列表可能需要一段时间。 我的用法不是很重要:
public ACombo[] PayHashLineCreate(SymbolList symbolList, ComboList comboTable, int windowWidth,List<List<int>> PayDistribution)
{
Console.Write("Creating Pay Hash ");
WindowWidth = windowWidth;
SymbolCount = symbolList.NumRegularSym;
var count = 0;
var filteredList = new SymbolList();
filteredList.AddRange(symbolList.Where(symbol => typeof (RegularSymbol) == symbol.GetType()));
filteredList.AddRange(symbolList.Where(symbol => typeof (ScatterSymbol) == symbol.GetType()));
var filteredSymbolListArray = filteredList.ToArray();
var filteredComboList = new ComboList();
filteredComboList.AddRange(comboTable.Where(combo => typeof (T) == combo.GetType()));
foreach (
var symbolArrangement in
CombinationsWithReplacement.GetCombinationsWithReplacementLexographicOrder(filteredSymbolListArray, windowWidth,PayDistribution))
{
Add(null);
foreach (var combo in filteredComboList)
{
var match = Compare(combo, symbolArrangement);
if (!match) continue;
this[count] = combo;
break;
}
count++;
}
Console.WriteLine("DONE");
return ToArray();
}
但重要的功能:
public static IEnumerable<List<T>> GetCombinationsWithReplacementLexographicOrder<T>(IList<T> pool,
int comboLength, List<List<int>> PayDistribution)
{
foreach (var list in GetCombinations(pool, comboLength, PayDistribution).Select(c =>
c.ToList()))
yield return list;
}
private static IEnumerable<IEnumerable<T>> GetCombinations<T>(IList<T> list, int length,
List<List<int>> PayDistribution)
{
if (length == 1) return list.Select(t => new[] { t });
return GetCombinations(list, length -1).SelectMany(t => list, (t1, t2) => t1.Concat(new[] { t2
}));
}
【问题讨论】:
-
我建议将
PayDistribution转换为Dictionary<T, List<int>>,以便您可以按符号查找分布。我没有看到GetCombinationsWithReplacementLexographicOrder添加了什么? -
您的
GetCombinations方法无法编译。此外,将代码更改为编译似乎表明length/windowWidth中出现了一个错误。 -
@NetMage 我添加了计数,认为我可以以另一种方式构建组合,以便以正确的顺序引用 Paydistribution。我已经删除了它,它又恢复了原来的样子。你是对的,它会崩溃。
-
@NetMage 如果 PayDistribution 是字典,函数会是什么样子?似乎很容易转换它。
标签: c# permutation