File indexing completed on 2024-10-06 06:48:46
0001 // kate: space-indent on; indent-width 2; replace-tabs on; 0002 /** This file is part of KsirK. 0003 Copyright (C) 2006-2007 Gael de Chalendar <kleag@free.fr> 0004 0005 This file was initialy part of XFrisk 0006 Copyright (C) 1995 and later Jean-Claude Colson and Others <who@nowhere.org> 0007 0008 KsirK is free software; you can redistribute it and/or 0009 modify it under the terms of the GNU General Public 0010 License as published by the Free Software Foundation, either version 2 0011 of the License, or (at your option) any later version. 0012 0013 This program is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 General Public License for more details. 0017 0018 You should have received a copy of the GNU General Public License 0019 along with this program; if not, write to the Free Software 0020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0021 02110-1301, USA 0022 */ 0023 0024 #ifndef KSIRK_GAMELOGIC_AICOLSONPLAYER_H 0025 #define KSIRK_GAMELOGIC_AICOLSONPLAYER_H 0026 0027 #include "aiplayer.h" 0028 0029 #include <map> 0030 0031 #define MAX_CARDS 10 0032 0033 namespace Ksirk 0034 { 0035 0036 namespace GameLogic 0037 { 0038 class Player; 0039 class Continent; 0040 class GameAutomaton; 0041 0042 /** 0043 * The AIColsonPlayer class is an AI player ported from the risk clone XFrisk, 0044 * this program being programed in C. I have just made it work, adapting some 0045 * data structures, but it remains a lot of work to port it to a plain object 0046 * oriented class and also to make it work with the goals (at least). 0047 * @author Jean-Claude Colson (original C version) 0048 * @author Gaƫl de Chalendar (aka Kleag) (C++ version for KsirK) 0049 */ 0050 class AIColsonPlayer : public AIPlayer 0051 { 0052 public: 0053 /** 0054 * Constructor with simple initializations 0055 */ 0056 explicit AIColsonPlayer( 0057 const QString & nomPlayer, unsigned int nbArmies, 0058 Nationality * myNation, PlayersArray& players, ONU* world, 0059 GameAutomaton* game ); 0060 0061 /** Default destructor. */ 0062 ~AIColsonPlayer() override; 0063 0064 0065 QString author() override {return "Jean-Claude COLSON";} 0066 0067 /** 0068 * Returns a pair of countries where the attacker have enough armies to 0069 * attack and the defender is a ennemy neighbour of the attacker. 0070 */ 0071 QPair< const Country*, const Country* > chooseBelligerant() override; 0072 0073 /** 0074 * Chooses the next action. In the current basic setting, chooses at random 0075 * between the three possibilities. For each, chooses randomly the 0076 * parameters.If the randomly chosen parameters end by an impossible 0077 * action, continue with next player. 0078 */ 0079 void chooseAttackMoveArmiesOrNextPlayer() override; 0080 0081 /** 0082 * Chooses a country to receive a new army in dotation 0083 */ 0084 Country* chooseReceivingCountry() override; 0085 0086 /** 0087 * makes all what is necessary to prepare and start the moving of armies 0088 */ 0089 bool moveArmiesAction() override; 0090 0091 /** 0092 * computes the next continent to try to conquer or defend 0093 */ 0094 const Continent* computeChoiceOfContinent(void); 0095 0096 /** 0097 * Called once when all players are created/loaded/joined and when the 0098 * game can start. Allows to initialize AIs with public data about other 0099 * players. 0100 */ 0101 void finalize() override; 0102 0103 /** 0104 * chooses to continue invasion with a certain amount of armies or to stop it 0105 */ 0106 void chooseInvasionAction() override; 0107 0108 private: 0109 0110 struct PlaceData 0111 { 0112 Country* dest; 0113 uint nb; 0114 }; 0115 0116 0117 0118 Player* RISK_GetOwnerOfCountry(int i); 0119 Continent* RISK_GetContinentOfCountry(int i); 0120 int RISK_GetNumArmiesOfCountry(int i); 0121 int RISK_GetNumArmiesOfPlayer(Player* player); 0122 /** 0123 * Returns the position in the countries list of the ith adjacent country of 0124 * country iCountry 0125 */ 0126 int RISK_GetAdjCountryOfCountry(int iCountry, int i); 0127 int RISK_GetNumCountriesOfPlayer(const Player* player); 0128 bool GAME_IsEnemyAdjacent(int i); 0129 int FindEnemyAdjacent(int iCountry, int distance); 0130 int GAME_FindEnemyAdjacent(int country); 0131 0132 0133 0134 // void COLSON_Play(void *pData, int iCommand, void *pArgs); 0135 0136 /* The species */ 0137 // DefineSpecies( 0138 // COLSON_Play, 0139 // "Ordinateur", 0140 // AUTHOR, 0141 // "0.01", 0142 // "Machine violente." 0143 // ) 0144 0145 int getTotalArmiesOfPlayer(const Player* player); 0146 0147 bool isContinentOfMission(const Player* player, const Continent* continent); 0148 0149 bool isEnemyPlayer(const Player* player); 0150 0151 bool isFriendPlayer(const Player* player); 0152 0153 int getNumEnemy(); 0154 0155 bool isStrongerPlayer(const Player* player); 0156 0157 bool isSmallerPlayer(const Player* player); 0158 0159 bool isContinentOfPlayer(const Continent* continent, const Player* player); 0160 0161 const Continent* GetContinentToFortify(int *attack); 0162 0163 const Continent* getContinentToConquier(int *attack); 0164 0165 int NbEnemyAdjacent(Country* iCountry); 0166 0167 int NbToEqualEnemyAdjacent(Country* iCountry); 0168 0169 int NbToAverageEnemyAdjacent(Country* iCountry); 0170 0171 bool ComputerAttack(int destCountry, bool die, int dif); 0172 0173 bool Fortify(); 0174 0175 bool Place(); 0176 0177 bool AttackEnemy(); 0178 0179 bool Attack(); 0180 0181 void HowManyArmiesToMove(int *nb); 0182 0183 bool Move(); 0184 0185 int AI_Place(int iCountry, int iNumArmies); 0186 int AI_Move(int iSrcCountry, int iDstCountry, int iNumArmies); 0187 0188 // void ExchangeCards(const Player* player); 0189 0190 std::map<const Player*, int> m_numTurn; 0191 std::map<const Player*, int> m_isEnemyPlayer; 0192 int m_levelEnemy; 0193 0194 /** false while finalize has not been called */ 0195 bool m_initialized; 0196 0197 int Attack_SrcCountry; 0198 int Attack_DestCountry; 0199 0200 PlaceData* m_placeData; 0201 0202 /** 0203 * (country,dist)->country : used to find a nearest enemy and to avoid 0204 * useless recursions 0205 */ 0206 std::map<pair<int,int>,int> m_enemyAdjacent; 0207 }; 0208 0209 } // closing namespace GameLogic 0210 0211 } // closing namespace Ksirk 0212 0213 #endif