My Project
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:
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  };
38  extern PathEncodingTable Path_Encoding_Table;
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());
61  ++depth;
62  }
63  void popMove(Move m)
64  {
65  --depth;
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:
圧縮していない moveの表現 .
Definition: basic_type.h:1052
Ptype ptype() const
Definition: basic_type.h:1155
Player player() const
Definition: basic_type.h:1195
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition: basic_type.h:1174
const Square to() const
Definition: basic_type.h:1132
const Square from() const
Definition: basic_type.h:1125
static const size_t MaxEncodingLength
Definition: pathEncoding.h:14
unsigned long long get(size_t depth, Square pos, Ptype ptype) const
Definition: pathEncoding.h:21
unsigned long long get(size_t depth, Move m) const
Definition: pathEncoding.h:28
CArray< CArray2d< unsigned long long, Square::SIZE, PTYPE_SIZE >, MaxEncodingLength > array_t
Definition: pathEncoding.h:17
void popMove(Move m)
Definition: pathEncoding.h:63
unsigned long long getPath() const
Definition: pathEncoding.h:69
int getDepth() const
Definition: pathEncoding.h:70
PathEncoding(int d=0)
Definition: pathEncoding.h:44
void pushMove(Move m)
Definition: pathEncoding.h:57
unsigned long long path
Definition: pathEncoding.h:41
PathEncoding(const PathEncoding &org, Move m)
Definition: pathEncoding.h:51
PathEncoding(Player turn, int d=0)
Definition: pathEncoding.h:47
Player turn() const
Definition: pathEncoding.h:56
unsigned int index() const
Definition: basic_type.h:572
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
@ PTYPE_MIN
Definition: basic_type.h:102
bool operator!=(Offset l, Offset r)
Definition: basic_type.h:516
Player
Definition: basic_type.h:8
@ WHITE
Definition: basic_type.h:10
@ BLACK
Definition: basic_type.h:9
PathEncodingTable Path_Encoding_Table
Definition: pathEncoding.cc:8
std::ostream & operator<<(std::ostream &os, Player player)
Definition: basic_type.cc:14
bool operator==(Square l, Square r)
Definition: basic_type.h:758