ai_interface Class Reference

#include <ai_interface.hpp>

Inheritance diagram for ai_interface:

Inheritance graph
[legend]
Collaboration diagram for ai_interface:

Collaboration graph
[legend]

List of all members.

Public Types

typedef gamemap::location location
 A convenient typedef for the often used 'location' object.
typedef std::multimap
< location, location
move_map
 The standard way in which a map of possible moves is recorded.

Public Member Functions

 ai_interface (info &arg)
 The constructor.
virtual ~ai_interface ()
virtual void play_turn ()=0
 Function that is called when the AI must play its turn.
teamcurrent_team ()
 Return a reference to the 'team' object for the AI.
const teamcurrent_team () const
void diagnostic (const std::string &msg)
 Show a diagnostic message on the screen.
void log_message (const std::string &msg)
 Display a debug message as a chat message.
events::generic_eventuser_interact ()
events::generic_eventunit_recruited ()
events::generic_eventunit_moved ()
events::generic_eventenemy_attacked ()

Protected Member Functions

void attack_enemy (const location u, const location target, int att_weapon, int def_weapon)
 This function should be called to attack an enemy.
location move_unit (location from, location to, std::map< location, paths > &possible_moves)
 This function should be called to move a unit.
location move_unit_partial (location from, location t, std::map< location, paths > &possible_moves)
 Identical to 'move_unit', except that the unit's movement isn't set to 0 after the move is complete.
void calculate_possible_moves (std::map< location, paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const std::set< location > *remove_destinations=NULL) const
 Calculate the moves units may possibly make.
void calculate_moves (const unit_map &units, std::map< location, paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const std::set< location > *remove_destinations=NULL, bool see_all=false) const
 A more fundamental version of calculate_possible_moves which allows the use of a speculative unit map.
bool recruit (const std::string &unit_name, location loc=location())
 Recruit a unit.
infoget_info ()
 functions to retrieve the 'info' object.
const infoget_info () const
void raise_user_interact ()
 Function which should be called frequently to allow the user to interact with the interface.
void raise_unit_recruited ()
 Notifies all interested observers of the event respectively.
void raise_unit_moved ()
void raise_enemy_attacked ()
virtual void get_inputs (std::vector< game_logic::formula_input > *inputs) const
virtual variant get_value (const std::string &key) const

Private Attributes

info info_
int last_interact_
events::generic_event user_interact_
events::generic_event unit_recruited_
events::generic_event unit_moved_
events::generic_event enemy_attacked_

Classes

struct  info
 info is structure which holds references to all the important objects that an AI might need access to, in order to make and implement its decisions. More...


Detailed Description

Definition at line 29 of file ai_interface.hpp.


Member Typedef Documentation

A convenient typedef for the often used 'location' object.

Definition at line 33 of file ai_interface.hpp.

typedef std::multimap<location,location> ai_interface::move_map

The standard way in which a map of possible moves is recorded.

Definition at line 36 of file ai_interface.hpp.


Constructor & Destructor Documentation

ai_interface::ai_interface ( info arg  )  [inline]

The constructor.

All derived classes should take an argument of type info& which they should pass to this constructor.

Definition at line 77 of file ai_interface.hpp.

virtual ai_interface::~ai_interface (  )  [inline, virtual]

Definition at line 80 of file ai_interface.hpp.


Member Function Documentation

virtual void ai_interface::play_turn (  )  [pure virtual]

Function that is called when the AI must play its turn.

Derived classes should implement their AI algorithm in this function.

Implemented in idle_ai, sample_ai, ai, ai2, dfool::dfool_ai, python_ai, and formula_ai.

Referenced by formula_ai::execute_variant(), and formula_ai::make_move().

team& ai_interface::current_team (  )  [inline]

const team& ai_interface::current_team (  )  const [inline]

Definition at line 88 of file ai_interface.hpp.

References info_, ai_interface::info::team_num, and ai_interface::info::teams.

void ai_interface::diagnostic ( const std::string &  msg  ) 

Show a diagnostic message on the screen.

Definition at line 400 of file ai.cpp.

References game_config::debug, ai_interface::info::disp, info_, and display::set_diagnostic().

void ai_interface::log_message ( const std::string &  msg  ) 

Display a debug message as a chat message.

Definition at line 407 of file ai.cpp.

References game_display::add_chat_message(), game_config::debug, ai_interface::info::disp, info_, and game_display::MESSAGE_PUBLIC.

Referenced by ai::attack_analysis::rating().

events::generic_event& ai_interface::user_interact (  )  [inline]

Definition at line 97 of file ai_interface.hpp.

References user_interact_.

events::generic_event& ai_interface::unit_recruited (  )  [inline]

Definition at line 98 of file ai_interface.hpp.

References unit_recruited_.

events::generic_event& ai_interface::unit_moved (  )  [inline]

Definition at line 99 of file ai_interface.hpp.

References unit_moved_.

events::generic_event& ai_interface::enemy_attacked (  )  [inline]

Definition at line 100 of file ai_interface.hpp.

References enemy_attacked_.

void ai_interface::attack_enemy ( const location  u,
const location  target,
int  weapon,
int  def_weapon 
) [protected]

This function should be called to attack an enemy.

Parameters:
u The location of the attacking unit. (Note this shouldn't be a reference since attack::attack() can invalidate the unit_map and references to the map are also invalid then.)
target The location of the target unit. This unit must be in range of the attacking unit's weapon. (See note at param u.)
weapon The number of the weapon (0-based) which should be used by the attacker. (It must be a valid weapon of the attacker.)
def_weapon The number of the weapon (0-based) which should be used by the defender. (It must be a valid weapon of the defender.)

Definition at line 1118 of file ai.cpp.

References replay::add_attack(), dialogs::advance_unit(), check_victory(), unit_map::count(), ai_interface::info::disp, unit_map::end(), lg::err, unit_map::find(), info_, LOG_STREAM, ai_interface::info::map, raise_enemy_attacked(), recorder, ai_interface::info::state, ai_interface::info::teams, and ai_interface::info::units.

Referenced by ai::attack_enemy(), and sample_ai::do_attacks().

gamemap::location ai_interface::move_unit ( location  from,
location  to,
std::map< location, paths > &  possible_moves 
) [protected]

This function should be called to move a unit.

Once the unit has been moved, its movement allowance is set to 0. 'from': the location of the unit being moved. 'to': the location to be moved to. This must be a valid move for the unit. 'possible_moves': the map of possible moves, as obtained from 'calculate_possible_moves'.

Reimplemented in ai.

Definition at line 416 of file ai.cpp.

References unit_map::end(), unit_map::find(), info_, loc, move_unit_partial(), and ai_interface::info::units.

Referenced by sample_ai::do_attacks(), sample_ai::do_moves(), sample_ai::get_villages(), and ai::move_unit().

gamemap::location ai_interface::move_unit_partial ( location  from,
location  t,
std::map< location, paths > &  possible_moves 
) [protected]

void ai_interface::calculate_possible_moves ( std::map< location, paths > &  possible_moves,
move_map srcdst,
move_map dstsrc,
bool  enemy,
bool  assume_full_movement = false,
const std::set< location > *  remove_destinations = NULL 
) const [protected]

Calculate the moves units may possibly make.

'possible_moves': a map which will be filled with the paths each unit can take to get to every possible destination. You probably don't want to use this object at all, except to pass to 'move_unit'. 'srcdst': a map of units to all their possible destinations 'dstsrc': a map of destinations to all the units that can move to that destination 'enemy': if true, a map of possible moves for enemies will be calculated. If false, a map of possible moves for units on the AI's side will be calculated. The AI's own leader will not be included in this map. 'assume_full_movement': if true, the function will operate on the assumption that all units can move their full movement allotment. 'remove_destinations': a pointer to a set of possible destinations to omit.

Referenced by ai::analyze_targets(), ai::choose_move(), sample_ai::do_attacks(), ai::do_move(), sample_ai::do_moves(), sample_ai::get_villages(), ai::move_group(), ai::move_leader_after_recruit(), ai::move_unit(), formula_ai::prepare_move(), and ai::retreat_units().

void ai_interface::calculate_moves ( const unit_map units,
std::map< location, paths > &  possible_moves,
move_map srcdst,
move_map dstsrc,
bool  enemy,
bool  assume_full_movement = false,
const std::set< location > *  remove_destinations = NULL,
bool  see_all = false 
) const [protected]

A more fundamental version of calculate_possible_moves which allows the use of a speculative unit map.

Referenced by dfool::dfool_ai::moveto().

bool ai_interface::recruit ( const std::string &  unit_name,
location  loc = location() 
) [protected]

info& ai_interface::get_info (  )  [inline, protected]

const info& ai_interface::get_info (  )  const [inline, protected]

Definition at line 149 of file ai_interface.hpp.

References info_.

void ai_interface::raise_user_interact (  )  [protected]

Function which should be called frequently to allow the user to interact with the interface.

This function will make sure that interaction doesn't occur too often, so there is no problem with calling it very regularly.

Definition at line 387 of file ai.cpp.

References last_interact_, events::generic_event::notify_observers(), and user_interact_.

Referenced by ai::choose_move(), ai::do_attack_analysis(), ai::do_move(), and ai::recruit_usage().

void ai_interface::raise_unit_recruited (  )  [inline, protected]

Notifies all interested observers of the event respectively.

Definition at line 158 of file ai_interface.hpp.

References events::generic_event::notify_observers(), and unit_recruited_.

Referenced by recruit().

void ai_interface::raise_unit_moved (  )  [inline, protected]

Definition at line 159 of file ai_interface.hpp.

References events::generic_event::notify_observers(), and unit_moved_.

Referenced by move_unit_partial().

void ai_interface::raise_enemy_attacked (  )  [inline, protected]

Definition at line 160 of file ai_interface.hpp.

References enemy_attacked_, and events::generic_event::notify_observers().

Referenced by attack_enemy().

void ai_interface::get_inputs ( std::vector< game_logic::formula_input > *  inputs  )  const [protected, virtual]

Reimplemented from game_logic::formula_callable.

Reimplemented in formula_ai.

Definition at line 2262 of file ai.cpp.

References game_logic::FORMULA_READ_ONLY.

Referenced by formula_ai::get_inputs().

variant ai_interface::get_value ( const std::string &  key  )  const [protected, virtual]


Member Data Documentation

Definition at line 166 of file ai_interface.hpp.

Referenced by raise_user_interact().

Definition at line 167 of file ai_interface.hpp.

Referenced by raise_user_interact(), and user_interact().

Definition at line 168 of file ai_interface.hpp.

Referenced by raise_unit_recruited(), and unit_recruited().

Definition at line 169 of file ai_interface.hpp.

Referenced by raise_unit_moved(), and unit_moved().

Definition at line 170 of file ai_interface.hpp.

Referenced by enemy_attacked(), and raise_enemy_attacked().


The documentation for this class was generated from the following files:

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs