Core/AHBot: Adjust AHBot bid and buyout chances

Apply an exponential formula to define the chance to bid/buyout an auction depending on auction price and item price ratio. The formula can be adjusted changing the new AuctionHouseBot.Buyer.ChanceFactor config parameter
Chance = 100 ^ (1 + (1 - (auction_price / item_price) / k)
k is the config parameter AuctionHouseBot.Buyer.ChanceFactor, the higher the number the higher chance to buy overpriced auctions.
This commit is contained in:
jackpoz
2015-08-01 18:48:55 +02:00
parent 59fe55dfc9
commit 177b6319d1
4 changed files with 38 additions and 18 deletions

View File

@@ -97,6 +97,11 @@ void AuctionBotConfig::SetConfig(AuctionBotConfigBoolValues index, char const* f
SetConfig(index, sConfigMgr->GetBoolDefault(fieldname, defvalue));
}
void AuctionBotConfig::SetConfig(AuctionBotConfigFloatValues index, char const* fieldname, float defvalue)
{
SetConfig(index, sConfigMgr->GetFloatDefault(fieldname, defvalue));
}
//Get AuctionHousebot configuration file
void AuctionBotConfig::GetConfigFromFile()
{
@@ -111,6 +116,8 @@ void AuctionBotConfig::GetConfigFromFile()
SetConfig(CONFIG_AHBOT_BUYER_HORDE_ENABLED, "AuctionHouseBot.Buyer.Horde.Enabled", false);
SetConfig(CONFIG_AHBOT_BUYER_NEUTRAL_ENABLED, "AuctionHouseBot.Buyer.Neutral.Enabled", false);
SetConfig(CONFIG_AHBOT_BUYER_CHANCE_FACTOR, "AuctionHouseBot.Buyer.ChanceFactor", 2.0f);
SetConfig(CONFIG_AHBOT_ITEMS_VENDOR, "AuctionHouseBot.Items.Vendor", false);
SetConfig(CONFIG_AHBOT_ITEMS_LOOT, "AuctionHouseBot.Items.Loot", true);
SetConfig(CONFIG_AHBOT_ITEMS_MISC, "AuctionHouseBot.Items.Misc", false);

View File

@@ -174,6 +174,12 @@ enum AuctionBotConfigBoolValues
CONFIG_UINT32_AHBOT_BOOL_COUNT
};
enum AuctionBotConfigFloatValues
{
CONFIG_AHBOT_BUYER_CHANCE_FACTOR,
CONFIG_AHBOT_FLOAT_COUNT
};
// All basic config data used by other AHBot classes for self-configure.
class AuctionBotConfig
{
@@ -196,8 +202,10 @@ public:
uint32 GetConfig(AuctionBotConfigUInt32Values index) const { return _configUint32Values[index]; }
bool GetConfig(AuctionBotConfigBoolValues index) const { return _configBoolValues[index]; }
float GetConfig(AuctionBotConfigFloatValues index) const { return _configFloatValues[index]; }
void SetConfig(AuctionBotConfigBoolValues index, bool value) { _configBoolValues[index] = value; }
void SetConfig(AuctionBotConfigUInt32Values index, uint32 value) { _configUint32Values[index] = value; }
void SetConfig(AuctionBotConfigFloatValues index, float value) { _configFloatValues[index] = value; }
uint32 GetConfigItemAmountRatio(AuctionHouseType houseType) const;
bool GetConfigBuyerEnabled(AuctionHouseType houseType) const;
@@ -217,6 +225,7 @@ private:
uint32 _configUint32Values[CONFIG_UINT32_AHBOT_UINT32_COUNT];
bool _configBoolValues[CONFIG_UINT32_AHBOT_BOOL_COUNT];
float _configFloatValues[CONFIG_AHBOT_FLOAT_COUNT];
void SetAHBotIncludes(const std::string& AHBotIncludes) { _AHBotIncludes = AHBotIncludes; }
void SetAHBotExcludes(const std::string& AHBotExcludes) { _AHBotExcludes = AHBotExcludes; }
@@ -225,6 +234,7 @@ private:
void SetConfigMax(AuctionBotConfigUInt32Values index, char const* fieldname, uint32 defvalue, uint32 maxvalue);
void SetConfigMinMax(AuctionBotConfigUInt32Values index, char const* fieldname, uint32 defvalue, uint32 minvalue, uint32 maxvalue);
void SetConfig(AuctionBotConfigBoolValues index, char const* fieldname, bool defvalue);
void SetConfig(AuctionBotConfigFloatValues index, char const* fieldname, float defvalue);
void GetConfigFromFile();
};

View File

@@ -157,18 +157,18 @@ bool AuctionBotBuyer::RollBuyChance(const BuyerItemInfo* ahInfo, const Item* ite
if (!auction->buyout)
return false;
uint32 itemBuyPrice = auction->buyout / item->GetCount();
uint32 itemPrice = item->GetTemplate()->SellPrice ? item->GetTemplate()->SellPrice : GetVendorPrice(item->GetTemplate()->Quality);
float itemBuyPrice = float(auction->buyout / item->GetCount());
float itemPrice = float(item->GetTemplate()->SellPrice ? item->GetTemplate()->SellPrice : GetVendorPrice(item->GetTemplate()->Quality));
// The AH cut needs to be added to the price, but we dont want a 100% chance to buy if the price is exactly AH default
itemPrice *= 1.4f;
// This value is between 0 and 100 and is used directly as the chance to buy or bid
// Value equal or above 100 means 100% chance and value below 0 means 0% chance
float chance = 100 / sqrt(itemBuyPrice / float(itemPrice));
float chance = std::min(100.f, std::pow(100.f, 1.f + (1.f - itemBuyPrice / itemPrice) / sAuctionBotConfig->GetConfig(CONFIG_AHBOT_BUYER_CHANCE_FACTOR)));
// If a player has bidded on item, have fifth of normal chance
if (auction->bidder)
chance = chance / 5;
chance = chance / 5.f;
if (ahInfo)
{
@@ -178,31 +178,29 @@ bool AuctionBotBuyer::RollBuyChance(const BuyerItemInfo* ahInfo, const Item* ite
// If there are more than 5 items on AH of this entry, try weigh in the average buyout price
if (ahInfo->BuyItemCount > 5)
{
chance *= 1 / sqrt(itemBuyPrice / avgBuyPrice);
}
chance *= 1.f / std::sqrt(itemBuyPrice / avgBuyPrice);
}
// Add config weigh in for quality
chance *= GetChanceMultiplier(item->GetTemplate()->Quality) / 100.0f;
float rand = frand(0, 100);
float rand = frand(0.f, 100.f);
bool win = rand <= chance;
TC_LOG_DEBUG("ahbot", "AHBot: %s BUY! chance = %.2f, price = %u, buyprice = %u.", win ? "WIN" : "LOSE", chance, itemPrice, itemBuyPrice);
TC_LOG_DEBUG("ahbot", "AHBot: %s BUY! chance = %.2f, price = %u, buyprice = %u.", win ? "WIN" : "LOSE", chance, uint32(itemPrice), uint32(itemBuyPrice));
return win;
}
// ahInfo can be NULL
bool AuctionBotBuyer::RollBidChance(const BuyerItemInfo* ahInfo, const Item* item, const AuctionEntry* auction, uint32 bidPrice)
{
uint32 itemBidPrice = bidPrice / item->GetCount();
uint32 itemPrice = item->GetTemplate()->SellPrice ? item->GetTemplate()->SellPrice : GetVendorPrice(item->GetTemplate()->Quality);
float itemBidPrice = float(bidPrice / item->GetCount());
float itemPrice = float(item->GetTemplate()->SellPrice ? item->GetTemplate()->SellPrice : GetVendorPrice(item->GetTemplate()->Quality));
// The AH cut needs to be added to the price, but we dont want a 100% chance to buy if the price is exactly AH default
itemPrice *= 1.4f;
// This value is between 0 and 100 and is used directly as the chance to buy or bid
// Value equal or above 100 means 100% chance and value below 0 means 0% chance
float chance = 100 / sqrt(itemBidPrice / float(itemPrice));
float chance = std::min(100.f, std::pow(100.f, 1.f + (1.f - itemBidPrice / itemPrice) / sAuctionBotConfig->GetConfig(CONFIG_AHBOT_BUYER_CHANCE_FACTOR)));
if (ahInfo)
{
@@ -212,21 +210,19 @@ bool AuctionBotBuyer::RollBidChance(const BuyerItemInfo* ahInfo, const Item* ite
// If there are more than 5 items on AH of this entry, try weigh in the average bid price
if (ahInfo->BidItemCount >= 5)
{
chance *= 1 / sqrt(itemBidPrice / avgBidPrice);
}
chance *= 1.f / std::sqrt(itemBidPrice / avgBidPrice);
}
// If a player has bidded on item, have fifth of normal chance
if (auction->bidder)
chance = chance / 5;
chance = chance / 5.f;
// Add config weigh in for quality
chance *= GetChanceMultiplier(item->GetTemplate()->Quality) / 100.0f;
float rand = frand(0, 100);
float rand = frand(0.f, 100.f);
bool win = rand <= chance;
TC_LOG_DEBUG("ahbot", "AHBot: %s BID! chance = %.2f, price = %u, bidprice = %u.", win ? "WIN" : "LOSE", chance, itemPrice, itemBidPrice);
TC_LOG_DEBUG("ahbot", "AHBot: %s BID! chance = %.2f, price = %u, bidprice = %u.", win ? "WIN" : "LOSE", chance, uint32(itemPrice), uint32(itemBidPrice));
return win;
}

View File

@@ -3115,6 +3115,13 @@ AuctionHouseBot.Buyer.Alliance.Enabled = 0
AuctionHouseBot.Buyer.Horde.Enabled = 0
AuctionHouseBot.Buyer.Neutral.Enabled = 0
# AuctionHouseBot.Buyer.ChanceFactor
# Description: k value in the formula used for the chance to buy an item "100^(1 + (1 - (AuctionBid / ItemPrice)) / k)"
# It must be a decimal number in the range of (0, +infinity). The higher the number the higher chance to buy overpriced auctions
# Default: 2
AuctionHouseBot.Buyer.ChanceFactor = 2
#
# AuctionHouseBot.Buyer.Baseprice.QUALITY
# Description: Base sellprices in copper for non priced items for each quality.