Source: ksirk/aiplayer.h


Annotated List
Files
Globals
Hierarchy
Index
/***************************************************************************
                          aiplayer.h  -  description
                             -------------------
    begin                : sam sep 14 2002
    copyright            : (C) 2002 by Gael de Chalendar
    email                : ksirk@tuxfamily.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef AIPLAYER_H
#define AIPLAYER_H

#include "global.h"
#include "player.h"
#include "onu.h"
#include "nationality.h"
#include "kgamewin.h"

#include 
#include 

/**
  * This class represents a computer player. It holds all strategic routines
  * @author Gael de Chalendar
  */

class AIPlayer : public Player, public QThread
{
Q_OBJECT

public: 
	~AIPlayer() {};

	/** 
	  * Constructor with simple initializations
	  */
	 AIPlayer(QString & nomPlayer, int nbArmies,
			 Nationality * myNation,PlayersArray* players, ONU* world,
			 KGameWindow* game );
	/**
	  * bit to bit comparison
	  */
	virtual int operator ==(AIPlayer Arg1);

	/** 
	  * This function is called whenever the player should choose an action (
	  * attack, defence, etc.). It has the responsability to choose the correct
	  * action depending on the state of the game.
	  */
	virtual void actionChoice(GameState state);

	/**
	  * Returns the list of the countries owned by this player
	  */
	QPtrList countries(void) const;

	/**
	  * Returns true (an AIPlayer is an AI)
	  */
	virtual bool isAI() const;

	virtual void run(void);

	/**
	  * Read property of QPtrQueue clickedPoints.
	  */
	virtual QPtrQueue* getClickedPoints();

	/**
	  * Read property of QPtrQueue ationsQueue.
	  */
	virtual QPtrQueue* getActionsQueue();

	/**
	  * Chooses the next action. In the current basic setting, chooses at random
	  * between the three possibilities. For each, chooses randomly the
	  * parameters.If the randomly choosen parameters end by an impossible 
	  * action, continue with next player.
	  */
	  void chooseAttackMoveArmiesOrNextPlayer(void);

	  /** set stopMe to true in order for the run method to return */
	void stop(void);

private: // Private attributes
	/**
	  * Pointer to the players. Informations about them is necessary decide of
	  * a strategy
	  */
	PlayersArray* allPlayers;

	/**
	  * Pointer to the World to consult it in order to decide the actions
	  */
	ONU* theWorld;

	/**
	  * a pointer to the game. Necessary to be able to access the number of
	  * attackers, etc. This solution is not very pretty... but an important
	  * architectural change should be done to avoid it (TODO).
	  */
	KGameWindow* theGame;

	/**
	  * This queue holds the points where the AI has decided to play. It is
	  * read by the main thread with the appropriate member methods.
	  */
	  QPtrQueue clickedPoints;

	/**
	  * This queue holds the codes of the actions done by the AI. It is
	  * read by the main thread with the appropriate member methods.
	  */
	  QPtrQueue actionsQueue;
  /** indicates to the thread if the run method should return */
  bool stopMe;

private: // Private methods
	/**
	  * Chooses a country to receive a new army in dotation
	  */
	Country* chooseReceivingCountry(void);
  /** Returns a pair of countries where the attacker have enough armies to attack and the defender is a ennemy neighbour of the attacker */
   std::pair< const Country*, const Country* > chooseBelligerant(void) const;

signals:
	void actionAtPoint(const QPoint &p);
};

#endif


Generated by: gael on noirdes.limsi.u-psud.fr on Fri Jan 3 17:03:38 2003, using kdoc 2.0a53.