My Project
hashKey.cc
Go to the documentation of this file.
1#include "osl/hashKey.h"
2#include "osl/random.h"
3#include <iomanip>
4#include <cstdlib>
5#include <iostream>
6#include <sstream>
7
8static_assert(sizeof(osl::HashKey) == sizeof(int)*4, "hash key size");
9
15
17{
18 for (uint64_t& value: HashMajorPawn)
20 for (uint64_t& value: HashPiece)
22}
23
24#ifndef MINIMAL
25std::ostream& osl::hash::operator<<(std::ostream& os,const osl::hash::HashKey& h)
26{
27 os << h.pieceStand();
28 const BoardKey& board_key = h.boardKey();
29 for (size_t i=0; i<board_key.size(); ++i)
30 {
31 os << ':'
32 << std::setfill('0') << std::setbase(16) << std::setw(8)
33 << board_key[i];
34 }
35 return os << ':' << std::setbase(10);
36}
37
38void osl::hash::HashKey::dumpContents(std::ostream& os) const
39{
40 os << pieceStand().getFlags();
41 for (size_t i=0; i<size(); ++i) {
42 os << ' ' << operator[](i);
43 }
44}
45
47{
48 dumpContents(std::cerr);
49}
50#endif
51
53{
54 for(int num=0;num<40;num++){
55 Piece p=state.pieceOf(num);
56 if(state.usedMask().test(num))
58 }
59 setPlayer(state.turn());
60}
61
63newHashWithMove(Move move) const
64{
65 return newMakeMove(move);
66}
67
69newMakeMove(Move move) const
70{
71 HashKey ret(*this);
72 if (! move.isPass())
73 {
74 assert(move.isValid());
75 Square from=move.from();
76 Square to=move.to();
77 Ptype capturePtype=move.capturePtype();
78 PtypeO ptypeO=move.ptypeO();
79 PtypeO oldPtypeO=move.oldPtypeO();
80 if (capturePtype!=PTYPE_EMPTY)
81 {
82 PtypeO capturePtypeO=newPtypeO(alt(move.player()),capturePtype);
83 PtypeO capturedPtypeO=captured(capturePtypeO);
84
85 HashGenTable::subHashKey(ret,to,capturePtypeO);
86 HashGenTable::addHashKey(ret,Square::STAND(),capturedPtypeO);
87 }
88 HashGenTable::subHashKey(ret,from,oldPtypeO);
89 HashGenTable::addHashKey(ret,to,ptypeO);
90 }
91 ret.changeTurn();
92 return ret;
93}
94
96newUnmakeMove(Move move) const
97{
98 HashKey ret(*this);
99 if (! move.isPass())
100 {
101 assert(move.isValid());
102 Square from=move.from();
103 Square to=move.to();
104 Ptype capturePtype=move.capturePtype();
105 PtypeO ptypeO=move.ptypeO();
106 PtypeO oldPtypeO=move.oldPtypeO();
107 if (capturePtype!=PTYPE_EMPTY)
108 {
109 PtypeO capturePtypeO=newPtypeO(alt(move.player()),capturePtype);
110 PtypeO capturedPtypeO=captured(capturePtypeO);
111
112 HashGenTable::addHashKey(ret,to,capturePtypeO);
113 HashGenTable::subHashKey(ret,Square::STAND(),capturedPtypeO);
114 }
115 HashGenTable::addHashKey(ret,from,oldPtypeO);
116 HashGenTable::subHashKey(ret,to,ptypeO);
117 }
118 ret.changeTurn();
119 return ret;
120}
121
122namespace osl
123{
125 hash::HashGenTable::key = {
126#include "bits/hash.txt"
127 };
128}
129
130// ;;; Local Variables:
131// ;;; mode:c++
132// ;;; c-basic-offset:2
133// ;;; End:
圧縮していない moveの表現 .
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
bool isValid() const
Player player() const
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
bool isPass() const
Ptype capturePtype() const
const Square to() const
const Square from() const
bool test(int num) const
Definition pieceMask.h:45
PtypeO ptypeO() const
Definition basic_type.h:824
const Square square() const
Definition basic_type.h:832
Player turn() const
const PieceMask & usedMask() const
const Piece pieceOf(int num) const
Definition simpleState.h:76
static const Square STAND()
Definition basic_type.h:548
static void subHashKey(HashKey &hk, Square sq, PtypeO ptypeo)
Definition hashKey.h:176
static void addHashKey(HashKey &hk, Square sq, PtypeO ptypeo)
Definition hashKey.h:172
void setRandom()
乱数で初期化.
Definition hashKey.cc:10
const PieceStand pieceStand() const
Definition hashKey.h:63
const BoardKey96 boardKey() const
Definition hashKey.h:53
const HashKey newMakeMove(Move) const
Definition hashKey.cc:69
const HashKey newHashWithMove(Move move) const
Definition hashKey.cc:63
void dumpContentsCerr() const
Definition hashKey.cc:46
void dumpContents(std::ostream &os) const
Definition hashKey.cc:38
const HashKey newUnmakeMove(Move) const
Definition hashKey.cc:96
std::ostream & operator<<(std::ostream &os, const HashKey &h)
Definition hashKey.cc:25
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
@ PTYPE_EMPTY
Definition basic_type.h:85
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
constexpr Player alt(Player player)
Definition basic_type.h:13
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
Definition basic_type.h:264
size_t size() const
Definition hashKey.h:23