| 1 |
/* sameBoardList.h |
| 2 |
*/ |
| 3 |
#ifndef _SAMEBOARDLIST_H |
| 4 |
#define _SAMEBOARDLIST_H |
| 5 |
|
| 6 |
#include "checkHashRecord.h" |
| 7 |
#include "checkAssert.h" |
| 8 |
#include "osl/checkmate/proofDisproof.h" |
| 9 |
#ifdef CHECKMATE_DEBUG |
| 10 |
# include "osl/stat/ratio.h" |
| 11 |
#endif |
| 12 |
#include "osl/stl/slist.h" |
| 13 |
|
| 14 |
namespace osl |
| 15 |
{ |
| 16 |
namespace checkmate |
| 17 |
{ |
| 18 |
/** |
| 19 |
* 同じ盤面(持駒は異なってよい)に関する CheckHashRecord のリスト. |
| 20 |
* ArrayCheckHashTable や DominanceTable が使う. |
| 21 |
*/ |
| 22 |
class SameBoardList |
| 23 |
{ |
| 24 |
public: |
| 25 |
typedef slist<CheckHashRecord> list_t; |
| 26 |
typedef list_t::iterator iterator; |
| 27 |
typedef list_t::const_iterator const_iterator; |
| 28 |
private: |
| 29 |
list_t colleagues; |
| 30 |
public: |
| 31 |
~SameBoardList(); |
| 32 |
void clear(); |
| 33 |
iterator begin() { return colleagues.begin(); } |
| 34 |
iterator end() { return colleagues.end(); } |
| 35 |
const_iterator begin() const { return colleagues.begin(); } |
| 36 |
const_iterator end() const { return colleagues.end(); } |
| 37 |
|
| 38 |
bool empty() const { return colleagues.empty(); } |
| 39 |
size_t size() const { return colleagues.size(); } |
| 40 |
size_t confirmNoVisitedRecords() const; |
| 41 |
CheckHashRecord *find(const PieceStand& black_stand) |
| 42 |
{ |
| 43 |
for (iterator p=begin(); p!=end(); ++p) |
| 44 |
{ |
| 45 |
if (p->stand(BLACK) == black_stand) |
| 46 |
return &*p; |
| 47 |
} |
| 48 |
return 0; |
| 49 |
} |
| 50 |
const CheckHashRecord *find(const PieceStand& black_stand) const |
| 51 |
{ |
| 52 |
for (const_iterator p=begin(); p!=end(); ++p) |
| 53 |
{ |
| 54 |
if (p->stand(BLACK) == black_stand) |
| 55 |
return &*p; |
| 56 |
} |
| 57 |
return 0; |
| 58 |
} |
| 59 |
private: |
| 60 |
inline static |
| 61 |
void setMoreProvable(unsigned int& proofLL, unsigned int& disproofUL, |
| 62 |
const CheckHashRecord *& final_by_dominance, |
| 63 |
CheckHashRecord& record); |
| 64 |
inline static |
| 65 |
void setLessProvable(unsigned int& proofUL, unsigned int& disproofLL, |
| 66 |
const CheckHashRecord *& final_by_dominance, |
| 67 |
CheckHashRecord& record); |
| 68 |
public: |
| 69 |
template <Player Attacker> |
| 70 |
CheckHashRecord *allocate(const PieceStand& black_stand, |
| 71 |
const PieceStand& white_stand, |
| 72 |
const PathEncoding& path, |
| 73 |
size_t& counter); |
| 74 |
CheckHashRecord *allocateSlow(Player attacker, |
| 75 |
const PieceStand& black_stand, |
| 76 |
const PieceStand& white_stand, |
| 77 |
const PathEncoding& path, |
| 78 |
size_t& counter); |
| 79 |
/** |
| 80 |
* 盤面が同じで攻方の持駒が多くisVisitedな CheckHashRecord があれば |
| 81 |
* 返す. |
| 82 |
*/ |
| 83 |
template <Player Attacker> |
| 84 |
const CheckHashRecord * |
| 85 |
findIneffectiveDropLoop(const PieceStand& black_stand) const |
| 86 |
{ |
| 87 |
for (list_t::const_iterator p=begin(); p!=end(); ++p) |
| 88 |
{ |
| 89 |
if (p->stand(BLACK) == black_stand) |
| 90 |
continue; |
| 91 |
if (p->stand(BLACK).template hasMoreThan<Attacker>(black_stand)) |
| 92 |
{ |
| 93 |
if (p->isVisited) // わざわざ持駒を少なくした |
| 94 |
{ |
| 95 |
return &*p; |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
return 0; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* @param isAttack 手番が攻方か受方か |
| 104 |
*/ |
| 105 |
template <bool isAttack> |
| 106 |
void updateSlow(Player attacker, |
| 107 |
CheckHashRecord& record, const PathEncoding& path) |
| 108 |
{ |
| 109 |
if (attacker == BLACK) |
| 110 |
{ |
| 111 |
check_assert(path.turn() == (isAttack ? BLACK : WHITE)); |
| 112 |
update<isAttack,BLACK>(record, path); |
| 113 |
} |
| 114 |
else |
| 115 |
{ |
| 116 |
check_assert(path.turn() == (isAttack ? WHITE : BLACK)); |
| 117 |
update<isAttack,WHITE>(record, path); |
| 118 |
} |
| 119 |
} |
| 120 |
void updateSlow(bool is_attack, Player attacker, |
| 121 |
CheckHashRecord& record, const PathEncoding& path); |
| 122 |
template <bool isAttack, Player Attacker> |
| 123 |
void update(CheckHashRecord& record, const PathEncoding& path); |
| 124 |
}; |
| 125 |
} // namespace checkmate |
| 126 |
} // namespace osl |
| 127 |
|
| 128 |
#endif /* _SAMEBOARDLIST_H */ |
| 129 |
// ;;; Local Variables: |
| 130 |
// ;;; mode:c++ |
| 131 |
// ;;; c-basic-offset:2 |
| 132 |
// ;;; End: |