00001
00002
00003
00004
00005
00006
00007 #ifndef GO_BOOK_H
00008 #define GO_BOOK_H
00009
00010 #include <iosfwd>
00011 #include <map>
00012 #include <string>
00013 #include <vector>
00014 #include "GtpEngine.h"
00015 #include "SgHash.h"
00016 #include "SgPoint.h"
00017
00018 class GoBoard;
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class GoGtpEngine;
00040
00041 class GoBook
00042 {
00043 public:
00044 class Entry
00045 {
00046 public:
00047
00048 int m_size;
00049
00050
00051 int m_line;
00052
00053 std::vector<SgPoint> m_sequence;
00054
00055 std::vector<SgPoint> m_moves;
00056
00057
00058 void ApplyTo(GoBoard& bd) const;
00059 };
00060
00061
00062
00063
00064
00065 void Add(const GoBoard& bd, SgPoint move);
00066
00067 void Clear();
00068
00069
00070
00071
00072 void Delete(const GoBoard& bd, SgPoint move);
00073
00074
00075
00076
00077
00078 const Entry& GetEntry(std::size_t index) const;
00079
00080
00081
00082
00083
00084
00085 int Line(const GoBoard& bd) const;
00086
00087
00088
00089
00090 SgPoint LookupMove(const GoBoard& bd) const;
00091
00092 std::vector<SgPoint> LookupAllMoves(const GoBoard& bd) const;
00093
00094 std::size_t NuEntries() const;
00095
00096
00097
00098
00099
00100 void Read(std::istream& in, const std::string& streamName = "");
00101
00102
00103 void Read(const std::string& filename);
00104
00105 void Write(std::ostream& out) const;
00106
00107 void WriteInfo(std::ostream& out) const;
00108
00109 private:
00110 class MapEntry
00111 {
00112 public:
00113
00114
00115
00116
00117
00118 int m_size;
00119
00120
00121 std::size_t m_id;
00122
00123
00124 int m_rotation;
00125 };
00126
00127 typedef std::multimap<SgHashCode,MapEntry> Map;
00128
00129 bool m_warningMaxSizeShown;
00130
00131 int m_lineCount;
00132
00133 std::string m_streamName;
00134
00135 std::vector<Entry> m_entries;
00136
00137
00138 Map m_map;
00139
00140 void InsertEntry(const std::vector<SgPoint>& sequence,
00141 const std::vector<SgPoint>& moves, int size,
00142 GoBoard& tempBoard, int line);
00143
00144 const GoBook::MapEntry* LookupEntry(const GoBoard& bd) const;
00145
00146 void ParseLine(const std::string& line, GoBoard& tempBoard);
00147
00148 std::vector<SgPoint> ReadPoints(std::istream& in) const;
00149
00150 void ThrowError(const std::string& message) const;
00151 };
00152
00153 inline const GoBook::Entry& GoBook::GetEntry(std::size_t index) const
00154 {
00155 SG_ASSERT(index < m_entries.size());
00156 return m_entries[index];
00157 }
00158
00159 inline std::size_t GoBook::NuEntries() const
00160 {
00161 return m_entries.size();
00162 }
00163
00164
00165
00166
00167 class GoBookCommands
00168 {
00169 public:
00170 GoBookCommands(GoGtpEngine &engine, const GoBoard& bd, GoBook& book);
00171
00172 void AddGoGuiAnalyzeCommands(GtpCommand& cmd);
00173
00174 void Register(GtpEngine& e);
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 void CmdAdd(GtpCommand& cmd);
00191 void CmdClear(GtpCommand& cmd);
00192 void CmdDelete(GtpCommand& cmd);
00193 void CmdInfo(GtpCommand& cmd);
00194 void CmdLoad(GtpCommand& cmd);
00195 void CmdMoves(GtpCommand& cmd);
00196 void CmdPosition(GtpCommand& cmd);
00197 void CmdSave(GtpCommand& cmd);
00198 void CmdSaveAs(GtpCommand& cmd);
00199
00200
00201 private:
00202 GoGtpEngine &m_engine;
00203
00204 const GoBoard& m_bd;
00205
00206 GoBook& m_book;
00207
00208 std::string m_fileName;
00209
00210 void PositionInfo(GtpCommand& cmd);
00211 };
00212
00213
00214
00215 #endif // GO_BOOK_H