Skip to content

Commit

Permalink
v2.3.4 - fix forfeit issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gekomad committed Nov 19, 2020
1 parent 5aefe6c commit 124b0bf
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 162 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Cinnamon is a chess program for Windows, Linux, Mac OS, Android and Raspberry Pi

Version
----------
2.3.3
2.3.4

News
----------
Expand Down
42 changes: 4 additions & 38 deletions src/Eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ Eval::~Eval() {
evalHash = nullptr;
}

template<int side>
void Eval::openFile() {
structureEval.openFile = 0;
structureEval.semiOpenFile[side] = 0;

for (u64 side_rooks = chessboard[ROOK_BLACK + side]; side_rooks; RESET_LSB(side_rooks)) {
const int o = BITScanForward(side_rooks);
if (!(FILE_[o] & (chessboard[WHITE] | chessboard[BLACK])))
structureEval.openFile |= FILE_[o];
else if (FILE_[o] & chessboard[side ^ 1])
structureEval.semiOpenFile[side] |= FILE_[o];
}
}

/**
* evaluate pawns for color at phase
* 1. if no pawns returns -NO_PAWNS
Expand Down Expand Up @@ -313,7 +299,7 @@ int Eval::evaluateQueen(const u64 enemies) {
*/

template<int side, Eval::_Tphase phase>
int Eval::evaluateKnight(const u64 enemiesPawns, const u64 notMyBits) {
int Eval::evaluateKnight(const u64 notMyBits) {
INC(evaluationCount[side]);
u64 knight = chessboard[KNIGHT_BLACK + side];
if (!knight) return 0;
Expand Down Expand Up @@ -469,21 +455,12 @@ int Eval::evaluateKing(int side, u64 squares) {
ADD(SCORE_DEBUG.DISTANCE_KING[side], DISTANCE_KING_OPENING[pos_king]);
result = DISTANCE_KING_OPENING[pos_king];
}
u64 POW2_king = POW2[pos_king];

//mobility
ASSERT(bitCount(squares & NEAR_MASK1[pos_king]) < (int) (sizeof(MOB_KING[phase]) / sizeof(int)))
result += MOB_KING[phase][bitCount(squares & NEAR_MASK1[pos_king])];
ADD(SCORE_DEBUG.MOB_KING[side], MOB_KING[phase][bitCount(squares & NEAR_MASK1[pos_king])]);
if (phase != OPEN) {
if ((structureEval.openFile & POW2_king) || (structureEval.semiOpenFile[side ^ 1] & POW2_king)) {
ADD(SCORE_DEBUG.END_OPENING_KING[side], -END_OPENING);
result -= END_OPENING;
if (bitCount(RANK[pos_king]) < 4) {
ADD(SCORE_DEBUG.END_OPENING_KING[side], -END_OPENING);
result -= END_OPENING;
}
}
}

ASSERT(pos_king < 64)
if (!(NEAR_MASK1[pos_king] & chessboard[side])) {
ADD(SCORE_DEBUG.PAWN_NEAR_KING[side], -PAWN_NEAR_KING);
Expand Down Expand Up @@ -547,9 +524,6 @@ short Eval::getScore(const u64 key, const int side, const int alpha, const int b
structureEval.posKingBit[WHITE] = POW2[structureEval.posKing[WHITE]];
structureEval.kingAttackers[WHITE] = structureEval.kingAttackers[BLACK] = 0;

openFile<WHITE>();
openFile<BLACK>();

_Tresult Tresult;
switch (phase) {
case OPEN :
Expand Down Expand Up @@ -596,12 +570,6 @@ short Eval::getScore(const u64 key, const int side, const int alpha, const int b
} else {
cout << " END\n";
}
cout << "|OPEN FILE: ";
if (!structureEval.openFile)cout << "none";
else
for (int i = 0; i < 8; i++) if (POW2[i] & structureEval.openFile)cout << (char) (65 + i) << " ";
cout << "\n";


cout << "|VALUES:";
cout << "\tPAWN: " << (double) constants::VALUEPAWN / 100.0;
Expand Down Expand Up @@ -737,9 +705,7 @@ short Eval::getScore(const u64 key, const int side, const int alpha, const int b
cout << "| distance: " << setw(10) <<
(double) (SCORE_DEBUG.DISTANCE_KING[WHITE]) / 100.0 << setw(10) <<
(double) (SCORE_DEBUG.DISTANCE_KING[BLACK]) / 100.0 << "\n";
cout << "| open file: " << setw(10) <<
(double) (SCORE_DEBUG.END_OPENING_KING[WHITE]) / 100.0 << setw(10) <<
(double) (SCORE_DEBUG.END_OPENING_KING[BLACK]) / 100.0 << "\n";

cout << "| pawn near: " << setw(10) <<
(double) (SCORE_DEBUG.PAWN_NEAR_KING[WHITE]) / 100.0 << setw(10) <<
(double) (SCORE_DEBUG.PAWN_NEAR_KING[BLACK]) / 100.0 << "\n";
Expand Down
19 changes: 5 additions & 14 deletions src/Eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class Eval: public GenMoves {
return lazyEvalSide<side>() - lazyEvalSide<side ^ 1>();
}

#ifdef DEBUG_MODE
unsigned lazyEvalCuts;
#endif
DEBUG(unsigned lazyEvalCuts)

protected:
STATIC_CONST int FUTIL_MARGIN = 154;
Expand All @@ -68,7 +66,6 @@ class Eval: public GenMoves {
STATIC_CONST int ENEMY_NEAR_KING = 2;
STATIC_CONST int FRIEND_NEAR_KING = 1;
STATIC_CONST int HALF_OPEN_FILE_Q = 3;
STATIC_CONST int END_OPENING = 6;
STATIC_CONST int BONUS2BISHOP = 18;
STATIC_CONST int BISHOP_PAWN_ON_SAME_COLOR = 5;
STATIC_CONST int CONNECTED_ROOKS = 7;
Expand Down Expand Up @@ -107,7 +104,6 @@ class Eval: public GenMoves {
int KING_SECURITY_KNIGHT[2];
int KING_SECURITY_ROOK[2];
int DISTANCE_KING[2];
int END_OPENING_KING[2];
int PAWN_NEAR_KING[2];
int MOB_KING[2];

Expand Down Expand Up @@ -158,9 +154,7 @@ class Eval: public GenMoves {
int kings[2];
} _Tresult;

#ifdef DEBUG_MODE
int evaluationCount[2];
#endif
DEBUG(int evaluationCount[2])

template<_Tphase phase>
void getRes(_Tresult &res) {
Expand Down Expand Up @@ -188,8 +182,8 @@ class Eval: public GenMoves {
BENCH(times->stop("eval rook"));

BENCH(times->start("eval knight"));
res.knights[BLACK] = evaluateKnight<BLACK, phase>(chessboard[WHITE], ~structureEval.allPiecesSide[BLACK]);
res.knights[WHITE] = evaluateKnight<WHITE, phase>(chessboard[BLACK], ~structureEval.allPiecesSide[WHITE]);
res.knights[BLACK] = evaluateKnight<BLACK, phase>(~structureEval.allPiecesSide[BLACK]);
res.knights[WHITE] = evaluateKnight<WHITE, phase>(~structureEval.allPiecesSide[WHITE]);
BENCH(times->stop("eval knight"));

BENCH(times->start("eval king"));
Expand All @@ -198,9 +192,6 @@ class Eval: public GenMoves {
BENCH(times->stop("eval king"));
}

template<int side>
void openFile();

template<int side, _Tphase phase>
int evaluatePawn();

Expand All @@ -211,7 +202,7 @@ class Eval: public GenMoves {
int evaluateQueen(const u64 enemies);

template<int side, _Tphase phase>
int evaluateKnight(const u64, const u64);
int evaluateKnight(const u64);

template<int side, Eval::_Tphase phase>
int evaluateRook(const u64, u64 enemies, u64 friends);
Expand Down
4 changes: 1 addition & 3 deletions src/GenMoves.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class GenMoves : public ChessBoard {

template<int side, uchar type>
bool inCheckSlow(const int from, const int to, const int pieceFrom, const int pieceTo, const int promotionPiece) {
bool result = false;
bool result;
switch (type & 0x3) {
case STANDARD_MOVE_MASK: {
u64 from1, to1 = -1;
Expand Down Expand Up @@ -622,9 +622,7 @@ class GenMoves : public ChessBoard {
_assert(0);
}

#ifdef DEBUG_MODE
ASSERT(!memcmp(&a, chessboard, sizeof(_Tchessboard)));
#endif
BENCH(times->stop("inCheck"))
return result;
}
Expand Down
14 changes: 5 additions & 9 deletions src/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ class Hash : public Singleton<Hash> {
if (zobristKeyR == (k ^ data)) {
return data;
}
#ifdef DEBUG_MODE
if (data)
readCollisions++;
#endif

DEBUG(if (data) readCollisions++)

return 0;
}

Expand All @@ -122,11 +121,8 @@ class Hash : public Singleton<Hash> {

_Thash *rootHashA = &(hashArray[HASH_GREATER][kMod]);

#ifdef DEBUG_MODE
if (rootHashA->u.dataU) {
INC(collisions);
}
#endif
DEBUG(if (rootHashA->u.dataU) INC(collisions))

if (rootHashA->u.dataS.depth >= tmp.dataS.depth && rootHashA->u.dataS.entryAge) {
return;
}
Expand Down
20 changes: 9 additions & 11 deletions src/IterativeDeeping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void IterativeDeeping::run() {

string tb = searchManager.probeRootTB();
if (!tb.empty()) {
debug("info string returned move from TB\n");
debug("info string returned move from TB\n")
_Tmove move;
searchManager.getMoveFromSan(tb, &move);
searchManager.makemove(&move);
Expand All @@ -119,24 +119,24 @@ void IterativeDeeping::run() {
int extension = 0;
string ponderMove;
searchManager.init();
int mateIn = INT_MAX;

string pvv;
_Tmove resultMove;

#ifdef DEBUG_MODE
u64 totMovesPrec = -1;
#endif

DEBUG(u64 totMovesPrec = -1)

while (searchManager.getRunning(0)) {
totMoves = 0;
++mply;
searchManager.init();

auto sc =searchManager.search(mply);
auto sc = searchManager.search(mply);

searchManager.setRunningThread(1);
searchManager.setRunning(1);
if (!searchManager.getRes(resultMove, ponderMove, pvv, &mateIn)) {
debug("IterativeDeeping cmove == 0. Exit");
if (!searchManager.getRes(resultMove, ponderMove, pvv)) {
debug("IterativeDeeping cmove == 0. Exit")
break;
}

Expand All @@ -146,7 +146,6 @@ void IterativeDeeping::run() {
timeTaken = Time::diffTime(end1, start1) + 1;
totMoves += searchManager.getTotMoves();


if (sc > _INFINITE - MAX_PLY) {
sc = 0x7fffffff;
}
Expand Down Expand Up @@ -236,8 +235,7 @@ void IterativeDeeping::run() {
if (searchManager.getForceCheck()) {
searchManager.setForceCheck(inMate);
searchManager.setRunning(1);

} else if (abs(sc) > _INFINITE - MAX_PLY) {
} else if (mply == 1 && abs(sc) > _INFINITE - MAX_PLY) {
searchManager.setForceCheck(true);
searchManager.setRunning(2);

Expand Down
6 changes: 3 additions & 3 deletions src/IterativeDeeping.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class IterativeDeeping : public Thread<IterativeDeeping> {

private:

#ifdef DEBUG_MODE
atomic_int checkSmp2;
#endif

DEBUG(atomic_int checkSmp2)

SearchManager &searchManager = Singleton<SearchManager>::getInstance();
int maxDepth;
string bestmove;
Expand Down
Loading

0 comments on commit 124b0bf

Please sign in to comment.