Fix cppcheck reported issues

And a TSC issue.
This commit is contained in:
Calcitem 2021-01-01 19:31:07 +08:00
parent 69cd736a92
commit 3345cf0c74
19 changed files with 80 additions and 81 deletions

View File

@ -36,10 +36,10 @@ Bitboard StarSquareBB12;
const std::string Bitboards::pretty(Bitboard b) const std::string Bitboards::pretty(Bitboard b)
{ {
std::string str = "+---+---+---+---+---+---+---+---+\n"; std::string str = "+---+---+---+---+---+---+---+---+\n";
for (File file = FILE_A; file <= FILE_C; ++file) { for (File f = FILE_A; f <= FILE_C; ++f) {
for (Rank rank = RANK_1; rank <= RANK_8; ++rank) { for (Rank r = RANK_1; r <= RANK_8; ++r) {
str += b & make_square(file, rank) ? "| X " : "| "; str += b & make_square(f, r) ? "| X " : "| ";
} }
str += "|\n+---+---+---+---+---+---+---+---+\n"; str += "|\n+---+---+---+---+---+---+---+---+\n";

View File

@ -36,7 +36,7 @@ void start_logger(const std::string &fname);
void* std_aligned_alloc(size_t alignment, size_t size); void* std_aligned_alloc(size_t alignment, size_t size);
void std_aligned_free(void* ptr); void std_aligned_free(void* ptr);
#ifdef ALIGNED_LARGE_PAGES #ifdef ALIGNED_LARGE_PAGES
void* aligned_large_pages_alloc(size_t size); // memory aligned by page size, min alignment: 4096 bytes void* aligned_large_pages_alloc(size_t allocSize); // memory aligned by page size, min alignment: 4096 bytes
void aligned_large_pages_free(void* mem); // nop if mem == nullptr void aligned_large_pages_free(void* mem); // nop if mem == nullptr
#endif // ALIGNED_LARGE_PAGES #endif // ALIGNED_LARGE_PAGES
@ -116,7 +116,7 @@ class PRNG
} }
public: public:
PRNG(uint64_t seed) : s(seed) explicit PRNG(uint64_t seed) : s(seed)
{ {
assert(seed); assert(seed);
} }

View File

@ -55,12 +55,12 @@ void MovePicker::score()
Square from, to; Square from, to;
Move m; Move m;
int ourMillsCount = 0; int ourMillsCount;
int theirMillsCount = 0; int theirMillsCount;
int ourPieceCount = 0; int ourPieceCount;
int theirPiecesCount = 0; int theirPiecesCount;
int bannedCount = 0; int bannedCount;
int emptyCount = 0; int emptyCount;
while (cur++->move != MOVE_NONE) { while (cur++->move != MOVE_NONE) {
m = cur->move; m = cur->move;

View File

@ -44,7 +44,7 @@ class MovePicker
public: public:
MovePicker(const MovePicker &) = delete; MovePicker(const MovePicker &) = delete;
MovePicker &operator=(const MovePicker &) = delete; MovePicker &operator=(const MovePicker &) = delete;
MovePicker(Position &position); explicit MovePicker(Position &p);
Move next_move(); Move next_move();
@ -68,7 +68,7 @@ public:
int moveCount { 0 }; int moveCount { 0 };
int move_count() int move_count() const
{ {
return moveCount; return moveCount;
} }

View File

@ -29,7 +29,7 @@ public:
isAutoRestart = enabled; isAutoRestart = enabled;
} }
bool getAutoRestart() bool getAutoRestart() const
{ {
return isAutoRestart; return isAutoRestart;
} }
@ -39,7 +39,7 @@ public:
isAutoChangeFirstMove = enabled; isAutoChangeFirstMove = enabled;
} }
bool getAutoChangeFirstMove() bool getAutoChangeFirstMove() const
{ {
return isAutoChangeFirstMove; return isAutoChangeFirstMove;
} }
@ -49,7 +49,7 @@ public:
resignIfMostLose = enabled; resignIfMostLose = enabled;
} }
bool getResignIfMostLose() bool getResignIfMostLose() const
{ {
return resignIfMostLose; return resignIfMostLose;
} }
@ -60,7 +60,7 @@ public:
// variation between different games against an opponent that tries to do the // variation between different games against an opponent that tries to do the
// same sequence of moves. By default, shuffling is enabled. // same sequence of moves. By default, shuffling is enabled.
bool getShufflingEnabled() bool getShufflingEnabled() const
{ {
return shufflingEnabled; return shufflingEnabled;
} }
@ -79,7 +79,7 @@ public:
#endif #endif
} }
bool isEndgameLearningEnabled() bool isEndgameLearningEnabled() const
{ {
#ifdef ENDGAME_LEARNING_FORCE #ifdef ENDGAME_LEARNING_FORCE
return true; return true;
@ -93,7 +93,7 @@ public:
IDSEnabled = enabled; IDSEnabled = enabled;
} }
bool getIDSEnabled() bool getIDSEnabled() const
{ {
return IDSEnabled; return IDSEnabled;
} }
@ -105,7 +105,7 @@ public:
depthExtension = enabled; depthExtension = enabled;
} }
bool getDepthExtension() bool getDepthExtension() const
{ {
return depthExtension; return depthExtension;
} }
@ -117,7 +117,7 @@ public:
openingBook = enabled; openingBook = enabled;
} }
bool getOpeningBook() bool getOpeningBook() const
{ {
return openingBook; return openingBook;
} }

View File

@ -135,10 +135,10 @@ public:
static void print_board(); static void print_board();
int piece_on_board_count(Color c); int piece_on_board_count(Color c) const;
int piece_in_hand_count(Color c); int piece_in_hand_count(Color c) const;
int piece_to_remove_count(); int piece_to_remove_count() const;
static bool is_star_square(Square s); static bool is_star_square(Square s);
@ -146,13 +146,13 @@ public:
// Other helpers // Other helpers
bool select_piece(Square s); bool select_piece(Square s);
bool select_piece(File file, Rank rank); bool select_piece(File f, Rank r);
void put_piece(Piece pc, Square s); void put_piece(Piece pc, Square s);
bool put_piece(File file, Rank rank); bool put_piece(File f, Rank r);
bool put_piece(Square s, bool updategameRecords = false); bool put_piece(Square s, bool updategameRecords = false);
bool remove_piece(File file, Rank rank); bool remove_piece(File f, Rank r);
bool remove_piece(Square s, bool updategameRecords = false); bool remove_piece(Square s, bool updategameRecords = false);
bool move_piece(File f1, Rank r1, File f2, Rank r2); bool move_piece(File f1, Rank r1, File f2, Rank r2);
@ -169,7 +169,7 @@ public:
int pieceToRemoveCount{ 0 }; int pieceToRemoveCount{ 0 };
int gamePly { 0 }; int gamePly { 0 };
Color sideToMove { NOCOLOR }; Color sideToMove { NOCOLOR };
Thread *thisThread; Thread *thisThread {nullptr};
StateInfo st; StateInfo st;
/// Mill Game /// Mill Game
@ -342,7 +342,7 @@ inline bool Position::move_piece(Square from, Square to)
inline Piece *Position::get_board() inline Piece *Position::get_board()
{ {
return (Piece *)board; return static_cast<Piece *>(board);
} }
inline Square Position::current_square() const inline Square Position::current_square() const
@ -365,17 +365,17 @@ inline const char *Position::get_record() const
return record; return record;
} }
inline int Position::piece_on_board_count(Color c) inline int Position::piece_on_board_count(Color c) const
{ {
return pieceOnBoardCount[c]; return pieceOnBoardCount[c];
} }
inline int Position::piece_in_hand_count(Color c) inline int Position::piece_in_hand_count(Color c) const
{ {
return pieceInHandCount[c]; return pieceInHandCount[c];
} }
inline int Position::piece_to_remove_count() inline int Position::piece_to_remove_count() const
{ {
return pieceToRemoveCount; return pieceToRemoveCount;
} }

View File

@ -129,7 +129,7 @@ const struct Rule RULES[N_RULES] = {
bool set_rule(int ruleIdx) bool set_rule(int ruleIdx)
{ {
if (ruleIdx <= 0 || ruleIdx > N_RULES) { if (ruleIdx <= 0 || ruleIdx >= N_RULES) {
return false; return false;
} }

View File

@ -105,7 +105,7 @@ public:
return p + 1; return p + 1;
} }
inline size_t length() inline size_t length() const
{ {
return (sizeof(T) * size()); return (sizeof(T) * size());
} }

View File

@ -60,8 +60,8 @@ struct timer {
using time_point = typename Clock::time_point; using time_point = typename Clock::time_point;
using duration = typename Clock::duration; using duration = typename Clock::duration;
timer(const duration duration) noexcept : expiry(Clock::now() + duration) {} explicit timer(const duration duration) noexcept : expiry(Clock::now() + duration) {}
timer(const time_point expiry) noexcept : expiry(expiry) {} explicit timer(const time_point expiry) noexcept : expiry(expiry) {}
bool done(time_point now = Clock::now()) const noexcept { bool done(time_point now = Clock::now()) const noexcept {
return now >= expiry; return now >= expiry;

View File

@ -37,7 +37,7 @@ class Test : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit Test(QWidget *parent = nullptr, QString key = "Key0"); explicit Test(QWidget *parent = nullptr, QString k = "Key0");
~Test(); ~Test();
void setKey(QString k) void setKey(QString k)

View File

@ -77,7 +77,7 @@ public:
string nextMove(); string nextMove();
Depth adjustDepth(); Depth adjustDepth();
int getTimeLimit() int getTimeLimit() const
{ {
return timeLimit; return timeLimit;
} }

View File

@ -53,14 +53,14 @@ struct TTEntry
private: private:
friend class TranspositionTable; friend class TranspositionTable;
int8_t value8; int8_t value8 {0};
int8_t depth8; int8_t depth8 {0};
uint8_t genBound8; uint8_t genBound8 {0};
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN #ifdef TRANSPOSITION_TABLE_FAKE_CLEAN
uint8_t age8; uint8_t age8 {0};
#endif // TRANSPOSITION_TABLE_FAKE_CLEAN #endif // TRANSPOSITION_TABLE_FAKE_CLEAN
#ifdef TT_MOVE_ENABLE #ifdef TT_MOVE_ENABLE
Move ttMove; Move ttMove {MOVE_NONE};
#endif // TT_MOVE_ENABLE #endif // TT_MOVE_ENABLE
}; };

View File

@ -231,12 +231,11 @@ void Game::gameReset()
// 2先手第2子 3后手第2子 // 2先手第2子 3后手第2子
// ...... // ......
PieceItem::Models md; PieceItem::Models md;
PieceItem *newP;
for (int i = 0; i < rule.piecesCount; i++) { for (int i = 0; i < rule.piecesCount; i++) {
// 先手的棋子 // 先手的棋子
md = isInverted ? PieceItem::Models::whitePiece : PieceItem::Models::blackPiece; md = isInverted ? PieceItem::Models::whitePiece : PieceItem::Models::blackPiece;
newP = new PieceItem; PieceItem *newP = new PieceItem;
newP->setModel(md); newP->setModel(md);
newP->setPos(scene.pos_p1); newP->setPos(scene.pos_p1);
newP->setNum(i + 1); newP->setNum(i + 1);
@ -360,7 +359,7 @@ void Game::setRule(int ruleNo, int stepLimited /*= -1*/, int timeLimited /*= -1*
elapsedSeconds[BLACK] = elapsedSeconds[WHITE] = 0; elapsedSeconds[BLACK] = elapsedSeconds[WHITE] = 0;
char record[64] = { 0 }; char record[64] = { 0 };
if (sprintf(record, "r%1u s%03u t%02u", r + 1, rule.maxStepsLedToDraw, 0) <= 0) { if (sprintf(record, "r%1d s%03d t%02d", r + 1, rule.maxStepsLedToDraw, 0) <= 0) {
assert(0); assert(0);
} }
string cmd(record); string cmd(record);
@ -519,6 +518,7 @@ void Game::playSound(GameSound soundType, Color c)
break; break;
}; };
#ifndef DONOT_PLAY_SOUND
QString soundPath = QString::fromStdString(soundDir + filename); QString soundPath = QString::fromStdString(soundDir + filename);
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
@ -526,7 +526,6 @@ void Game::playSound(GameSound soundType, Color c)
return; return;
} }
#ifndef DONOT_PLAY_SOUND
if (hasSound) { if (hasSound) {
QSound::play(soundPath); QSound::play(soundPath);
} }
@ -781,14 +780,14 @@ bool Game::isAIsTurn()
} }
// 关键槽函数根据QGraphicsScene的信号和状态来执行选子、落子或去子 // 关键槽函数根据QGraphicsScene的信号和状态来执行选子、落子或去子
bool Game::actionPiece(QPointF pos) bool Game::actionPiece(QPointF p)
{ {
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
// 点击非落子点,不执行 // 点击非落子点,不执行
File file; File f;
Rank rank; Rank r;
if (!scene.pos2polar(pos, file, rank)) { if (!scene.pos2polar(p, f, r)) {
return false; return false;
} }
@ -848,11 +847,11 @@ bool Game::actionPiece(QPointF pos)
// 判断执行选子、落子或去子 // 判断执行选子、落子或去子
bool result = false; bool result = false;
PieceItem *piece = nullptr; PieceItem *piece = nullptr;
QGraphicsItem *item = scene.itemAt(pos, QTransform()); QGraphicsItem *item = scene.itemAt(p, QTransform());
switch (position.get_action()) { switch (position.get_action()) {
case Action::place: case Action::place:
if (position.put_piece(file, rank)) { if (position.put_piece(f, r)) {
if (position.get_action() == Action::remove) { if (position.get_action() == Action::remove) {
// 播放成三音效 // 播放成三音效
playSound(GameSound::mill, position.side_to_move()); playSound(GameSound::mill, position.side_to_move());
@ -871,7 +870,7 @@ bool Game::actionPiece(QPointF pos)
piece = qgraphicsitem_cast<PieceItem *>(item); piece = qgraphicsitem_cast<PieceItem *>(item);
if (!piece) if (!piece)
break; break;
if (position.select_piece(file, rank)) { if (position.select_piece(f, r)) {
// 播放选子音效 // 播放选子音效
playSound(GameSound::select, position.side_to_move()); playSound(GameSound::select, position.side_to_move());
result = true; result = true;
@ -882,7 +881,7 @@ bool Game::actionPiece(QPointF pos)
break; break;
case Action::remove: case Action::remove:
if (position.remove_piece(file, rank)) { if (position.remove_piece(f, r)) {
// 播放音效 // 播放音效
playSound(GameSound::remove, position.side_to_move()); playSound(GameSound::remove, position.side_to_move());
result = true; result = true;
@ -1344,7 +1343,7 @@ bool Game::updateScence(Position &p)
int ipos = p.current_square(); int ipos = p.current_square();
if (ipos) { if (ipos) {
key = board[p.current_square()]; key = board[p.current_square()];
ipos = key & B_STONE ? (key - B_STONE_1) * 2 : (key - W_STONE_1) * 2 + 1; ipos = (key & B_STONE) ? (key - B_STONE_1) * 2 : (key - W_STONE_1) * 2 + 1;
if (ipos >= 0 && ipos < nTotalPieces) { if (ipos >= 0 && ipos < nTotalPieces) {
currentPiece = pieceList.at(static_cast<size_t>(ipos)); currentPiece = pieceList.at(static_cast<size_t>(ipos));
currentPiece->setSelected(true); currentPiece->setSelected(true);
@ -1588,7 +1587,7 @@ void Game::setTips()
reasonStr = turnStr + "超时判负。"; reasonStr = turnStr + "超时判负。";
break; break;
case GameOverReason::drawReasonThreefoldRepetition: case GameOverReason::drawReasonThreefoldRepetition:
tips = "三次重复局面判和。"; reasonStr = "三次重复局面判和。";
break; break;
default: default:
break; break;

View File

@ -80,7 +80,7 @@ class Game : public QObject
Q_OBJECT Q_OBJECT
public: public:
Game( explicit Game(
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
GameScene &scene, GameScene &scene,
#endif #endif
@ -356,7 +356,7 @@ public slots:
// 更新棋局显示,每步后执行才能刷新局面 // 更新棋局显示,每步后执行才能刷新局面
bool updateScence(); bool updateScence();
bool updateScence(Position &position); bool updateScence(Position &p);
#ifdef NET_FIGHT_SUPPORT #ifdef NET_FIGHT_SUPPORT
// 显示网络配置窗口 // 显示网络配置窗口

View File

@ -1098,26 +1098,26 @@ void MillGameWindow::on_actionAbout_A_triggered()
} }
#ifdef MOBILE_APP_UI #ifdef MOBILE_APP_UI
void MillGameWindow::mousePressEvent(QMouseEvent *event) void MillGameWindow::mousePressEvent(QMouseEvent *mouseEvent)
{ {
if (event->button() == Qt::LeftButton) { if (mouseEvent->button() == Qt::LeftButton) {
m_move = true; m_move = true;
m_startPoint = event->globalPos(); m_startPoint = mouseEvent->globalPos();
m_windowPoint = this->frameGeometry().topLeft(); m_windowPoint = this->frameGeometry().topLeft();
} }
} }
void MillGameWindow::mouseMoveEvent(QMouseEvent *event) void MillGameWindow::mouseMoveEvent(QMouseEvent *mouseEvent)
{ {
if (event->buttons() & Qt::LeftButton) { if (mouseEvent->buttons() & Qt::LeftButton) {
QPoint relativePos = event->globalPos() - m_startPoint; QPoint relativePos = mouseEvent->globalPos() - m_startPoint;
this->move(m_windowPoint + relativePos ); this->move(m_windowPoint + relativePos );
} }
} }
void MillGameWindow::mouseReleaseEvent(QMouseEvent *event) void MillGameWindow::mouseReleaseEvent(QMouseEvent *mouseEvent)
{ {
if (event->button() == Qt::LeftButton) { if (mouseEvent->button() == Qt::LeftButton) {
m_move = false; m_move = false;
} }
} }

View File

@ -51,9 +51,9 @@ protected:
bool eventFilter(QObject *watched, QEvent *event) override; bool eventFilter(QObject *watched, QEvent *event) override;
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
#ifdef MOBILE_APP_UI #ifdef MOBILE_APP_UI
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *mouseEvent) override;
void mouseMoveEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *mouseEvent) override;
void mouseReleaseEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *mouseEvent) override;
#endif /* MOBILE_APP_UI */ #endif /* MOBILE_APP_UI */
private slots: private slots:

View File

@ -168,21 +168,21 @@ void PieceItem::paint(QPainter *painter,
} }
} }
void PieceItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void PieceItem::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{ {
// 鼠标按下时变为握住的手形 // 鼠标按下时变为握住的手形
setCursor(Qt::ClosedHandCursor); setCursor(Qt::ClosedHandCursor);
QGraphicsItem::mousePressEvent(event); QGraphicsItem::mousePressEvent(mouseEvent);
} }
void PieceItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void PieceItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{ {
QGraphicsItem::mouseMoveEvent(event); QGraphicsItem::mouseMoveEvent(mouseEvent);
} }
void PieceItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void PieceItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{ {
// 鼠标松开时变为伸开的手形 // 鼠标松开时变为伸开的手形
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
QGraphicsItem::mouseReleaseEvent(event); QGraphicsItem::mouseReleaseEvent(mouseEvent);
} }

View File

@ -114,10 +114,10 @@ private:
enum Models model; enum Models model;
// 棋子序号黑白都从1开始 // 棋子序号黑白都从1开始
int num = 1; int num {1};
// 棋子尺寸 // 棋子尺寸
int size; int size {0};
// 有无删除线 // 有无删除线
bool deleted {false}; bool deleted {false};
@ -126,10 +126,10 @@ private:
bool showNum {false}; bool showNum {false};
// 选中子标识线宽度 // 选中子标识线宽度
int selectLineWeight; int selectLineWeight {0};
// 删除线宽度 // 删除线宽度
int removeLineWeight; int removeLineWeight {0};
// 选中线颜色 // 选中线颜色
QColor selectLineColor; QColor selectLineColor;

View File

@ -42,7 +42,7 @@ class Server : public QDialog
public: public:
explicit Server(QWidget *parent = nullptr, uint16_t port = 33333); explicit Server(QWidget *parent = nullptr, uint16_t port = 33333);
~Server(); ~Server();
void setAction(const QString &action); void setAction(const QString &a);
void setPort(uint16_t p) void setPort(uint16_t p)
{ {
port = p; port = p;