2021-05-15 18:23:38 +02:00
|
|
|
/*
|
2021-05-15 21:04:26 +02:00
|
|
|
* PriorityEvaluator.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2021-05-15 18:23:38 +02:00
|
|
|
*/
|
|
|
|
#pragma once
|
2023-09-16 07:13:16 +02:00
|
|
|
#if __has_include(<fuzzylite/Headers.h>)
|
|
|
|
# include <fuzzylite/Headers.h>
|
|
|
|
#else
|
|
|
|
# include <fl/Headers.h>
|
|
|
|
#endif
|
2020-05-04 17:58:43 +02:00
|
|
|
#include "../Goals/CGoal.h"
|
2021-05-16 13:55:47 +02:00
|
|
|
#include "../Pathfinding/AIPathfinder.h"
|
2020-05-04 17:58:43 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2022-09-26 20:01:07 +02:00
|
|
|
namespace NKAI
|
|
|
|
{
|
|
|
|
|
2020-05-04 17:58:43 +02:00
|
|
|
class BuildingInfo;
|
2021-05-16 13:55:47 +02:00
|
|
|
class Nullkiller;
|
2023-02-28 09:07:59 +02:00
|
|
|
struct HitMapInfo;
|
2020-05-04 17:58:43 +02:00
|
|
|
|
|
|
|
class RewardEvaluator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const Nullkiller * ai;
|
|
|
|
|
|
|
|
RewardEvaluator(const Nullkiller * ai) : ai(ai) {}
|
|
|
|
|
|
|
|
uint64_t getArmyReward(const CGObjectInstance * target, const CGHeroInstance * hero, const CCreatureSet * army, bool checkGold) const;
|
2023-05-14 08:17:15 +02:00
|
|
|
uint64_t getArmyGrowth(const CGObjectInstance * target, const CGHeroInstance * hero, const CCreatureSet * army) const;
|
2020-05-04 17:58:43 +02:00
|
|
|
int getGoldCost(const CGObjectInstance * target, const CGHeroInstance * hero, const CCreatureSet * army) const;
|
|
|
|
float getEnemyHeroStrategicalValue(const CGHeroInstance * enemy) const;
|
|
|
|
float getResourceRequirementStrength(int resType) const;
|
2024-04-20 14:28:42 +02:00
|
|
|
float getResourceRequirementStrength(const TResources & res) const;
|
|
|
|
float getStrategicalValue(const CGObjectInstance * target, const CGHeroInstance * hero = nullptr) const;
|
2024-07-12 17:41:46 +02:00
|
|
|
float getConquestValue(const CGObjectInstance* target) const;
|
2020-05-04 17:58:43 +02:00
|
|
|
float getTotalResourceRequirementStrength(int resType) const;
|
2023-09-30 17:47:47 +02:00
|
|
|
float evaluateWitchHutSkillScore(const CGObjectInstance * hut, const CGHeroInstance * hero, HeroRole role) const;
|
2020-05-04 17:58:43 +02:00
|
|
|
float getSkillReward(const CGObjectInstance * target, const CGHeroInstance * hero, HeroRole role) const;
|
|
|
|
int32_t getGoldReward(const CGObjectInstance * target, const CGHeroInstance * hero) const;
|
|
|
|
uint64_t getUpgradeArmyReward(const CGTownInstance * town, const BuildingInfo & bi) const;
|
2023-02-28 09:07:59 +02:00
|
|
|
const HitMapInfo & getEnemyHeroDanger(const int3 & tile, uint8_t turn) const;
|
2023-06-11 18:21:50 +02:00
|
|
|
uint64_t townArmyGrowth(const CGTownInstance * town) const;
|
2023-09-24 12:07:42 +02:00
|
|
|
uint64_t getManaRecoveryArmyReward(const CGHeroInstance * hero) const;
|
2020-05-04 17:58:43 +02:00
|
|
|
};
|
2021-05-15 18:23:38 +02:00
|
|
|
|
2021-05-16 13:38:53 +02:00
|
|
|
struct DLL_EXPORT EvaluationContext
|
|
|
|
{
|
|
|
|
float movementCost;
|
|
|
|
std::map<HeroRole, float> movementCostByRole;
|
|
|
|
int manaCost;
|
|
|
|
uint64_t danger;
|
|
|
|
float closestWayRatio;
|
|
|
|
float armyLossPersentage;
|
|
|
|
float armyReward;
|
2023-05-14 08:17:15 +02:00
|
|
|
uint64_t armyGrowth;
|
2021-05-16 13:38:53 +02:00
|
|
|
int32_t goldReward;
|
|
|
|
int32_t goldCost;
|
|
|
|
float skillReward;
|
|
|
|
float strategicalValue;
|
2024-07-12 17:41:46 +02:00
|
|
|
float conquestValue;
|
2021-05-16 13:38:53 +02:00
|
|
|
HeroRole heroRole;
|
|
|
|
uint8_t turn;
|
2020-05-04 17:58:43 +02:00
|
|
|
RewardEvaluator evaluator;
|
2021-05-16 13:55:33 +02:00
|
|
|
float enemyHeroDangerRatio;
|
2024-07-15 18:12:52 +02:00
|
|
|
float threat;
|
2024-07-12 17:41:46 +02:00
|
|
|
float armyInvolvement;
|
2024-08-11 18:21:24 +02:00
|
|
|
int defenseValue;
|
2024-07-12 23:36:41 +02:00
|
|
|
bool isDefend;
|
2024-08-14 22:53:48 +02:00
|
|
|
int threatTurns;
|
2024-07-19 15:25:24 +02:00
|
|
|
TResources buildingCost;
|
2024-07-15 18:12:52 +02:00
|
|
|
bool involvesSailing;
|
2024-07-19 15:25:24 +02:00
|
|
|
bool isTradeBuilding;
|
2024-08-14 22:53:48 +02:00
|
|
|
bool isChain;
|
2024-08-15 18:16:23 +02:00
|
|
|
bool isEnemy;
|
2021-05-16 13:38:53 +02:00
|
|
|
|
2020-05-04 17:58:43 +02:00
|
|
|
EvaluationContext(const Nullkiller * ai);
|
2023-06-04 15:02:02 +02:00
|
|
|
|
|
|
|
void addNonCriticalStrategicalValue(float value);
|
2021-05-16 13:38:53 +02:00
|
|
|
};
|
|
|
|
|
2021-05-16 13:15:03 +02:00
|
|
|
class IEvaluationContextBuilder
|
|
|
|
{
|
|
|
|
public:
|
2022-09-22 10:02:16 +02:00
|
|
|
virtual ~IEvaluationContextBuilder() = default;
|
2021-05-16 13:38:53 +02:00
|
|
|
virtual void buildEvaluationContext(EvaluationContext & evaluationContext, Goals::TSubgoal goal) const = 0;
|
2021-05-16 13:15:03 +02:00
|
|
|
};
|
2021-05-15 18:23:38 +02:00
|
|
|
|
2020-05-04 17:58:43 +02:00
|
|
|
class Nullkiller;
|
|
|
|
|
2021-05-15 21:02:27 +02:00
|
|
|
class PriorityEvaluator
|
2021-05-15 18:23:38 +02:00
|
|
|
{
|
|
|
|
public:
|
2020-05-04 17:58:43 +02:00
|
|
|
PriorityEvaluator(const Nullkiller * ai);
|
2021-05-15 18:23:38 +02:00
|
|
|
~PriorityEvaluator();
|
|
|
|
void initVisitTile();
|
|
|
|
|
2024-08-24 14:55:26 +02:00
|
|
|
float evaluate(Goals::TSubgoal task, int priorityTier = 0);
|
2021-05-15 18:23:38 +02:00
|
|
|
|
|
|
|
private:
|
2020-05-04 17:58:43 +02:00
|
|
|
const Nullkiller * ai;
|
|
|
|
|
2021-05-15 21:02:27 +02:00
|
|
|
fl::Engine * engine;
|
2021-05-15 18:23:38 +02:00
|
|
|
fl::InputVariable * armyLossPersentageVariable;
|
2021-05-15 21:02:27 +02:00
|
|
|
fl::InputVariable * heroRoleVariable;
|
2021-05-16 13:14:07 +02:00
|
|
|
fl::InputVariable * mainTurnDistanceVariable;
|
|
|
|
fl::InputVariable * scoutTurnDistanceVariable;
|
2021-05-16 13:19:00 +02:00
|
|
|
fl::InputVariable * turnVariable;
|
2021-05-15 18:23:38 +02:00
|
|
|
fl::InputVariable * goldRewardVariable;
|
|
|
|
fl::InputVariable * armyRewardVariable;
|
2023-05-14 08:17:15 +02:00
|
|
|
fl::InputVariable * armyGrowthVariable;
|
2021-05-15 20:57:40 +02:00
|
|
|
fl::InputVariable * dangerVariable;
|
2021-05-15 21:02:27 +02:00
|
|
|
fl::InputVariable * skillRewardVariable;
|
2021-05-16 13:13:35 +02:00
|
|
|
fl::InputVariable * strategicalValueVariable;
|
2021-05-15 21:02:27 +02:00
|
|
|
fl::InputVariable * rewardTypeVariable;
|
|
|
|
fl::InputVariable * closestHeroRatioVariable;
|
2024-04-16 23:10:15 +02:00
|
|
|
fl::InputVariable * goldPressureVariable;
|
2021-05-16 13:19:00 +02:00
|
|
|
fl::InputVariable * goldCostVariable;
|
2021-05-16 13:55:33 +02:00
|
|
|
fl::InputVariable * fearVariable;
|
2021-05-15 18:23:38 +02:00
|
|
|
fl::OutputVariable * value;
|
2021-05-16 13:38:53 +02:00
|
|
|
std::vector<std::shared_ptr<IEvaluationContextBuilder>> evaluationContextBuilders;
|
2021-05-16 13:15:03 +02:00
|
|
|
|
2021-05-16 13:38:53 +02:00
|
|
|
EvaluationContext buildEvaluationContext(Goals::TSubgoal goal) const;
|
2021-05-15 18:23:38 +02:00
|
|
|
};
|
2022-09-26 20:01:07 +02:00
|
|
|
|
|
|
|
}
|