Skip to content

Commit 039fed8

Browse files
committed
v2.5
1 parent 54fe4ae commit 039fed8

36 files changed

+5906
-3515
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@ Cinnamon is a chess program for Windows, Linux, Mac OS, Android and Raspberry Pi
88

99
Version
1010
----------
11-
2.4
11+
2.5
1212

1313
News
1414
----------
15-
- Reverse Futility Pruning
16-
- Stalemate improvement
17-
- Trasposition Table improvement
18-
- Bug fix in castle
19-
- Bug fix in en passant
20-
- Speeded up Perft
21-
- Compilable with MS Visual Studio
15+
- Time management
16+
- Tapered eval
2217

2318
Useful links
2419
----------
25-
- [Cinnamon written in Rust](https://github.com/gekomad/cinnamon_r)
2620
- [Bitboard Calculator](https://gekomad.github.io/Cinnamon/BitboardCalculator/)
2721
- [Auriga Distributed Perft](https://github.com/gekomad/Auriga)
2822
- [Web Eval debugger](https://github.com/gekomad/chess-engine-eval-debugger)

src/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
cmake_minimum_required(VERSION 3.17)
1+
cmake_minimum_required(VERSION 3.16)
22
project(cinnamon_debug)
33

44
# debug
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-braced-scalar-init -fsanitize=address -mbmi2 -DUSE_BMI2 -g -DDEBUG_MODE -pthread -Wall -Wpedantic -W -std=c++11 -DDLOG_LEVEL=_TRACE -funroll-loops -msse4.2 -DHAS_POPCNT -mpopcnt -msse3 -DHAS_BSF -m64 ")
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftrapv -fwrapv -fsanitize=address -mbmi2 -DUSE_BMI2 -g -pthread -Wall -Wpedantic -W -std=c++11 -DDLOG_LEVEL=_TRACE -funroll-loops -msse4.2 -DHAS_POPCNT -mpopcnt -msse3 -DHAS_BSF -m64 ")
66

77
# bench
8-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-braced-scalar-init -mbmi2 -DUSE_BMI2 -pthread -Wpedantic -W -DBENCH_MODE -std=c++11 -DDLOG_LEVEL=_FATAL -Wall -O3 -DNDEBUG -funroll-loops -msse4.2 -DHAS_POPCNT -mpopcnt -msse3 -DHAS_BSF -m64 ")
8+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi2 -DUSE_BMI2 -pthread -Wpedantic -W -DBENCH_MODE -std=c++11 -DDLOG_LEVEL=_FATAL -Wall -O3 -DNDEBUG -funroll-loops -msse4.2 -DHAS_POPCNT -mpopcnt -msse3 -DHAS_BSF -m64 ")
9+
10+
# release
11+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi2 -DUSE_BMI2 -pthread -Wpedantic -W -std=c++11 -DDLOG_LEVEL=_FATAL -Wall -O3 -DNDEBUG -funroll-loops -msse4.2 -DHAS_POPCNT -mpopcnt -msse3 -DHAS_BSF -m64 ")
912

1013
# unit test
11-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-braced-scalar-init -fsanitize=address -g -pthread -Wall -Wpedantic -W -std=c++11 -DDLOG_LEVEL=_TRACE -DFULL_TEST -DDEBUG_MODE -funroll-loops -msse4.2 -DHAS_POPCNT -mpopcnt -msse3 -DHAS_BSF -m64 ")
14+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -O3 -pthread -Wall -Wpedantic -W -std=c++11 -DDLOG_LEVEL=_TRACE -DFULL_TEST -funroll-loops -msse4.2 -DHAS_POPCNT -mpopcnt -msse3 -DHAS_BSF -m64 ")
1215

1316
# tuning
14-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-braced-scalar-init -mbmi2 -DUSE_BMI2 -O3 -pthread -Wall -Wpedantic -W -std=c++11 -DTUNING -DNDEBUG -DDLOG_LEVEL=_FATAL -funroll-loops -msse4.2 -DHAS_POPCNT -mpopcnt -msse3 -DHAS_BSF -m64 ")
17+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi2 -DUSE_BMI2 -O3 -pthread -Wall -Wpedantic -W -std=c++11 -DTUNING -DNDEBUG -DDLOG_LEVEL=_FATAL -funroll-loops -msse4.2 -DHAS_POPCNT -mpopcnt -msse3 -DHAS_BSF -m64 ")
1518

1619
include_directories(db/gtb)
1720
include_directories(db/gtb/compression)
@@ -99,7 +102,7 @@ set(SOURCE_FILES
99102
Uci.cpp
100103
Uci.h
101104
unistd.h
102-
)
105+
db/TB.h)
103106

104107
set(CMAKE_CXX_COMPILER "clang++")
105108
add_executable(cinnamon_debug ${SOURCE_FILES})

src/ChessBoard.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ void ChessBoard::makeZobristKey() {
4343

4444
for (u64 x2 = rightCastle; x2; RESET_LSB(x2)) {
4545
const int position = BITScanForward(x2);
46-
updateZobristKey(RIGHT_CASTLE_IDX, position);//12
46+
updateZobristKey(RIGHT_CASTLE_RAND, position);//12
4747
}
4848

4949
if (enPassant != NO_ENPASSANT) {
50-
updateZobristKey(ENPASSANT_IDX, enPassant);//13
50+
updateZobristKey(ENPASSANT_RAND, enPassant);//13
5151
}
52-
53-
updateZobristKey(SIDETOMOVE_IDX, sideToMove); //14
52+
static constexpr uchar SIDETOMOVE_RAND = 14;
53+
updateZobristKey(SIDETOMOVE_RAND, sideToMove);
5454

5555
}
5656

@@ -159,19 +159,16 @@ void ChessBoard::display() const {
159159
cout << endl;
160160
}
161161

162-
string ChessBoard::moveToString(const _Tmove *move) {
163-
string a = decodeBoardinv(move->type, move->from, move->side);
164-
if (move->type & 0xc) return a;
165-
string b = decodeBoardinv(move->type, move->to, move->side);
166-
if (move->promotionPiece != NO_PROMOTION) (a + b) += (char) tolower(FEN_PIECE[move->promotionPiece]);
167-
return a + b;
168-
}
169-
170162
void ChessBoard::print(const _Tmove *move) {
171-
cout << moveToString(move) << " " << flush;
163+
cout << decodeBoardinv(move, move->side) << " " << flush;
172164
}
173165

174-
string ChessBoard::decodeBoardinv(const uchar type, const int a, const uchar side) {
166+
string
167+
ChessBoard::decodeBoardinv(const _Tmove *move, const uchar side, const bool verbose) {
168+
const uchar type = move->type;
169+
const int from = move->from;
170+
const int to = move->to;
171+
const int promotionPiece = move->promotionPiece;
175172
if (type & QUEEN_SIDE_CASTLE_MOVE_MASK && side == WHITE) {
176173
return isChess960() ? BOARD[startPosWhiteKing] + BOARD[startPosWhiteRookQueenSide] : "e1c1";
177174
}
@@ -185,17 +182,24 @@ string ChessBoard::decodeBoardinv(const uchar type, const int a, const uchar sid
185182
return isChess960() ? BOARD[startPosBlackKing] + BOARD[startPosBlackRookKingSide] : "e8g8";
186183
}
187184
assert(!(type & 0xC));
188-
if (a >= 0 && a < 64) {
189-
return BOARD[a];
185+
assert (to >= 0 && to < 64);
186+
string cap = "";
187+
string res = "";
188+
if (verbose) {
189+
if (move->capturedPiece != SQUARE_EMPTY) cap = "*"; else cap = "-";
190+
}
191+
res = BOARD[from] + cap + BOARD[to];
192+
if (promotionPiece != NO_PROMOTION) {
193+
res += tolower(FEN_PIECE[promotionPiece]);
190194
}
191-
_assert(0)
195+
return res;
192196
}
193197

194198
void ChessBoard::clearChessboard() {
195199
memset(chessboard, 0, sizeof(_Tchessboard));
196200
enPassant = NO_ENPASSANT;
197201
rightCastle = 0;
198-
sideToMove=0;
202+
sideToMove = 0;
199203
}
200204

201205
int ChessBoard::loadFen(const string &fen) {
@@ -226,7 +230,7 @@ int ChessBoard::loadFen(const string &fen) {
226230
iss >> a2;
227231
a2 += " 1";
228232
if (String::isNumber(a2))
229-
movesCount = stoi(a2);
233+
movesCount = stoi(a2);
230234

231235
int ix = 0;
232236
array<int, 64> s;
@@ -268,28 +272,28 @@ int ChessBoard::loadFen(const string &fen) {
268272
startPosBlackKing = BITScanForward(chessboard[KING_BLACK]);
269273
auto whiteRookKingSide = [&](const char c) {
270274
startPosWhiteRookKingSide = BITScanForward(chessboard[ROOK_WHITE] & 0xffULL);
271-
updateZobristKey(RIGHT_CASTLE_IDX, 4);
275+
updateZobristKey(RIGHT_CASTLE_RAND, 4);
272276
assert(4 == BITScanForward(RIGHT_KING_CASTLE_WHITE_MASK));
273277
rightCastle |= RIGHT_KING_CASTLE_WHITE_MASK;
274278
whiteRookKingSideCastle = c;
275279
};
276280
auto blackRookKingSide = [&](const char c) {
277281
startPosBlackRookKingSide = BITScanForward(chessboard[ROOK_BLACK] & 0xff00000000000000ULL);
278-
updateZobristKey(RIGHT_CASTLE_IDX, 6);
282+
updateZobristKey(RIGHT_CASTLE_RAND, 6);
279283
assert(6 == BITScanForward(RIGHT_KING_CASTLE_BLACK_MASK));
280284
rightCastle |= RIGHT_KING_CASTLE_BLACK_MASK;
281285
blackRookKingSideCastle = c;
282286
};
283287
auto whiteRookQueenSide = [&](const char c) {
284288
startPosWhiteRookQueenSide = BITScanReverse(chessboard[ROOK_WHITE] & 0xffULL);
285-
updateZobristKey(RIGHT_CASTLE_IDX, 5);
289+
updateZobristKey(RIGHT_CASTLE_RAND, 5);
286290
assert(5 == BITScanForward(RIGHT_QUEEN_CASTLE_WHITE_MASK));
287291
rightCastle |= RIGHT_QUEEN_CASTLE_WHITE_MASK;
288292
whiteRookQueenSideCastle = c;
289293
};
290294
auto blackRookQueenSide = [&](const char c) {
291295
startPosBlackRookQueenSide = BITScanReverse(chessboard[ROOK_BLACK] & 0xff00000000000000ULL);
292-
updateZobristKey(RIGHT_CASTLE_IDX, 7);
296+
updateZobristKey(RIGHT_CASTLE_RAND, 7);
293297
assert(7 == BITScanForward(RIGHT_QUEEN_CASTLE_BLACK_MASK));
294298
rightCastle |= RIGHT_QUEEN_CASTLE_BLACK_MASK;
295299
blackRookQueenSideCastle = c;
@@ -347,7 +351,7 @@ int ChessBoard::loadFen(const string &fen) {
347351
} else {
348352
enPassant += 8;
349353
}
350-
updateZobristKey(ENPASSANT_IDX, enPassant);
354+
updateZobristKey(ENPASSANT_RAND, enPassant);
351355
break;
352356
}
353357
}

src/ChessBoard.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ChessBoard {
4444
public:
4545
ChessBoard();
4646

47-
string decodeBoardinv(const uchar type, const int a, const uchar side);
47+
string decodeBoardinv(const _Tmove *move, const uchar side, const bool verbose = false);
4848

4949
virtual ~ChessBoard();
5050

@@ -54,10 +54,6 @@ class ChessBoard {
5454

5555
void clearChessboard();
5656

57-
const _Tchessboard &getChessboard() const {
58-
return chessboard;
59-
}
60-
6157
void setSide(const bool b) {
6258
sideToMove = b;
6359
}
@@ -72,10 +68,17 @@ class ChessBoard {
7268

7369
string boardToFen() const;
7470

71+
uchar rightCastle;
72+
73+
uchar enPassant;
7574
uchar sideToMove;
76-
protected:
75+
76+
void print(const _Tmove *move);
7777

7878
_Tchessboard chessboard;
79+
protected:
80+
81+
7982
uchar startPosWhiteKing;
8083
uchar startPosWhiteRookKingSide;
8184
uchar startPosWhiteRookQueenSide;
@@ -84,9 +87,7 @@ class ChessBoard {
8487
uchar startPosBlackRookKingSide;
8588
uchar startPosBlackRookQueenSide;
8689

87-
uchar rightCastle;
8890

89-
uchar enPassant;
9091
string MATCH_QUEENSIDE;
9192
string MATCH_QUEENSIDE_WHITE;
9293
string MATCH_KINGSIDE_WHITE;
@@ -98,9 +99,8 @@ class ChessBoard {
9899

99100
void makeZobristKey();
100101

101-
void print(const _Tmove *move);
102102

103-
#ifdef DEBUG_MODE
103+
#ifndef NDEBUG
104104

105105
void updateZobristKey(int piece, int position) {
106106
ASSERT_RANGE(position, 0, 63)
@@ -119,7 +119,5 @@ class ChessBoard {
119119
char blackRookKingSideCastle;
120120
char blackRookQueenSideCastle;
121121

122-
string moveToString(const _Tmove *move);
123-
124122
int loadFen();
125123
};

0 commit comments

Comments
 (0)