public void CanUseDecisionProcess() { var container = CreateContainer(); var log = container.GetInstance <ILog>(); var item = "Gold accessory"; var targetGrade = 1; var failstack = 0; var initialState = new EnhancementState(failstack); var process = new EnhancementProcess(initialState) { Rewards = new List <IActionReward <EnhancementState> > { new NumberOfAttemptsReward(targetGrade) } }; var policy = new JustEnhancePolicy(item, targetGrade) { TrackNumberOfAttempts = true }; var value = process.GetOptimalValue(policy); log.Info($"Optimal value : {value}"); Assert.Equal(3.1213873601591193, value); }
public void CanCalculateSuccessProbability() { var container = CreateContainer(); var log = container.GetInstance <ILog>(); var item = "Silver Embroidered"; var targetGrade = 2; var failstack = 0; var initialState = new EnhancementState(failstack) { Items = new [] { 50, 1, 0, 0, 0, }, }; var process = new EnhancementProcess(initialState) { Rewards = new List <IActionReward <EnhancementState> > { new SuccessProbabilityReward(targetGrade) } }; var policy = new JustEnhancePolicy(item, targetGrade); var value = process.GetOptimalValue(policy); log.Info($"Enhancement probability : {value}"); Assert.Equal(0.6391845543605477, value); }
public void CanGetExpectedNumberOfAttemptsViaProcess() { var container = CreateContainer(); var log = container.GetInstance <ILog>(); var item = "Silver Embroidered"; var targetGrade = 2; var failstack = 36; var initialState = new EnhancementState(failstack); initialState.Items[targetGrade - 1] = int.MaxValue; var process = new EnhancementProcess(initialState) { Rewards = new List <IActionReward <EnhancementState> > { new NumberOfAttemptsReward(targetGrade) } }; var policy = new JustEnhancePolicy(item, targetGrade) { TrackNumberOfAttempts = true }; var value = process.GetOptimalValue(policy); log.Info($"Optimal value : {value}"); Assert.Equal(2.0855537713302703, value); }
public void CanCalculateSuccessProbabilityWithTieredFailstack() { var container = CreateContainer(); var log = container.GetInstance <ILog>(); var item = "Silver Embroidered"; var targetGrade = 3; // var quantities = Enumerable.Range(3, 3).Select(i => 10 * i); // var quantities = new List<int> { 20, 24, 28, 32, 36, 40 }; var quantities = new List <int> { 10 }; // var quantities = new List<int> { 8, 12, 16, 24, 28, 32 }; var probabilities = new Dictionary <(int, int, int, int, int), double>(); var costs = new Dictionary <(int, int, int, int, int), double>(); var efficiency = new Dictionary <(int, int, int, int, int), double>(); foreach (var quantity in quantities) { var initialState = new EnhancementState() { Items = new [] { quantity, 0, 0, 0, 0, }, StoredFailstacks = new [] { 0, 0, 0, 0, }, }; var minFailstack = new[] { 10, 19, 28, 40 }; var maxFailstack = new[] { 10, 20, 30, 40 }; for (var grade = targetGrade; grade < minFailstack.Length; ++grade) { minFailstack[grade] = -1; maxFailstack[grade] = -1; } var it = new TierIterator(targetGrade, quantity, minFailstack, maxFailstack); do { // log.Info($"({it.Quantity}:{string.Join(',', it.Failstacks)})"); var key = (quantity, it.Failstacks[0], it.Failstacks[1], it.Failstacks[2], it.Failstacks[3]); var process = new EnhancementProcess(initialState) { Rewards = new List <IActionReward <EnhancementState> > { new SuccessProbabilityReward(targetGrade) } }; var costProcess = new EnhancementProcess(initialState) { Rewards = new List <IActionReward <EnhancementState> > { new FailstackReward() } }; var policy = new TieredFailstackPolicy(item, targetGrade, new Dictionary <int, int> { { 0, it.Failstacks[0] }, { 1, it.Failstacks[1] }, { 2, it.Failstacks[2] }, { 3, it.Failstacks[3] }, }) { Log = null }; probabilities[key] = process.GetOptimalValue(policy); costs[key] = -costProcess.GetOptimalValue(policy, 1); efficiency[key] = (int)(costs[key] / probabilities[key] / 100); // log.Info($"Enhancement probability for {quantity} items and failstack ({string.Join(',', it.Failstacks.ToList().Where(i => i > 0).ToList())}): {probabilities[key]} at {costs[key]}, efficiency : {efficiency[key]}"); it = it.Next(); }while (it != null); if (quantity == 10) { Assert.Equal(0.15627782835360016, probabilities[(10, 10, 19, 28, -1)]);