mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
NKAI: various behavior fixes, undo max_gold_preasure
This commit is contained in:
@@ -863,7 +863,7 @@ std::optional<BattleAction> CBattleAI::considerFleeingOrSurrendering()
|
|||||||
|
|
||||||
bs.turnsSkippedByDefense = movesSkippedByDefense / bs.ourStacks.size();
|
bs.turnsSkippedByDefense = movesSkippedByDefense / bs.ourStacks.size();
|
||||||
|
|
||||||
if(!bs.canFlee || !bs.canSurrender)
|
if(!bs.canFlee && !bs.canSurrender)
|
||||||
{
|
{
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
@@ -779,25 +779,21 @@ void AIGateway::makeTurn()
|
|||||||
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex);
|
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex);
|
||||||
setThreadName("AIGateway::makeTurn");
|
setThreadName("AIGateway::makeTurn");
|
||||||
|
|
||||||
|
cb->sendMessage("vcmieagles");
|
||||||
|
|
||||||
|
retrieveVisitableObjs();
|
||||||
|
|
||||||
if(cb->getDate(Date::DAY_OF_WEEK) == 1)
|
if(cb->getDate(Date::DAY_OF_WEEK) == 1)
|
||||||
{
|
{
|
||||||
std::vector<const CGObjectInstance *> objs;
|
for(const CGObjectInstance * obj : nullkiller->memory->visitableObjs)
|
||||||
retrieveVisitableObjs(objs, true);
|
|
||||||
|
|
||||||
for(const CGObjectInstance * obj : objs)
|
|
||||||
{
|
{
|
||||||
if(isWeeklyRevisitable(obj))
|
if(isWeeklyRevisitable(obj))
|
||||||
{
|
{
|
||||||
addVisitableObj(obj);
|
|
||||||
nullkiller->memory->markObjectUnvisited(obj);
|
nullkiller->memory->markObjectUnvisited(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cb->sendMessage("vcmieagles");
|
|
||||||
|
|
||||||
retrieveVisitableObjs();
|
|
||||||
|
|
||||||
#if NKAI_TRACE_LEVEL == 0
|
#if NKAI_TRACE_LEVEL == 0
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1106,26 +1102,13 @@ void AIGateway::waitTillFree()
|
|||||||
status.waitTillFree();
|
status.waitTillFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIGateway::retrieveVisitableObjs(std::vector<const CGObjectInstance *> & out, bool includeOwned) const
|
|
||||||
{
|
|
||||||
foreach_tile_pos([&](const int3 & pos)
|
|
||||||
{
|
|
||||||
for(const CGObjectInstance * obj : myCb->getVisitableObjs(pos, false))
|
|
||||||
{
|
|
||||||
if(includeOwned || obj->tempOwner != playerID)
|
|
||||||
out.push_back(obj);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void AIGateway::retrieveVisitableObjs()
|
void AIGateway::retrieveVisitableObjs()
|
||||||
{
|
{
|
||||||
foreach_tile_pos([&](const int3 & pos)
|
foreach_tile_pos([&](const int3 & pos)
|
||||||
{
|
{
|
||||||
for(const CGObjectInstance * obj : myCb->getVisitableObjs(pos, false))
|
for(const CGObjectInstance * obj : myCb->getVisitableObjs(pos, false))
|
||||||
{
|
{
|
||||||
if(obj->tempOwner != playerID)
|
addVisitableObj(obj);
|
||||||
addVisitableObj(obj);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -195,7 +195,6 @@ public:
|
|||||||
|
|
||||||
void validateObject(const CGObjectInstance * obj); //checks if object is still visible and if not, removes references to it
|
void validateObject(const CGObjectInstance * obj); //checks if object is still visible and if not, removes references to it
|
||||||
void validateObject(ObjectIdRef obj); //checks if object is still visible and if not, removes references to it
|
void validateObject(ObjectIdRef obj); //checks if object is still visible and if not, removes references to it
|
||||||
void retrieveVisitableObjs(std::vector<const CGObjectInstance *> & out, bool includeOwned = false) const;
|
|
||||||
void retrieveVisitableObjs();
|
void retrieveVisitableObjs();
|
||||||
virtual std::vector<const CGObjectInstance *> getFlaggedObjects() const;
|
virtual std::vector<const CGObjectInstance *> getFlaggedObjects() const;
|
||||||
|
|
||||||
|
@@ -167,7 +167,7 @@ void BuildAnalyzer::update()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
goldPreasure = ai->getLockedResources()[EGameResID::GOLD] / 5000.0f
|
goldPreasure = ai->getLockedResources()[EGameResID::GOLD] / 5000.0f
|
||||||
+ (float)armyCost[EGameResID::GOLD] / (1 + ai->getFreeGold() + (float)dailyIncome[EGameResID::GOLD] * 7.0f);
|
+ (float)armyCost[EGameResID::GOLD] / (1 + 2 * ai->getFreeGold() + (float)dailyIncome[EGameResID::GOLD] * 7.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
logAi->trace("Gold preasure: %f", goldPreasure);
|
logAi->trace("Gold preasure: %f", goldPreasure);
|
||||||
|
@@ -227,7 +227,12 @@ void ObjectClusterizer::clusterize()
|
|||||||
auto obj = objs[i];
|
auto obj = objs[i];
|
||||||
|
|
||||||
if(!shouldVisitObject(obj))
|
if(!shouldVisitObject(obj))
|
||||||
return;
|
{
|
||||||
|
#if NKAI_TRACE_LEVEL >= 2
|
||||||
|
logAi->trace("Skip object %s%s.", obj->getObjectName(), obj->visitablePos().toString());
|
||||||
|
#endif
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
#if NKAI_TRACE_LEVEL >= 2
|
#if NKAI_TRACE_LEVEL >= 2
|
||||||
logAi->trace("Check object %s%s.", obj->getObjectName(), obj->visitablePos().toString());
|
logAi->trace("Check object %s%s.", obj->getObjectName(), obj->visitablePos().toString());
|
||||||
|
@@ -150,17 +150,15 @@ ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj)
|
|||||||
case Obj::MINE:
|
case Obj::MINE:
|
||||||
case Obj::ABANDONED_MINE:
|
case Obj::ABANDONED_MINE:
|
||||||
case Obj::PANDORAS_BOX:
|
case Obj::PANDORAS_BOX:
|
||||||
{
|
|
||||||
const CArmedInstance * a = dynamic_cast<const CArmedInstance *>(obj);
|
|
||||||
return a->getArmyStrength();
|
|
||||||
}
|
|
||||||
case Obj::CRYPT: //crypt
|
case Obj::CRYPT: //crypt
|
||||||
case Obj::CREATURE_BANK: //crebank
|
case Obj::CREATURE_BANK: //crebank
|
||||||
case Obj::DRAGON_UTOPIA:
|
case Obj::DRAGON_UTOPIA:
|
||||||
case Obj::SHIPWRECK: //shipwreck
|
case Obj::SHIPWRECK: //shipwreck
|
||||||
case Obj::DERELICT_SHIP: //derelict ship
|
case Obj::DERELICT_SHIP: //derelict ship
|
||||||
// case Obj::PYRAMID:
|
{
|
||||||
return estimateBankDanger(dynamic_cast<const CBank *>(obj));
|
const CArmedInstance * a = dynamic_cast<const CArmedInstance *>(obj);
|
||||||
|
return a->getArmyStrength();
|
||||||
|
}
|
||||||
case Obj::PYRAMID:
|
case Obj::PYRAMID:
|
||||||
{
|
{
|
||||||
if(obj->subID == 0)
|
if(obj->subID == 0)
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
namespace NKAI
|
namespace NKAI
|
||||||
{
|
{
|
||||||
|
|
||||||
const float MAX_GOLD_PEASURE = 0.6f;
|
const float MAX_GOLD_PEASURE = 0.3f;
|
||||||
const float MIN_PRIORITY = 0.01f;
|
const float MIN_PRIORITY = 0.01f;
|
||||||
const float SMALL_SCAN_MIN_PRIORITY = 0.4f;
|
const float SMALL_SCAN_MIN_PRIORITY = 0.4f;
|
||||||
|
|
||||||
|
@@ -162,11 +162,11 @@ uint64_t getCreatureBankArmyReward(const CGObjectInstance * target, const CGHero
|
|||||||
{
|
{
|
||||||
result += (c.data.type->getAIValue() * c.data.count) * c.chance;
|
result += (c.data.type->getAIValue() * c.data.count) * c.chance;
|
||||||
}
|
}
|
||||||
else
|
/*else
|
||||||
{
|
{
|
||||||
//we will need to discard the weakest stack
|
//we will need to discard the weakest stack
|
||||||
result += (c.data.type->getAIValue() * c.data.count - weakestStackPower) * c.chance;
|
result += (c.data.type->getAIValue() * c.data.count - weakestStackPower) * c.chance;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
result /= 100; //divide by total chance
|
result /= 100; //divide by total chance
|
||||||
|
|
||||||
@@ -277,6 +277,8 @@ uint64_t RewardEvaluator::getArmyReward(
|
|||||||
{
|
{
|
||||||
const float enemyArmyEliminationRewardRatio = 0.5f;
|
const float enemyArmyEliminationRewardRatio = 0.5f;
|
||||||
|
|
||||||
|
auto relations = ai->cb->getPlayerRelations(target->tempOwner, ai->playerID);
|
||||||
|
|
||||||
if(!target)
|
if(!target)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -301,7 +303,7 @@ uint64_t RewardEvaluator::getArmyReward(
|
|||||||
case Obj::DRAGON_UTOPIA:
|
case Obj::DRAGON_UTOPIA:
|
||||||
return 10000;
|
return 10000;
|
||||||
case Obj::HERO:
|
case Obj::HERO:
|
||||||
return ai->cb->getPlayerRelations(target->tempOwner, ai->playerID) == PlayerRelations::ENEMIES
|
return relations == PlayerRelations::ENEMIES
|
||||||
? enemyArmyEliminationRewardRatio * dynamic_cast<const CGHeroInstance *>(target)->getArmyStrength()
|
? enemyArmyEliminationRewardRatio * dynamic_cast<const CGHeroInstance *>(target)->getArmyStrength()
|
||||||
: 0;
|
: 0;
|
||||||
case Obj::PANDORAS_BOX:
|
case Obj::PANDORAS_BOX:
|
||||||
@@ -319,6 +321,11 @@ uint64_t RewardEvaluator::getArmyGrowth(
|
|||||||
if(!target)
|
if(!target)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
auto relations = ai->cb->getPlayerRelations(target->tempOwner, hero->tempOwner);
|
||||||
|
|
||||||
|
if(relations != PlayerRelations::ENEMIES)
|
||||||
|
return 0;
|
||||||
|
|
||||||
switch(target->ID)
|
switch(target->ID)
|
||||||
{
|
{
|
||||||
case Obj::TOWN:
|
case Obj::TOWN:
|
||||||
@@ -542,15 +549,18 @@ float RewardEvaluator::getSkillReward(const CGObjectInstance * target, const CGH
|
|||||||
case Obj::GARDEN_OF_REVELATION:
|
case Obj::GARDEN_OF_REVELATION:
|
||||||
case Obj::MARLETTO_TOWER:
|
case Obj::MARLETTO_TOWER:
|
||||||
case Obj::MERCENARY_CAMP:
|
case Obj::MERCENARY_CAMP:
|
||||||
case Obj::SHRINE_OF_MAGIC_GESTURE:
|
|
||||||
case Obj::SHRINE_OF_MAGIC_INCANTATION:
|
|
||||||
case Obj::TREE_OF_KNOWLEDGE:
|
case Obj::TREE_OF_KNOWLEDGE:
|
||||||
return 1;
|
return 1;
|
||||||
case Obj::LEARNING_STONE:
|
case Obj::LEARNING_STONE:
|
||||||
return 1.0f / std::sqrt(hero->level);
|
return 1.0f / std::sqrt(hero->level);
|
||||||
case Obj::ARENA:
|
case Obj::ARENA:
|
||||||
case Obj::SHRINE_OF_MAGIC_THOUGHT:
|
|
||||||
return 2;
|
return 2;
|
||||||
|
case Obj::SHRINE_OF_MAGIC_INCANTATION:
|
||||||
|
return 0.2f;
|
||||||
|
case Obj::SHRINE_OF_MAGIC_GESTURE:
|
||||||
|
return 0.3f;
|
||||||
|
case Obj::SHRINE_OF_MAGIC_THOUGHT:
|
||||||
|
return 0.5f;
|
||||||
case Obj::LIBRARY_OF_ENLIGHTENMENT:
|
case Obj::LIBRARY_OF_ENLIGHTENMENT:
|
||||||
return 8;
|
return 8;
|
||||||
case Obj::WITCH_HUT:
|
case Obj::WITCH_HUT:
|
||||||
@@ -597,6 +607,8 @@ int32_t RewardEvaluator::getGoldReward(const CGObjectInstance * target, const CG
|
|||||||
if(!target)
|
if(!target)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
auto relations = ai->cb->getPlayerRelations(target->tempOwner, hero->tempOwner);
|
||||||
|
|
||||||
const int dailyIncomeMultiplier = 5;
|
const int dailyIncomeMultiplier = 5;
|
||||||
const float enemyArmyEliminationGoldRewardRatio = 0.2f;
|
const float enemyArmyEliminationGoldRewardRatio = 0.2f;
|
||||||
const int32_t heroEliminationBonus = GameConstants::HERO_GOLD_COST / 2;
|
const int32_t heroEliminationBonus = GameConstants::HERO_GOLD_COST / 2;
|
||||||
@@ -637,7 +649,7 @@ int32_t RewardEvaluator::getGoldReward(const CGObjectInstance * target, const CG
|
|||||||
//Objectively saves us 2500 to hire hero
|
//Objectively saves us 2500 to hire hero
|
||||||
return GameConstants::HERO_GOLD_COST;
|
return GameConstants::HERO_GOLD_COST;
|
||||||
case Obj::HERO:
|
case Obj::HERO:
|
||||||
return ai->cb->getPlayerRelations(target->tempOwner, ai->playerID) == PlayerRelations::ENEMIES
|
return relations == PlayerRelations::ENEMIES
|
||||||
? heroEliminationBonus + enemyArmyEliminationGoldRewardRatio * getArmyCost(dynamic_cast<const CGHeroInstance *>(target))
|
? heroEliminationBonus + enemyArmyEliminationGoldRewardRatio * getArmyCost(dynamic_cast<const CGHeroInstance *>(target))
|
||||||
: 0;
|
: 0;
|
||||||
default:
|
default:
|
||||||
@@ -788,7 +800,7 @@ public:
|
|||||||
if(heroRole == HeroRole::MAIN)
|
if(heroRole == HeroRole::MAIN)
|
||||||
evaluationContext.heroRole = heroRole;
|
evaluationContext.heroRole = heroRole;
|
||||||
|
|
||||||
if (target && ai->cb->getPlayerRelations(target->tempOwner, hero->tempOwner) == PlayerRelations::ENEMIES)
|
if (target)
|
||||||
{
|
{
|
||||||
evaluationContext.goldReward += evaluationContext.evaluator.getGoldReward(target, hero);
|
evaluationContext.goldReward += evaluationContext.evaluator.getGoldReward(target, hero);
|
||||||
evaluationContext.armyReward += evaluationContext.evaluator.getArmyReward(target, hero, army, checkGold);
|
evaluationContext.armyReward += evaluationContext.evaluator.getArmyReward(target, hero, army, checkGold);
|
||||||
@@ -1022,7 +1034,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task)
|
|||||||
+ (evaluationContext.skillReward > 0 ? 1 : 0)
|
+ (evaluationContext.skillReward > 0 ? 1 : 0)
|
||||||
+ (evaluationContext.strategicalValue > 0 ? 1 : 0);
|
+ (evaluationContext.strategicalValue > 0 ? 1 : 0);
|
||||||
|
|
||||||
auto goldRewardPerTurn = evaluationContext.goldReward / std::log2f(evaluationContext.movementCost * 10);
|
float goldRewardPerTurn = evaluationContext.goldReward / std::log2f(2 + evaluationContext.movementCost * 10);
|
||||||
|
|
||||||
double result = 0;
|
double result = 0;
|
||||||
|
|
||||||
@@ -1055,13 +1067,13 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if NKAI_TRACE_LEVEL >= 2
|
#if NKAI_TRACE_LEVEL >= 2
|
||||||
logAi->trace("Evaluated %s, loss: %f, turn: %d, turns main: %f, scout: %f, gold: %d, cost: %d, army gain: %d, danger: %d, role: %s, strategical value: %f, cwr: %f, fear: %f, result %f",
|
logAi->trace("Evaluated %s, loss: %f, turn: %d, turns main: %f, scout: %f, gold: %f, cost: %d, army gain: %d, danger: %d, role: %s, strategical value: %f, cwr: %f, fear: %f, result %f",
|
||||||
task->toString(),
|
task->toString(),
|
||||||
evaluationContext.armyLossPersentage,
|
evaluationContext.armyLossPersentage,
|
||||||
(int)evaluationContext.turn,
|
(int)evaluationContext.turn,
|
||||||
evaluationContext.movementCostByRole[HeroRole::MAIN],
|
evaluationContext.movementCostByRole[HeroRole::MAIN],
|
||||||
evaluationContext.movementCostByRole[HeroRole::SCOUT],
|
evaluationContext.movementCostByRole[HeroRole::SCOUT],
|
||||||
evaluationContext.goldReward,
|
goldRewardPerTurn,
|
||||||
evaluationContext.goldCost,
|
evaluationContext.goldCost,
|
||||||
evaluationContext.armyReward,
|
evaluationContext.armyReward,
|
||||||
evaluationContext.danger,
|
evaluationContext.danger,
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define NKAI_PATHFINDER_TRACE_LEVEL 0
|
#define NKAI_PATHFINDER_TRACE_LEVEL 0
|
||||||
#define NKAI_TRACE_LEVEL 2
|
#define NKAI_TRACE_LEVEL 0
|
||||||
|
|
||||||
#include "../../../lib/pathfinder/CGPathNode.h"
|
#include "../../../lib/pathfinder/CGPathNode.h"
|
||||||
#include "../../../lib/pathfinder/INodeStorage.h"
|
#include "../../../lib/pathfinder/INodeStorage.h"
|
||||||
@@ -258,7 +258,7 @@ public:
|
|||||||
{
|
{
|
||||||
double ratio = (double)danger / (armyValue * hero->getFightingStrength());
|
double ratio = (double)danger / (armyValue * hero->getFightingStrength());
|
||||||
|
|
||||||
return (uint64_t)(armyValue * ratio * ratio * ratio);
|
return (uint64_t)(armyValue * ratio * ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
STRONG_INLINE
|
STRONG_INLINE
|
||||||
|
@@ -170,7 +170,6 @@ RuleBlock: basic
|
|||||||
rule: if heroRole is SCOUT and turn is NOW and mainTurnDistance is MEDIUM then Value is BAD
|
rule: if heroRole is SCOUT and turn is NOW and mainTurnDistance is MEDIUM then Value is BAD
|
||||||
rule: if heroRole is SCOUT and turn is NEXT and mainTurnDistance is LONG then Value is BAD
|
rule: if heroRole is SCOUT and turn is NEXT and mainTurnDistance is LONG then Value is BAD
|
||||||
rule: if heroRole is SCOUT and turn is NOW and scoutTurnDistance is LONG then Value is BAD
|
rule: if heroRole is SCOUT and turn is NOW and scoutTurnDistance is LONG then Value is BAD
|
||||||
rule: if heroRole is SCOUT and turn is NOW and scoutTurnDistance is MEDIUM then Value is BAD with 0.3
|
|
||||||
rule: if heroRole is SCOUT and fear is HIGH then Value is BAD with 0.8
|
rule: if heroRole is SCOUT and fear is HIGH then Value is BAD with 0.8
|
||||||
rule: if heroRole is SCOUT and fear is MEDIUM then Value is BAD with 0.5
|
rule: if heroRole is SCOUT and fear is MEDIUM then Value is BAD with 0.5
|
||||||
rule: if heroRole is MAIN and fear is HIGH then Value is BAD with 0.5
|
rule: if heroRole is MAIN and fear is HIGH then Value is BAD with 0.5
|
||||||
@@ -252,6 +251,11 @@ RuleBlock: gold
|
|||||||
rule: if goldReward is MEDIUM and goldPreasure is HIGH and heroRole is MAIN and danger is not NONE and armyLoss is LOW then Value is BITHIGH
|
rule: if goldReward is MEDIUM and goldPreasure is HIGH and heroRole is MAIN and danger is not NONE and armyLoss is LOW then Value is BITHIGH
|
||||||
rule: if goldReward is SMALL and goldPreasure is HIGH and heroRole is SCOUT and danger is NONE then Value is MEDIUM
|
rule: if goldReward is SMALL and goldPreasure is HIGH and heroRole is SCOUT and danger is NONE then Value is MEDIUM
|
||||||
rule: if goldReward is SMALL and goldPreasure is HIGH and heroRole is MAIN and danger is not NONE and armyLoss is LOW then Value is SMALL
|
rule: if goldReward is SMALL and goldPreasure is HIGH and heroRole is MAIN and danger is not NONE and armyLoss is LOW then Value is SMALL
|
||||||
|
rule: if goldReward is LOWEST then Value is SMALL with 0.1
|
||||||
|
rule: if goldReward is SMALL then Value is SMALL with 0.2
|
||||||
|
rule: if goldReward is MEDIUM then Value is SMALL with 0.5
|
||||||
|
rule: if goldReward is BIG then Value is SMALL
|
||||||
|
rule: if goldReward is HUGE then Value is BITHIGH
|
||||||
RuleBlock: skill reward
|
RuleBlock: skill reward
|
||||||
enabled: true
|
enabled: true
|
||||||
conjunction: AlgebraicProduct
|
conjunction: AlgebraicProduct
|
||||||
|
Reference in New Issue
Block a user