説明を見る。00001
00002
00003 #ifndef OSL_PATH_ENCODING_H
00004 #define OSL_PATH_ENCODING_H
00005
00006 #include "osl/basic_type.h"
00007 #include "osl/container.h"
00008 #include <iosfwd>
00009 namespace osl
00010 {
00011 class PathEncodingTable
00012 {
00013 public:
00014 static const size_t MaxEncodingLength = 256;
00015 private:
00016 typedef CArray<CArray2d<unsigned long long, Square::SIZE, PTYPE_SIZE>,
00017 MaxEncodingLength> array_t;
00018 array_t values;
00019 public:
00020 void init();
00021 unsigned long long get(size_t depth, Square pos, Ptype ptype) const
00022 {
00023 return values[depth][pos.index()][ptype-PTYPE_MIN];
00024 }
00028 unsigned long long get(size_t depth, Move m) const
00029 {
00030 const Square from = m.from();
00031 const Square to = m.to();
00032 const Ptype fromPtype = m.oldPtype();
00033 const Ptype toPtype = m.ptype();
00034 depth %= 256;
00035 return get(depth, from, fromPtype) + get(depth, to, toPtype) + 1;
00036 }
00037 };
00038 extern PathEncodingTable Path_Encoding_Table;
00039 class PathEncoding
00040 {
00041 unsigned long long path;
00042 int depth;
00043 public:
00044 explicit PathEncoding(int d=0) : path(0), depth(d)
00045 {
00046 }
00047 explicit PathEncoding(Player turn, int d=0)
00048 : path((turn == BLACK) ? 0 : 1), depth(d)
00049 {
00050 }
00051 PathEncoding(const PathEncoding& org, Move m)
00052 : path(org.path), depth(org.depth)
00053 {
00054 pushMove(m);
00055 }
00056 Player turn() const { return (path % 2) ? WHITE : BLACK; }
00057 void pushMove(Move m)
00058 {
00059 assert(m.player() == turn());
00060 path += Path_Encoding_Table.get(depth, m);
00061 ++depth;
00062 }
00063 void popMove(Move m)
00064 {
00065 --depth;
00066 path -= Path_Encoding_Table.get(depth, m);
00067 assert(m.player() == turn());
00068 }
00069 unsigned long long getPath() const { return path; }
00070 int getDepth() const { return depth; }
00071 };
00072
00073 inline bool operator==(const PathEncoding& l, const PathEncoding& r)
00074 {
00075 return l.getPath() == r.getPath();
00076 }
00077 inline bool operator!=(const PathEncoding& l, const PathEncoding& r)
00078 {
00079 return !(l == r);
00080 }
00081 std::ostream& operator<<(std::ostream&, const PathEncoding&);
00082 }
00083
00084 #endif
00085
00086
00087
00088
00089