我想置换替换,但如果符号不在列表中,请跳过。当前,该实现不依赖于PayDistribution。它仅使用符号列表。因此,如果我发送(A,B,C)的symbolList和windowWidth为3,我将得到:
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函数中添加一个检查,但是我不确定如何做。真正希望通过跳过来加快速度。对于大的symbolList,可能需要一段时间。我的用法不是很重要:
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
和由匹配滤波器组合Dictionary
用于每个位置:
private static IEnumerable<List<T>> GetCombinationsWithReplacementLexographicOrder<T>(IList<T> list, int length, List<List<int>> PayDistribution) {
var PayMap = PayDistribution.Select(g => g.Select((pd,i) => (pd,i)).ToDictionary(pdi => list[pdi.i], pdi => pdi.pd > 0)).ToList();
foreach (var c in GetCombinations(list, length, PayMap))
yield return c.ToList();
}
private static IEnumerable<IEnumerable<T>> GetCombinations<T>(IList<T> list, int length, List<Dictionary<T, bool>> PayMaps, int pos = 1) {
var payMap = PayMaps[length-pos];
if (pos == length)
return list.Where(t => payMap[t]).Select(t => new[] { t });
return GetCombinations(list, length, PayMaps, pos + 1)
.SelectMany(t => list.Where(t2 => payMap[t2]), (t1, t2) => t1.Concat(new[] { t2 }));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句