ai_dfool.hpp

Go to the documentation of this file.
00001 /* $Id: ai_dfool.hpp 25333 2008-03-30 13:49:03Z jhinrichs $ */
00002 /*
00003    Copyright (C) 2007 - 2008
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 //! @file ai_dfool.hpp
00016 //! The Standard-AI ??.
00017 //! This ai uses for its decisions only units it has "seen".
00018 
00019 #ifndef AI_DFOOL_HPP_INCLUDED
00020 #define AI_DFOOL_HPP_INCLUDED
00021 
00022 #include "global.hpp"
00023 
00024 #include "ai_interface.hpp"
00025 #include "map.hpp"
00026 #include "unit_map.hpp"
00027 #include "unit.hpp"
00028 
00029 #include <vector>
00030 #include <list>
00031 #include <map>
00032 #include <string>
00033 
00034 namespace dfool {
00035   typedef std::vector<std::string> unit_list;
00036 
00037 //  class target {
00038 //  public:
00039 //    target(config& command, unit_history u_hist, info& ai_info);
00040 //    double value(location loc, unit& u, unit_history u_hist, info ai_info);
00041 //   private:
00042 //     config unit_filter_;
00043 //     config terrain_filter_;
00044 //     std::string hex_val_;
00045 //     std::string number;
00046 //     std::string id;
00047 //   };
00048 
00049   class unit_memory{
00050   public:
00051     unit_memory(const config& cfg);
00052     void add_unit_sighting(unit u, gamemap::location l, size_t t);
00053     void remove_unit_sighting(std::string id);
00054     //void purge(int turn = -1); // Clean outdated entries
00055     void write(config& temp);
00056     // Create a map based upon units seen since turn
00057     void known_map(unit_map& units, size_t turn=0);
00058   private:
00059     void write_element(int i, config& temp);
00060     // Could replace these with a single vector of memory elements
00061     std::vector<unit> units_;
00062     std::vector<std::string> ids_;
00063     std::vector<size_t> turns_;
00064     std::vector<gamemap::location> locations_;
00065   };
00066 
00067   class evaluator{
00068   public:
00069     evaluator(const game_state& s, std::map<std::string, evaluator*>* m):function_map_(m),state(s){};
00070     virtual ~evaluator(){};
00071     virtual std::string value(const std::string& s);
00072   private:
00073     std::map<std::string, evaluator*>* function_map_;
00074     const game_state& state;
00075   };
00076 
00077   class arithmetic_evaluator : public evaluator {
00078   public:
00079     arithmetic_evaluator(const game_state& s, std::map<std::string, evaluator*>* m):evaluator(s,m){};
00080     std::string value(const std::string& s);
00081   private:
00082     std::list<std::string> parse_tokens(const std::string&);
00083     std::string evaluate_tokens(std::list<std::string>&);
00084   };
00085 
00086   class distance_evaluator : public arithmetic_evaluator {
00087   public:
00088     distance_evaluator(const game_state& s, std::map<std::string, evaluator*>* m):arithmetic_evaluator(s,m){};
00089     std::string value(const std::string& s);
00090   private:
00091     std::list<std::string> parse_tokens(const std::string&);
00092     std::string evaluate_tokens(std::list<std::string>&);
00093   };
00094 
00095   //! An ai that keeps track of what it has "seen",
00096   //! does not target units that it has not "seen",
00097   //! and does not make decisions based on unseen units.
00098   class dfool_ai : public ai_interface {
00099   public:
00100     dfool_ai(info& i) : ai_interface(i),unit_memory_(i.teams[i.team_num-1].ai_memory()){}
00101     void play_turn();
00102   private:
00103     //    std::map<std::string,target> target_map_;
00104     unit_list all_units();
00105     unit_list visible_units();
00106     unit_list my_units();
00107     unit_list filter_units(const config& filter,unit_list& ul, unit_map& um);
00108     bool moveto(config::child_list::const_iterator o, unit_map::const_iterator m);
00109     unit_map::iterator unit(std::string unit_id, unit_map& um);
00110 
00111     unit_memory unit_memory_;
00112 
00113   };
00114 
00115 } // end namespace dfool
00116 
00117 #endif

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