From 50b5c7b87f2d9ceb26cf8c4da11ecf4b31472846 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 13 May 2016 01:35:17 +0200 Subject: [PATCH] Correct STM algorithm when overpaying with cards from the same game us: X X Y them: Y Y Z trade: Y -> X + Z New: toGive: 1 toReceive: 2 + 0 -> 0 + 2 diff: 1 - 0 = 1 1 > 0 ? True Old: toGive: 1 toReceive: 2 1 > 2 ? False --- ArchiSteamFarm/Trading.cs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index 31ef9295a..44e61a233 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -165,34 +165,47 @@ namespace ArchiSteamFarm { } // Calculate our value of items to give - uint itemsToGiveDupesValue = 0; + List amountsToGive = new List(tradeOffer.ItemsToGive.Count); foreach (Steam.Item item in tradeOffer.ItemsToGive) { Tuple key = new Tuple(item.ClassID, item.InstanceID); uint amount; if (!amountMap.TryGetValue(key, out amount)) { + amountsToGive.Add(0); continue; } - itemsToGiveDupesValue += amount; + amountsToGive.Add(amount); } + // Sort it ascending + amountsToGive.Sort(); + // Calculate our value of items to receive - uint itemsToReceiveDupesValue = 0; + List amountsToReceive = new List(tradeOffer.ItemsToReceive.Count); foreach (Steam.Item item in tradeOffer.ItemsToReceive) { Tuple key = new Tuple(item.ClassID, item.InstanceID); uint amount; if (!amountMap.TryGetValue(key, out amount)) { + amountsToReceive.Add(0); continue; } - itemsToReceiveDupesValue += amount; + amountsToReceive.Add(amount); } - // Trade is worth for us if we're in total trading more of our dupes for less of our dupes (or at least same amount) - // Which means that itemsToGiveDupesValue should be greater than itemsToReceiveDupesValue - return itemsToGiveDupesValue > itemsToReceiveDupesValue; + // Sort it ascending + amountsToReceive.Sort(); + + // Check actual difference + int difference = 0; + for (int i = 0; i < amountsToGive.Count; i++) { + difference += (int) (amountsToGive[i] - amountsToReceive[i]); + } + + // Trade is worth for us if the difference is greater than 0 + return difference > 0; } } }