pathEncoding.h
Go to the documentation of this file.
/* pathEncoding.h
*/
#ifndef OSL_PATH_ENCODING_H
#define OSL_PATH_ENCODING_H
#include "osl/basic_type.h"
#include "osl/container.h"
#include <iosfwd>
namespace osl
{
class PathEncodingTable
{
public:
static const size_t MaxEncodingLength = 256;
private:
typedef CArray<CArray2d<unsigned long long, Square::SIZE, PTYPE_SIZE>,
MaxEncodingLength> array_t;
array_t values;
public:
void init();
unsigned long long get(size_t depth, Square pos, Ptype ptype) const
{
return values[depth][pos.index()][ptype-PTYPE_MIN];
}
unsigned long long get(size_t depth, Move m) const
{
const Square from = m.from();
const Square to = m.to();
const Ptype fromPtype = m.oldPtype();
const Ptype toPtype = m.ptype();
depth %= 256;
return get(depth, from, fromPtype) + get(depth, to, toPtype) + 1;
}
};
extern PathEncodingTable Path_Encoding_Table;
class PathEncoding
{
unsigned long long path;
int depth;
public:
explicit PathEncoding(int d=0) : path(0), depth(d)
{
}
explicit PathEncoding(Player turn, int d=0)
: path((turn == BLACK) ? 0 : 1), depth(d)
{
}
PathEncoding(const PathEncoding& org, Move m)
: path(org.path), depth(org.depth)
{
pushMove(m);
}
Player turn() const { return (path % 2) ? WHITE : BLACK; }
void pushMove(Move m)
{
assert(m.player() == turn());
path += Path_Encoding_Table.get(depth, m);
++depth;
}
void popMove(Move m)
{
--depth;
path -= Path_Encoding_Table.get(depth, m);
assert(m.player() == turn());
}
unsigned long long getPath() const { return path; }
int getDepth() const { return depth; }
};
inline bool operator==(const PathEncoding& l, const PathEncoding& r)
{
return l.getPath() == r.getPath();
}
inline bool operator!=(const PathEncoding& l, const PathEncoding& r)
{
return !(l == r);
}
std::ostream& operator<<(std::ostream&, const PathEncoding&);
} // namespace osl
#endif /* OSL_PATH_ENCODING_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; coding:utf-8
// ;;; c-basic-offset:2
// ;;; End:
basic_type.h
osl::CArray
Definition container.h:20
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::ptype
Ptype ptype() const
Definition basic_type.h:1155
osl::Move::player
Player player() const
Definition basic_type.h:1195
osl::Move::oldPtype
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition basic_type.h:1174
osl::Move::to
const Square to() const
Definition basic_type.h:1132
osl::Move::from
const Square from() const
Definition basic_type.h:1125
osl::PathEncodingTable
Definition pathEncoding.h:12
osl::PathEncodingTable::MaxEncodingLength
static const size_t MaxEncodingLength
Definition pathEncoding.h:14
osl::PathEncodingTable::values
array_t values
Definition pathEncoding.h:18
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::PathEncodingTable::init
void init()
Definition pathEncoding.cc:18
osl::PathEncodingTable::array_t
CArray< CArray2d< unsigned long long, Square::SIZE, PTYPE_SIZE >, MaxEncodingLength > array_t
Definition pathEncoding.h:17
osl::PathEncoding::popMove
void popMove(Move m)
Definition pathEncoding.h:63
osl::PathEncoding::getPath
unsigned long long getPath() const
Definition pathEncoding.h:69
osl::PathEncoding::depth
int depth
Definition pathEncoding.h:42
osl::PathEncoding::getDepth
int getDepth() const
Definition pathEncoding.h:70
osl::PathEncoding::PathEncoding
PathEncoding(int d=0)
Definition pathEncoding.h:44
osl::PathEncoding::pushMove
void pushMove(Move m)
Definition pathEncoding.h:57
osl::PathEncoding::path
unsigned long long path
Definition pathEncoding.h:41
osl::PathEncoding::PathEncoding
PathEncoding(const PathEncoding &org, Move m)
Definition pathEncoding.h:51
osl::PathEncoding::PathEncoding
PathEncoding(Player turn, int d=0)
Definition pathEncoding.h:47
osl::PathEncoding::turn
Player turn() const
Definition pathEncoding.h:56
osl::Square
Definition basic_type.h:532
osl::Square::index
unsigned int index() const
Definition basic_type.h:572
container.h
PathEncoding
Definition pathEncoding.cc:12
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::PTYPE_MIN
@ PTYPE_MIN
Definition basic_type.h:102
osl::operator!=
bool operator!=(Offset l, Offset r)
Definition basic_type.h:516
osl::Player
Player
Definition basic_type.h:8
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::Path_Encoding_Table
PathEncodingTable Path_Encoding_Table
Definition pathEncoding.cc:8
osl::operator<<
std::ostream & operator<<(std::ostream &os, Player player)
Definition basic_type.cc:14
osl::operator==
bool operator==(Square l, Square r)
Definition basic_type.h:758