Fix some VC Code analysis issues
This commit is contained in:
parent
25a71d0a7d
commit
f5c4a5f7d9
|
@ -61,7 +61,7 @@ extern Bitboard SquareBB[SQ_32];
|
|||
extern Bitboard StarSquareBB9;
|
||||
extern Bitboard StarSquareBB12;
|
||||
|
||||
inline Bitboard square_bb(Square s)
|
||||
inline Bitboard square_bb(Square s) noexcept
|
||||
{
|
||||
if (!(SQ_BEGIN <= s && s < SQ_END))
|
||||
return 0;
|
||||
|
@ -69,12 +69,12 @@ inline Bitboard square_bb(Square s)
|
|||
return SquareBB[s];
|
||||
}
|
||||
|
||||
inline Bitboard star_square_bb_9()
|
||||
inline Bitboard star_square_bb_9() noexcept
|
||||
{
|
||||
return StarSquareBB9;
|
||||
}
|
||||
|
||||
inline Bitboard star_square_bb_12()
|
||||
inline Bitboard star_square_bb_12() noexcept
|
||||
{
|
||||
return StarSquareBB12;
|
||||
}
|
||||
|
@ -82,47 +82,47 @@ inline Bitboard star_square_bb_12()
|
|||
/// Overloads of bitwise operators between a Bitboard and a Square for testing
|
||||
/// whether a given bit is set in a bitboard, and for setting and clearing bits.
|
||||
|
||||
inline Bitboard operator&(Bitboard b, Square s)
|
||||
inline Bitboard operator&(Bitboard b, Square s) noexcept
|
||||
{
|
||||
return b & square_bb(s);
|
||||
}
|
||||
|
||||
inline Bitboard operator|(Bitboard b, Square s)
|
||||
inline Bitboard operator|(Bitboard b, Square s) noexcept
|
||||
{
|
||||
return b | square_bb(s);
|
||||
}
|
||||
|
||||
inline Bitboard operator^(Bitboard b, Square s)
|
||||
inline Bitboard operator^(Bitboard b, Square s) noexcept
|
||||
{
|
||||
return b ^ square_bb(s);
|
||||
}
|
||||
|
||||
inline Bitboard &operator|=(Bitboard &b, Square s)
|
||||
inline Bitboard &operator|=(Bitboard &b, Square s) noexcept
|
||||
{
|
||||
return b |= square_bb(s);
|
||||
}
|
||||
|
||||
inline Bitboard &operator^=(Bitboard &b, Square s)
|
||||
inline Bitboard &operator^=(Bitboard &b, Square s) noexcept
|
||||
{
|
||||
return b ^= square_bb(s);
|
||||
}
|
||||
|
||||
inline Bitboard operator&(Square s, Bitboard b)
|
||||
inline Bitboard operator&(Square s, Bitboard b) noexcept
|
||||
{
|
||||
return b & s;
|
||||
}
|
||||
|
||||
inline Bitboard operator|(Square s, Bitboard b)
|
||||
inline Bitboard operator|(Square s, Bitboard b) noexcept
|
||||
{
|
||||
return b | s;
|
||||
}
|
||||
|
||||
inline Bitboard operator^(Square s, Bitboard b)
|
||||
inline Bitboard operator^(Square s, Bitboard b) noexcept
|
||||
{
|
||||
return b ^ s;
|
||||
}
|
||||
|
||||
inline Bitboard operator|(Square s1, Square s2)
|
||||
inline Bitboard operator|(Square s1, Square s2) noexcept
|
||||
{
|
||||
return square_bb(s1) | s2;
|
||||
}
|
||||
|
@ -136,29 +136,29 @@ constexpr bool more_than_one(Bitboard b)
|
|||
/// rank_bb() and file_bb() return a bitboard representing all the squares on
|
||||
/// the given file or rank.
|
||||
|
||||
inline Bitboard rank_bb(Rank r)
|
||||
constexpr Bitboard rank_bb(Rank r) noexcept
|
||||
{
|
||||
return Rank1BB << (r - 1);
|
||||
}
|
||||
|
||||
inline Bitboard rank_bb(Square s)
|
||||
constexpr Bitboard rank_bb(Square s)
|
||||
{
|
||||
return rank_bb(rank_of(s));
|
||||
}
|
||||
|
||||
inline Bitboard file_bb(File f)
|
||||
constexpr Bitboard file_bb(File f) noexcept
|
||||
{
|
||||
return FileABB << (f - 1);
|
||||
}
|
||||
|
||||
inline Bitboard file_bb(Square s)
|
||||
constexpr Bitboard file_bb(Square s)
|
||||
{
|
||||
return file_bb(file_of(s));
|
||||
}
|
||||
|
||||
/// popcount() counts the number of non-zero bits in a bitboard
|
||||
|
||||
inline int popcount(Bitboard b)
|
||||
inline int popcount(Bitboard b) noexcept
|
||||
{
|
||||
#ifdef DONOT_USE_POPCNT
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class Evaluation
|
|||
{
|
||||
public:
|
||||
Evaluation() = delete;
|
||||
explicit Evaluation(Position &p) : pos(p)
|
||||
explicit Evaluation(Position &p) noexcept : pos(p)
|
||||
{
|
||||
}
|
||||
Evaluation &operator=(const Evaluation &) = delete;
|
||||
|
@ -119,7 +119,7 @@ Value Evaluation::value()
|
|||
} else if (pos.get_action() == Action::select &&
|
||||
pos.is_all_surrounded() &&
|
||||
rule.isLoseButNotChangeSideWhenNoWay) {
|
||||
Value delta = pos.side_to_move() == BLACK ? -VALUE_MATE : VALUE_MATE;
|
||||
const Value delta = pos.side_to_move() == BLACK ? -VALUE_MATE : VALUE_MATE;
|
||||
value += delta;
|
||||
}
|
||||
else if (pos.piece_on_board_count(BLACK) < rule.piecesAtLeastCount) {
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Mills
|
|||
29 ----- 28 ----- 27
|
||||
*/
|
||||
|
||||
void adjacent_squares_init()
|
||||
void adjacent_squares_init() noexcept
|
||||
{
|
||||
// Note: Not follow order of MoveDirection array
|
||||
const int adjacentSquares12[SQUARE_NB][MD_NB] = {
|
||||
|
@ -386,7 +386,7 @@ void move_priority_list_shuffle()
|
|||
}
|
||||
|
||||
if (gameOptions.getShufflingEnabled()) {
|
||||
uint32_t seed = static_cast<uint32_t>(now());
|
||||
const uint32_t seed = static_cast<uint32_t>(now());
|
||||
|
||||
std::shuffle(movePriorityList0.begin(), movePriorityList0.end(), std::default_random_engine(seed));
|
||||
std::shuffle(movePriorityList1.begin(), movePriorityList1.end(), std::default_random_engine(seed));
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
namespace Mills
|
||||
{
|
||||
|
||||
void adjacent_squares_init();
|
||||
void adjacent_squares_init() noexcept;
|
||||
void mill_table_init();
|
||||
void move_priority_list_shuffle();
|
||||
|
||||
|
|
18
src/misc.cpp
18
src/misc.cpp
|
@ -289,17 +289,17 @@ const std::string compiler_info()
|
|||
/// Debug functions used mainly to collect run-time statistics
|
||||
static std::atomic<int64_t> hits[2], means[2];
|
||||
|
||||
void dbg_hit_on(bool b)
|
||||
void dbg_hit_on(bool b) noexcept
|
||||
{
|
||||
++hits[0]; if (b) ++hits[1];
|
||||
}
|
||||
|
||||
void dbg_hit_on(bool c, bool b)
|
||||
void dbg_hit_on(bool c, bool b) noexcept
|
||||
{
|
||||
if (c) dbg_hit_on(b);
|
||||
}
|
||||
|
||||
void dbg_mean_of(int v)
|
||||
void dbg_mean_of(int v) noexcept
|
||||
{
|
||||
++means[0]; means[1] += v;
|
||||
}
|
||||
|
@ -376,8 +376,8 @@ void prefetch(void *addr)
|
|||
|
||||
void prefetch_range(void *addr, size_t len)
|
||||
{
|
||||
char *cp;
|
||||
char *end = (char *)addr + len;
|
||||
char *cp = nullptr;
|
||||
const char *end = (char *)addr + len;
|
||||
|
||||
for (cp = (char *)addr; cp < end; cp += PREFETCH_STRIDE)
|
||||
prefetch(cp);
|
||||
|
@ -609,7 +609,7 @@ int best_group(size_t idx)
|
|||
void bindThisThread(size_t idx)
|
||||
{
|
||||
// Use only local variables to be thread-safe
|
||||
int group = best_group(idx);
|
||||
const int group = best_group(idx);
|
||||
|
||||
if (group == -1)
|
||||
return;
|
||||
|
@ -648,7 +648,7 @@ string argv0; // path+name of the executable binary, as given by argv
|
|||
string binaryDirectory; // path of the executable directory
|
||||
string workingDirectory; // path of the working directory
|
||||
|
||||
void init(int argc, char *argv[])
|
||||
void init(int argc, const char *argv[])
|
||||
{
|
||||
(void)argc;
|
||||
string pathSeparator;
|
||||
|
@ -672,13 +672,13 @@ void init(int argc, char *argv[])
|
|||
// extract the working directory
|
||||
workingDirectory = "";
|
||||
char buff[40000];
|
||||
char *cwd = GETCWD(buff, 40000);
|
||||
const char *cwd = GETCWD(buff, 40000);
|
||||
if (cwd)
|
||||
workingDirectory = cwd;
|
||||
|
||||
// extract the binary directory path from argv0
|
||||
binaryDirectory = argv0;
|
||||
size_t pos = binaryDirectory.find_last_of("\\/");
|
||||
const size_t pos = binaryDirectory.find_last_of("\\/");
|
||||
if (pos == std::string::npos)
|
||||
binaryDirectory = "." + pathSeparator;
|
||||
else
|
||||
|
|
18
src/misc.h
18
src/misc.h
|
@ -40,9 +40,9 @@ void* aligned_large_pages_alloc(size_t allocSize); // memory aligned by page siz
|
|||
void aligned_large_pages_free(void* mem); // nop if mem == nullptr
|
||||
#endif // ALIGNED_LARGE_PAGES
|
||||
|
||||
void dbg_hit_on(bool b);
|
||||
void dbg_hit_on(bool c, bool b);
|
||||
void dbg_mean_of(int v);
|
||||
void dbg_hit_on(bool b) noexcept;
|
||||
void dbg_hit_on(bool c, bool b) noexcept;
|
||||
void dbg_mean_of(int v) noexcept;
|
||||
void dbg_print();
|
||||
|
||||
typedef std::chrono::milliseconds::rep TimePoint; // A value in milliseconds
|
||||
|
@ -134,16 +134,16 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
inline uint64_t mul_hi64(uint64_t a, uint64_t b) {
|
||||
constexpr uint64_t mul_hi64(uint64_t a, uint64_t b) {
|
||||
#if defined(__GNUC__) && defined(IS_64BIT)
|
||||
__extension__ typedef unsigned __int128 uint128;
|
||||
return ((uint128)a * (uint128)b) >> 64;
|
||||
#else
|
||||
uint64_t aL = (uint32_t)a, aH = a >> 32;
|
||||
uint64_t bL = (uint32_t)b, bH = b >> 32;
|
||||
uint64_t c1 = (aL * bL) >> 32;
|
||||
uint64_t c2 = aH * bL + c1;
|
||||
uint64_t c3 = aL * bH + (uint32_t)c2;
|
||||
const uint64_t aL = (uint32_t)a, aH = a >> 32;
|
||||
const uint64_t bL = (uint32_t)b, bH = b >> 32;
|
||||
const uint64_t c1 = (aL * bL) >> 32;
|
||||
const uint64_t c2 = aH * bL + c1;
|
||||
const uint64_t c3 = aL * bH + (uint32_t)c2;
|
||||
return aH * bH + (c2 >> 32) + (c3 >> 32);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ ExtMove *generate<PLACE>(Position &pos, ExtMove *moveList)
|
|||
template<>
|
||||
ExtMove *generate<MOVE>(Position &pos, ExtMove *moveList)
|
||||
{
|
||||
Square from, to;
|
||||
Square from = SQ_0, to = SQ_0;
|
||||
ExtMove *cur = moveList;
|
||||
|
||||
// move piece that location weak first
|
||||
|
@ -88,8 +88,8 @@ ExtMove *generate<REMOVE>(Position &pos, ExtMove *moveList)
|
|||
{
|
||||
Square s;
|
||||
|
||||
Color us = pos.side_to_move();
|
||||
Color them = ~us;
|
||||
const Color us = pos.side_to_move();
|
||||
const Color them = ~us;
|
||||
|
||||
ExtMove *cur = moveList;
|
||||
|
||||
|
|
|
@ -39,12 +39,12 @@ struct ExtMove
|
|||
Move move;
|
||||
int value;
|
||||
|
||||
operator Move() const
|
||||
operator Move() const noexcept
|
||||
{
|
||||
return move;
|
||||
}
|
||||
|
||||
void operator=(Move m)
|
||||
void operator=(Move m) noexcept
|
||||
{
|
||||
move = m;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ struct ExtMove
|
|||
operator float() const = delete;
|
||||
};
|
||||
|
||||
inline bool operator<(const ExtMove &f, const ExtMove &s)
|
||||
inline bool operator<(const ExtMove &f, const ExtMove &s) noexcept
|
||||
{
|
||||
return f.value < s.value;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
// partial_insertion_sort() sorts moves in descending order up to and including
|
||||
// a given limit. The order of moves smaller than the limit is left unspecified.
|
||||
void partial_insertion_sort(ExtMove *begin, ExtMove *end, int limit)
|
||||
void partial_insertion_sort(ExtMove *begin, const ExtMove *end, int limit)
|
||||
{
|
||||
for (ExtMove *sortedEnd = begin, *p = begin + 1; p < end; ++p)
|
||||
if (p->value >= limit) {
|
||||
|
@ -41,7 +41,7 @@ void partial_insertion_sort(ExtMove *begin, ExtMove *end, int limit)
|
|||
/// ordering is at the current node.
|
||||
|
||||
/// MovePicker constructor for the main search
|
||||
MovePicker::MovePicker(Position &p)
|
||||
MovePicker::MovePicker(Position &p) noexcept
|
||||
: pos(p)
|
||||
{
|
||||
}
|
||||
|
@ -52,15 +52,15 @@ template<GenType Type>
|
|||
void MovePicker::score()
|
||||
{
|
||||
cur = moves;
|
||||
Square from, to;
|
||||
Move m;
|
||||
Square from = SQ_0, to = SQ_0;
|
||||
Move m = MOVE_NONE;
|
||||
|
||||
int ourMillsCount;
|
||||
int theirMillsCount;
|
||||
int ourPieceCount;
|
||||
int theirPiecesCount;
|
||||
int bannedCount;
|
||||
int emptyCount;
|
||||
int ourMillsCount = 0;
|
||||
int theirMillsCount = 0;
|
||||
int ourPieceCount = 0;
|
||||
int theirPiecesCount = 0;
|
||||
int bannedCount = 0;
|
||||
int emptyCount = 0;
|
||||
|
||||
while (cur++->move != MOVE_NONE) {
|
||||
m = cur->move;
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
class Position;
|
||||
struct ExtMove;
|
||||
|
||||
void partial_insertion_sort(ExtMove *begin, ExtMove *end, int limit);
|
||||
void partial_insertion_sort(ExtMove *begin, const ExtMove *end, int limit);
|
||||
|
||||
|
||||
/// MovePicker class is used to pick one pseudo legal move at a time from the
|
||||
|
@ -44,18 +44,18 @@ class MovePicker
|
|||
public:
|
||||
MovePicker(const MovePicker &) = delete;
|
||||
MovePicker &operator=(const MovePicker &) = delete;
|
||||
explicit MovePicker(Position &p);
|
||||
explicit MovePicker(Position &p) noexcept;
|
||||
|
||||
Move next_move();
|
||||
|
||||
template<GenType> void score();
|
||||
|
||||
ExtMove *begin()
|
||||
ExtMove *begin() noexcept
|
||||
{
|
||||
return cur;
|
||||
}
|
||||
|
||||
ExtMove *end()
|
||||
ExtMove *end() noexcept
|
||||
{
|
||||
return endMoves;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
int moveCount { 0 };
|
||||
|
||||
int move_count() const
|
||||
int move_count() const noexcept
|
||||
{
|
||||
return moveCount;
|
||||
}
|
||||
|
|
32
src/option.h
32
src/option.h
|
@ -24,32 +24,32 @@
|
|||
class GameOptions
|
||||
{
|
||||
public:
|
||||
void setAutoRestart(bool enabled)
|
||||
void setAutoRestart(bool enabled) noexcept
|
||||
{
|
||||
isAutoRestart = enabled;
|
||||
}
|
||||
|
||||
bool getAutoRestart() const
|
||||
bool getAutoRestart() const noexcept
|
||||
{
|
||||
return isAutoRestart;
|
||||
}
|
||||
|
||||
void setAutoChangeFirstMove(bool enabled)
|
||||
void setAutoChangeFirstMove(bool enabled) noexcept
|
||||
{
|
||||
isAutoChangeFirstMove = enabled;
|
||||
}
|
||||
|
||||
bool getAutoChangeFirstMove() const
|
||||
bool getAutoChangeFirstMove() const noexcept
|
||||
{
|
||||
return isAutoChangeFirstMove;
|
||||
}
|
||||
|
||||
void setResignIfMostLose(bool enabled)
|
||||
void setResignIfMostLose(bool enabled) noexcept
|
||||
{
|
||||
resignIfMostLose = enabled;
|
||||
}
|
||||
|
||||
bool getResignIfMostLose() const
|
||||
bool getResignIfMostLose() const noexcept
|
||||
{
|
||||
return resignIfMostLose;
|
||||
}
|
||||
|
@ -60,17 +60,17 @@ public:
|
|||
// variation between different games against an opponent that tries to do the
|
||||
// same sequence of moves. By default, shuffling is enabled.
|
||||
|
||||
bool getShufflingEnabled() const
|
||||
bool getShufflingEnabled() const noexcept
|
||||
{
|
||||
return shufflingEnabled;
|
||||
}
|
||||
|
||||
void setShufflingEnabled(bool enabled)
|
||||
void setShufflingEnabled(bool enabled) noexcept
|
||||
{
|
||||
shufflingEnabled = enabled;
|
||||
}
|
||||
|
||||
void setLearnEndgameEnabled(bool enabled)
|
||||
void setLearnEndgameEnabled(bool enabled) noexcept
|
||||
{
|
||||
#ifdef ENDGAME_LEARNING_FORCE
|
||||
learnEndgame = true;
|
||||
|
@ -79,7 +79,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
bool isEndgameLearningEnabled() const
|
||||
bool isEndgameLearningEnabled() const noexcept
|
||||
{
|
||||
#ifdef ENDGAME_LEARNING_FORCE
|
||||
return true;
|
||||
|
@ -88,36 +88,36 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
void setIDSEnabled(bool enabled)
|
||||
void setIDSEnabled(bool enabled) noexcept
|
||||
{
|
||||
IDSEnabled = enabled;
|
||||
}
|
||||
|
||||
bool getIDSEnabled() const
|
||||
bool getIDSEnabled() const noexcept
|
||||
{
|
||||
return IDSEnabled;
|
||||
}
|
||||
|
||||
// DepthExtension
|
||||
|
||||
void setDepthExtension(bool enabled)
|
||||
void setDepthExtension(bool enabled) noexcept
|
||||
{
|
||||
depthExtension = enabled;
|
||||
}
|
||||
|
||||
bool getDepthExtension() const
|
||||
bool getDepthExtension() const noexcept
|
||||
{
|
||||
return depthExtension;
|
||||
}
|
||||
|
||||
// OpeningBook
|
||||
|
||||
void setOpeningBook(bool enabled)
|
||||
void setOpeningBook(bool enabled) noexcept
|
||||
{
|
||||
openingBook = enabled;
|
||||
}
|
||||
|
||||
bool getOpeningBook() const
|
||||
bool getOpeningBook() const noexcept
|
||||
{
|
||||
return openingBook;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ using std::string;
|
|||
|
||||
namespace Zobrist
|
||||
{
|
||||
const int KEY_MISC_BIT = 2;
|
||||
constexpr int KEY_MISC_BIT = 2;
|
||||
Key psq[PIECE_TYPE_NB][SQUARE_NB];
|
||||
Key side;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ const string PieceToChar(Piece p)
|
|||
return "*";
|
||||
}
|
||||
|
||||
Piece CharToPiece(char ch)
|
||||
Piece CharToPiece(char ch) noexcept
|
||||
{
|
||||
|
||||
if (ch == '*') {
|
||||
|
@ -210,7 +210,7 @@ Position &Position::set(const string &fenStr, Thread *th)
|
|||
incremented after Black's move.
|
||||
*/
|
||||
|
||||
unsigned char token;
|
||||
unsigned char token = '\0';
|
||||
Square sq = SQ_A1;
|
||||
std::istringstream ss(fenStr);
|
||||
|
||||
|
@ -375,9 +375,9 @@ bool Position::legal(Move m) const
|
|||
{
|
||||
assert(is_ok(m));
|
||||
|
||||
Color us = sideToMove;
|
||||
Square from = from_sq(m);
|
||||
Square to = to_sq(m);
|
||||
const Color us = sideToMove;
|
||||
const Square from = from_sq(m);
|
||||
const Square to = to_sq(m);
|
||||
|
||||
if (from == to) {
|
||||
return false;
|
||||
|
@ -401,7 +401,7 @@ void Position::do_move(Move m)
|
|||
{
|
||||
bool ret = false;
|
||||
|
||||
MoveType mt = type_of(m);
|
||||
const MoveType mt = type_of(m);
|
||||
|
||||
switch (mt) {
|
||||
case MOVETYPE_REMOVE:
|
||||
|
@ -449,8 +449,8 @@ void Position::undo_move(Sanmill::Stack<Position> &ss)
|
|||
Key Position::key_after(Move m) const
|
||||
{
|
||||
Key k = st.key;
|
||||
Square s = static_cast<Square>(to_sq(m));;
|
||||
MoveType mt = type_of(m);
|
||||
const Square s = static_cast<Square>(to_sq(m));;
|
||||
const MoveType mt = type_of(m);
|
||||
|
||||
if (mt == MOVETYPE_REMOVE) {
|
||||
k ^= Zobrist::psq[~side_to_move()][s];
|
||||
|
@ -524,7 +524,7 @@ bool Position::reset()
|
|||
break;
|
||||
}
|
||||
|
||||
if (snprintf(record, RECORD_LEN_MAX, "r%1u s%03u t%02u",
|
||||
if (snprintf(record, RECORD_LEN_MAX, "r%1d s%03d t%02d",
|
||||
r + 1, rule.maxStepsLedToDraw, 0) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
@ -573,7 +573,7 @@ bool Position::put_piece(Square s, bool updateRecord)
|
|||
pieceInHandCount[us]--;
|
||||
pieceOnBoardCount[us]++;
|
||||
|
||||
Piece pc = board[s] = piece;
|
||||
const Piece pc = board[s] = piece;
|
||||
byTypeBB[ALL_PIECES] |= byTypeBB[type_of(pc)] |= s;
|
||||
byColorBB[color_of(pc)] |= s; // TODO: Put ban?
|
||||
|
||||
|
@ -585,7 +585,7 @@ bool Position::put_piece(Square s, bool updateRecord)
|
|||
|
||||
currentSquare = s;
|
||||
|
||||
int n = mills_count(currentSquare);
|
||||
const int n = mills_count(currentSquare);
|
||||
|
||||
if (n == 0) {
|
||||
assert(pieceInHandCount[BLACK] >= 0 && pieceInHandCount[WHITE] >= 0);
|
||||
|
@ -639,7 +639,7 @@ bool Position::put_piece(Square s, bool updateRecord)
|
|||
st.rule50++;
|
||||
}
|
||||
|
||||
Piece pc = board[currentSquare];
|
||||
const Piece pc = board[currentSquare];
|
||||
|
||||
board[s] = pc;
|
||||
update_key(s);
|
||||
|
@ -656,9 +656,8 @@ bool Position::put_piece(Square s, bool updateRecord)
|
|||
SET_BIT(byColorBB[color_of(pc)], s);
|
||||
|
||||
currentSquare = s;
|
||||
int n = mills_count(currentSquare);
|
||||
const int n = mills_count(currentSquare);
|
||||
|
||||
// midgame
|
||||
if (n == 0) {
|
||||
action = Action::select;
|
||||
change_side_to_move();
|
||||
|
@ -714,13 +713,13 @@ bool Position::remove_piece(Square s, bool updateRecord)
|
|||
SET_BIT(byTypeBB[type_of(pc)], s);
|
||||
} else {
|
||||
// Remove only
|
||||
Piece pc = board[s];
|
||||
const Piece pc = board[s];
|
||||
|
||||
CLEAR_BIT(byTypeBB[ALL_PIECES], s);
|
||||
CLEAR_BIT(byTypeBB[type_of(pc)], s);
|
||||
CLEAR_BIT(byColorBB[color_of(pc)], s);
|
||||
|
||||
pc = board[s] = NO_PIECE;
|
||||
board[s] = NO_PIECE;
|
||||
}
|
||||
|
||||
if (updateRecord) {
|
||||
|
@ -807,11 +806,11 @@ bool Position::resign(Color loser)
|
|||
|
||||
bool Position::command(const char *cmd)
|
||||
{
|
||||
unsigned int ruleNo;
|
||||
unsigned t;
|
||||
int step;
|
||||
File file1, file2;
|
||||
Rank rank1, rank2;
|
||||
unsigned int ruleNo = 0;
|
||||
unsigned t = 0;
|
||||
int step = 0;
|
||||
File file1 = FILE_A, file2 = FILE_A;
|
||||
Rank rank1 = RANK_1, rank2 = RANK_1;
|
||||
int args = 0;
|
||||
|
||||
if (sscanf(cmd, "r%1u s%3d t%2u", &ruleNo, &step, &t) == 3) {
|
||||
|
@ -862,7 +861,7 @@ bool Position::command(const char *cmd)
|
|||
return false;
|
||||
}
|
||||
|
||||
Color Position::get_winner() const
|
||||
Color Position::get_winner() const noexcept
|
||||
{
|
||||
return winner;
|
||||
}
|
||||
|
@ -957,7 +956,7 @@ void Position::remove_ban_stones()
|
|||
s = static_cast<Square>(f * RANK_NB + r);
|
||||
|
||||
if (board[s] == BAN_STONE) {
|
||||
Piece pc = board[s];
|
||||
const Piece pc = board[s];
|
||||
byTypeBB[ALL_PIECES] ^= s;
|
||||
byTypeBB[type_of(pc)] ^= s;
|
||||
board[s] = NO_PIECE;
|
||||
|
@ -985,7 +984,7 @@ inline Key Position::update_key(Square s)
|
|||
// PieceType is board[s]
|
||||
|
||||
// 0b00 - no piece, 0b01 = 1 black, 0b10 = 2 white, 0b11 = 3 ban
|
||||
int pieceType = color_on(s);
|
||||
const int pieceType = color_on(s);
|
||||
// TODO: this is std, but current code can work
|
||||
//Location loc = board[s];
|
||||
//int pieceType = loc == 0x0f? 3 : loc >> 4;
|
||||
|
@ -1092,8 +1091,8 @@ int Position::potential_mills_count(Square to, Color c, Square from)
|
|||
CLEAR_BIT(byColorBB[color_of(locbak)], from);
|
||||
}
|
||||
|
||||
Bitboard bc = byColorBB[c];
|
||||
Bitboard *mt = millTableBB[to];
|
||||
const Bitboard bc = byColorBB[c];
|
||||
const Bitboard *mt = millTableBB[to];
|
||||
|
||||
for (int l = 0; l < LD_NB; l++) {
|
||||
if ((bc & mt[l]) == mt[l]) {
|
||||
|
@ -1116,8 +1115,8 @@ int Position::mills_count(Square s)
|
|||
{
|
||||
int n = 0;
|
||||
|
||||
Bitboard bc = byColorBB[color_on(s)];
|
||||
Bitboard *mt = millTableBB[s];
|
||||
const Bitboard bc = byColorBB[color_on(s)];
|
||||
const Bitboard *mt = millTableBB[s];
|
||||
|
||||
for (auto i = 0; i < LD_NB; ++i) {
|
||||
if (((bc & mt[i]) == mt[i])) {
|
||||
|
@ -1176,7 +1175,7 @@ void Position::surrounded_pieces_count(Square s, int &ourPieceCount, int &theirP
|
|||
continue;
|
||||
}
|
||||
|
||||
enum Piece pieceType = static_cast<Piece>(board[moveSquare]);
|
||||
const enum Piece pieceType = static_cast<Piece>(board[moveSquare]);
|
||||
|
||||
switch (pieceType) {
|
||||
case NO_PIECE:
|
||||
|
@ -1272,7 +1271,7 @@ void Position::reset_bb()
|
|||
memset(byColorBB, 0, sizeof(byColorBB));
|
||||
|
||||
for (Square s = SQ_BEGIN; s < SQ_END; ++s) {
|
||||
Piece pc = board[s];
|
||||
const Piece pc = board[s];
|
||||
byTypeBB[ALL_PIECES] |= byTypeBB[type_of(pc)] |= s;
|
||||
byColorBB[color_of(pc)] |= s;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
void undo_move(Sanmill::Stack<Position> &ss);
|
||||
|
||||
// Accessing hash keys
|
||||
Key key() const;
|
||||
Key key() const noexcept;
|
||||
Key key_after(Move m) const;
|
||||
void construct_key();
|
||||
Key revert_key(Square s);
|
||||
|
@ -95,7 +95,7 @@ public:
|
|||
|
||||
/// Mill Game
|
||||
|
||||
Piece *get_board();
|
||||
Piece *get_board() noexcept;
|
||||
Square current_square() const;
|
||||
enum Phase get_phase() const;
|
||||
enum Action get_action() const;
|
||||
|
@ -113,7 +113,7 @@ public:
|
|||
void set_side_to_move(Color c);
|
||||
|
||||
void change_side_to_move();
|
||||
Color get_winner() const;
|
||||
Color get_winner() const noexcept;
|
||||
void set_gameover(Color w, GameOverReason reason);
|
||||
|
||||
void mirror(std::vector <std::string> &moveHistory, bool cmdChange = true);
|
||||
|
@ -229,7 +229,7 @@ template<PieceType Pt> inline int Position::count(Color c) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
inline Key Position::key() const
|
||||
inline Key Position::key() const noexcept
|
||||
{
|
||||
return st.key;
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ inline void Position::put_piece(Piece pc, Square s)
|
|||
|
||||
inline bool Position::put_piece(File f, Rank r)
|
||||
{
|
||||
bool ret = put_piece(make_square(f, r), true);
|
||||
const bool ret = put_piece(make_square(f, r), true);
|
||||
|
||||
if (ret) {
|
||||
update_score();
|
||||
|
@ -287,7 +287,7 @@ inline bool Position::move_piece(File f1, Rank r1, File f2, Rank r2)
|
|||
|
||||
inline bool Position::remove_piece(File f, Rank r)
|
||||
{
|
||||
bool ret = remove_piece(make_square(f, r), true);
|
||||
const bool ret = remove_piece(make_square(f, r), true);
|
||||
|
||||
if (ret) {
|
||||
update_score();
|
||||
|
@ -315,7 +315,7 @@ inline bool Position::move_piece(Square from, Square to)
|
|||
|
||||
/// Mill Game
|
||||
|
||||
inline Piece *Position::get_board()
|
||||
inline Piece *Position::get_board() noexcept
|
||||
{
|
||||
return static_cast<Piece *>(board);
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ const struct Rule RULES[N_RULES] = {
|
|||
}
|
||||
};
|
||||
|
||||
bool set_rule(int ruleIdx)
|
||||
bool set_rule(int ruleIdx) noexcept
|
||||
{
|
||||
if (ruleIdx <= 0 || ruleIdx >= N_RULES) {
|
||||
return false;
|
||||
|
|
|
@ -58,6 +58,6 @@ struct Rule
|
|||
#define N_RULES 4
|
||||
extern const struct Rule RULES[N_RULES];
|
||||
extern struct Rule rule;
|
||||
extern bool set_rule(int ruleIdx);
|
||||
extern bool set_rule(int ruleIdx) noexcept;
|
||||
|
||||
#endif /* RULE_H */
|
||||
|
|
|
@ -48,7 +48,7 @@ Value search(Position *pos, Sanmill::Stack<Position> &ss, Depth depth, Depth ori
|
|||
|
||||
/// Search::init() is called at startup to initialize various lookup tables
|
||||
|
||||
void Search::init()
|
||||
void Search::init() noexcept
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -80,10 +80,10 @@ int Thread::search()
|
|||
|
||||
Value value = VALUE_ZERO;
|
||||
|
||||
Depth d = adjustDepth();
|
||||
const Depth d = adjustDepth();
|
||||
adjustedDepth = d;
|
||||
|
||||
time_t time0 = time(nullptr);
|
||||
const time_t time0 = time(nullptr);
|
||||
srand(static_cast<unsigned int>(time0));
|
||||
|
||||
#ifdef TIME_STAT
|
||||
|
@ -97,7 +97,7 @@ int Thread::search()
|
|||
|
||||
#ifdef THREEFOLD_REPETITION
|
||||
if (rootPos->get_phase() == Phase::moving) {
|
||||
Key key = rootPos->key();
|
||||
const Key key = rootPos->key();
|
||||
|
||||
for (auto i : posKeyHistory) {
|
||||
if (key == i)
|
||||
|
@ -132,7 +132,7 @@ int Thread::search()
|
|||
if (gameOptions.getIDSEnabled()) {
|
||||
loggerDebug("IDS: ");
|
||||
|
||||
Depth depthBegin = 2;
|
||||
const Depth depthBegin = 2;
|
||||
Value lastValue = VALUE_ZERO;
|
||||
|
||||
loggerDebug("\n==============================\n");
|
||||
|
@ -204,7 +204,7 @@ vector<Key> posKeyHistory;
|
|||
|
||||
Value search(Position *pos, Sanmill::Stack<Position> &ss, Depth depth, Depth originDepth, Value alpha, Value beta, Move &bestMove)
|
||||
{
|
||||
Value value;
|
||||
Value value = VALUE_ZERO;
|
||||
Value bestValue = -VALUE_INFINITE;
|
||||
|
||||
Depth epsilon;
|
||||
|
@ -214,7 +214,7 @@ Value search(Position *pos, Sanmill::Stack<Position> &ss, Depth depth, Depth ori
|
|||
#endif // TT_MOVE_ENABLE
|
||||
|
||||
#if defined (TRANSPOSITION_TABLE_ENABLE) || defined(ENDGAME_LEARNING)
|
||||
Key posKey = pos->key();
|
||||
const Key posKey = pos->key();
|
||||
#endif
|
||||
|
||||
#ifdef ENDGAME_LEARNING
|
||||
|
@ -242,7 +242,7 @@ Value search(Position *pos, Sanmill::Stack<Position> &ss, Depth depth, Depth ori
|
|||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
Bound type = BOUND_NONE;
|
||||
|
||||
Value probeVal = TranspositionTable::probe(posKey, depth, alpha, beta, type
|
||||
const Value probeVal = TranspositionTable::probe(posKey, depth, alpha, beta, type
|
||||
#ifdef TT_MOVE_ENABLE
|
||||
, ttMove
|
||||
#endif // TT_MOVE_ENABLE
|
||||
|
@ -316,7 +316,7 @@ Value search(Position *pos, Sanmill::Stack<Position> &ss, Depth depth, Depth ori
|
|||
|
||||
MovePicker mp(*pos);
|
||||
Move nextMove = mp.next_move();
|
||||
int moveCount = mp.move_count();
|
||||
const int moveCount = mp.move_count();
|
||||
|
||||
if (moveCount == 1 && depth == originDepth) {
|
||||
bestMove = nextMove;
|
||||
|
@ -340,10 +340,10 @@ Value search(Position *pos, Sanmill::Stack<Position> &ss, Depth depth, Depth ori
|
|||
|
||||
for (int i = 0; i < moveCount; i++) {
|
||||
ss.push(*(pos));
|
||||
Color before = pos->sideToMove;
|
||||
const Color before = pos->sideToMove;
|
||||
Move move = mp.moves[i].move;
|
||||
pos->do_move(move);
|
||||
Color after = pos->sideToMove;
|
||||
const Color after = pos->sideToMove;
|
||||
|
||||
if (gameOptions.getDepthExtension() == true && moveCount == 1) {
|
||||
epsilon = 1;
|
||||
|
|
|
@ -36,7 +36,7 @@ using namespace std;
|
|||
namespace Search
|
||||
{
|
||||
|
||||
void init();
|
||||
void init() noexcept;
|
||||
void clear();
|
||||
|
||||
} // namespace Search
|
||||
|
|
|
@ -48,7 +48,7 @@ struct rdtscp_clock {
|
|||
return time_point(duration((static_cast<std::uint64_t>(hi) << 32) | lo));
|
||||
#endif // WIN32
|
||||
#else
|
||||
unsigned int ui = 0;
|
||||
constexpr unsigned int ui = 0;
|
||||
return time_point(duration((static_cast<std::uint64_t>(ui))));
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -40,12 +40,12 @@ public:
|
|||
explicit Test(QWidget *parent = nullptr, QString k = "Key0");
|
||||
~Test();
|
||||
|
||||
void setKey(QString k)
|
||||
void setKey(QString k) noexcept
|
||||
{
|
||||
key = k;
|
||||
}
|
||||
|
||||
QString getKey()
|
||||
QString getKey() noexcept
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
|
|
@ -52,10 +52,10 @@ Thread::Thread(size_t n
|
|||
, QObject *parent
|
||||
#endif
|
||||
) :
|
||||
idx(n), stdThread(&Thread::idle_loop, this),
|
||||
#ifdef QT_GUI_LIB
|
||||
QObject(parent),
|
||||
#endif
|
||||
idx(n), stdThread(&Thread::idle_loop, this),
|
||||
timeLimit(3600)
|
||||
{
|
||||
wait_for_search_finished();
|
||||
|
@ -76,7 +76,7 @@ Thread::~Thread()
|
|||
|
||||
/// Thread::clear() reset histories, usually before a new game
|
||||
|
||||
void Thread::clear()
|
||||
void Thread::clear() noexcept
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
@ -254,19 +254,19 @@ void Thread::analyze(Color c)
|
|||
float bwinrate, wwinrate, drawrate;
|
||||
#endif // !QT_GUI_LIB
|
||||
|
||||
int d = (int)originDepth;
|
||||
int v = (int)bestvalue;
|
||||
int lv = (int)lastvalue;
|
||||
bool win = v >= VALUE_MATE;
|
||||
bool lose = v <= -VALUE_MATE;
|
||||
int np = v / VALUE_EACH_PIECE;
|
||||
const int d = (int)originDepth;
|
||||
const int v = (int)bestvalue;
|
||||
const int lv = (int)lastvalue;
|
||||
const bool win = v >= VALUE_MATE;
|
||||
const bool lose = v <= -VALUE_MATE;
|
||||
const int np = v / VALUE_EACH_PIECE;
|
||||
|
||||
string strUs = (c == BLACK ? "Black" : "White");
|
||||
string strThem = (c == BLACK ? "White" : "Black");
|
||||
|
||||
loggerDebug("Depth: %d\n\n", adjustedDepth);
|
||||
|
||||
Position *p = rootPos;
|
||||
const Position *p = rootPos;
|
||||
|
||||
cout << *p << "\n" << endl;
|
||||
cout << std::dec;
|
||||
|
@ -389,7 +389,7 @@ Depth Thread::adjustDepth()
|
|||
Depth d = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
Depth reduce = 0;
|
||||
constexpr Depth reduce = 0;
|
||||
#else
|
||||
Depth reduce = 0;
|
||||
#endif
|
||||
|
@ -436,10 +436,10 @@ Depth Thread::adjustDepth()
|
|||
};
|
||||
#endif /* ENDGAME_LEARNING */
|
||||
|
||||
const Depth flyingDepth = 9;
|
||||
constexpr Depth flyingDepth = 9;
|
||||
|
||||
if (rootPos->phase == Phase::placing) {
|
||||
int index = rule.piecesCount * 2 - rootPos->count<IN_HAND>(BLACK) - rootPos->count<IN_HAND>(WHITE);
|
||||
const int index = rule.piecesCount * 2 - rootPos->count<IN_HAND>(BLACK) - rootPos->count<IN_HAND>(WHITE);
|
||||
|
||||
if (rule.piecesCount == 12) {
|
||||
assert(0 <= index && index <= 24);
|
||||
|
@ -451,10 +451,10 @@ Depth Thread::adjustDepth()
|
|||
}
|
||||
|
||||
if (rootPos->phase == Phase::moving) {
|
||||
int pb = rootPos->count<ON_BOARD>(BLACK);
|
||||
int pw = rootPos->count<ON_BOARD>(WHITE);
|
||||
const int pb = rootPos->count<ON_BOARD>(BLACK);
|
||||
const int pw = rootPos->count<ON_BOARD>(WHITE);
|
||||
|
||||
int pieces = pb + pw;
|
||||
const int pieces = pb + pw;
|
||||
int diff = pb - pw;
|
||||
|
||||
if (diff < 0) {
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
);
|
||||
virtual ~Thread();
|
||||
int search();
|
||||
void clear();
|
||||
void clear() noexcept;
|
||||
void idle_loop();
|
||||
void start_searching();
|
||||
void wait_for_search_finished();
|
||||
|
@ -172,7 +172,7 @@ struct ThreadPool : public std::vector<Thread *>
|
|||
std::atomic_bool stop, increaseDepth;
|
||||
|
||||
private:
|
||||
uint64_t accumulate(std::atomic<uint64_t> Thread:: *member) const
|
||||
uint64_t accumulate(std::atomic<uint64_t> Thread:: *member) const noexcept
|
||||
{
|
||||
uint64_t sum = 0;
|
||||
for (Thread *th : *this)
|
||||
|
|
6
src/tt.h
6
src/tt.h
|
@ -35,17 +35,17 @@ using namespace CTSL;
|
|||
|
||||
struct TTEntry
|
||||
{
|
||||
Value value() const
|
||||
Value value() const noexcept
|
||||
{
|
||||
return (Value)value8;
|
||||
}
|
||||
|
||||
Depth depth() const
|
||||
Depth depth() const noexcept
|
||||
{
|
||||
return (Depth)depth8 + DEPTH_OFFSET;
|
||||
}
|
||||
|
||||
Bound bound() const
|
||||
Bound bound() const noexcept
|
||||
{
|
||||
return (Bound)(genBound8);
|
||||
}
|
||||
|
|
12
src/types.h
12
src/types.h
|
@ -389,12 +389,12 @@ inline T& operator--(T& d) { return d = T(int(d) - 1); }
|
|||
|
||||
#define ENABLE_FULL_OPERATORS_ON(T) \
|
||||
ENABLE_BASE_OPERATORS_ON(T) \
|
||||
constexpr T operator*(int i, T d) { return T(i * int(d)); } \
|
||||
constexpr T operator*(T d, int i) { return T(int(d) * i); } \
|
||||
constexpr T operator/(T d, int i) { return T(int(d) / i); } \
|
||||
constexpr int operator/(T d1, T d2) { return int(d1) / int(d2); } \
|
||||
inline T& operator*=(T& d, int i) { return d = T(int(d) * i); } \
|
||||
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
|
||||
constexpr T operator*(int i, T d) noexcept { return T(i * int(d)); } \
|
||||
constexpr T operator*(T d, int i) noexcept { return T(int(d) * i); } \
|
||||
constexpr T operator/(T d, int i) noexcept { return T(int(d) / i); } \
|
||||
constexpr int operator/(T d1, T d2) noexcept { return int(d1) / int(d2); } \
|
||||
inline T& operator*=(T& d, int i) noexcept { return d = T(int(d) * i); } \
|
||||
inline T& operator/=(T& d, int i) noexcept { return d = T(int(d) / i); }
|
||||
|
||||
ENABLE_FULL_OPERATORS_ON(Value)
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ string UCI::move(Move m)
|
|||
{
|
||||
string move;
|
||||
|
||||
Square to = to_sq(m);
|
||||
const Square to = to_sq(m);
|
||||
|
||||
if (m == MOVE_NONE)
|
||||
return "(none)";
|
||||
|
@ -277,7 +277,7 @@ string UCI::move(Move m)
|
|||
if (m < 0) {
|
||||
move = "-" + UCI::square(to);
|
||||
} else if (m & 0x7f00) {
|
||||
Square from = from_sq(m);
|
||||
const Square from = from_sq(m);
|
||||
move = UCI::square(from) + "->" + UCI::square(to);
|
||||
} else {
|
||||
move = UCI::square(to);
|
||||
|
|
|
@ -127,7 +127,7 @@ bool CaseInsensitiveLess::operator() (const string &s1, const string &s2) const
|
|||
{
|
||||
|
||||
return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
|
||||
[](char c1, char c2) { return tolower(c1) < tolower(c2); });
|
||||
[](char c1, char c2) noexcept { return tolower(c1) < tolower(c2); });
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
Type = UserType + 1
|
||||
};
|
||||
|
||||
int type() const override
|
||||
int type() const noexcept override
|
||||
{
|
||||
return Type;
|
||||
}
|
||||
|
|
|
@ -51,11 +51,11 @@ private slots:
|
|||
void displayError(QAbstractSocket::SocketError socketError);
|
||||
void enableGetActionButton();
|
||||
void sessionOpened();
|
||||
void setPort(uint16_t p)
|
||||
void setPort(uint16_t p) noexcept
|
||||
{
|
||||
this->port = p;
|
||||
}
|
||||
uint16_t getPort()
|
||||
uint16_t getPort() noexcept
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ void Game::gameReset()
|
|||
currentRow = 0;
|
||||
|
||||
// 发出信号通知主窗口更新LCD显示
|
||||
QTime qtime = QTime(0, 0, 0, 0).addSecs(static_cast<int>(remainingTime[BLACK]));
|
||||
const QTime qtime = QTime(0, 0, 0, 0).addSecs(static_cast<int>(remainingTime[BLACK]));
|
||||
emit time1Changed(qtime.toString("hh:mm:ss"));
|
||||
emit time2Changed(qtime.toString("hh:mm:ss"));
|
||||
|
||||
|
@ -298,7 +298,7 @@ void Game::gameReset()
|
|||
//playSound(":/sound/resources/sound/newgame.wav");
|
||||
}
|
||||
|
||||
void Game::setEditing(bool arg)
|
||||
void Game::setEditing(bool arg) noexcept
|
||||
{
|
||||
isEditing = arg;
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ void Game::setRule(int ruleNo, int stepLimited /*= -1*/, int timeLimited /*= -1*
|
|||
return;
|
||||
}
|
||||
|
||||
int r = ruleNo;
|
||||
const int r = ruleNo;
|
||||
elapsedSeconds[BLACK] = elapsedSeconds[WHITE] = 0;
|
||||
|
||||
char record[64] = { 0 };
|
||||
|
@ -395,7 +395,7 @@ void Game::getAiDepthTime(int &time1, int &time2)
|
|||
time2 = aiThread[WHITE]->getTimeLimit();
|
||||
}
|
||||
|
||||
void Game::setAnimation(bool arg)
|
||||
void Game::setAnimation(bool arg) noexcept
|
||||
{
|
||||
hasAnimation = arg;
|
||||
|
||||
|
@ -406,7 +406,7 @@ void Game::setAnimation(bool arg)
|
|||
durationTime = 0;
|
||||
}
|
||||
|
||||
void Game::setSound(bool arg)
|
||||
void Game::setSound(bool arg) noexcept
|
||||
{
|
||||
hasSound = arg;
|
||||
}
|
||||
|
@ -699,7 +699,7 @@ void Game::timerEvent(QTimerEvent *event)
|
|||
emit time2Changed(qt2.toString("hh:mm:ss"));
|
||||
|
||||
// 如果胜负已分
|
||||
Color winner = position.get_winner();
|
||||
const Color winner = position.get_winner();
|
||||
if (winner != NOBODY) {
|
||||
// 停止计时
|
||||
killTimer(timeID);
|
||||
|
@ -783,8 +783,8 @@ bool Game::actionPiece(QPointF p)
|
|||
|
||||
if (QMessageBox::Ok == msgBox.exec()) {
|
||||
#endif /* !MOBILE_APP_UI */
|
||||
int rowCount = manualListModel.rowCount();
|
||||
int removeCount = rowCount - currentRow - 1;
|
||||
const int rowCount = manualListModel.rowCount();
|
||||
const int removeCount = rowCount - currentRow - 1;
|
||||
manualListModel.removeRows(currentRow + 1, rowCount - currentRow - 1);
|
||||
|
||||
for (int i = 0; i < removeCount; i++) {
|
||||
|
@ -888,7 +888,7 @@ bool Game::actionPiece(QPointF p)
|
|||
|
||||
// 播放胜利或失败音效
|
||||
#ifndef DONOT_PLAY_WIN_SOUND
|
||||
Color winner = position.get_winner();
|
||||
const Color winner = position.get_winner();
|
||||
if (winner != NOBODY &&
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over."))
|
||||
playSound(GameSound::win, winner);
|
||||
|
@ -913,7 +913,7 @@ bool Game::actionPiece(QPointF p)
|
|||
|
||||
bool Game::resign()
|
||||
{
|
||||
bool result = position.resign(position.sideToMove);
|
||||
const bool result = position.resign(position.sideToMove);
|
||||
|
||||
if (!result) {
|
||||
return false;
|
||||
|
@ -942,8 +942,8 @@ bool Game::resign()
|
|||
// 关键槽函数,棋谱的命令行执行,与actionPiece独立
|
||||
bool Game::command(const string &cmd, bool update /* = true */)
|
||||
{
|
||||
int total;
|
||||
float bwinrate, wwinrate, drawrate;
|
||||
int total = 0;
|
||||
float bwinrate = 0.0f, wwinrate = 0.0f, drawrate = 0.0f;
|
||||
|
||||
Q_UNUSED(hasSound)
|
||||
|
||||
|
@ -1025,7 +1025,7 @@ bool Game::command(const string &cmd, bool update /* = true */)
|
|||
|
||||
// 播放胜利或失败音效
|
||||
#ifndef DONOT_PLAY_WIN_SOUND
|
||||
Color winner = position.get_winner();
|
||||
const Color winner = position.get_winner();
|
||||
if (winner != NOBODY &&
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) {
|
||||
playSound(GameSound::win, winner);
|
||||
|
|
|
@ -89,27 +89,27 @@ public:
|
|||
//主窗口菜单栏明细
|
||||
const map<int, QStringList> getActions();
|
||||
|
||||
int getRuleIndex()
|
||||
int getRuleIndex() noexcept
|
||||
{
|
||||
return ruleIndex;
|
||||
}
|
||||
|
||||
int getTimeLimit()
|
||||
int getTimeLimit() noexcept
|
||||
{
|
||||
return timeLimit;
|
||||
}
|
||||
|
||||
int getStepsLimit()
|
||||
int getStepsLimit() noexcept
|
||||
{
|
||||
return stepsLimit;
|
||||
}
|
||||
|
||||
bool isAnimation()
|
||||
bool isAnimation() noexcept
|
||||
{
|
||||
return hasAnimation;
|
||||
}
|
||||
|
||||
void setDurationTime(int i)
|
||||
void setDurationTime(int i) noexcept
|
||||
{
|
||||
durationTime = i;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
|
||||
void humanResign();
|
||||
|
||||
Position *getPosition()
|
||||
Position *getPosition() noexcept
|
||||
{
|
||||
return &position;
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public slots:
|
|||
void gameReset();
|
||||
|
||||
// 设置编辑棋局状态
|
||||
void setEditing(bool arg = true);
|
||||
void setEditing(bool arg = true) noexcept;
|
||||
|
||||
// 设置黑白反转状态
|
||||
void setInvert(bool arg = true);
|
||||
|
@ -219,10 +219,10 @@ public slots:
|
|||
void setEngineWhite(bool enabled);
|
||||
|
||||
// 是否有落子动画
|
||||
void setAnimation(bool arg = true);
|
||||
void setAnimation(bool arg = true) noexcept;
|
||||
|
||||
// 是否有落子音效
|
||||
void setSound(bool arg = true);
|
||||
void setSound(bool arg = true) noexcept;
|
||||
|
||||
// 播放声音
|
||||
static void playSound(GameSound soundType, Color c);
|
||||
|
|
|
@ -92,7 +92,7 @@ void GameScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
|||
}
|
||||
|
||||
// 如果是棋盘
|
||||
QGraphicsItem *item = itemAt(mouseEvent->scenePos(), QTransform());
|
||||
const QGraphicsItem *item = itemAt(mouseEvent->scenePos(), QTransform());
|
||||
|
||||
if (!item || item->type() == BoardItem::Type) {
|
||||
QPointF p = mouseEvent->scenePos();
|
||||
|
|
|
@ -92,8 +92,8 @@ MillGameWindow::MillGameWindow(QWidget * parent) :
|
|||
|
||||
// 主窗口居中显示
|
||||
QRect deskTopRect = QGuiApplication::primaryScreen()->geometry();
|
||||
int unitw = (deskTopRect.width() - width()) / 2;
|
||||
int unith = (deskTopRect.height() - height()) / 2;
|
||||
const int unitw = (deskTopRect.width() - width()) / 2;
|
||||
const int unith = (deskTopRect.height() - height()) / 2;
|
||||
this->move(unitw, unith);
|
||||
|
||||
#if defined(_DEBUG) || defined(TEST_MODE)
|
||||
|
@ -141,7 +141,7 @@ bool MillGameWindow::eventFilter(QObject *watched, QEvent *event)
|
|||
// 重载这个函数只是为了让规则菜单(动态)显示提示
|
||||
if (watched == ui.menu_R &&
|
||||
event->type() == QEvent::ToolTip) {
|
||||
auto *he = dynamic_cast <QHelpEvent *> (event);
|
||||
const auto *he = dynamic_cast <QHelpEvent *> (event);
|
||||
QAction *action = ui.menu_R->actionAt(he->pos());
|
||||
if (action) {
|
||||
QToolTip::showText(he->globalPos(), action->toolTip(), this);
|
||||
|
@ -380,7 +380,7 @@ void MillGameWindow::initialize()
|
|||
const int screen_iPhone_SE[] = {640, 1136};
|
||||
this->resize(QSize(screen_iPhone_SE[0], screen_iPhone_SE[1]));
|
||||
#else /* MOBILE_APP_UI */
|
||||
int h = QApplication::desktop()->height();
|
||||
const int h = QApplication::desktop()->height();
|
||||
this->resize(QSize(h * 3/4, h * 3/4));
|
||||
|
||||
ui.pushButton_back->setVisible(false);
|
||||
|
@ -419,8 +419,8 @@ void MillGameWindow::ctxMenu(const QPoint &pos)
|
|||
|
||||
void MillGameWindow::ruleInfo()
|
||||
{
|
||||
int s = game->getStepsLimit();
|
||||
int t = game->getTimeLimit();
|
||||
const int s = game->getStepsLimit();
|
||||
const int t = game->getTimeLimit();
|
||||
|
||||
QString tl(" 不限时");
|
||||
QString sl(" 不限步");
|
||||
|
|
|
@ -23,15 +23,15 @@
|
|||
#include "config.h"
|
||||
|
||||
#ifdef MOBILE_APP_UI
|
||||
const short BOARD_SIZE = 500; // 棋盘大小
|
||||
constexpr short BOARD_SIZE = 500; // 棋盘大小
|
||||
#else
|
||||
const short BOARD_SIZE = 600; // 棋盘大小
|
||||
constexpr short BOARD_SIZE = 600; // 棋盘大小
|
||||
#endif /* MOBILE_APP_UI */
|
||||
|
||||
const short BOARD_MINISIZE = 150; // 最小宽高,即1/4大小
|
||||
const short PIECE_SIZE = 56; // 棋子大小
|
||||
const short LINE_INTERVAL = 72; // 线间距
|
||||
const short LINE_WEIGHT = 3; // 线宽
|
||||
constexpr short BOARD_MINISIZE = 150; // 最小宽高,即1/4大小
|
||||
constexpr short PIECE_SIZE = 56; // 棋子大小
|
||||
constexpr short LINE_INTERVAL = 72; // 线间距
|
||||
constexpr short LINE_WEIGHT = 3; // 线宽
|
||||
|
||||
#endif // GRAPHICSCONST
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ class ManualListView : public QListView
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ManualListView(QWidget *parent = nullptr) : QListView(parent)
|
||||
ManualListView(QWidget *parent = nullptr) noexcept : QListView(parent)
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ protected slots:
|
|||
// 如果包含model
|
||||
if (model()) {
|
||||
// 判断
|
||||
QModelIndex square = model()->index(model()->rowCount() - 1, 0);
|
||||
const QModelIndex square = model()->index(model()->rowCount() - 1, 0);
|
||||
if (square == bottomRight && newEmptyRow) {
|
||||
setCurrentIndex(square);
|
||||
QAbstractItemView::scrollToBottom();
|
||||
|
|
|
@ -146,7 +146,7 @@ void PieceItem::paint(QPainter *painter,
|
|||
if (isSelected()) {
|
||||
QPen pen(selectLineColor, selectLineWeight, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
|
||||
painter->setPen(pen);
|
||||
int xy = (size - selectLineWeight) / 2;
|
||||
const int xy = (size - selectLineWeight) / 2;
|
||||
|
||||
painter->drawLine(-xy, -xy, -xy, -xy / 2);
|
||||
painter->drawLine(-xy, -xy, -xy / 2, -xy);
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
Type = UserType + 2
|
||||
};
|
||||
|
||||
int type() const override
|
||||
int type() const noexcept override
|
||||
{
|
||||
return Type;
|
||||
}
|
||||
|
@ -64,27 +64,27 @@ public:
|
|||
whitePiece = 0x4, // 白色棋子
|
||||
};
|
||||
|
||||
enum Models getModel()
|
||||
enum Models getModel() noexcept
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
void setModel(enum Models m)
|
||||
void setModel(enum Models m) noexcept
|
||||
{
|
||||
this->model = m;
|
||||
}
|
||||
|
||||
int getNum()
|
||||
int getNum() noexcept
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
void setNum(int n)
|
||||
void setNum(int n) noexcept
|
||||
{
|
||||
num = n;
|
||||
}
|
||||
|
||||
bool isDeleted()
|
||||
bool isDeleted() noexcept
|
||||
{
|
||||
return deleted;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public:
|
|||
update(boundingRect());
|
||||
}
|
||||
|
||||
void setShowNum(bool show = true)
|
||||
void setShowNum(bool show = true) noexcept
|
||||
{
|
||||
this->showNum = show;
|
||||
}
|
||||
|
|
|
@ -43,11 +43,11 @@ public:
|
|||
explicit Server(QWidget *parent = nullptr, uint16_t port = 33333);
|
||||
~Server();
|
||||
void setAction(const QString &a);
|
||||
void setPort(uint16_t p)
|
||||
void setPort(uint16_t p) noexcept
|
||||
{
|
||||
port = p;
|
||||
}
|
||||
uint16_t getPort()
|
||||
uint16_t getPort() noexcept
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue