Skip to content

Commit 3abccdc

Browse files
committed
Move classify_leaf() to c'tor in bitbases
No functional change.
1 parent 8d6d022 commit 3abccdc

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/bitbase.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ namespace {
5555

5656
struct KPKPosition {
5757

58-
operator Result() const { return res; }
59-
Result classify_leaf(unsigned idx);
58+
KPKPosition(unsigned idx);
59+
operator Result() const { return result; }
6060
Result classify(const std::vector<KPKPosition>& db)
6161
{ return us == WHITE ? classify<WHITE>(db) : classify<BLACK>(db); }
6262

@@ -65,7 +65,7 @@ namespace {
6565

6666
Color us;
6767
Square bksq, wksq, psq;
68-
Result res;
68+
Result result;
6969
};
7070

7171
} // namespace
@@ -83,11 +83,12 @@ bool Bitbases::probe_kpk(Square wksq, Square wpsq, Square bksq, Color us) {
8383
void Bitbases::init_kpk() {
8484

8585
unsigned idx, repeat = 1;
86-
std::vector<KPKPosition> db(IndexMax);
86+
std::vector<KPKPosition> db;
87+
db.reserve(IndexMax);
8788

8889
// Initialize db with known win / draw positions
8990
for (idx = 0; idx < IndexMax; idx++)
90-
db[idx].classify_leaf(idx);
91+
db.push_back(KPKPosition(idx));
9192

9293
// Iterate through the positions until no more of the unknown positions can be
9394
// changed to either wins or draws (15 cycles needed).
@@ -104,33 +105,32 @@ void Bitbases::init_kpk() {
104105

105106
namespace {
106107

107-
Result KPKPosition::classify_leaf(unsigned idx) {
108+
KPKPosition::KPKPosition(unsigned idx) {
108109

109110
wksq = Square((idx >> 0) & 0x3F);
110111
bksq = Square((idx >> 6) & 0x3F);
111112
us = Color ((idx >> 12) & 0x01);
112113
psq = File ((idx >> 13) & 0x03) | Rank(RANK_7 - (idx >> 15));
114+
result = UNKNOWN;
113115

114116
// Check if two pieces are on the same square or if a king can be captured
115117
if ( square_distance(wksq, bksq) <= 1 || wksq == psq || bksq == psq
116118
|| (us == WHITE && (StepAttacksBB[PAWN][psq] & bksq)))
117-
return res = INVALID;
119+
result = INVALID;
118120

119-
if (us == WHITE)
121+
else if (us == WHITE)
120122
{
121123
// Immediate win if pawn can be promoted without getting captured
122124
if ( rank_of(psq) == RANK_7
123125
&& wksq != psq + DELTA_N
124126
&& ( square_distance(bksq, psq + DELTA_N) > 1
125127
||(StepAttacksBB[KING][wksq] & (psq + DELTA_N))))
126-
return res = WIN;
128+
result = WIN;
127129
}
128130
// Immediate draw if is stalemate or king captures undefended pawn
129131
else if ( !(StepAttacksBB[KING][bksq] & ~(StepAttacksBB[KING][wksq] | StepAttacksBB[PAWN][psq]))
130132
|| (StepAttacksBB[KING][bksq] & psq & ~StepAttacksBB[KING][wksq]))
131-
return res = DRAW;
132-
133-
return res = UNKNOWN;
133+
result = DRAW;
134134
}
135135

136136
template<Color Us>
@@ -165,9 +165,9 @@ namespace {
165165
}
166166

167167
if (Us == WHITE)
168-
return res = r & WIN ? WIN : r & UNKNOWN ? UNKNOWN : DRAW;
168+
return result = r & WIN ? WIN : r & UNKNOWN ? UNKNOWN : DRAW;
169169
else
170-
return res = r & DRAW ? DRAW : r & UNKNOWN ? UNKNOWN : WIN;
170+
return result = r & DRAW ? DRAW : r & UNKNOWN ? UNKNOWN : WIN;
171171
}
172172

173173
} // namespace

0 commit comments

Comments
 (0)