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/basic_type.h"
7 #include "osl/container.h"
8 #include <iosfwd>
9 namespace osl
10 {
12  {
13  public:
14  static const size_t MaxEncodingLength = 256;
15  private:
17  MaxEncodingLength> array_t;
18  array_t values;
19  public:
20  void init();
21  unsigned long long get(size_t depth, Square pos, Ptype ptype) const
22  {
23  return values[depth][pos.index()][ptype-PTYPE_MIN];
24  }
28  unsigned long long get(size_t depth, Move m) const
29  {
30  const Square from = m.from();
31  const Square to = m.to();
32  const Ptype fromPtype = m.oldPtype();
33  const Ptype toPtype = m.ptype();
34  depth %= 256;
35  return get(depth, from, fromPtype) + get(depth, to, toPtype) + 1;
36  }
37  };
40  {
41  unsigned long long path;
42  int depth;
43  public:
44  explicit PathEncoding(int d=0) : path(0), depth(d)
45  {
46  }
47  explicit PathEncoding(Player turn, int d=0)
48  : path((turn == BLACK) ? 0 : 1), depth(d)
49  {
50  }
52  : path(org.path), depth(org.depth)
53  {
54  pushMove(m);
55  }
56  Player turn() const { return (path % 2) ? WHITE : BLACK; }
57  void pushMove(Move m)
58  {
59  assert(m.player() == turn());
60  path += Path_Encoding_Table.get(depth, m);
61  ++depth;
62  }
63  void popMove(Move m)
64  {
65  --depth;
66  path -= Path_Encoding_Table.get(depth, m);
67  assert(m.player() == turn());
68  }
69  unsigned long long getPath() const { return path; }
70  int getDepth() const { return depth; }
71  };
72 
73  inline bool operator==(const PathEncoding& l, const PathEncoding& r)
74  {
75  return l.getPath() == r.getPath();
76  }
77  inline bool operator!=(const PathEncoding& l, const PathEncoding& r)
78  {
79  return !(l == r);
80  }
81  std::ostream& operator<<(std::ostream&, const PathEncoding&);
82 } // namespace osl
83 
84 #endif /* OSL_PATH_ENCODING_H */
85 // ;;; Local Variables:
86 // ;;; mode:c++
87 // ;;; coding:utf-8
88 // ;;; c-basic-offset:2
89 // ;;; End:
std::ostream & operator<<(std::ostream &os, Player player)
Definition: basic_type.cc:14
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:83
CArray< CArray2d< unsigned long long, Square::SIZE, PTYPE_SIZE >, MaxEncodingLength > array_t
Definition: pathEncoding.h:17
unsigned long long getPath() const
Definition: pathEncoding.h:69
PathEncoding(int d=0)
Definition: pathEncoding.h:44
unsigned long long path
Definition: pathEncoding.h:41
圧縮していない moveの表現 .
Definition: basic_type.h:1051
PathEncodingTable Path_Encoding_Table
Definition: pathEncoding.cc:8
PathEncoding(Player turn, int d=0)
Definition: pathEncoding.h:47
Player player() const
Definition: basic_type.h:1195
static const size_t MaxEncodingLength
Definition: pathEncoding.h:14
PathEncoding(const PathEncoding &org, Move m)
Definition: pathEncoding.h:51
Player
Definition: basic_type.h:8
void popMove(Move m)
Definition: pathEncoding.h:63
bool operator==(Square l, Square r)
Definition: basic_type.h:758
bool operator!=(Offset l, Offset r)
Definition: basic_type.h:516
int getDepth() const
Definition: pathEncoding.h:70
Player turn() const
Definition: pathEncoding.h:56
unsigned long long get(size_t depth, Square pos, Ptype ptype) const
Definition: pathEncoding.h:21
void pushMove(Move m)
Definition: pathEncoding.h:57