mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Move KPKBitbase[] where it belongs
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
d653aeca05
commit
c1c0984452
3 changed files with 21 additions and 55 deletions
|
@ -47,13 +47,23 @@ namespace {
|
||||||
|
|
||||||
const int IndexMax = 2 * 24 * 64 * 64;
|
const int IndexMax = 2 * 24 * 64 * 64;
|
||||||
|
|
||||||
|
uint8_t KPKBitbase[IndexMax / 8];
|
||||||
|
|
||||||
Result classify_wtm(const KPKPosition& pos, const Result bb[]);
|
Result classify_wtm(const KPKPosition& pos, const Result bb[]);
|
||||||
Result classify_btm(const KPKPosition& pos, const Result bb[]);
|
Result classify_btm(const KPKPosition& pos, const Result bb[]);
|
||||||
int compute_index(Square wksq, Square bksq, Square psq, Color stm);
|
int compute_index(Square wksq, Square bksq, Square wpsq, Color stm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void generate_kpk_bitbase(uint8_t bitbase[]) {
|
int probe_kpk_bitbase(Square wksq, Square wpsq, Square bksq, Color stm) {
|
||||||
|
|
||||||
|
int index = compute_index(wksq, bksq, wpsq, stm);
|
||||||
|
|
||||||
|
return KPKBitbase[index / 8] & (1 << (index & 7));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void init_kpk_bitbase() {
|
||||||
|
|
||||||
bool repeat;
|
bool repeat;
|
||||||
int i, j, b;
|
int i, j, b;
|
||||||
|
@ -86,7 +96,7 @@ void generate_kpk_bitbase(uint8_t bitbase[]) {
|
||||||
|
|
||||||
} while (repeat);
|
} while (repeat);
|
||||||
|
|
||||||
// Compress result and map into supplied bitbase parameter
|
// Compress result and map into KPKBitbase[]
|
||||||
for (i = 0; i < 24576; i++)
|
for (i = 0; i < 24576; i++)
|
||||||
{
|
{
|
||||||
b = 0;
|
b = 0;
|
||||||
|
@ -94,16 +104,16 @@ void generate_kpk_bitbase(uint8_t bitbase[]) {
|
||||||
if (bb[8*i+j] == RESULT_WIN || bb[8*i+j] == RESULT_LOSS)
|
if (bb[8*i+j] == RESULT_WIN || bb[8*i+j] == RESULT_LOSS)
|
||||||
b |= (1 << j);
|
b |= (1 << j);
|
||||||
|
|
||||||
bitbase[i] = (uint8_t)b;
|
KPKBitbase[i] = (uint8_t)b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
int compute_index(Square wksq, Square bksq, Square psq, Color stm) {
|
int compute_index(Square wksq, Square bksq, Square wpsq, Color stm) {
|
||||||
|
|
||||||
int p = int(square_file(psq)) + (int(square_rank(psq)) - 1) * 4;
|
int p = int(square_file(wpsq)) + (int(square_rank(wpsq)) - 1) * 4;
|
||||||
int r = int(stm) + 2 * int(bksq) + 128 * int(wksq) + 8192 * p;
|
int r = int(stm) + 2 * int(bksq) + 128 * int(wksq) + 8192 * p;
|
||||||
|
|
||||||
assert(r >= 0 && r < IndexMax);
|
assert(r >= 0 && r < IndexMax);
|
||||||
|
|
|
@ -17,21 +17,13 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Includes
|
|
||||||
////
|
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "bitcount.h"
|
#include "bitcount.h"
|
||||||
#include "endgame.h"
|
#include "endgame.h"
|
||||||
#include "pawns.h"
|
#include "pawns.h"
|
||||||
|
|
||||||
|
extern int probe_kpk_bitbase(Square wksq, Square wpsq, Square bksq, Color stm);
|
||||||
////
|
|
||||||
//// Local definitions
|
|
||||||
////
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -69,9 +61,6 @@ namespace {
|
||||||
// and knight in KR vs KN endgames.
|
// and knight in KR vs KN endgames.
|
||||||
const int KRKNKingKnightDistancePenalty[8] = { 0, 0, 4, 10, 20, 32, 48, 70 };
|
const int KRKNKingKnightDistancePenalty[8] = { 0, 0, 4, 10, 20, 32, 48, 70 };
|
||||||
|
|
||||||
// Bitbase for KP vs K
|
|
||||||
uint8_t KPKBitbase[24576];
|
|
||||||
|
|
||||||
// Various inline functions for accessing the above arrays
|
// Various inline functions for accessing the above arrays
|
||||||
inline Value mate_table(Square s) {
|
inline Value mate_table(Square s) {
|
||||||
return Value(MateTable[s]);
|
return Value(MateTable[s]);
|
||||||
|
@ -89,23 +78,6 @@ namespace {
|
||||||
return Value(KRKNKingKnightDistancePenalty[d]);
|
return Value(KRKNKingKnightDistancePenalty[d]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function for probing the KP vs K bitbase
|
|
||||||
int probe_kpk(Square wksq, Square wpsq, Square bksq, Color stm);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Functions
|
|
||||||
////
|
|
||||||
|
|
||||||
/// init_bitbases() is called during program initialization, and simply loads
|
|
||||||
/// bitbases from disk into memory. At the moment, there is only the bitbase
|
|
||||||
/// for KP vs K, but we may decide to add other bitbases later.
|
|
||||||
extern void generate_kpk_bitbase(uint8_t bitbase[]);
|
|
||||||
|
|
||||||
void init_bitbases() {
|
|
||||||
generate_kpk_bitbase(KPKBitbase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,7 +176,7 @@ Value EvaluationFunction<KPK>::apply(const Position& pos) const {
|
||||||
wpsq = flop_square(wpsq);
|
wpsq = flop_square(wpsq);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!probe_kpk(wksq, wpsq, bksq, stm))
|
if (!probe_kpk_bitbase(wksq, wpsq, bksq, stm))
|
||||||
return VALUE_DRAW;
|
return VALUE_DRAW;
|
||||||
|
|
||||||
Value result = VALUE_KNOWN_WIN
|
Value result = VALUE_KNOWN_WIN
|
||||||
|
@ -890,21 +862,5 @@ ScaleFactor ScalingFunction<KPKP>::apply(const Position& pos) const {
|
||||||
|
|
||||||
// Probe the KPK bitbase with the weakest side's pawn removed. If it's a
|
// Probe the KPK bitbase with the weakest side's pawn removed. If it's a
|
||||||
// draw, it's probably at least a draw even with the pawn.
|
// draw, it's probably at least a draw even with the pawn.
|
||||||
return probe_kpk(wksq, wpsq, bksq, stm) ? SCALE_FACTOR_NONE : SCALE_FACTOR_ZERO;
|
return probe_kpk_bitbase(wksq, wpsq, bksq, stm) ? SCALE_FACTOR_NONE : SCALE_FACTOR_ZERO;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// Probe the KP vs K bitbase
|
|
||||||
|
|
||||||
int probe_kpk(Square wksq, Square wpsq, Square bksq, Color stm) {
|
|
||||||
|
|
||||||
int wp = square_file(wpsq) + 4 * (square_rank(wpsq) - 1);
|
|
||||||
int index = int(stm) + 2 * bksq + 128 * wksq + 8192 * wp;
|
|
||||||
|
|
||||||
assert(index >= 0 && index < 24576 * 8);
|
|
||||||
|
|
||||||
return KPKBitbase[index / 8] & (1 << (index & 7));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ using namespace std;
|
||||||
|
|
||||||
extern bool execute_uci_command(const string& cmd);
|
extern bool execute_uci_command(const string& cmd);
|
||||||
extern void benchmark(int argc, char* argv[]);
|
extern void benchmark(int argc, char* argv[]);
|
||||||
extern void init_bitbases();
|
extern void init_kpk_bitbase();
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ int main(int argc, char* argv[]) {
|
||||||
Position::init_zobrist();
|
Position::init_zobrist();
|
||||||
Position::init_piece_square_tables();
|
Position::init_piece_square_tables();
|
||||||
init_eval(1);
|
init_eval(1);
|
||||||
init_bitbases();
|
init_kpk_bitbase();
|
||||||
init_search();
|
init_search();
|
||||||
init_threads();
|
init_threads();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue