Skip to content

Commit

Permalink
Each evaluator should return a single slot result
Browse files Browse the repository at this point in the history
  • Loading branch information
ajon542 committed Feb 27, 2017
1 parent b8493b3 commit 52b5176
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ private void Simulate()

ReelWindow reelWindow = new ReelWindow(paytable.ReelGroup, randomNumbers);

SlotResults results = evaluator.Evaluate(paytable, reelWindow, rng);
SlotResult result = evaluator.Evaluate(paytable, reelWindow, rng);

totalWin += results.TotalWin;
totalWin += result.TotalWin;

Progress = (float)currentSimulation / (float)modelData.NumberOfSimulations;
currentSimulation++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace GDK.MathEngine.Evaluators
{
public class AnywaysEvaluator : IEvaluator
{
public SlotResults Evaluate (Paytable paytable, ReelWindow reelWindow, IRng rng)
public SlotResult Evaluate (Paytable paytable, ReelWindow reelWindow, IRng rng)
{
throw new System.NotImplementedException ();
}
Expand Down
2 changes: 1 addition & 1 deletion GDK/Assets/Components/MathEngine/Evaluators/IEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ namespace GDK.MathEngine.Evaluators
/// </remarks>
public interface IEvaluator
{
SlotResults Evaluate (Paytable paytable, ReelWindow reelWindow, IRng rng);
SlotResult Evaluate (Paytable paytable, ReelWindow reelWindow, IRng rng);
}
}
14 changes: 5 additions & 9 deletions GDK/Assets/Components/MathEngine/Evaluators/PaylineEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ public class PaylineEvaluator : IEvaluator
{
private ReelWindow reelWindow;

public SlotResults Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)
public SlotResult Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)
{
// TODO: Each evaluator should add to this rather than creating a new one.
SlotResults results = new SlotResults();

SlotResult result = new SlotResult();
PaylinesComponent component = new PaylinesComponent();

// Iterate through each payline defined in the paytable.
Expand Down Expand Up @@ -46,18 +44,16 @@ public SlotResults Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)
if (bestPayCombo != null)
{
component.PayResults.Add(new PayResult { PayCombo = bestPayCombo, Payline = payline });
results.TotalWin += bestPayCombo.PayAmount;
result.TotalWin += bestPayCombo.PayAmount;
}
}

SlotResult slotResult = new SlotResult();
results.Results.Add(slotResult);
if (component.PayResults.Count > 0)
{
slotResult.AddComponent<PaylinesComponent>(component);
result.AddComponent<PaylinesComponent>(component);
}

return results;
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PaytableEvaluator : IEvaluator
{
private IRng rng;

public SlotResults Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)
public SlotResult Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)
{
//PaylineEvaluator paylineEvaluator = new PaylineEvaluator ();
//ScatterEvaluator scatterEvaluator = new ScatterEvaluator ();
Expand Down
8 changes: 3 additions & 5 deletions GDK/Assets/Components/MathEngine/Evaluators/PickEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public PickEvaluator (string pickFeatureId)
PickFeatureId = pickFeatureId;
}

public SlotResults Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)
public SlotResult Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)
{
if (paytable.PickTableGroup.PickTable.ContainsKey (PickFeatureId) == false)
{
Expand All @@ -26,7 +26,6 @@ public SlotResults Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)
List<PickItem> pickItems = new List<PickItem> (pickTable.PickItemList);

PickItem item;
SlotResults results = new SlotResults ();
PickComponent component = new PickComponent();

do
Expand All @@ -46,11 +45,10 @@ public SlotResults Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)

// Add the pick component to the slot result.
SlotResult slotResult = new SlotResult();
results.Results.Add(slotResult);
if (component.PickResults.Count > 0)
slotResult.AddComponent<PickComponent>(component);
return results;

return slotResult;
}
}
}
80 changes: 40 additions & 40 deletions GDK/Assets/Components/MathEngine/Evaluators/ScatterEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,57 @@

namespace GDK.MathEngine.Evaluators
{
public class ScatterEvaluator : IEvaluator
{
private ReelWindow reelWindow;

public SlotResults Evaluate (Paytable paytable, ReelWindow reelWindow, IRng rng)
{
SlotResults results = new SlotResults ();
public class ScatterEvaluator : IEvaluator
{
private ReelWindow reelWindow;

public SlotResult Evaluate(Paytable paytable, ReelWindow reelWindow, IRng rng)
{
SlotResult result = new SlotResult();
ScattersComponent component = new ScattersComponent();
List<PayCombo> payCombos = paytable.ScatterComboGroup.Combos;
for (int combo = 0; combo < payCombos.Count; ++combo)
{
PayCombo payCombo = payCombos [combo];
int bestPayAmount = 0;
PayCombo bestPayCombo = null;

// TODO: This assumes the scatter combo contains one type of symbol only.
// In almost all cases, this will be true so leaving it for now.
bool match = false;
Symbol symbol = payCombo.SymbolsInPayCombo[0];
if (reelWindow.SymbolPositions.ContainsKey (symbol) &&

List<PayCombo> payCombos = paytable.ScatterComboGroup.Combos;
for (int combo = 0; combo < payCombos.Count; ++combo)
{
PayCombo payCombo = payCombos[combo];
int bestPayAmount = 0;
PayCombo bestPayCombo = null;

// TODO: This assumes the scatter combo contains one type of symbol only.
// In almost all cases, this will be true so leaving it for now.
bool match = false;
Symbol symbol = payCombo.SymbolsInPayCombo[0];
if (reelWindow.SymbolPositions.ContainsKey(symbol) &&
reelWindow.SymbolPositions[symbol].Count >= payCombo.SymbolsInPayCombo.Count)
{
match = true;
}
if (match && (payCombo.PayAmount >= bestPayAmount))
{
bestPayCombo = payCombo;
bestPayAmount = payCombo.PayAmount;
}

if (bestPayCombo != null)
{
{
match = true;
}

if (match && (payCombo.PayAmount >= bestPayAmount))
{
bestPayCombo = payCombo;
bestPayAmount = payCombo.PayAmount;
}

if (bestPayCombo != null)
{
// TODO: Might be able to optimize this but making PaylineCoord and SymbolPosition the same thing...
Payline payline = new Payline();
foreach (var position in reelWindow.SymbolPositions[symbol])
{
payline.AddPaylineCoord(new PaylineCoord { ReelIndex = position.ReelIndex, Offset = position.ReelOffset });
}
component.PayResults.Add(new PayResult { PayCombo = bestPayCombo, Payline = payline });
}
}
result.TotalWin += bestPayCombo.PayAmount;
}
}

SlotResult slotResult = new SlotResult();
results.Results.Add(slotResult);
if (component.PayResults.Count > 0)
slotResult.AddComponent<ScattersComponent>(component);
{
result.AddComponent<ScattersComponent>(component);
}

return results;
}
}
return result;
}
}
}
2 changes: 2 additions & 0 deletions GDK/Assets/Components/MathEngine/SlotResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class SlotResult
{
private List<IComponent> components { get; set; }

public int TotalWin { get; set; }

public SlotResult()
{
components = new List<IComponent>();
Expand Down
Loading

0 comments on commit 52b5176

Please sign in to comment.