Skip to content

Commit 0677d2e

Browse files
author
Jesper Torp Kristensen
committed
Refactoring: Got rid of uchar
1 parent 28ac00e commit 0677d2e

35 files changed

+822
-847
lines changed

src/board.hxx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public:
7777
void get_encoded_piece_list(vector<PiecePos> &l) const;
7878

7979
// returns b7b6b5b4b3b2b1b0. bi is 1 iff transformation i is legal
80-
uchar allowed_symmetries() {
80+
uint8_t allowed_symmetries() {
8181
if (castling) return 1;
8282
if (get_num_pawns()) return 1+2;
8383
return 0xFF;
@@ -87,7 +87,7 @@ public:
8787
bool transform_board(int transformation);
8888
bool inv_transform_board(int transformation) {
8989
assert(0<=transformation && transformation<8);
90-
const uchar INV[8] = {0,1,2,3,4,6,5,7};
90+
const uint8_t INV[8] = {0,1,2,3,4,6,5,7};
9191
return transform_board(INV[transformation]);
9292
}
9393

@@ -108,19 +108,19 @@ public:
108108
inline Position en_passant_square() const { return en_passant; }
109109

110110
inline bool not_all_castling_capabilities_lost() { return castling; }
111-
inline uchar get_castling_capabilities() { return castling; }
111+
inline uint8_t get_castling_capabilities() { return castling; }
112112

113-
inline uchar get_num_pieces() const {
113+
inline uint8_t get_num_pieces() const {
114114
return piece_count.individual.num_pieces;
115115
}
116-
inline uchar get_num_pieces(int player) const {
116+
inline uint8_t get_num_pieces(int player) const {
117117
return piece_count.individual.num_colored_pieces[player];
118118
}
119119
// Counts only knights, bishops, rooks and queens
120-
inline uchar get_num_non_zugzwang_pieces(int player) const {
120+
inline uint8_t get_num_non_zugzwang_pieces(int player) const {
121121
return (piece_count.individual.num_non_zugzwang_pieces >> (4*player)) & 0xF;
122122
}
123-
inline uchar get_num_pawns() const {
123+
inline uint8_t get_num_pawns() const {
124124
return get_num_pieces() - 2 -
125125
(piece_count.individual.num_non_zugzwang_pieces & 0xF) -
126126
(piece_count.individual.num_non_zugzwang_pieces >> 4);
@@ -175,10 +175,10 @@ protected:
175175
// WHITE_SHORT_CASTLING (2<<4)
176176
// BLACK_LONG_CASTLING (4<<4)
177177
// BLACK_SHORT_CASTLING (8<<4)
178-
uchar castling;
178+
uint8_t castling;
179179

180180
// If an uninvertible move was made last turn, moves_played_since_progress is 0
181-
uchar moves_played_since_progress;
181+
uint8_t moves_played_since_progress;
182182

183183
// player <=> blacks turn
184184
// player is not used as a part of the Undo struct. It is simply here
@@ -253,11 +253,11 @@ struct HashBoard {
253253
b.print_board(os);
254254
}
255255

256-
uchar board[32];
256+
uint8_t board[32];
257257

258258
Position en_passant;
259-
uchar castling;
260-
uchar moves_played_since_progress;
259+
uint8_t castling;
260+
uint8_t moves_played_since_progress;
261261
bool player;
262262

263263
int moves_played;

src/board_2.cxx

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
//##########################################
1616

17-
uchar CHECK_TABLE[0x10000];//is 0,1 or 2
18-
uchar DIRECTION[64][64];// "unsigned" direction: [0..3] or INVALID_DIRECTION or KNIGHT_DIRECTION
17+
uint8_t CHECK_TABLE[0x10000];//is 0,1 or 2
18+
uint8_t DIRECTION[64][64];// "unsigned" direction: [0..3] or INVALID_DIRECTION or KNIGHT_DIRECTION
1919

2020
// "signed" direction: [0..7] or INVALID_DIRECTION or KNIGHT_DIRECTION
2121
// SDIRECTION[x][y] is the direction from x to y
22-
uchar SDIRECTION[64][64];
22+
uint8_t SDIRECTION[64][64];
2323

2424
Position DIRECTION_MOVE_TABLE[8][64];
2525

@@ -902,7 +902,7 @@ void Board2::init_CHECK_TABLE() {
902902
for (int i=0; i<0x10000; i++) {
903903
for (int j=0; j<8; j++)
904904
L[j] = (i>>(2*j))&3;
905-
uchar check = 0;
905+
uint8_t check = 0;
906906
bool threat;
907907

908908
// Check in one direction:
@@ -1322,7 +1322,7 @@ bool Board2::find_legal_move(Move& move) {
13221322
// - hence the position would be illegal.
13231323
// prev_num_checks is the number of checks against black king after undoing the move.
13241324
// If prev_num_checks != 0, then threat_pos determines the position of one of the threats.
1325-
triple<int,uchar,Position> Board2::retro_move_count_checks(Position from, Position to,
1325+
triple<int,uint8_t,Position> Board2::retro_move_count_checks(Position from, Position to,
13261326
Piece original_piece, Piece piece_killed) {
13271327

13281328
int check_count = num_checks;
@@ -1332,7 +1332,7 @@ triple<int,uchar,Position> Board2::retro_move_count_checks(Position from, Positi
13321332
if (IS_SHORT_DISTANCE_PIECE[original_piece] &&
13331333
BIT_BOARDS[original_piece][from][king_pos[player]]) {
13341334
// This piece can't have moved from "from". It could have taken the king.
1335-
return triple<int,uchar,Position>(42,0,0);
1335+
return triple<int,uint8_t,Position>(42,0,0);
13361336
}
13371337

13381338
if (IS_SHORT_DISTANCE_PIECE[board[to]])
@@ -1426,13 +1426,13 @@ triple<int,uchar,Position> Board2::retro_move_count_checks(Position from, Positi
14261426

14271427
if (check_count) {
14281428
// No reason to proceed
1429-
return triple<int,uchar,Position>(check_count, 0, 0);
1429+
return triple<int,uint8_t,Position>(check_count, 0, 0);
14301430
}
14311431

14321432
//###############################################################################
14331433
//###############################################################################
14341434

1435-
uchar prev_num_checks = 0;
1435+
uint8_t prev_num_checks = 0;
14361436
Position threat_pos = ILLEGAL_POS;
14371437
{
14381438
if (PIECE_KIND[board[to]]==KING) {
@@ -1511,7 +1511,7 @@ triple<int,uchar,Position> Board2::retro_move_count_checks(Position from, Positi
15111511

15121512

15131513
{ // Check other long distance threats
1514-
const uchar *tmp = DIAG_PIECE_PATTERN[player ? WKING : BKING];
1514+
const uint8_t *tmp = DIAG_PIECE_PATTERN[player ? WKING : BKING];
15151515

15161516
for (int d=0; d<4; d++) {
15171517
uint pattern = board_lines[d][DIAG_INDEX[from][d]];
@@ -1609,7 +1609,7 @@ triple<int,uchar,Position> Board2::retro_move_count_checks(Position from, Positi
16091609
}
16101610
}
16111611

1612-
return triple<int,uchar,Position>(check_count, prev_num_checks, threat_pos);
1612+
return triple<int,uint8_t,Position>(check_count, prev_num_checks, threat_pos);
16131613
}
16141614

16151615
struct EnPassantPP {
@@ -1729,10 +1729,10 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
17291729
// Add one entry representing no en passant possible
17301730
ep_possibilities.push_back(EnPassantPP(ILLEGAL_POS, ILLEGAL_POS, ILLEGAL_POS));
17311731

1732-
const uchar LEGAL_FROM = 1;
1733-
const uchar LEGAL_TO = 2;
1734-
const uchar PAWN_2_FORWARD_NOT_ALLOWED = 4;
1735-
uchar LEGAL_FROM_TO[64];
1732+
const uint8_t LEGAL_FROM = 1;
1733+
const uint8_t LEGAL_TO = 2;
1734+
const uint8_t PAWN_2_FORWARD_NOT_ALLOWED = 4;
1735+
uint8_t LEGAL_FROM_TO[64];
17361736

17371737
if (get_num_pawns()) {
17381738
// if en passant is possible, then unique last move is that pawn 2 forward
@@ -1914,7 +1914,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
19141914
// rook/king move to p can gain castling capability.
19151915
// ADDED_CASTLING[p] is nonzero for a nonempty square, if a rook-capturing move
19161916
// is retracted, and the rook may have had castling capability before.
1917-
uchar ADDED_CASTLING[64];
1917+
uint8_t ADDED_CASTLING[64];
19181918
memset(ADDED_CASTLING, 0, 64);
19191919

19201920
{ // Find out if extra castling capabilities will be adding by undoing certain
@@ -1990,7 +1990,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
19901990
int refl = KING_REFLECTIONS[player][king_pos[player]];
19911991

19921992
if (board[a1]) {
1993-
const uchar C[2][8] = {{WHITE_LONG_CASTLING, WHITE_SHORT_CASTLING, 0, 0,
1993+
const uint8_t C[2][8] = {{WHITE_LONG_CASTLING, WHITE_SHORT_CASTLING, 0, 0,
19941994
WHITE_LONG_CASTLING, 0, WHITE_SHORT_CASTLING, 0},
19951995
{0,0,BLACK_LONG_CASTLING,BLACK_SHORT_CASTLING,
19961996
0,BLACK_LONG_CASTLING,0,BLACK_SHORT_CASTLING}};
@@ -2001,7 +2001,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
20012001
}
20022002

20032003
if (board[h1]) {
2004-
const uchar C[2][8] = {{WHITE_SHORT_CASTLING,WHITE_LONG_CASTLING,0,0,
2004+
const uint8_t C[2][8] = {{WHITE_SHORT_CASTLING,WHITE_LONG_CASTLING,0,0,
20052005
0,WHITE_LONG_CASTLING,0,WHITE_SHORT_CASTLING},
20062006
{0,0,BLACK_SHORT_CASTLING,BLACK_LONG_CASTLING,
20072007
BLACK_LONG_CASTLING,0,BLACK_SHORT_CASTLING,0}};
@@ -2012,7 +2012,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
20122012
}
20132013

20142014
if (board[a8]) {
2015-
const uchar C[2][8] = {{0,0,WHITE_LONG_CASTLING,WHITE_SHORT_CASTLING,
2015+
const uint8_t C[2][8] = {{0,0,WHITE_LONG_CASTLING,WHITE_SHORT_CASTLING,
20162016
WHITE_SHORT_CASTLING,0,WHITE_LONG_CASTLING,0},
20172017
{BLACK_LONG_CASTLING,BLACK_SHORT_CASTLING,0,0,
20182018
0,BLACK_SHORT_CASTLING,0,BLACK_LONG_CASTLING}};
@@ -2023,7 +2023,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
20232023
}
20242024

20252025
if (board[h8]) {
2026-
const uchar C[2][8] = {{0,0,WHITE_SHORT_CASTLING,WHITE_LONG_CASTLING,
2026+
const uint8_t C[2][8] = {{0,0,WHITE_SHORT_CASTLING,WHITE_LONG_CASTLING,
20272027
0,WHITE_SHORT_CASTLING,0,WHITE_LONG_CASTLING},
20282028
{BLACK_SHORT_CASTLING,BLACK_LONG_CASTLING,0,0,
20292029
BLACK_SHORT_CASTLING,0,BLACK_LONG_CASTLING,0}};
@@ -2077,7 +2077,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
20772077
// The necessary squares are empty
20782078
//cerr << "Finder ep?\n";
20792079

2080-
triple<int,uchar,Position> t;
2080+
triple<int,uint8_t,Position> t;
20812081

20822082
// Pawns present, only transf. 0 and 1 might be legal
20832083

@@ -2177,15 +2177,15 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
21772177
BPAWN, BPAWN, BPAWN, BPAWN, BKNIGHT, BBISHOP, BROOK, BQUEEN, 0
21782178
};
21792179

2180-
const uchar TRANSF[36] =
2180+
const uint8_t TRANSF[36] =
21812181
{ 5, 4, 2, 0, 0, 0, 0, 0, 0,
21822182
5, 4, 2, 0, 0, 0, 0, 0, 0,
21832183
2, 0, 5, 4, 0, 0, 0, 0, 0,
21842184
2, 0, 5, 4, 0, 0, 0, 0, 0
21852185
};
21862186

21872187
// ALLOWED_T used when added castling puts demands on transformation
2188-
const uchar ALLOWED_T[36] =
2188+
const uint8_t ALLOWED_T[36] =
21892189
{ 0xA0, 0x50, 0x0C, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
21902190
0xA0, 0x50, 0x0C, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
21912191
0x0C, 0x03, 0xA0, 0x50, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
@@ -2226,7 +2226,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
22262226
do {
22272227
++ki;
22282228

2229-
triple<int,uchar,Position> t = retro_move_count_checks(move.from, to, board[to], KILLED[ki]);
2229+
triple<int,uint8_t,Position> t = retro_move_count_checks(move.from, to, board[to], KILLED[ki]);
22302230

22312231
if (t.first == 0) {
22322232
// Undoing this move gives a position for which no move can capture the king.
@@ -2239,21 +2239,21 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
22392239
// "own" and "opponent" are relative to the player undoing a move
22402240

22412241
// can't be moved out of do...while loop as it is dependent on ki
2242-
uchar adding_own_castling = ADDED_CASTLING[move.from] &&
2242+
uint8_t adding_own_castling = ADDED_CASTLING[move.from] &&
22432243
((1 << (ADDED_CASTLING[move.from] & 0x0F)) & allowed_transformations & ALLOWED_T[ki]) &&
22442244
((KING_CASTLING_POSITIONS[move.from] && PIECE_KIND[board[to]]==KING) ||
22452245
(!KING_CASTLING_POSITIONS[move.from] && PIECE_KIND[board[to]]==ROOK));
2246-
uchar own_castling_transf = 0;
2246+
uint8_t own_castling_transf = 0;
22472247
if (adding_own_castling) {
22482248
adding_own_castling = ADDED_CASTLING[move.from] & 0xF0;
22492249
//cerr << "adding_own_castling = " << adding_own_castling << "\n";
22502250
own_castling_transf = ADDED_CASTLING[move.from] & 0x0F;
22512251
}
22522252

2253-
uchar adding_opponent_castling = ADDED_CASTLING[move.to] &&
2253+
uint8_t adding_opponent_castling = ADDED_CASTLING[move.to] &&
22542254
PIECE_KIND[KILLED[ki]]==ROOK &&
22552255
((1 << (ADDED_CASTLING[move.to] & 0x0F)) & allowed_transformations & ALLOWED_T[ki]);
2256-
uchar opponent_castling_transf = 0;
2256+
uint8_t opponent_castling_transf = 0;
22572257
if (adding_opponent_castling) {
22582258
adding_opponent_castling = ADDED_CASTLING[move.to] & 0xF0;
22592259
opponent_castling_transf = ADDED_CASTLING[move.to] & 0x0F;
@@ -2441,15 +2441,15 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
24412441
if ((kill!=0) == diagonal_move) {
24422442

24432443
// Beware!, do not use move, but instead to,from
2444-
uchar adding_opponent_castling = ADDED_CASTLING[to] &&
2444+
uint8_t adding_opponent_castling = ADDED_CASTLING[to] &&
24452445
PIECE_KIND[kill]==ROOK && (ADDED_CASTLING[to] & 0x0F) == t;
24462446
if (adding_opponent_castling)
24472447
adding_opponent_castling = ADDED_CASTLING[to] & 0xF0;
24482448

24492449

24502450
Piece pawns[2][4] = {{BPAWN, WPAWN, FILE_H_TO_A_PAWN, FILE_A_TO_H_PAWN},
24512451
{WPAWN, BPAWN, FILE_A_TO_H_PAWN, FILE_H_TO_A_PAWN}};
2452-
triple<int,uchar,Position> tr = retro_move_count_checks(from, to, pawns[player][r], kill);
2452+
triple<int,uint8_t,Position> tr = retro_move_count_checks(from, to, pawns[player][r], kill);
24532453
if (t && tr.third!=ILLEGAL_POS)
24542454
tr.third = reflect(tr.third, t);
24552455

@@ -2521,7 +2521,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
25212521
0,58,0,0,0,0,61,0
25222522
}};
25232523

2524-
const uchar UNDONE_CASTLING[64] =
2524+
const uint8_t UNDONE_CASTLING[64] =
25252525
{ 0,BLACK_SHORT_CASTLING,BLACK_LONG_CASTLING,0,0,BLACK_LONG_CASTLING,BLACK_SHORT_CASTLING,0,
25262526
BLACK_SHORT_CASTLING,0,0,0,0,0,0,BLACK_SHORT_CASTLING,
25272527
BLACK_LONG_CASTLING,0,0,0,0,0,0,BLACK_LONG_CASTLING,
@@ -2562,7 +2562,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
25622562

25632563
if (!king_checked) {
25642564
// Move rook
2565-
triple<int,uchar,Position> t = retro_move_count_checks(rook_move.from, rook_move.to,
2565+
triple<int,uint8_t,Position> t = retro_move_count_checks(rook_move.from, rook_move.to,
25662566
board[rook_move.to], 0);
25672567

25682568
if (t.first == 0) {
@@ -2574,7 +2574,7 @@ Board2::get_retro_moves(bool allow_pawn_promotion, bool allow_castling,
25742574

25752575
int transf = KING_REFLECTIONS[player^1][king_move.from];
25762576

2577-
uchar adding_own_castling = ADDED_CASTLING[king_move.from] & 0xF0;
2577+
uint8_t adding_own_castling = ADDED_CASTLING[king_move.from] & 0xF0;
25782578

25792579
for (uint i=0; i<ep_possibilities.size(); i++) {
25802580
if (ep_possibilities[i].accepted(rook_move.from, rook_move.to, undo.en_passant, 0)) {

src/board_2.hxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public:
9898
(~(CASTLING_LOST[move.from] & CASTLING_LOST[move.to]) & castling);
9999
}
100100

101-
uchar get_num_checks() { return num_checks; }
101+
uint8_t get_num_checks() { return num_checks; }
102102

103103
// position_is_unreachable is set by set_check_invariants().
104104
// Hence it will abso be set by loadFEN and set_board.
@@ -131,7 +131,7 @@ protected:
131131

132132
// ####### BEGIN board_2.hxx 2 byte block ########
133133
// Do not change the order, it is the same as in Undo => optimized copying
134-
uchar num_checks;
134+
uint8_t num_checks;
135135
// king threats
136136
Position threat_pos; // only defined if num_checks != 0
137137
// ####### END board_2.hxx 2 byte block ########
@@ -169,7 +169,7 @@ protected:
169169

170170
private:
171171
Position captured_en_passant_pawn(Position from, Position pawn_capture_pos);
172-
triple<int,uchar,Position> retro_move_count_checks(Position from, Position to,
172+
triple<int,uint8_t,Position> retro_move_count_checks(Position from, Position to,
173173
Piece original_piece, Piece piece_killed);
174174

175175
// static tables (how to assure only one copy ?)
@@ -198,9 +198,9 @@ private:
198198
};
199199
ostream& operator<<(ostream& os, const ull& bit_board);
200200

201-
extern uchar CHECK_TABLE[0x10000];//0,1 or 2
202-
extern uchar DIRECTION[64][64];// "unsigned" direction: [0..3] or ...
203-
extern uchar SDIRECTION[64][64];// "signed" direction: [0..7] or ...
201+
extern uint8_t CHECK_TABLE[0x10000];//0,1 or 2
202+
extern uint8_t DIRECTION[64][64];// "unsigned" direction: [0..3] or ...
203+
extern uint8_t SDIRECTION[64][64];// "signed" direction: [0..7] or ...
204204
extern Position DIRECTION_MOVE_TABLE[8][64];
205205
extern ull BIT_BOARDS[13+2][64];
206206
extern ull BB_LINES[64][64];

src/board_2_king_lines.hxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// Example:
3333
// board_lines[NORTH][ DIAG_INDEX[e2][NORTH] ]
3434
// gives the vertical line through e2.
35-
static const uchar DIAG_INDEX[64][4] =
35+
static const uint8_t DIAG_INDEX[64][4] =
3636
{{0, 0, 7, 0},
3737
{0, 1, 6, 1},
3838
{0, 2, 5, 2},
@@ -124,7 +124,7 @@ static const uchar DIAG_INDEX[64][4] =
124124
// By modifying DIAG_PIECE_PATTERN to give +4 for black pieces and by
125125
// using another table, DIAG_PATTERN, to do the shifting, the work
126126
// for white and black can be done simultaneously.
127-
static const uchar DIAG_PIECE_PATTERN[13+2][4] = // [piece][direction]
127+
static const uint8_t DIAG_PIECE_PATTERN[13+2][4] = // [piece][direction]
128128
{{0,0,0,0},
129129
{3,3,3,3}, // WPAWN = OBSTACLE for both players
130130
{3,3,3,3}, // WKNIGHT = OBSTACLE for both players
@@ -174,7 +174,7 @@ inline bool straight_direction(int d) { return !(d&~3); }
174174
inline void Board2::king_line_insert_piece(Position pos, Piece piece) {
175175
assert(legal_pos(pos) && piece && legal_pos(king_pos[player^1]));
176176

177-
const uchar *tmp = DIAG_PIECE_PATTERN[piece];
177+
const uint8_t *tmp = DIAG_PIECE_PATTERN[piece];
178178

179179
uint *pattern = &(board_lines[0][DIAG_INDEX[pos][0]]);
180180
*pattern |= DIAG_PATTERN[pos&7][tmp[0]];
@@ -412,7 +412,7 @@ void Board2::set_check_invariants() {
412412

413413
// Check long distance threats
414414
Piece piece = board[pos];
415-
const uchar *tmp = DIAG_PIECE_PATTERN[piece];
415+
const uint8_t *tmp = DIAG_PIECE_PATTERN[piece];
416416

417417
uint pattern = board_lines[0][DIAG_INDEX[pos][0]];
418418
pattern &= AND_DPP_PATTERN[pos&7];
@@ -525,7 +525,7 @@ bool Board2::check_if_king_placed(Position pos) const {
525525

526526
// Check long distance threats
527527
Piece piece = KING + 6*player;
528-
const uchar *tmp = DIAG_PIECE_PATTERN[piece];
528+
const uint8_t *tmp = DIAG_PIECE_PATTERN[piece];
529529

530530
uint pattern = board_lines[0][DIAG_INDEX[pos][0]];
531531
pattern &= AND_DPP_PATTERN[pos&7];

0 commit comments

Comments
 (0)