mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 15:14:41 +00:00
Further STM logic improvement
This commit is contained in:
parent
f83b4120e5
commit
1d6804168b
2 changed files with 31 additions and 3 deletions
|
@ -249,6 +249,28 @@ namespace ArchiSteamFarm.Tests {
|
|||
Assert.IsTrue(AcceptsTrade(inventory, itemsToGive, itemsToReceive));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SingleGameSingleTypeBigDifferenceReject() {
|
||||
HashSet<Steam.Asset> inventory = new HashSet<Steam.Asset> {
|
||||
CreateItem(1),
|
||||
CreateItem(2, 2),
|
||||
CreateItem(3, 2),
|
||||
CreateItem(4, 3),
|
||||
CreateItem(5, 10)
|
||||
};
|
||||
|
||||
HashSet<Steam.Asset> itemsToGive = new HashSet<Steam.Asset> {
|
||||
CreateItem(2),
|
||||
CreateItem(5)
|
||||
};
|
||||
HashSet<Steam.Asset> itemsToReceive = new HashSet<Steam.Asset> {
|
||||
CreateItem(3),
|
||||
CreateItem(4)
|
||||
};
|
||||
|
||||
Assert.IsFalse(AcceptsTrade(inventory, itemsToGive, itemsToReceive));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SingleGameSingleTypeGoodAccept() {
|
||||
HashSet<Steam.Asset> inventory = new HashSet<Steam.Asset> { CreateItem(1, 2) };
|
||||
|
|
|
@ -177,9 +177,15 @@ namespace ArchiSteamFarm {
|
|||
|
||||
// At this point we're sure that both number of unique items in the set stays the same, as well as number of our actual sets
|
||||
// We need to ensure set progress here and keep in mind overpaying, so we'll calculate neutrality as a difference in amounts at appropriate indexes
|
||||
// The higher the neutrality the better the trade, with 0 being the absolute minimum we're willing to accept
|
||||
if (afterAmounts.Select((t, i) => (int) (t - beforeAmounts[i])).Sum() < 0) {
|
||||
return false;
|
||||
// Neutrality can't reach value below 0 at any single point of calculation, as that would imply a loss of progress even if we'd end up with a positive value by the end
|
||||
int neutrality = 0;
|
||||
|
||||
for (byte i = 0; i < afterAmounts.Count; i++) {
|
||||
neutrality += (int) (afterAmounts[i] - beforeAmounts[i]);
|
||||
|
||||
if (neutrality < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue