1 // Copyright (C) 2004 John Farrell
2 // Copyright (C) 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2005, 2006 Andrea Paternesi
4 // Copyright (C) 2006 Vibhu Rishi
5 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
6 // Copyright (C) 2007, 2008 Ole Laursen
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Library General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #include "real_player.h"
41 //! A more complex artificial intelligence Player.
43 * After examining if it buys additional production, this AI uses the classical
44 * strategy technique of:
45 * - analyse the game situation - this involves identifying stacks and cities as
46 * threats, and deciding which are the greatest threats to which cities.
47 * - allocate resources to deal with the threats to our best advantage.
49 * TODO: Ruins are also identified as threats, though they are not handled yet.
50 * TODO: The Ai only buys basic productions
51 * TODO: The AI doesn't rally make use of the multifight, and it cannot really
52 * handle the results (not checked)
53 * TODO: The Ai should be able to upgrade cities (Increases their income etc.)
54 * TODO: AI is way too defensive (in fact, the fast AI tends to win games)
56 * The code is split up in several classes. Be sure to read the comments there
57 * before trying to read the code. :)
59 * - AI_Analysis includes the code for the assessment of the game situation
60 * - AI_Allocation distributes the AI's ressources the engage threats
61 * - Threat/Threatlist contains the code for the definition of single threats
62 * and the container class for threats
63 * - AICityInfo is used to collect the threats and reinforcements etc. of a
64 * single city of the AI.
66 * Also see the Player class for the derivation scheme of players.
69 class AI_Smart : public RealPlayer
73 * Make a new AI_Smart player.
75 * @param name The name of the player.
76 * @param armyset The Id of the player's Armyset.
77 * @param color The player's colour.
78 * @param width The width of the player's FogMap.
79 * @param height The height of the player's FogMap.
80 * @param player_no The Id of the player. If this value is -1,
81 * the next free Id it used.
83 //! Default constructor.
84 AI_Smart(std::string name, guint32 armyset, Gdk::Color color,
85 int width, int height, int player_no = -1);
88 AI_Smart(const Player&);
89 //! Loading constructor. See XML_Helper for an explanation.
90 AI_Smart(XML_Helper* helper);
94 virtual bool isComputer() const {return true;};
95 virtual void abortTurn();
96 virtual bool startTurn();
97 virtual void invadeCity(City* c);
98 virtual bool chooseHero(HeroProto *hero, City* c, int gold);
99 virtual Reward *chooseReward(Ruin *ruin, Sage *sage, Stack *stack);
100 virtual void heroGainsLevel(Hero * a);
101 virtual bool chooseTreachery (Stack *stack, Player *player, Vector <int> pos);
102 virtual Army::Stat chooseStat(Hero *hero);
103 virtual bool chooseQuest(Hero *hero);
106 // Choose a new type of army to buy production for.
107 int chooseArmyTypeToBuy(City *c, bool quick);
109 // Consider buying new production for this city
110 int maybeBuyProduction(City *c, bool quick);
112 // Set the city to produce the best armies possible
113 void setProduction(City *c);
114 int setBestProduction(City *c);
115 int setQuickProduction(City *c);
117 // assign a score to an army type to try to figure out which is best
118 // which is best for buying
119 int scoreBestArmyType(const ArmyProto *proto);
120 //which is best for producing
121 int scoreBestArmyType(const ArmyProdBase *a);
122 //which is quickest for producing.
123 int scoreQuickArmyType(const ArmyProdBase *proto);
124 //which is quickest for buying
125 int scoreQuickArmyType(const ArmyProto *proto);
127 // suggest somewhere that a hero stack might like to visit
128 Location *getAlternateHeroTarget(Stack *s);
130 // what is the biggest danger to this city?
131 Threat *getBiggestDangerTo(City *city, Threatlist *threats);
133 // examine cities to see if we need to change production
134 void examineCities();
136 // buy a scout if we need to
137 void maybeBuyScout();
139 bool cityNewlyTaken(City *city, guint32 turns = 2) const;
142 int d_mustmakemoney; // used to avoid to buy new production
143 // and to reinforce cities to earn more money