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>
9namespace 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の表現 .
Ptype ptype() const
Player player() const
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
const Square to() const
const Square from() const
static const size_t MaxEncodingLength
unsigned long long get(size_t depth, Square pos, Ptype ptype) const
unsigned long long get(size_t depth, Move m) const
CArray< CArray2d< unsigned long long, Square::SIZE, PTYPE_SIZE >, MaxEncodingLength > array_t
void popMove(Move m)
unsigned long long getPath() const
int getDepth() const
PathEncoding(int d=0)
void pushMove(Move m)
unsigned long long path
PathEncoding(const PathEncoding &org, Move m)
PathEncoding(Player turn, int d=0)
Player turn() const
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
std::ostream & operator<<(std::ostream &os, Player player)
Definition basic_type.cc:14
bool operator==(Square l, Square r)
Definition basic_type.h:758