00001 //---------------------------------------------------------------------------- 00002 /** @file CacheBook.hpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef CACHEBOOK_HPP 00007 #define CACHEBOOK_HPP 00008 00009 #include "Hex.hpp" 00010 #include "HexState.hpp" 00011 00012 _BEGIN_BENZENE_NAMESPACE_ 00013 00014 //---------------------------------------------------------------------------- 00015 00016 /** Uses previously-generated opening moves that have been recorded 00017 to prevent re-computing them. 00018 00019 A cache book is just a map of state hashes to HexPoints. 00020 00021 Not using StateMap since may not want same behaviour in rotated positions. 00022 */ 00023 00024 class CacheBook 00025 { 00026 public: 00027 CacheBook(); 00028 bool Exists(const HexState& state) const; 00029 HexPoint& operator[](const HexState& state); 00030 std::size_t Size() const; 00031 00032 private: 00033 std::map<hash_t, HexPoint> m_map; 00034 00035 void ParseFile(std::ifstream& inFile); 00036 std::vector<HexPoint> ReadPoints(std::istringstream& in) const; 00037 }; 00038 00039 inline bool CacheBook::Exists(const HexState& state) const 00040 { 00041 return m_map.find(state.Hash()) != m_map.end(); 00042 } 00043 00044 inline HexPoint& CacheBook::operator[](const HexState& state) 00045 { 00046 return m_map[state.Hash()]; 00047 } 00048 00049 inline std::size_t CacheBook::Size() const 00050 { 00051 return m_map.size(); 00052 } 00053 00054 //---------------------------------------------------------------------------- 00055 00056 _END_BENZENE_NAMESPACE_ 00057 00058 #endif // CACHEBOOK_HPP