Last active
August 29, 2015 14:00
-
-
Save KonyukhovSergey/11247918 to your computer and use it in GitHub Desktop.
Revisions
-
KonyukhovSergey revised this gist
Apr 24, 2014 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,5 +26,15 @@ public bool purchasePack(string name, int count, int oneItemMaxPrice) { } } if(bestPackItem != null) { if(bestPackItem.MakeAuctionBid(bestPackItem.buyBackPrice)) { Log("item '" + bestPackItem.item.name + "'purchased"); return true; } else { Log("error: " + GetLastError().ToString()); } } return false; } -
KonyukhovSergey created this gist
Apr 24, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ public bool purchasePack(string name, int count, int oneItemMaxPrice) { List<AuctionItem> items = new List<AuctionItem>(); foreach(var item in getAuctionBuyList(new AuctionRequestParams(name))) { double oneItemPrice = (double)item.buyBackPrice / (double)item.item.count; if(item.buyBackPrice > 0 && oneItemPrice < oneItemMaxPrice) { items.Add(item); } } items.Sort((a, b) => { return ((double)a.buyBackPrice / a.item.count) < ((double)b.buyBackPrice / b.item.count) ? -1 : 1; }); AuctionItem bestPackItem = null; int minDeltaCount = int.MaxValue; foreach(var item in items) { int deltaCount = Math.Abs(item.item.count - count); if(deltaCount <= minDeltaCount) { bestPackItem = item; minDeltaCount = deltaCount; } } return false; }