parent
69cd736a92
commit
3345cf0c74
|
@ -36,10 +36,10 @@ Bitboard StarSquareBB12;
|
|||
const std::string Bitboards::pretty(Bitboard b)
|
||||
{
|
||||
std::string str = "+---+---+---+---+---+---+---+---+\n";
|
||||
for (File file = FILE_A; file <= FILE_C; ++file) {
|
||||
for (Rank rank = RANK_1; rank <= RANK_8; ++rank) {
|
||||
for (File f = FILE_A; f <= FILE_C; ++f) {
|
||||
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";
|
||||
|
|
|
@ -36,7 +36,7 @@ void start_logger(const std::string &fname);
|
|||
void* std_aligned_alloc(size_t alignment, size_t size);
|
||||
void std_aligned_free(void* ptr);
|
||||
#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
|
||||
#endif // ALIGNED_LARGE_PAGES
|
||||
|
||||
|
@ -116,7 +116,7 @@ class PRNG
|
|||
}
|
||||
|
||||
public:
|
||||
PRNG(uint64_t seed) : s(seed)
|
||||
explicit PRNG(uint64_t seed) : s(seed)
|
||||
{
|
||||
assert(seed);
|
||||
}
|
||||
|
|
|
@ -55,12 +55,12 @@ void MovePicker::score()
|
|||
Square from, to;
|
||||
Move m;
|
||||
|
||||
int ourMillsCount = 0;
|
||||
int theirMillsCount = 0;
|
||||
int ourPieceCount = 0;
|
||||
int theirPiecesCount = 0;
|
||||
int bannedCount = 0;
|
||||
int emptyCount = 0;
|
||||
int ourMillsCount;
|
||||
int theirMillsCount;
|
||||
int ourPieceCount;
|
||||
int theirPiecesCount;
|
||||
int bannedCount;
|
||||
int emptyCount;
|
||||
|
||||
while (cur++->move != MOVE_NONE) {
|
||||
m = cur->move;
|
||||
|
|
|
@ -44,7 +44,7 @@ class MovePicker
|
|||
public:
|
||||
MovePicker(const MovePicker &) = delete;
|
||||
MovePicker &operator=(const MovePicker &) = delete;
|
||||
MovePicker(Position &position);
|
||||
explicit MovePicker(Position &p);
|
||||
|
||||
Move next_move();
|
||||
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
int moveCount { 0 };
|
||||
|
||||
int move_count()
|
||||
int move_count() const
|
||||
{
|
||||
return moveCount;
|
||||
}
|
||||
|
|
16
src/option.h
16
src/option.h
|
@ -29,7 +29,7 @@ public:
|
|||
isAutoRestart = enabled;
|
||||
}
|
||||
|
||||
bool getAutoRestart()
|
||||
bool getAutoRestart() const
|
||||
{
|
||||
return isAutoRestart;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public:
|
|||
isAutoChangeFirstMove = enabled;
|
||||
}
|
||||
|
||||
bool getAutoChangeFirstMove()
|
||||
bool getAutoChangeFirstMove() const
|
||||
{
|
||||
return isAutoChangeFirstMove;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public:
|
|||
resignIfMostLose = enabled;
|
||||
}
|
||||
|
||||
bool getResignIfMostLose()
|
||||
bool getResignIfMostLose() const
|
||||
{
|
||||
return resignIfMostLose;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
// variation between different games against an opponent that tries to do the
|
||||
// same sequence of moves. By default, shuffling is enabled.
|
||||
|
||||
bool getShufflingEnabled()
|
||||
bool getShufflingEnabled() const
|
||||
{
|
||||
return shufflingEnabled;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
bool isEndgameLearningEnabled()
|
||||
bool isEndgameLearningEnabled() const
|
||||
{
|
||||
#ifdef ENDGAME_LEARNING_FORCE
|
||||
return true;
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
IDSEnabled = enabled;
|
||||
}
|
||||
|
||||
bool getIDSEnabled()
|
||||
bool getIDSEnabled() const
|
||||
{
|
||||
return IDSEnabled;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public:
|
|||
depthExtension = enabled;
|
||||
}
|
||||
|
||||
bool getDepthExtension()
|
||||
bool getDepthExtension() const
|
||||
{
|
||||
return depthExtension;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ public:
|
|||
openingBook = enabled;
|
||||
}
|
||||
|
||||
bool getOpeningBook()
|
||||
bool getOpeningBook() const
|
||||
{
|
||||
return openingBook;
|
||||
}
|
||||
|
|
|
@ -135,10 +135,10 @@ public:
|
|||
|
||||
static void print_board();
|
||||
|
||||
int piece_on_board_count(Color c);
|
||||
int piece_in_hand_count(Color c);
|
||||
int piece_on_board_count(Color c) const;
|
||||
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);
|
||||
|
||||
|
@ -146,13 +146,13 @@ public:
|
|||
|
||||
// Other helpers
|
||||
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);
|
||||
bool put_piece(File file, Rank rank);
|
||||
bool put_piece(File f, Rank r);
|
||||
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 move_piece(File f1, Rank r1, File f2, Rank r2);
|
||||
|
@ -169,7 +169,7 @@ public:
|
|||
int pieceToRemoveCount{ 0 };
|
||||
int gamePly { 0 };
|
||||
Color sideToMove { NOCOLOR };
|
||||
Thread *thisThread;
|
||||
Thread *thisThread {nullptr};
|
||||
StateInfo st;
|
||||
|
||||
/// Mill Game
|
||||
|
@ -342,7 +342,7 @@ inline bool Position::move_piece(Square from, Square to)
|
|||
|
||||
inline Piece *Position::get_board()
|
||||
{
|
||||
return (Piece *)board;
|
||||
return static_cast<Piece *>(board);
|
||||
}
|
||||
|
||||
inline Square Position::current_square() const
|
||||
|
@ -365,17 +365,17 @@ inline const char *Position::get_record() const
|
|||
return record;
|
||||
}
|
||||
|
||||
inline int Position::piece_on_board_count(Color c)
|
||||
inline int Position::piece_on_board_count(Color c) const
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
inline int Position::piece_to_remove_count()
|
||||
inline int Position::piece_to_remove_count() const
|
||||
{
|
||||
return pieceToRemoveCount;
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ const struct Rule RULES[N_RULES] = {
|
|||
|
||||
bool set_rule(int ruleIdx)
|
||||
{
|
||||
if (ruleIdx <= 0 || ruleIdx > N_RULES) {
|
||||
if (ruleIdx <= 0 || ruleIdx >= N_RULES) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ public:
|
|||
return p + 1;
|
||||
}
|
||||
|
||||
inline size_t length()
|
||||
inline size_t length() const
|
||||
{
|
||||
return (sizeof(T) * size());
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ struct timer {
|
|||
using time_point = typename Clock::time_point;
|
||||
using duration = typename Clock::duration;
|
||||
|
||||
timer(const duration duration) noexcept : expiry(Clock::now() + duration) {}
|
||||
timer(const time_point expiry) noexcept : expiry(expiry) {}
|
||||
explicit timer(const duration duration) noexcept : expiry(Clock::now() + duration) {}
|
||||
explicit timer(const time_point expiry) noexcept : expiry(expiry) {}
|
||||
|
||||
bool done(time_point now = Clock::now()) const noexcept {
|
||||
return now >= expiry;
|
||||
|
|
|
@ -37,7 +37,7 @@ class Test : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Test(QWidget *parent = nullptr, QString key = "Key0");
|
||||
explicit Test(QWidget *parent = nullptr, QString k = "Key0");
|
||||
~Test();
|
||||
|
||||
void setKey(QString k)
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
string nextMove();
|
||||
Depth adjustDepth();
|
||||
|
||||
int getTimeLimit()
|
||||
int getTimeLimit() const
|
||||
{
|
||||
return timeLimit;
|
||||
}
|
||||
|
|
10
src/tt.h
10
src/tt.h
|
@ -53,14 +53,14 @@ struct TTEntry
|
|||
private:
|
||||
friend class TranspositionTable;
|
||||
|
||||
int8_t value8;
|
||||
int8_t depth8;
|
||||
uint8_t genBound8;
|
||||
int8_t value8 {0};
|
||||
int8_t depth8 {0};
|
||||
uint8_t genBound8 {0};
|
||||
#ifdef TRANSPOSITION_TABLE_FAKE_CLEAN
|
||||
uint8_t age8;
|
||||
uint8_t age8 {0};
|
||||
#endif // TRANSPOSITION_TABLE_FAKE_CLEAN
|
||||
#ifdef TT_MOVE_ENABLE
|
||||
Move ttMove;
|
||||
Move ttMove {MOVE_NONE};
|
||||
#endif // TT_MOVE_ENABLE
|
||||
};
|
||||
|
||||
|
|
|
@ -231,12 +231,11 @@ void Game::gameReset()
|
|||
// 2:先手第2子; 3:后手第2子
|
||||
// ......
|
||||
PieceItem::Models md;
|
||||
PieceItem *newP;
|
||||
|
||||
for (int i = 0; i < rule.piecesCount; i++) {
|
||||
// 先手的棋子
|
||||
md = isInverted ? PieceItem::Models::whitePiece : PieceItem::Models::blackPiece;
|
||||
newP = new PieceItem;
|
||||
PieceItem *newP = new PieceItem;
|
||||
newP->setModel(md);
|
||||
newP->setPos(scene.pos_p1);
|
||||
newP->setNum(i + 1);
|
||||
|
@ -360,7 +359,7 @@ void Game::setRule(int ruleNo, int stepLimited /*= -1*/, int timeLimited /*= -1*
|
|||
elapsedSeconds[BLACK] = elapsedSeconds[WHITE] = 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);
|
||||
}
|
||||
string cmd(record);
|
||||
|
@ -519,6 +518,7 @@ void Game::playSound(GameSound soundType, Color c)
|
|||
break;
|
||||
};
|
||||
|
||||
#ifndef DONOT_PLAY_SOUND
|
||||
QString soundPath = QString::fromStdString(soundDir + filename);
|
||||
|
||||
#ifndef TRAINING_MODE
|
||||
|
@ -526,7 +526,6 @@ void Game::playSound(GameSound soundType, Color c)
|
|||
return;
|
||||
}
|
||||
|
||||
#ifndef DONOT_PLAY_SOUND
|
||||
if (hasSound) {
|
||||
QSound::play(soundPath);
|
||||
}
|
||||
|
@ -781,14 +780,14 @@ bool Game::isAIsTurn()
|
|||
}
|
||||
|
||||
// 关键槽函数,根据QGraphicsScene的信号和状态来执行选子、落子或去子
|
||||
bool Game::actionPiece(QPointF pos)
|
||||
bool Game::actionPiece(QPointF p)
|
||||
{
|
||||
#ifndef TRAINING_MODE
|
||||
// 点击非落子点,不执行
|
||||
File file;
|
||||
Rank rank;
|
||||
File f;
|
||||
Rank r;
|
||||
|
||||
if (!scene.pos2polar(pos, file, rank)) {
|
||||
if (!scene.pos2polar(p, f, r)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -848,11 +847,11 @@ bool Game::actionPiece(QPointF pos)
|
|||
// 判断执行选子、落子或去子
|
||||
bool result = false;
|
||||
PieceItem *piece = nullptr;
|
||||
QGraphicsItem *item = scene.itemAt(pos, QTransform());
|
||||
QGraphicsItem *item = scene.itemAt(p, QTransform());
|
||||
|
||||
switch (position.get_action()) {
|
||||
case Action::place:
|
||||
if (position.put_piece(file, rank)) {
|
||||
if (position.put_piece(f, r)) {
|
||||
if (position.get_action() == Action::remove) {
|
||||
// 播放成三音效
|
||||
playSound(GameSound::mill, position.side_to_move());
|
||||
|
@ -871,7 +870,7 @@ bool Game::actionPiece(QPointF pos)
|
|||
piece = qgraphicsitem_cast<PieceItem *>(item);
|
||||
if (!piece)
|
||||
break;
|
||||
if (position.select_piece(file, rank)) {
|
||||
if (position.select_piece(f, r)) {
|
||||
// 播放选子音效
|
||||
playSound(GameSound::select, position.side_to_move());
|
||||
result = true;
|
||||
|
@ -882,7 +881,7 @@ bool Game::actionPiece(QPointF pos)
|
|||
break;
|
||||
|
||||
case Action::remove:
|
||||
if (position.remove_piece(file, rank)) {
|
||||
if (position.remove_piece(f, r)) {
|
||||
// 播放音效
|
||||
playSound(GameSound::remove, position.side_to_move());
|
||||
result = true;
|
||||
|
@ -1344,7 +1343,7 @@ bool Game::updateScence(Position &p)
|
|||
int ipos = p.current_square();
|
||||
if (ipos) {
|
||||
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) {
|
||||
currentPiece = pieceList.at(static_cast<size_t>(ipos));
|
||||
currentPiece->setSelected(true);
|
||||
|
@ -1588,7 +1587,7 @@ void Game::setTips()
|
|||
reasonStr = turnStr + "超时判负。";
|
||||
break;
|
||||
case GameOverReason::drawReasonThreefoldRepetition:
|
||||
tips = "三次重复局面判和。";
|
||||
reasonStr = "三次重复局面判和。";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -80,7 +80,7 @@ class Game : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Game(
|
||||
explicit Game(
|
||||
#ifndef TRAINING_MODE
|
||||
GameScene &scene,
|
||||
#endif
|
||||
|
@ -356,7 +356,7 @@ public slots:
|
|||
|
||||
// 更新棋局显示,每步后执行才能刷新局面
|
||||
bool updateScence();
|
||||
bool updateScence(Position &position);
|
||||
bool updateScence(Position &p);
|
||||
|
||||
#ifdef NET_FIGHT_SUPPORT
|
||||
// 显示网络配置窗口
|
||||
|
|
|
@ -1098,26 +1098,26 @@ void MillGameWindow::on_actionAbout_A_triggered()
|
|||
}
|
||||
|
||||
#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_startPoint = event->globalPos();
|
||||
m_startPoint = mouseEvent->globalPos();
|
||||
m_windowPoint = this->frameGeometry().topLeft();
|
||||
}
|
||||
}
|
||||
|
||||
void MillGameWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
void MillGameWindow::mouseMoveEvent(QMouseEvent *mouseEvent)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
QPoint relativePos = event->globalPos() - m_startPoint;
|
||||
if (mouseEvent->buttons() & Qt::LeftButton) {
|
||||
QPoint relativePos = mouseEvent->globalPos() - m_startPoint;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,9 +51,9 @@ protected:
|
|||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
#ifdef MOBILE_APP_UI
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *mouseEvent) override;
|
||||
void mouseMoveEvent(QMouseEvent *mouseEvent) override;
|
||||
void mouseReleaseEvent(QMouseEvent *mouseEvent) override;
|
||||
#endif /* MOBILE_APP_UI */
|
||||
|
||||
private slots:
|
||||
|
|
|
@ -168,21 +168,21 @@ void PieceItem::paint(QPainter *painter,
|
|||
}
|
||||
}
|
||||
|
||||
void PieceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
void PieceItem::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
// 鼠标按下时变为握住的手形
|
||||
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);
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
QGraphicsItem::mouseReleaseEvent(mouseEvent);
|
||||
}
|
||||
|
|
|
@ -114,10 +114,10 @@ private:
|
|||
enum Models model;
|
||||
|
||||
// 棋子序号,黑白都从1开始
|
||||
int num = 1;
|
||||
int num {1};
|
||||
|
||||
// 棋子尺寸
|
||||
int size;
|
||||
int size {0};
|
||||
|
||||
// 有无删除线
|
||||
bool deleted {false};
|
||||
|
@ -126,10 +126,10 @@ private:
|
|||
bool showNum {false};
|
||||
|
||||
// 选中子标识线宽度
|
||||
int selectLineWeight;
|
||||
int selectLineWeight {0};
|
||||
|
||||
// 删除线宽度
|
||||
int removeLineWeight;
|
||||
int removeLineWeight {0};
|
||||
|
||||
// 选中线颜色
|
||||
QColor selectLineColor;
|
||||
|
|
|
@ -42,7 +42,7 @@ class Server : public QDialog
|
|||
public:
|
||||
explicit Server(QWidget *parent = nullptr, uint16_t port = 33333);
|
||||
~Server();
|
||||
void setAction(const QString &action);
|
||||
void setAction(const QString &a);
|
||||
void setPort(uint16_t p)
|
||||
{
|
||||
port = p;
|
||||
|
|
Loading…
Reference in New Issue