All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pathEncoding.h
Go to the documentation of this file.
1 /* pathEncoding.h
2  */
3 #ifndef OSL_PATH_ENCODING_H
4 #define OSL_PATH_ENCODING_H
5 
6 #include "osl/move.h"
7 #include "osl/misc/carray.h"
8 #include "osl/misc/carray2d.h"
9 #include <iosfwd>
10 namespace osl
11 {
13  {
14  public:
15  static const size_t MaxEncodingLength = 256;
16  private:
17  typedef CArray<CArray2d<unsigned long long, Square::SIZE, PTYPE_SIZE>,
20  public:
23  unsigned long long get(size_t depth, Square pos, Ptype ptype) const
24  {
25  return values[depth](pos.index(), ptype-PTYPE_MIN);
26  }
30  unsigned long long get(size_t depth, Move m) const
31  {
32  const Square from = m.from();
33  const Square to = m.to();
34  const Ptype fromPtype = m.oldPtype();
35  const Ptype toPtype = m.ptype();
36  depth %= 256;
37  return get(depth, from, fromPtype) + get(depth, to, toPtype) + 1;
38  }
39  };
40  extern const PathEncodingTable Path_Encoding_Table;
42  {
43  unsigned long long path;
44  int depth;
45  public:
46  explicit PathEncoding(int d=0) : path(0), depth(d)
47  {
48  }
49  explicit PathEncoding(Player turn, int d=0)
50  : path((turn == BLACK) ? 0 : 1), depth(d)
51  {
52  }
54  : path(org.path), depth(org.depth)
55  {
56  pushMove(m);
57  }
58  Player turn() const { return (path % 2) ? WHITE : BLACK; }
59  void pushMove(Move m)
60  {
61  assert(m.player() == turn());
63  ++depth;
64  }
65  void popMove(Move m)
66  {
67  --depth;
69  assert(m.player() == turn());
70  }
71  unsigned long long getPath() const { return path; }
72  int getDepth() const { return depth; }
73  };
74 
75  inline bool operator==(const PathEncoding& l, const PathEncoding& r)
76  {
77  return l.getPath() == r.getPath();
78  }
79  inline bool operator!=(const PathEncoding& l, const PathEncoding& r)
80  {
81  return !(l == r);
82  }
83  std::ostream& operator<<(std::ostream&, const PathEncoding&);
84 } // namespace osl
85 
86 #endif /* OSL_PATH_ENCODING_H */
87 // ;;; Local Variables:
88 // ;;; mode:c++
89 // ;;; c-basic-offset:2
90 // ;;; End: