File: PriorityEvaluator.h

package info (click to toggle)
vcmi 1.6.5%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 32,060 kB
  • sloc: cpp: 238,971; python: 265; sh: 224; xml: 157; ansic: 78; objc: 61; makefile: 49
file content (152 lines) | stat: -rw-r--r-- 4,397 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* 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
*
*/
#pragma once
#if __has_include(<fuzzylite/Headers.h>)
#  include <fuzzylite/Headers.h>
#else
#  include <fl/Headers.h>
#endif
#include "../Goals/CGoal.h"
#include "../Pathfinding/AIPathfinder.h"

VCMI_LIB_NAMESPACE_BEGIN

VCMI_LIB_NAMESPACE_END

namespace NKAI
{

class BuildingInfo;
class Nullkiller;
struct HitMapInfo;

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;
	uint64_t getArmyGrowth(const CGObjectInstance * target, const CGHeroInstance * hero, const CCreatureSet * army) const;
	int getGoldCost(const CGObjectInstance * target, const CGHeroInstance * hero, const CCreatureSet * army) const;
	float getEnemyHeroStrategicalValue(const CGHeroInstance * enemy) const;
	float getResourceRequirementStrength(int resType) const;
	float getResourceRequirementStrength(const TResources & res) const;
	float getStrategicalValue(const CGObjectInstance * target, const CGHeroInstance * hero = nullptr) const;
	float getConquestValue(const CGObjectInstance* target) const;
	float getTotalResourceRequirementStrength(int resType) const;
	float evaluateWitchHutSkillScore(const CGObjectInstance * hut, const CGHeroInstance * hero, HeroRole role) const;
	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;
	const HitMapInfo & getEnemyHeroDanger(const int3 & tile, uint8_t turn) const;
	uint64_t townArmyGrowth(const CGTownInstance * town) const;
	float getManaRecoveryArmyReward(const CGHeroInstance * hero) const;
};

struct DLL_EXPORT EvaluationContext
{
	float movementCost;
	std::map<HeroRole, float> movementCostByRole;
	int manaCost;
	uint64_t danger;
	float closestWayRatio;
	float armyLossPersentage;
	float armyReward;
	uint64_t armyGrowth;
	int32_t goldReward;
	int32_t goldCost;
	float skillReward;
	float strategicalValue;
	float conquestValue;
	HeroRole heroRole;
	uint8_t turn;
	RewardEvaluator evaluator;
	float enemyHeroDangerRatio;
	float threat;
	float armyInvolvement;
	int defenseValue;
	bool isDefend;
	int threatTurns;
	TResources buildingCost;
	bool involvesSailing;
	bool isTradeBuilding;
	bool isExchange;
	bool isArmyUpgrade;
	bool isHero;
	bool isEnemy;
	int explorePriority;

	EvaluationContext(const Nullkiller * ai);

	void addNonCriticalStrategicalValue(float value);
};

class IEvaluationContextBuilder
{
public:
	virtual ~IEvaluationContextBuilder() = default;
	virtual void buildEvaluationContext(EvaluationContext & evaluationContext, Goals::TSubgoal goal) const = 0;
};

class Nullkiller;

class PriorityEvaluator
{
public:
	PriorityEvaluator(const Nullkiller * ai);
	~PriorityEvaluator();
	void initVisitTile();

	float evaluate(Goals::TSubgoal task, int priorityTier = BUILDINGS);

	enum PriorityTier : int32_t
	{
		BUILDINGS = 0,
		INSTAKILL,
		INSTADEFEND,
		KILL,
		UPGRADE,
		HIGH_PRIO_EXPLORE,
		HUNTER_GATHER,
		LOW_PRIO_EXPLORE,
		FAR_KILL,
		FAR_HUNTER_GATHER,
		DEFEND
	};

private:
	const Nullkiller * ai;

	fl::Engine * engine;
	fl::InputVariable * armyLossPersentageVariable;
	fl::InputVariable * heroRoleVariable;
	fl::InputVariable * mainTurnDistanceVariable;
	fl::InputVariable * scoutTurnDistanceVariable;
	fl::InputVariable * turnVariable;
	fl::InputVariable * goldRewardVariable;
	fl::InputVariable * armyRewardVariable;
	fl::InputVariable * armyGrowthVariable;
	fl::InputVariable * dangerVariable;
	fl::InputVariable * skillRewardVariable;
	fl::InputVariable * strategicalValueVariable;
	fl::InputVariable * rewardTypeVariable;
	fl::InputVariable * closestHeroRatioVariable;
	fl::InputVariable * goldPressureVariable;
	fl::InputVariable * goldCostVariable;
	fl::InputVariable * fearVariable;
	fl::OutputVariable * value;
	std::vector<std::shared_ptr<IEvaluationContextBuilder>> evaluationContextBuilders;

	EvaluationContext buildEvaluationContext(Goals::TSubgoal goal) const;
};

}