Skip to content

Commit dd735c8

Browse files
author
Jesper Torp Kristensen
committed
Fixed error and restructure
1 parent b9d04a8 commit dd735c8

34 files changed

+3021
-3378
lines changed

default.set

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Endgame_output_preprocessed_bdd_tables = false
5555
Endgame_mark_unreachable_as_dont_cares = true
5656

5757
// if 0, then only static test is performed, otherwise n moves is tried undone
58-
Endgame_unreachability_depth_test = 3
58+
Endgame_unreachability_depth_test = 0
5959

6060
Endgame_directory = "endgames/"
6161

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ chess: $(MODS)
1414
g++ $(MODS) -o $@
1515

1616
%.o: %.cxx
17-
$(CXX) $(CFLAGS) -c -o $@ $<
17+
$(CXX) $(CFLAGS_DB) -c -o $@ $<
1818

1919
%.d: %.cxx
2020
g++ -MM $< -o $@

src/board.cxx

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -328,33 +328,31 @@ bool Board::set_board(vector<PiecePos> &piece_list, int player_turn,
328328
reset_all();
329329

330330
int king_pos[2];
331-
#define wking_pos king_pos[WHITE]
332-
#define bking_pos king_pos[BLACK]
333-
wking_pos = bking_pos = -1;
331+
king_pos[WHITE] = king_pos[BLACK] = -1;
334332

335333
// Find position of kings
336334
for (uint i=0; i<piece_list.size(); i++) {
337335
if (piece_list[i].piece == WKING) {
338-
assert(wking_pos == -1);
339-
wking_pos = piece_list[i].pos;
336+
assert(king_pos[WHITE] == -1);
337+
king_pos[WHITE] = piece_list[i].pos;
340338
}
341339
if (piece_list[i].piece == BKING) {
342-
assert(bking_pos == -1);
343-
bking_pos = piece_list[i].pos;
340+
assert(king_pos[BLACK] == -1);
341+
king_pos[BLACK] = piece_list[i].pos;
344342
}
345343
}
346-
assert(wking_pos != -1 && bking_pos != -1);
344+
assert(king_pos[WHITE] != -1 && king_pos[BLACK] != -1);
347345

348-
if (abs(COLUMN[wking_pos]-COLUMN[bking_pos]) <= 1 &&
349-
abs(ROW[wking_pos]-ROW[bking_pos]) <= 1) return false;// kings to close
346+
if (abs(COLUMN[king_pos[WHITE]]-COLUMN[king_pos[BLACK]]) <= 1 &&
347+
abs(ROW[king_pos[WHITE]]-ROW[king_pos[BLACK]]) <= 1) return false;// kings to close
350348

351349
Position en_passant_unique_encoding = 0;
352350

353351
{ // Decode castling/en passant
354352
Piece tmp_board[64];
355353
memset(tmp_board, 0, 64);
356-
tmp_board[wking_pos] = WKING;
357-
tmp_board[bking_pos] = BKING;
354+
tmp_board[king_pos[WHITE]] = WKING;
355+
tmp_board[king_pos[BLACK]] = BKING;
358356

359357
int transf = -1;
360358

@@ -387,21 +385,21 @@ bool Board::set_board(vector<PiecePos> &piece_list, int player_turn,
387385
if (rook_color) {
388386
if (king_color) {
389387
// black rook on own king => short castling
390-
piece_list[i].pos = DECODE_SHORT_CASTLING_ROOK[bking_pos];
388+
piece_list[i].pos = DECODE_SHORT_CASTLING_ROOK[king_pos[BLACK]];
391389
_castling |= BLACK_SHORT_CASTLING;
392390
} else {
393391
// black rook on opponent king => long castling
394-
piece_list[i].pos = DECODE_LONG_CASTLING_ROOK[bking_pos];
392+
piece_list[i].pos = DECODE_LONG_CASTLING_ROOK[king_pos[BLACK]];
395393
_castling |= BLACK_LONG_CASTLING;
396394
}
397395
} else {
398396
if (king_color) {
399397
// white rook on opponent king => long castling
400-
piece_list[i].pos = DECODE_LONG_CASTLING_ROOK[wking_pos];
398+
piece_list[i].pos = DECODE_LONG_CASTLING_ROOK[king_pos[WHITE]];
401399
_castling |= WHITE_LONG_CASTLING;
402400
} else {
403401
// white rook on own king => short castling
404-
piece_list[i].pos = DECODE_SHORT_CASTLING_ROOK[wking_pos];
402+
piece_list[i].pos = DECODE_SHORT_CASTLING_ROOK[king_pos[WHITE]];
405403
_castling |= WHITE_SHORT_CASTLING;
406404
}
407405
}
@@ -501,19 +499,16 @@ bool Board::set_board(vector<PiecePos> &piece_list, int player_turn,
501499
// Do the transformation
502500
for (uint i=0; i<piece_list.size(); i++)
503501
piece_list[i].pos = reflect(piece_list[i].pos, transf);
504-
wking_pos = reflect(wking_pos, transf);
505-
bking_pos = reflect(bking_pos, transf);
502+
king_pos[WHITE] = reflect(king_pos[WHITE], transf);
503+
king_pos[BLACK] = reflect(king_pos[BLACK], transf);
506504

507505

508506
if (_en_passant != ILLEGAL_POS)
509507
_en_passant = reflect(_en_passant, transf);
510508
}
511509
}
512510

513-
place_kings(wking_pos, bking_pos);
514-
515-
#undef wking_pos
516-
#undef bking_pos
511+
place_kings(king_pos[WHITE], king_pos[BLACK]);
517512

518513
for (unsigned int i=0; i<piece_list.size(); i++) {
519514
if (PIECE_KIND[piece_list[i].piece] != KING) {
@@ -1025,22 +1020,6 @@ string Board::toFEN() const {
10251020
s[index] = 0;
10261021
return s;
10271022
}
1028-
/*
1029-
a b c d e f g h
1030-
+-----------------+ |
1031-
8 | | 8 | 1b
1032-
7 | | 7 |
1033-
6 | | 6 | White has lost castling
1034-
5 | | 5 | Black has lost castling
1035-
4 | P p | 4 |
1036-
3 | e | 3 | moves played since progress = 0
1037-
2 | | 2 |
1038-
1 | K k | 1 | en passant at a3
1039-
+-----------------+ |
1040-
a b c d e f g h
1041-
loadfen 8/8/8/8/Pp6/8/8/K3k3 b - a3
1042-
index database
1043-
*/
10441023

10451024

10461025
//#############################################################

src/board.hxx

Lines changed: 45 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ extern const string game_status_texts[7];
156156
#define DB_ARRAY_LENGTH (3*DB_BQUEEN_VALUE+1)
157157
extern const int ENDGAME_HASHING_CONSTANTS[13];
158158

159-
// Nothing may evaluate to more/less than +/-WIN
160-
#define INF 0x7FFFFFFF
161-
#define WIN 0x003FFFFF
162-
163159
extern const uint PIECE_COUNT_CONSTANTS[13];
164160
extern const uint ENDGAME_HASHING_INSUFFICIENT_MATERIAL_CONSTANTS[13][2];
165161

@@ -250,11 +246,11 @@ void print_map64(ostream &os, TYPE *list64, int num_digits=0, int base=10) {
250246
template <class TYPE>
251247
void print_latex_map64(ostream &os, TYPE *list64, int num_digits=0, int base=10) {
252248
os << "{\\setlength\\tabcolsep{0.7\\tabcolsep}\n"
253-
<< "\\begin{footnotesize}\n"
254-
<< "\\begin{center}\n"
255-
<< "\\begin{tabular}{c|cccccccc|c}\n"
256-
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
257-
<< "\\cline{2-9}\n";
249+
<< "\\begin{footnotesize}\n"
250+
<< "\\begin{center}\n"
251+
<< "\\begin{tabular}{c|cccccccc|c}\n"
252+
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
253+
<< "\\cline{2-9}\n";
258254

259255
for (int r=7; r>=0; r--) {
260256
os << (r+1) << " & ";
@@ -266,11 +262,11 @@ void print_latex_map64(ostream &os, TYPE *list64, int num_digits=0, int base=10)
266262
}
267263

268264
os << "\\cline{2-9}\n"
269-
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
270-
<< "\\end{tabular}\n"
271-
<< "\\end{center}\n"
272-
<< "\\end{footnotesize}\n"
273-
<< "}\n";
265+
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
266+
<< "\\end{tabular}\n"
267+
<< "\\end{center}\n"
268+
<< "\\end{footnotesize}\n"
269+
<< "}\n";
274270
}
275271

276272
// TYPE is signed value
@@ -309,11 +305,11 @@ void print_signed_map64(OSTREAM &os, TYPE *list64, int num_digits=0, int base=10
309305
template <class TYPE>
310306
void print_latex_signed_map64(ostream &os, TYPE *list64, int num_digits=0, int base=10) {
311307
os << "{\\setlength\\tabcolsep{0.7\\tabcolsep}\n"
312-
<< "\\begin{footnotesize}\n"
313-
<< "\\begin{center}\n"
314-
<< "\\begin{tabular}{c|cccccccc|c}\n"
315-
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
316-
<< "\\cline{2-9}\n";
308+
<< "\\begin{footnotesize}\n"
309+
<< "\\begin{center}\n"
310+
<< "\\begin{tabular}{c|cccccccc|c}\n"
311+
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
312+
<< "\\cline{2-9}\n";
317313

318314
for (int r=7; r>=0; r--) {
319315
os << (r+1) << " & ";
@@ -325,11 +321,11 @@ void print_latex_signed_map64(ostream &os, TYPE *list64, int num_digits=0, int b
325321
}
326322

327323
os << "\\cline{2-9}\n"
328-
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
329-
<< "\\end{tabular}\n"
330-
<< "\\end{center}\n"
331-
<< "\\end{footnotesize}\n"
332-
<< "}\n";
324+
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
325+
<< "\\end{tabular}\n"
326+
<< "\\end{center}\n"
327+
<< "\\end{footnotesize}\n"
328+
<< "}\n";
333329
}
334330

335331
// TYPE is signed value
@@ -350,12 +346,12 @@ void print_string_map64(ostream &os, TYPE *list64, int padded_length) {
350346
os << (r+1) << " |";
351347
for (int c=0; c<8; c++) {
352348
for (int i=list64[8*r+c].size(); i<=padded_length; i++)
353-
os << ' ';
349+
os << ' ';
354350
os << list64[8*r+c];
355351
}
356352
os << " | " << (r+1) << '\n';
357353
}
358-
354+
359355
os << " +";
360356
for (int i=0; i<=padded_length; i++) os << "--------";
361357
os << "-+\n";
@@ -371,29 +367,29 @@ void print_string_map64(ostream &os, TYPE *list64, int padded_length) {
371367
template <class TYPE>
372368
void print_latex_string_map64(ostream &os, TYPE *list64, int padded_length) {
373369
os << "{\\setlength\\tabcolsep{0.7\\tabcolsep}\n"
374-
<< "\\begin{footnotesize}\n"
375-
<< "\\begin{center}\n"
376-
<< "\\begin{tabular}{c|cccccccc|c}\n"
377-
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
378-
<< "\\cline{2-9}\n";
370+
<< "\\begin{footnotesize}\n"
371+
<< "\\begin{center}\n"
372+
<< "\\begin{tabular}{c|cccccccc|c}\n"
373+
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
374+
<< "\\cline{2-9}\n";
379375

380376
for (int r=7; r>=0; r--) {
381377
os << (r+1) << " & ";
382378
for (int c=0; c<8; c++) {
383379
if (c) os << '&';
384380
for (int i=list64[8*r+c].size(); i<padded_length; i++)
385-
os << ' ';
381+
os << ' ';
386382
os << list64[8*r+c];
387383
}
388384
os << " & " << (r+1) << "\\\\\n";
389385
}
390386

391387
os << "\\cline{2-9}\n"
392-
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
393-
<< "\\end{tabular}\n"
394-
<< "\\end{center}\n"
395-
<< "\\end{footnotesize}\n"
396-
<< "}\n";
388+
<< "\\multicolumn{1}{c}{}& a& b& c& d& e& f& g&\\multicolumn{1}{c}{h}\\\\\n"
389+
<< "\\end{tabular}\n"
390+
<< "\\end{center}\n"
391+
<< "\\end{footnotesize}\n"
392+
<< "}\n";
397393
}
398394

399395
//################################
@@ -434,8 +430,8 @@ public:
434430
// If so, piece_list, _castling and _en_passant are updated accordingly.
435431
// piece_list might be changed if piece overlap encodes castling
436432
bool set_board(vector<PiecePos> &piece_list, int player_turn,
437-
int &_castling, int &_en_passant,// use 0, ILLEGAL_POS as default
438-
int _moves_played_since_progress = 0, int full_move_number = 50);
433+
int &_castling, int &_en_passant,// use 0, ILLEGAL_POS as default
434+
int _moves_played_since_progress = 0, int full_move_number = 50);
439435
bool set_board(vector<PiecePos> &piece_list, int player_turn) {
440436
int _castling = 0;
441437
int _en_passant = ILLEGAL_POS;
@@ -447,15 +443,17 @@ public:
447443
int index = 0;
448444
for (int i=0; i<64; i++)
449445
if (board[i]) {
450-
assert((uint)index < l.size());
451-
l[index++] = PiecePos(board[i], i);
446+
assert((uint)index < l.size());
447+
l[index++] = PiecePos(board[i], i);
452448
}
453449
assert((uint)index == l.size());
454450
}
455-
// get_encoded_piece_list encodes en passant and castling in the position of the pieces
456-
// (castling only encoded if ENDGAME_TABLE_WITH_CASTLING==1)
457-
void get_encoded_piece_list(vector<PiecePos> &l) const;
458451

452+
/**
453+
* get_encoded_piece_list encodes en passant and castling in the position of the pieces
454+
* (castling only encoded if ENDGAME_TABLE_WITH_CASTLING==1)
455+
*/
456+
void get_encoded_piece_list(vector<PiecePos> &l) const;
459457

460458
// returns b7b6b5b4b3b2b1b0. bi is 1 iff transformation i is legal
461459
uchar allowed_symmetries() {
@@ -503,8 +501,8 @@ public:
503501
}
504502
uchar get_num_pawns() const {
505503
return get_num_pieces() - 2 -
506-
(piece_count.individual.num_non_zugzwang_pieces & 0xF) -
507-
(piece_count.individual.num_non_zugzwang_pieces >> 4);
504+
(piece_count.individual.num_non_zugzwang_pieces & 0xF) -
505+
(piece_count.individual.num_non_zugzwang_pieces >> 4);
508506
}
509507

510508
bool get_insufficient_material_a() const {
@@ -521,7 +519,7 @@ public:
521519
}
522520

523521
int get_moves_played() { return moves_played; }
524-
522+
525523
bool played_from_scratch;
526524
string initial_position;
527525

@@ -585,23 +583,6 @@ protected:
585583
// In half-moves. Eg. in move 5.b moves_played is 2*(5-1)+1
586584
int moves_played;
587585

588-
/*
589-
// Keep track of the number of each type of pieces
590-
uchar piece_count[13];
591-
592-
// Returns true if the numbers of pieces can be reached from the initial position.
593-
// Ie. max 15 pieces (not counting king). 6 rooks and 6 queens not possible.
594-
bool valid_piece_count(bool player) {
595-
if (player) {
596-
return 15 >= max(0, piece_count[BKNIGHT]-2) + max(0, piece_count[BBISHOP]-2)
597-
+ max(0, piece_count[BROOK]-2) + max(0, piece_count[BQUEEN]-1) + piece_count[BPAWN];
598-
} else {
599-
return 15 >= max(0, piece_count[WKNIGHT]-2) + max(0, piece_count[WBISHOP]-2)
600-
+ max(0, piece_count[WROOK]-2) + max(0, piece_count[WQUEEN]-1) + piece_count[WPAWN];
601-
}
602-
}
603-
*/
604-
605586
union {
606587
struct {
607588
// WARNING: big-little endian dependent code

src/board_2.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,9 +1306,7 @@ Move Board2::sanToMove(string san) {
13061306

13071307
//########################################################
13081308

1309-
// Nemmest kun at tillade null move hvis en_passant mulig
1310-
// Nødvendig hvis der er skak
1311-
bool Board2::try_execute_null_move() {
1309+
bool Board2::make_null_move() {
13121310
if (num_checks || en_passant != ILLEGAL_POS) return false;
13131311
player ^= 1;
13141312
++moves_played;

src/board_2.hxx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,12 @@ public:
2020

2121
virtual bool loadFEN(string FEN);
2222

23-
// Only used by endgame table generator (?)
24-
/*
25-
bool set_player(bool new_player) {
26-
if (player == new_player) return true;
27-
if (num_checks) return false;
28-
return Board::set_player(new_player);
29-
}
30-
*/
31-
3223
Move moves() const;
3324
Move moves_from_pos(Position pos) const;
3425
Move moves_to_dest(Position dest) const;
3526
Move moves_from_to(Position pos, Position dest) const;
3627

37-
// If you are only interestet in one kind of pieces,
28+
// If you are only interested in one kind of pieces,
3829
// specify which one (the kind - eg. QUEEN instead of BQUEEN)
3930
bool next_move(Move &move, Piece piece_kind = 0) const;
4031

@@ -117,8 +108,10 @@ public:
117108
// If this is not posible, the depth which fails are returned. Otherwise 0.
118109
int unreachable_position(int test_depth);
119110

120-
121-
virtual bool try_execute_null_move();
111+
/**
112+
* Returns true if successful.
113+
*/
114+
virtual bool make_null_move();
122115
virtual void undo_null_move();
123116

124117
Position get_king_position(int stm) { return king_pos[stm]; }

0 commit comments

Comments
 (0)