hexmove.h

Go to the documentation of this file.
00001 /*                            Package   : libhex
00002  * hexmove.h                  Created   : 2008/02/19
00003  *                            Author    : Alex Tingle
00004  *
00005  *    Copyright (C) 2008, Alex Tingle.
00006  *
00007  *    This file is part of the libhex application.
00008  *
00009  *    libhex is free software; you can redistribute it and/or
00010  *    modify it under the terms of the GNU Lesser General Public
00011  *    License as published by the Free Software Foundation; either
00012  *    version 2.1 of the License, or (at your option) any later version.
00013  *
00014  *    libhex is distributed in the hope that it will be useful,
00015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  *    Lesser General Public License for more details.
00018  *
00019  *    You should have received a copy of the GNU Lesser General Public
00020  *    License along with this library; if not, write to the Free Software
00021  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  */
00023 
00024 #ifndef FIRETREE__HEXMOVE_H
00025 #define FIRETREE__HEXMOVE_H 1
00026 
00027 
00028 #include "hex.h"
00029 
00030 
00031 namespace hex {
00032 
00034 namespace move {
00035 
00036 
00037 class no_solution: public hex::exception
00038 {
00039 public:
00040   no_solution(const std::string& w) throw(): hex::exception(w) {}
00041   virtual ~no_solution() throw() {}
00042 };
00043 
00044 
00045 typedef double Cost;
00046 
00047 
00049 class Topography
00050 {
00051   bool  _has_default;
00053   Cost  _default;
00055   std::map<hex::Hex*,Cost>  _hexes;
00059   std::map<hex::Edge*,Cost>  _edges;
00060 public:
00061   Topography();
00062   Topography(Cost default_hex_cost);
00063   virtual ~Topography() {}
00064   
00066   std::set<hex::Hex*> accessible(void) const;
00067 
00069   void increase_hex_cost(hex::Hex* h, Cost c);
00071   void override_hex_cost(hex::Hex* h, Cost c);
00072         
00074   void increase_edge_cost(hex::Edge* e, Cost c);
00076   void override_edge_cost(hex::Edge* e, Cost c);
00077 
00078   // Convenience functions.
00079   void increase_cost(const hex::Area& a, Cost c);
00080   void override_cost(const hex::Area& a, Cost c);
00081   void increase_cost(const hex::Boundary& b, Cost c);
00082   void override_cost(const hex::Boundary& b, Cost c);
00083 
00086   hex::Path best_path(hex::Hex* start, hex::Hex* goal) const throw(no_solution);
00087 
00089   hex::Area horizon(hex::Hex* start, Cost budget) const throw(no_solution);
00090 
00091 protected:
00092   struct Step
00093     {
00094       hex::Hex*  to_hex;
00095       Cost       cost;
00096     };
00097 
00101   Step step(hex::Hex* from_hex, Direction direction) const;
00102 };
00103 
00104 
00109 class _Route
00110 {
00111   Cost             _value; 
00112 
00113 public:
00114   std::list<Hex*>  path;  
00115   Cost             cost;  
00116 
00118   static _Route factory(hex::Hex* start, hex::Hex* goal=NULL);
00119 
00121   _Route step(hex::Hex* next, Cost cost, hex::Hex* goal=NULL) const;
00122      
00125   hex::Distance distance(hex::Hex* goal) const;
00126 
00128   bool operator<(const _Route& right) const { return _value < right._value; }
00129 };
00130 
00131 
00132 } // end namespace move
00133 } // end namespace hex
00134 
00135 #endif

Generated on Thu Feb 21 00:00:54 2008 for libhex by  doxygen 1.5.1