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