00001 #ifndef MOVE_HPP
00002 #define MOVE_HPP
00003
00004 #include <map>
00005 #include <string>
00006
00007 template <typename BoardCoord>
00008 class Move
00009 {
00010 private:
00011 bool m_legal;
00013 int m_color;
00015 BoardCoord m_start;
00016 BoardCoord m_dest;
00018 typedef std::map<std::string, int> ParameterMap;
00019 std::map<std::string, int> m_parameters;
00024 void checkCoordsLegality()
00025 {
00026 if ( !m_start.isValid() || !m_dest.isValid() )
00027 {
00028 m_legal=false;
00029 }
00030 }
00031
00032 public:
00035 Move():m_legal(false) {}
00036
00044 Move(int color, const BoardCoord& start, const BoardCoord& dest)
00045 :m_legal(true),m_color(color),m_start(start),m_dest(dest)
00046 {
00047 checkCoordsLegality();
00048 }
00049
00058 Move(int color, const BoardCoord& start, const BoardCoord& dest, const ParameterMap& parameters)
00059 :m_legal(true),m_color(color),m_start(start),m_dest(dest),m_parameters(parameters)
00060 {
00061 checkCoordsLegality();
00062 }
00063
00068 void setProperty(const std::string & name, int value)
00069 {
00070
00071 m_parameters[name] = value;
00072 }
00073
00078 bool hasProperty(const std::string& name)const
00079 {
00080 const ParameterMap::const_iterator itProp = m_parameters.find(name);
00081 if ( itProp != m_parameters.end() )
00082 {
00083 return true;
00084 }
00085
00086 return false;
00087 }
00088
00093 int getProperty(const std::string& name)const
00094 {
00095 const ParameterMap::const_iterator itProp = m_parameters.find(name);
00096 if ( itProp != m_parameters.end() )
00097 {
00098 return itProp->second;
00099 }
00100
00101
00102 return -1;
00103 }
00104
00108 bool isLegal()const { return m_legal; }
00109
00112 void invalidate() { m_legal = false; }
00113
00117 int color()const { return m_color; }
00118
00122 const BoardCoord& start()const { return m_start; }
00123
00127 const BoardCoord& dest()const { return m_dest; }
00128 };
00129
00152 #endif