8#include <unordered_map>
16 boost::scoped_array<NumEffectState>
state;
18 typedef std::pair<const HashKey, std::pair<int, Move>>
entry_t;
19 typedef std::forward_list<const entry_t*>
list_t;
20 typedef std::unordered_map<BoardKey, list_t, std::hash<BoardKey>>
index_t;
38 depth = p->second.first;
39 best_move = p->second.second;
47 for (
const entry_t *q: p->second) {
48 assert(q->first.boardKey() == key.
boardKey());
49 if (attack ==
BLACK) {
50 if (q->first.blackStand().isSuperiorOrEqualTo(key.
blackStand())) {
51 if (q->second.first >=
depth)
54 if (q->second.first <
depth)
59 if (q->first.blackStand().isSuperiorOrEqualTo(key.
blackStand())) {
60 if (q->second.first <
depth)
63 if (q->second.first >=
depth)
88 table->state[0] = state;
89 return (is_or_node ?
orNode(key, dummy) :
andNode(key, dummy));
95 std::vector<Move>& pv)
const
97 table->state[0] = src;
100 for (
int i=0; i<
table->maxDepth(); ++i) {
102 if (is_or_node ^ (i%2))
109 table->state[0].makeMove(next);
119 if (height >=
table->maxDepth())
126 table->store(key, 1, best_move);
131 table->store(key, 3, best_move);
137 if (!
record.proof_disproof.isCheckmateSuccess()) {
143 if (
table->find(key, recorded, best_move))
148 if (!
record.best_move.isNormal())
159 new_record =
table->table.findProofOracle(new_key, next_white_stand,
record.best_move);
161 table->state[height+1] =
table->state[height];
167 best_move =
record.best_move;
179 if (height >=
table->maxDepth())
183 if (
table->find(key, recorded, best_move))
195 for (
size_t i=0; i<moves->size(); ++i)
198 if (i > 0 && !
table->expectMoreDepth(
alt((*moves)[i].player()), new_key, result))
200 table->state[height+1] =
table->state[height];
201 table->state[height+1].makeMove((*moves)[i]);
203 const int depth =
orNode(new_key, dummy, height+1);
207 if (result <
depth+1) {
209 best_move = (*moves)[i];
213 table->store(key, result, best_move);
bool isNormal() const
INVALID でも PASS でもない.
const PieceStand nextStand(Player pl, Move move) const
bool isSuperiorOrEqualTo(PieceStand other) const
static void generateEscape(const NumEffectState &, bool need_full_width, Square grand_parent_delay_last_to, DfpnMoveVector &)
Pは攻撃側
CheckMoveVector DfpnMoveVector
深さ固定で,その深さまで depth first searchで読む詰将棋.
const ProofDisproof hasCheckmateMoveOfTurn(int depth, Move &best_move)
証明数(proof number)と反証数(disproof number).
bool isCheckmateSuccess() const
std::unique_ptr< Table > table
int depth(const HashKey &key, const NumEffectState &state, bool is_or_node) const
ProofTreeDepthDfpn(const DfpnTable &table)
void retrievePV(const NumEffectState &state, bool is_or_node, std::vector< Move > &pv) const
int orNode(const HashKey &key, Move &best_move, int height=0) const
int andNode(const HashKey &key, Move &best_move, int height=0) const
const PieceStand blackStand() const
const BoardKey96 boardKey() const
const HashKey newMakeMove(Move) const
const HashKey newHashWithMove(Move move) const
constexpr Player alt(Player player)
ProofDisproof proof_disproof
bool find(const HashKey &key, int &depth, Move &best_move) const
std::pair< const HashKey, std::pair< int, Move > > entry_t
std::forward_list< const entry_t * > list_t
Table(const DfpnTable &t)
std::unordered_map< HashKey, std::pair< int, Move >, std::hash< HashKey > > map_t
std::unordered_map< BoardKey, list_t, std::hash< BoardKey > > index_t
void store(const HashKey &key, int depth, Move best_move=Move())
boost::scoped_array< NumEffectState > state
bool expectMoreDepth(Player attack, const HashKey &key, int depth) const