From: Marco Costalba Date: Tue, 23 Sep 2008 22:32:53 +0000 (+0200) Subject: Warnings termination fest X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=7dd0c39714cbb6829d7cbf9da36fa46995e7a61e Warnings termination fest A bunch of Intel C++ warnings removed, other silent out. Still few remaining but need deeper look. Also usual whitespace crap removal noise. Signed-off-by: Marco Costalba --- diff --git a/src/Makefile b/src/Makefile index 2e37cccc..2b89bc12 100644 --- a/src/Makefile +++ b/src/Makefile @@ -35,7 +35,7 @@ OBJS = bitboard.o color.o pawns.o material.o endgame.o evaluate.o main.o \ all: $(EXE) .depend -clean: +clean: $(RM) *.o .depend glaurung @@ -43,9 +43,9 @@ clean: ### Compiler: ### -CXX = g++ +# CXX = g++ # CXX = g++-4.2 -# CXX = icpc +CXX = icpc ### @@ -80,6 +80,10 @@ CXXFLAGS += -Wall -g CXXFLAGS += -O3 -fno-exceptions -fomit-frame-pointer -fno-rtti -fstrict-aliasing +# Disable most annoying warnings for the Intel C++ compiler + +CXXFLAGS += -wd383,869,981 + # Compiler optimization flags for the Intel C++ compiler in Mac OS X: @@ -88,16 +92,16 @@ CXXFLAGS += -O3 -fno-exceptions -fomit-frame-pointer -fno-rtti -fstrict-aliasing # Profiler guided optimization with the Intel C++ compiler. To use it, first # create the directory ./profdata if it does not already exist, and delete its -# contents if it does exist. Then compile with -prof_gen, and run the +# contents if it does exist. Then compile with -prof_gen, and run the # resulting binary for a while (for instance, do ./glaurung bench 128 1, and -# wait 15 minutes for the benchmark to complete). Then do a 'make clean', and +# wait 15 minutes for the benchmark to complete). Then do a 'make clean', and # recompile with -prof_use. -# CXXFLAGS += -prof_gen -prof_dir ./profdata +# CXXFLAGS += -prof_gen -prof_dir profdata # CXXFLAGS += -prof_use -prof_dir ./profdata -# Profiler guided optimization with GCC. I've never been able to make this +# Profiler guided optimization with GCC. I've never been able to make this # work. # CXXFLAGS += -fprofile-generate @@ -125,7 +129,7 @@ LDFLAGS += -lm -lpthread # LDFLAGS += -arch x86_64 -# Backwards compatibility with Mac OS X 10.4 when compiling under 10.5 with +# Backwards compatibility with Mac OS X 10.4 when compiling under 10.5 with # GCC 4.0. I haven't found a way to make it work with GCC 4.2. # CXXFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk diff --git a/src/bitboard.cpp b/src/bitboard.cpp index 298db7a7..8250e829 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -21,14 +21,14 @@ //// Includes //// -#ifdef _MSC_VER - #include - #ifdef _WIN64 - #pragma intrinsic(_BitScanForward64) - #else - #pragma intrinsic(_BitScanForward) - #endif - #define USING_INTRINSICS +#ifdef _MSC_VER + #include + #ifdef _WIN64 + #pragma intrinsic(_BitScanForward64) + #else + #pragma intrinsic(_BitScanForward) + #endif + #define USING_INTRINSICS #endif #include @@ -284,7 +284,7 @@ namespace { #if defined(USE_COMPACT_ROOK_ATTACKS) void init_file_and_rank_attacks(); #endif -}; +} //// @@ -356,22 +356,22 @@ Square first_1(Bitboard b) { Square pop_1st_bit(Bitboard *b) { - unsigned long index; - uint32_t *l, *h; - - if (*(l = (uint32_t*)b) != 0) - { - _BitScanForward(&index, *l); - *l &= ~(1 << index); - } - else if (*(h = (uint32_t*)b + 1) != 0) - { - _BitScanForward(&index, *h); - *h &= ~(1 << index); - index += 32; - } else - return SQ_NONE; - + unsigned long index; + uint32_t *l, *h; + + if (*(l = (uint32_t*)b) != 0) + { + _BitScanForward(&index, *l); + *l &= ~(1 << index); + } + else if (*(h = (uint32_t*)b + 1) != 0) + { + _BitScanForward(&index, *h); + *h &= ~(1 << index); + index += 32; + } else + return SQ_NONE; + return Square(index); } diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 12542af0..67d5be24 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -6,12 +6,12 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + Glaurung is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -105,7 +105,7 @@ namespace { // 8 9 10 11 12 13 14 15 V( 24), V( 27), V(28), V(29), V(30), V(31), V(32), V(33) }; - + const Value EndgameRookMobilityBonus[] = { // 0 1 2 3 4 5 6 7 V(-30), V(-18), V(-6), V(6), V(18), V(30), V(42), V(54), @@ -200,7 +200,7 @@ namespace { ((1ULL << SQ_A1) | (1ULL << SQ_H1)), ((1ULL << SQ_A8) | (1ULL << SQ_H8)) }; - + /// King safety constants and variables. The king safety scores are taken /// from the array SafetyTable[]. Various little "meta-bonuses" measuring /// the strength of the attack are added up into an integer, which is used @@ -212,7 +212,7 @@ namespace { const int BishopAttackWeight = 2; const int KnightAttackWeight = 2; - // Bonuses for safe checks for each piece type. + // Bonuses for safe checks for each piece type. int QueenContactCheckBonus = 4; int RookContactCheckBonus = 2; int QueenCheckBonus = 2; @@ -268,7 +268,7 @@ namespace { void evaluate_trapped_bishop_a1h1(const Position &pos, Square s, Color us, EvalInfo &ei); - Value apply_weight(Value v, int w); + inline Value apply_weight(Value v, int w); Value scale_by_game_phase(Value mv, Value ev, Phase ph, ScaleFactor sf[]); int count_1s_8bit(Bitboard b); @@ -352,7 +352,7 @@ Value evaluate(const Position &pos, EvalInfo &ei, int threadID) { s = pos.knight_list(c, i); evaluate_knight(pos, s, c, ei); } - + // Bishops for(int i = 0; i < pos.bishop_count(c); i++) { s = pos.bishop_list(c, i); @@ -390,8 +390,8 @@ Value evaluate(const Position &pos, EvalInfo &ei, int threadID) { } ei.attackedBy[c][0] = - ei.attackedBy[c][PAWN] | ei.attackedBy[c][KNIGHT] - | ei.attackedBy[c][BISHOP] | ei.attackedBy[c][ROOK] + ei.attackedBy[c][PAWN] | ei.attackedBy[c][KNIGHT] + | ei.attackedBy[c][BISHOP] | ei.attackedBy[c][ROOK] | ei.attackedBy[c][QUEEN] | ei.attackedBy[c][KING]; } @@ -420,7 +420,7 @@ Value evaluate(const Position &pos, EvalInfo &ei, int threadID) { ei.pi->kingside_storm_value(BLACK); else if(square_file(pos.king_square(WHITE)) <= FILE_D && square_file(pos.king_square(BLACK)) >= FILE_E) - ei.mgValue += + ei.mgValue += ei.pi->kingside_storm_value(WHITE) - ei.pi->queenside_storm_value(BLACK); } @@ -483,7 +483,7 @@ Value quick_evaluate(const Position &pos) { Value mgValue, egValue; ScaleFactor factor[2] = {SCALE_FACTOR_NORMAL, SCALE_FACTOR_NORMAL}; Phase phase; - + assert(pos.is_ok()); stm = pos.side_to_move(); @@ -496,7 +496,7 @@ Value quick_evaluate(const Position &pos) { return Sign[stm] * value; } - + /// init_eval() initializes various tables used by the evaluation function. @@ -573,7 +573,7 @@ namespace { // evaluate_knight() assigns bonuses and penalties to a knight of a given // color on a given square. - + void evaluate_knight(const Position &p, Square s, Color us, EvalInfo &ei) { Color them = opposite_color(us); @@ -587,7 +587,7 @@ namespace { Bitboard bb = (b & ei.attackedBy[them][KING]); if(bb) ei.attacked[us] += count_1s_max_15(bb); } - + // Mobility int mob = count_1s_max_15(b & ~p.pieces_of_color(us)); ei.mgMobility += Sign[us] * MidgameKnightMobilityBonus[mob]; @@ -596,7 +596,7 @@ namespace { // Knight outposts: if(p.square_is_weak(s, them)) { Value v, bonus; - + // Initial bonus based on square: v = bonus = KnightOutpostBonus[relative_square(us, s)]; @@ -619,13 +619,13 @@ namespace { // evaluate_bishop() assigns bonuses and penalties to a bishop of a given // color on a given square. - + void evaluate_bishop(const Position &p, Square s, Color us, EvalInfo &ei) { Color them = opposite_color(us); Bitboard b = bishop_attacks_bb(s, p.occupied_squares() & ~p.queens(us)); - + ei.attackedBy[us][BISHOP] |= b; // King attack @@ -644,7 +644,7 @@ namespace { // Bishop outposts: if(p.square_is_weak(s, them)) { Value v, bonus; - + // Initial bonus based on square: v = bonus = BishopOutpostBonus[relative_square(us, s)]; @@ -661,17 +661,17 @@ namespace { ei.mgValue += Sign[us] * bonus; ei.egValue += Sign[us] * bonus; - } + } } - + // evaluate_rook() assigns bonuses and penalties to a rook of a given // color on a given square. - + void evaluate_rook(const Position &p, Square s, Color us, EvalInfo &ei) { Color them = opposite_color(us); - + // Open and half-open files: File f = square_file(s); if(ei.pi->file_is_half_open(us, f)) { @@ -741,7 +741,7 @@ namespace { // evaluate_queen() assigns bonuses and penalties to a queen of a given // color on a given square. - + void evaluate_queen(const Position &p, Square s, Color us, EvalInfo &ei) { Color them = opposite_color(us); @@ -763,7 +763,7 @@ namespace { Bitboard bb = (b & ei.attackedBy[them][KING]); if(bb) ei.attacked[us] += count_1s_max_15(bb); } - + // Mobility int mob = count_1s(b & ~p.pieces_of_color(us)); ei.mgMobility += Sign[us] * MidgameQueenMobilityBonus[mob]; @@ -773,9 +773,9 @@ namespace { // evaluate_king() assigns bonuses and penalties to a king of a given // color on a given square. - + void evaluate_king(const Position &p, Square s, Color us, EvalInfo &ei) { - + int shelter = 0, sign = Sign[us]; // King shelter. @@ -788,7 +788,7 @@ namespace { } // King safety. This is quite complicated, and is almost certainly far - // from optimally tuned. + // from optimally tuned. Color them = opposite_color(us); if(p.queen_count(them) >= 1 && ei.attackCount[them] >= 2 && p.non_pawn_material(them) >= QueenValueMidgame + RookValueMidgame @@ -796,7 +796,7 @@ namespace { // Is it the attackers turn to move? bool sente = (them == p.side_to_move()); - + // Find the attacked squares around the king which has no defenders // apart from the king itself: Bitboard undefended = @@ -869,7 +869,7 @@ namespace { } } } - + // Analyse safe distance checks: if(QueenCheckBonus > 0 || RookCheckBonus > 0) { b = p.rook_attacks(s) & ~p.pieces_of_color(them) & ~ei.attacked_by(us); @@ -1079,7 +1079,7 @@ namespace { // evaluate_trapped_bishop_a7h7() determines whether a bishop on a7/h7 // (a2/h2 for black) is trapped by enemy pawns, and assigns a penalty // if it is. - + void evaluate_trapped_bishop_a7h7(const Position &pos, Square s, Color us, EvalInfo &ei) { Piece pawn = pawn_of_color(opposite_color(us)); @@ -1109,7 +1109,7 @@ namespace { // (a8/h8 for black) is trapped by a friendly pawn on b2/g2 (b7/g7 for // black), and assigns a penalty if it is. This pattern can obviously // only occur in Chess960 games. - + void evaluate_trapped_bishop_a1h1(const Position &pos, Square s, Color us, EvalInfo &ei) { Piece pawn = pawn_of_color(us); @@ -1139,7 +1139,7 @@ namespace { penalty = TrappedBishopA1H1Penalty; else penalty = TrappedBishopA1H1Penalty / 2; - + ei.mgValue -= Sign[us] * penalty; ei.egValue -= Sign[us] * penalty; } @@ -1157,7 +1157,7 @@ namespace { // scale_by_game_phase interpolates between a middle game and an endgame // score, based on game phase. It also scales the return value by a // ScaleFactor array. - + Value scale_by_game_phase(Value mv, Value ev, Phase ph, ScaleFactor sf[]) { assert(mv > -VALUE_INFINITE && mv < VALUE_INFINITE); assert(ev > -VALUE_INFINITE && ev < VALUE_INFINITE); @@ -1181,7 +1181,7 @@ namespace { // count_1s_8bit() counts the number of nonzero bits in the 8 least // significant bits of a Bitboard. This function is used by the king // shield evaluation. - + int count_1s_8bit(Bitboard b) { return int(BitCount8Bit[b & 0xFF]); } @@ -1194,15 +1194,15 @@ namespace { uciWeight = (uciWeight * 0x100) / 100; return (uciWeight * internalWeight) / 0x100; } - + // init_safety() initizes the king safety evaluation, based on UCI // parameters. It is called from read_weights(). - + void init_safety() { double a, b; int maxSlope, peak, i, j; - + QueenContactCheckBonus = get_option_value_int("Queen Contact Check Bonus"); RookContactCheckBonus = get_option_value_int("Rook Contact Check Bonus"); QueenCheckBonus = get_option_value_int("Queen Check Bonus"); @@ -1216,7 +1216,7 @@ namespace { b = get_option_value_int("King Safety X Intercept") * 1.0; maxSlope = get_option_value_int("King Safety Max Slope"); peak = (get_option_value_int("King Safety Max Value") * 256) / 100; - + for(i = 0; i < 100; i++) { if(i < b) SafetyTable[i] = Value(0); else if(get_option_value_string("King Safety Curve") == "Quadratic") @@ -1234,5 +1234,5 @@ namespace { if(SafetyTable[i] > Value(peak)) SafetyTable[i] = Value(peak); } - + } diff --git a/src/material.cpp b/src/material.cpp index c7bb810d..63033d80 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -6,12 +6,12 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + Glaurung is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -49,14 +49,14 @@ namespace { Key KNPKMaterialKey, KKNPMaterialKey; Key KPKPMaterialKey; -}; +} //// //// Functions //// -/// MaterialInfo::init() is called during program initialization. It +/// MaterialInfo::init() is called during program initialization. It /// precomputes material hash keys for a few basic endgames, in order /// to make it easy to recognize such endgames when they occur. @@ -179,7 +179,7 @@ void MaterialInfoTable::clear() { /// MaterialInfoTable::get_material_info() takes a position object as input, /// computes or looks up a MaterialInfo object, and returns a pointer to it. /// If the material configuration is not already present in the table, it -/// is stored there, so we don't have to recompute everything when the +/// is stored there, so we don't have to recompute everything when the /// same material configuration occurs again. MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) { @@ -187,7 +187,7 @@ MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) { int index = key & (size - 1); MaterialInfo *mi = entries + index; - // If mi->key matches the position's material hash key, it means that we + // If mi->key matches the position's material hash key, it means that we // have analysed this material configuration before, and we can simply // return the information we found the last time instead of recomputing it: if(mi->key == key) @@ -350,11 +350,11 @@ MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) { } // Evaluate the material balance. - + Color c; int sign; Value egValue = Value(0), mgValue = Value(0); - + for(c = WHITE, sign = 1; c <= BLACK; c++, sign = -sign) { // No pawns makes it difficult to win, even with a material advantage: @@ -376,16 +376,16 @@ MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) { } } } - + // Bishop pair: if(pos.bishop_count(c) >= 2) { mgValue += sign * BishopPairMidgameBonus; egValue += sign * BishopPairEndgameBonus; } - // Knights are stronger when there are many pawns on the board. The + // Knights are stronger when there are many pawns on the board. The // formula is taken from Larry Kaufman's paper "The Evaluation of Material - // Imbalances in Chess": + // Imbalances in Chess": // http://mywebpages.comcast.net/danheisman/Articles/evaluation_of_material_imbalance.htm mgValue += sign * Value(pos.knight_count(c)*(pos.pawn_count(c)-5)*16); egValue += sign * Value(pos.knight_count(c)*(pos.pawn_count(c)-5)*16); @@ -396,7 +396,7 @@ MaterialInfo *MaterialInfoTable::get_material_info(const Position &pos) { mgValue -= sign * v; egValue -= sign * v; } - + } mi->mgValue = int16_t(mgValue); diff --git a/src/mersenne.cpp b/src/mersenne.cpp index 2213e4ac..fee3027f 100644 --- a/src/mersenne.cpp +++ b/src/mersenne.cpp @@ -1,12 +1,12 @@ -/* +/* A C-program for MT19937, with initialization improved 2002/1/26. Coded by Takuji Nishimura and Makoto Matsumoto. - Before using, initialize the state by using init_genrand(seed) + Before using, initialize the state by using init_genrand(seed) or init_by_array(init_key, key_length). Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, - All rights reserved. + All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -19,8 +19,8 @@ notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - 3. The names of its contributors may not be used to endorse or promote - products derived from this software without specific prior written + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -42,8 +42,9 @@ */ #include "types.h" +#include "mersenne.h" -/* Period parameters */ +/* Period parameters */ #define N 624 #define M 397 #define MATRIX_A 0x9908b0dfUL /* constant vector a */ @@ -54,12 +55,12 @@ static unsigned long mt[N]; /* the array for the state vector */ static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */ /* initializes mt[N] with a seed */ -void init_genrand(unsigned long s) +static void init_genrand(unsigned long s) { mt[0]= s & 0xffffffffUL; for (mti=1; mti> 30)) + mti); + mt[mti] = + (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ /* In the previous versions, MSBs of the seed affect */ /* only MSBs of the array mt[]. */ @@ -73,7 +74,7 @@ void init_genrand(unsigned long s) /* init_key is the array for initializing keys */ /* key_length is its length */ /* slight change for C++, 2004/2/26 */ -void init_by_array(unsigned long init_key[], int key_length) +static void init_by_array(unsigned long init_key[], int key_length) { int i, j, k; init_genrand(19650218UL); @@ -95,7 +96,7 @@ void init_by_array(unsigned long init_key[], int key_length) if (i>=N) { mt[0] = mt[N-1]; i=1; } } - mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ + mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ } /* generates a random number on [0,0xffffffff]-interval */ @@ -123,7 +124,7 @@ uint32_t genrand_int32(void) { mti = 0; } - + y = mt[mti++]; /* Tempering */ diff --git a/src/position.cpp b/src/position.cpp index 57f4fd02..a9bf1f12 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -6,12 +6,12 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + Glaurung is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -101,7 +101,7 @@ void Position::from_fen(const std::string &fen) { case 'p': this->put_piece(BP, square); file++; break; case '/': file = FILE_A; rank--; break; case ' ': break; - default: + default: std::cout << "Error in FEN at character " << i << std::endl; return; } @@ -138,7 +138,7 @@ void Position::from_fen(const std::string &fen) { else if(fen[i] >= 'A' && fen[i] <= 'H') { File rookFile, kingFile = FILE_NONE; for(Square square = SQ_B1; square <= SQ_G1; square++) - if(this->piece_on(square) == WK) + if(this->piece_on(square) == WK) kingFile = square_file(square); if(kingFile == FILE_NONE) { std::cout << "Error in FEN at character " << i << std::endl; @@ -158,7 +158,7 @@ void Position::from_fen(const std::string &fen) { else if(fen[i] >= 'a' && fen[i] <= 'h') { File rookFile, kingFile = FILE_NONE; for(Square square = SQ_B8; square <= SQ_G8; square++) - if(this->piece_on(square) == BK) + if(this->piece_on(square) == BK) kingFile = square_file(square); if(kingFile == FILE_NONE) { std::cout << "Error in FEN at character " << i << std::endl; @@ -194,9 +194,9 @@ void Position::from_fen(const std::string &fen) { for(Square sq = SQ_A1; sq <= SQ_H8; sq++) castleRightsMask[sq] = ALL_CASTLES; - castleRightsMask[make_square(initialKFile, RANK_1)] ^= + castleRightsMask[make_square(initialKFile, RANK_1)] ^= (WHITE_OO|WHITE_OOO); - castleRightsMask[make_square(initialKFile, RANK_8)] ^= + castleRightsMask[make_square(initialKFile, RANK_8)] ^= (BLACK_OO|BLACK_OOO); castleRightsMask[make_square(initialKRFile, RANK_1)] ^= WHITE_OO; castleRightsMask[make_square(initialKRFile, RANK_8)] ^= BLACK_OO; @@ -260,8 +260,8 @@ const std::string Position::to_fen() const { /// the standard output. void Position::print() const { - char pieceStrings[][8] = - {"| ? ", "| P ", "| N ", "| B ", "| R ", "| Q ", "| K ", "| ? ", + char pieceStrings[][8] = + {"| ? ", "| P ", "| N ", "| B ", "| R ", "| Q ", "| K ", "| ? ", "| ? ", "|=P=", "|=N=", "|=B=", "|=R=", "|=Q=", "|=K=" }; @@ -277,7 +277,7 @@ void Position::print() const { } std::cout << "|\n"; } - std::cout << "+---+---+---+---+---+---+---+---+\n"; + std::cout << "+---+---+---+---+---+---+---+---+\n"; std::cout << this->to_fen() << std::endl; std::cout << key << std::endl; } @@ -345,7 +345,7 @@ Bitboard Position::discovered_check_candidates(Color c) const { dc |= (squares_between(s, ksq) & b2); } } - + sliders = this->bishops_and_queens(c); if(sliders & BishopPseudoAttacks[ksq]) { b2 = this->bishop_attacks(ksq) & this->pieces_of_color(c); @@ -358,7 +358,7 @@ Bitboard Position::discovered_check_candidates(Color c) const { return dc; } - + /// Position::square_is_attacked() checks whether the given side attacks the /// given square. @@ -413,7 +413,7 @@ bool Position::piece_attacks_square(Square f, Square t) const { return false; } - + /// Position::find_checkers() computes the checkersBB bitboard, which /// contains a nonzero bit for each checking piece (0, 1 or 2). It @@ -427,7 +427,7 @@ void Position::find_checkers() { } -/// Position::move_is_legal() tests whether a pseudo-legal move is legal. +/// Position::move_is_legal() tests whether a pseudo-legal move is legal. /// There are two versions of this function: One which takes only a /// move as input, and one which takes a move and a bitboard of pinned /// pieces. The latter function is faster, and should always be preferred @@ -480,15 +480,15 @@ bool Position::move_is_legal(Move m, Bitboard pinned) const { (!(rook_attacks_bb(ksq, b) & this->rooks_and_queens(them)) && !(bishop_attacks_bb(ksq, b) & this->bishops_and_queens(them))); } - - // If the moving piece is a king, check whether the destination + + // If the moving piece is a king, check whether the destination // square is attacked by the opponent. if(from == ksq) return !(this->square_is_attacked(move_to(m), them)); // A non-king move is legal if and only if it is not pinned or it // is moving along the ray towards or away from the king. if(!bit_is_set(pinned, from)) return true; - if(direction_between_squares(from, ksq) == + if(direction_between_squares(from, ksq) == direction_between_squares(move_to(m), ksq)) return true; @@ -534,7 +534,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const { return true; // Discovered check? else if(bit_is_set(dcCandidates, from) && - direction_between_squares(from, ksq) != + direction_between_squares(from, ksq) != direction_between_squares(to, ksq)) return true; // Promotion with check? @@ -565,7 +565,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const { clear_bit(&b, from); clear_bit(&b, capsq); set_bit(&b, to); return - ((rook_attacks_bb(ksq, b) & this->rooks_and_queens(us)) || + ((rook_attacks_bb(ksq, b) & this->rooks_and_queens(us)) || (bishop_attacks_bb(ksq, b) & this->bishops_and_queens(us))); } return false; @@ -603,7 +603,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const { case KING: // Discovered check? if(bit_is_set(dcCandidates, from) && - direction_between_squares(from, ksq) != + direction_between_squares(from, ksq) != direction_between_squares(to, ksq)) return true; // Castling with check? @@ -627,7 +627,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const { return bit_is_set(rook_attacks_bb(rto, b), ksq); } - + return false; default: @@ -678,7 +678,7 @@ bool Position::move_attacks_square(Move m, Square s) const { -/// Position::backup() is called when making a move. All information +/// Position::backup() is called when making a move. All information /// necessary to restore the position when the move is later unmade /// is saved to an UndoInfo object. The function Position::restore /// does the reverse operation: When one does a backup followed by @@ -865,7 +865,7 @@ void Position::do_move(Move m, UndoInfo &u, Bitboard dcCandidates) { castleRights &= castleRightsMask[from]; castleRights &= castleRightsMask[to]; key ^= zobCastle[castleRights]; - + // Update checkers bitboard: checkersBB = EmptyBoardBB; Square ksq = this->king_square(them); @@ -1033,8 +1033,8 @@ void Position::do_castle_move(Move m) { } -/// Position::do_promotion_move() is a private method used to make a promotion -/// move. It is called from the main Position::do_move function. The +/// Position::do_promotion_move() is a private method used to make a promotion +/// move. It is called from the main Position::do_move function. The /// UndoInfo object, which has been initialized in Position::do_move, is /// used to store the captured piece (if any). @@ -1058,7 +1058,7 @@ void Position::do_promotion_move(Move m, UndoInfo &u) { assert(this->color_of_piece_on(to) == them || this->square_is_empty(to)); capture = this->type_of_piece_on(to); - + if(capture) { assert(capture != KING); @@ -1137,7 +1137,7 @@ void Position::do_promotion_move(Move m, UndoInfo &u) { // Update material: npMaterial[us] += piece_value_midgame(promotion); - + // Clear the en passant square: if(epSquare != SQ_NONE) { key ^= zobEp[epSquare]; @@ -1151,7 +1151,7 @@ void Position::do_promotion_move(Move m, UndoInfo &u) { // Reset rule 50 counter: rule50 = 0; - + // Update checkers BB: checkersBB = attacks_to(this->king_square(them), us); } @@ -1165,7 +1165,7 @@ void Position::do_promotion_move(Move m, UndoInfo &u) { void Position::do_ep_move(Move m) { Color us, them; Square from, to, capsq; - + assert(this->is_ok()); assert(move_is_ok(m)); assert(move_is_ep(m)); @@ -1340,7 +1340,7 @@ void Position::undo_castle_move(Move m) { assert(move_is_ok(m)); assert(move_is_castle(m)); - // When we have arrived here, some work has already been done by + // When we have arrived here, some work has already been done by // Position::undo_move. In particular, the side to move has been switched, // so the code below is correct. us = this->side_to_move(); @@ -1409,7 +1409,7 @@ void Position::undo_promotion_move(Move m, const UndoInfo &u) { assert(move_is_ok(m)); assert(move_promotion(m)); - // When we have arrived here, some work has already been done by + // When we have arrived here, some work has already been done by // Position::undo_move. In particular, the side to move has been switched, // so the code below is correct. us = this->side_to_move(); @@ -1428,7 +1428,7 @@ void Position::undo_promotion_move(Move m, const UndoInfo &u) { clear_bit(&(byColorBB[us]), to); clear_bit(&(byTypeBB[promotion]), to); clear_bit(&(byTypeBB[0]), to); // HACK: byTypeBB[0] == occupied squares - + // Insert pawn at source square: set_bit(&(byColorBB[us]), from); set_bit(&(byTypeBB[PAWN]), from); @@ -1488,7 +1488,7 @@ void Position::undo_ep_move(Move m) { assert(move_is_ok(m)); assert(move_is_ep(m)); - // When we have arrived here, some work has already been done by + // When we have arrived here, some work has already been done by // Position::undo_move. In particular, the side to move has been switched, // so the code below is correct. us = this->side_to_move(); @@ -1540,7 +1540,7 @@ void Position::undo_ep_move(Move m) { void Position::do_null_move(UndoInfo &u) { assert(this->is_ok()); assert(!this->is_check()); - + // Back up the information necessary to undo the null move to the supplied // UndoInfo object. In the case of a null move, the only thing we need to // remember is the last move made and the en passant square. @@ -1562,7 +1562,7 @@ void Position::do_null_move(UndoInfo &u) { mgValue += (sideToMove == WHITE)? TempoValueMidgame : -TempoValueMidgame; egValue += (sideToMove == WHITE)? TempoValueEndgame : -TempoValueEndgame; - + assert(this->is_ok()); } @@ -1572,7 +1572,7 @@ void Position::do_null_move(UndoInfo &u) { void Position::undo_null_move(const UndoInfo &u) { assert(this->is_ok()); assert(!this->is_check()); - + // Restore information from the supplied UndoInfo object: lastMove = u.lastMove; epSquare = u.epSquare; @@ -1587,7 +1587,7 @@ void Position::undo_null_move(const UndoInfo &u) { mgValue += (sideToMove == WHITE)? TempoValueMidgame : -TempoValueMidgame; egValue += (sideToMove == WHITE)? TempoValueEndgame : -TempoValueEndgame; - + assert(this->is_ok()); } @@ -1673,7 +1673,7 @@ int Position::see(Square from, Square to) const { // before beginning the next iteration: lastCapturingPieceValue = seeValues[pt]; c = opposite_color(c); - + // Stop after a king capture: if(pt == KING && (attackers & this->pieces_of_color(c))) { assert(n < 32); @@ -1718,7 +1718,7 @@ void Position::clear() { } checkersBB = EmptyBoardBB; - + lastMove = MOVE_NONE; sideToMove = WHITE; @@ -1741,7 +1741,7 @@ void Position::clear() { void Position::reset_game_ply() { gamePly = 0; } - + /// Position::put_piece() puts a piece on the given square of the board, /// updating the board array, bitboards, and piece counts. @@ -1765,7 +1765,7 @@ void Position::put_piece(Piece p, Square s) { } -/// Position::allow_oo() gives the given side the right to castle kingside. +/// Position::allow_oo() gives the given side the right to castle kingside. /// Used when setting castling rights during parsing of FEN strings. void Position::allow_oo(Color c) { @@ -1793,7 +1793,7 @@ Key Position::compute_key() const { if(this->square_is_occupied(s)) result ^= zobrist[this->color_of_piece_on(s)][this->type_of_piece_on(s)][s]; - + if(this->ep_square() != SQ_NONE) result ^= zobEp[this->ep_square()]; result ^= zobCastle[castleRights]; @@ -1803,10 +1803,10 @@ Key Position::compute_key() const { } -/// Position::compute_pawn_key() computes the hash key of the position. The -/// hash key is usually updated incrementally as moves are made and unmade, -/// the compute_pawn_key() function is only used when a new position is set -/// up, and to verify the correctness of the pawn hash key when running in +/// Position::compute_pawn_key() computes the hash key of the position. The +/// hash key is usually updated incrementally as moves are made and unmade, +/// the compute_pawn_key() function is only used when a new position is set +/// up, and to verify the correctness of the pawn hash key when running in /// debug mode. Key Position::compute_pawn_key() const { @@ -1841,7 +1841,7 @@ Key Position::compute_material_key() const { } return result; } - + /// Position::compute_mg_value() and Position::compute_eg_value() compute the /// incremental scores for the middle game and the endgame. These functions @@ -1919,7 +1919,7 @@ bool Position::is_mate() { MOVE_NONE, Depth(0)); return mp.get_next_move() == MOVE_NONE; } - else + else return false; } @@ -1931,10 +1931,10 @@ bool Position::is_mate() { bool Position::is_draw() const { // Draw by material? if(!this->pawns() && - this->non_pawn_material(WHITE) + this->non_pawn_material(BLACK) + this->non_pawn_material(WHITE) + this->non_pawn_material(BLACK) <= BishopValueMidgame) return true; - + // Draw by the 50 moves rule? if(rule50 > 100 || (rule50 == 100 && !this->is_check())) return true; @@ -1943,7 +1943,7 @@ bool Position::is_draw() const { for(int i = 2; i < Min(gamePly, rule50); i += 2) if(history[gamePly - i] == key) return true; - + return false; } @@ -1964,7 +1964,7 @@ bool Position::has_mate_threat(Color c) { if(this->is_check()) return false; - + // If the input color is not equal to the side to move, do a null move if(c != stm) this->do_null_move(u1); @@ -1998,15 +1998,15 @@ void Position::init_zobrist() { for(int j = 0; j < 8; j++) for(int k = 0; k < 64; k++) zobrist[i][j][k] = Key(genrand_int64()); - + for(int i = 0; i < 64; i++) zobEp[i] = Key(genrand_int64()); - + for(int i = 0; i < 16; i++) zobCastle[i] = genrand_int64(); - + zobSideToMove = genrand_int64(); - + for(int i = 0; i < 2; i++) for(int j = 0; j < 8; j++) for(int k = 0; k < 16; k++) @@ -2099,7 +2099,7 @@ void Position::flipped_copy(const Position &pos) { assert(this->is_ok()); } - + /// Position::is_ok() performs some consitency checks for the position object. /// This is meant to be helpful when debugging. @@ -2144,7 +2144,7 @@ bool Position::is_ok() const { if(kingCount[0] != 1 || kingCount[1] != 1) return false; } - + // Can the side to move capture the opponent's king? if(debugKingCapture) { Color us = this->side_to_move(); @@ -2197,7 +2197,7 @@ bool Position::is_ok() const { // Material hash key OK? if(debugMaterialKey && materialKey != this->compute_material_key()) return false; - + // Incremental eval OK? if(debugIncrementalEval) { if(mgValue != this->compute_mg_value()) @@ -2232,6 +2232,6 @@ bool Position::is_ok() const { return false; } } - + return true; } diff --git a/src/san.cpp b/src/san.cpp index 68515170..c144407e 100644 --- a/src/san.cpp +++ b/src/san.cpp @@ -6,12 +6,12 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + Glaurung is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -48,7 +48,7 @@ namespace { /// Functions - + Ambiguity move_ambiguity(Position &pos, Move m); const std::string time_string(int milliseconds); const std::string score_string(Value v); @@ -152,7 +152,7 @@ const std::string move_to_san(Position &pos, Move m) { Move move_from_san(Position &pos, const std::string &movestr) { assert(pos.is_ok()); - + MovePicker mp = MovePicker(pos, false, MOVE_NONE, MOVE_NONE, MOVE_NONE, MOVE_NONE, OnePly); @@ -180,7 +180,7 @@ Move move_from_san(Position &pos, const std::string &movestr) { int i; // Initialize str[] by making a copy of movestr with the characters - // 'x', '=', '+' and '#' removed. + // 'x', '=', '+' and '#' removed. cc = str; for(i=0, c=cstr; i<10 && *c!='\0' && *c!='\n' && *c!=' '; i++, c++) if(!strchr("x=+#", *c)) { @@ -237,7 +237,7 @@ Move move_from_san(Position &pos, const std::string &movestr) { // Look for a matching move: Move m, move = MOVE_NONE; int matches = 0; - + while((m = mp.get_next_move()) != MOVE_NONE) { bool match = true; if(pos.type_of_piece_on(move_from(m)) != pt) @@ -255,7 +255,7 @@ Move move_from_san(Position &pos, const std::string &movestr) { matches++; } } - + if(matches == 1) return move; else @@ -391,7 +391,7 @@ namespace { s << hours << ':'; s << std::setw(2) << std::setfill('0') << minutes << ':'; s << std::setw(2) << std::setfill('0') << seconds; - + return s.str(); } @@ -413,5 +413,5 @@ namespace { } return s.str(); } - + } diff --git a/src/search.cpp b/src/search.cpp index c2974dcf..4b966f61 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -69,16 +69,16 @@ namespace { public: RootMoveList(Position &pos, Move searchMoves[]); - Move get_move(int moveNum) const; - Value get_move_score(int moveNum) const; - void set_move_score(int moveNum, Value score); - void set_move_nodes(int moveNum, int64_t nodes); + inline Move get_move(int moveNum) const; + inline Value get_move_score(int moveNum) const; + inline void set_move_score(int moveNum, Value score); + inline void set_move_nodes(int moveNum, int64_t nodes); void set_move_pv(int moveNum, const Move pv[]); - Move get_move_pv(int moveNum, int i) const; - int64_t get_move_cumulative_nodes(int moveNum) const; - int move_count() const; + inline Move get_move_pv(int moveNum, int i) const; + inline int64_t get_move_cumulative_nodes(int moveNum) const; + inline int move_count() const; Move scan_for_easy_move() const; - void sort(); + inline void sort(); void sort_multipv(int n); private: @@ -416,7 +416,7 @@ void think(const Position &pos, bool infinite, bool ponder, int side_to_move, int myTime = time[side_to_move]; int myIncrement = increment[side_to_move]; int oppTime = time[1 - side_to_move]; - + TimeAdvantage = myTime - oppTime; if(!movesToGo) { // Sudden death time control @@ -2184,7 +2184,7 @@ namespace { bool overTime = t > AbsoluteMaxSearchTime || (RootMoveNumber == 1 && t > MaxSearchTime + ExtraSearchTime) - || ( !FailHigh && !fail_high_ply_1() && !Problem + || ( !FailHigh && !fail_high_ply_1() && !Problem && t > 6*(MaxSearchTime + ExtraSearchTime)); if ( (Iteration >= 2 && (!InfiniteSearch && overTime)) diff --git a/src/tt.h b/src/tt.h index ec3d72b4..c1dd8508 100644 --- a/src/tt.h +++ b/src/tt.h @@ -72,7 +72,7 @@ public: int full(); private: - TTEntry* first_entry(const Position &pos) const; + inline TTEntry* first_entry(const Position &pos) const; unsigned size; int writes;