Skip to content

Instantly share code, notes, and snippets.

@KonyukhovSergey
Last active August 29, 2015 14:00
Show Gist options
  • Save KonyukhovSergey/11254670 to your computer and use it in GitHub Desktop.
Save KonyukhovSergey/11254670 to your computer and use it in GitHub Desktop.

Revisions

  1. KonyukhovSergey revised this gist Apr 24, 2014. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -14,23 +14,21 @@ public int purchasePack(string name, int count, int oneItemMaxPrice) {
    return ((double)a.buyBackPrice / a.item.count) < ((double)b.buyBackPrice / b.item.count) ? -1 : 1;
    });

    AuctionItem bestPackItem = null;

    int purchasedCount = 0;

    foreach(var item in items) {
    if(item.item.count + purchasedCount > count * 2) {
    continue;
    }
    if(bestPackItem.MakeAuctionBid(bestPackItem.buyBackPrice)) {
    Log("item '" + bestPackItem.item.name + "' count = " + item.item.count.ToString() + " purchased");
    if(item.MakeAuctionBid(item.buyBackPrice)) {
    Log("item '" + item.item.name + "' count = " + item.item.count.ToString() + " purchased");
    purchasedCount += item.item.count;
    if(purchasedCount >= count) {
    break;
    }
    }
    else {
    Log("purchase error: " + GetLastError().ToString() + " for item '" + bestPackItem.item.name + "' count = " + item.item.count.ToString());
    Log("purchase error: " + GetLastError().ToString() + " for item '" + item.item.name + "' count = " + item.item.count.ToString());
    }
    }

  2. KonyukhovSergey created this gist Apr 24, 2014.
    38 changes: 38 additions & 0 deletions gistfile1.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    public int 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) {
    Log("item: '" + item.item.name + "', count = " + item.item.count + " oneItemPrice = " + oneItemPrice.ToString("####.##"));
    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 purchasedCount = 0;

    foreach(var item in items) {
    if(item.item.count + purchasedCount > count * 2) {
    continue;
    }
    if(bestPackItem.MakeAuctionBid(bestPackItem.buyBackPrice)) {
    Log("item '" + bestPackItem.item.name + "' count = " + item.item.count.ToString() + " purchased");
    purchasedCount += item.item.count;
    if(purchasedCount >= count) {
    break;
    }
    }
    else {
    Log("purchase error: " + GetLastError().ToString() + " for item '" + bestPackItem.item.name + "' count = " + item.item.count.ToString());
    }
    }

    return purchasedCount;
    }