Qt 改为需 C++17 支持并消除部分 clang 警告
This commit is contained in:
parent
560d0d4bbb
commit
118017173e
|
@ -68,9 +68,9 @@ DISTFILES += \
|
|||
|
||||
RC_FILE += NineChess.rc
|
||||
|
||||
# With C++14 support
|
||||
# With C++17 support
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
CONFIG += c++14
|
||||
CONFIG += c++17
|
||||
} else {
|
||||
QMAKE_CXXFLAGS += -std=c++0x
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <climits>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
template <typename T, size_t BlockSize = 4096>
|
||||
class MemoryPool
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef MEMORY_BLOCK_TCC
|
||||
#define MEMORY_BLOCK_TCC
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
template <typename T, size_t BlockSize>
|
||||
inline typename MemoryPool<T, BlockSize>::size_type
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
AiThread::AiThread(int id, QObject *parent) :
|
||||
QThread(parent),
|
||||
chess_(nullptr),
|
||||
waiting_(false),
|
||||
chess_(nullptr),
|
||||
aiDepth(2),
|
||||
aiTime(120)
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ void AiThread::setAi(const NineChess &chess)
|
|||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AiThread::setAi(const NineChess &chess, int depth, int time)
|
||||
void AiThread::setAi(const NineChess &chess, NineChessAi_ab::depth_t depth, int time)
|
||||
{
|
||||
mutex.lock();
|
||||
this->chess_ = &chess;
|
||||
|
|
|
@ -37,7 +37,7 @@ class AiThread : public QThread
|
|||
|
||||
public:
|
||||
explicit AiThread(int id, QObject *parent = nullptr);
|
||||
~AiThread();
|
||||
~AiThread() override;
|
||||
|
||||
signals:
|
||||
// 着法信号
|
||||
|
@ -55,7 +55,7 @@ protected:
|
|||
public:
|
||||
// AI设置
|
||||
void setAi(const NineChess &chess);
|
||||
void setAi(const NineChess &chess, int depth, int time);
|
||||
void setAi(const NineChess &chess, NineChessAi_ab::depth_t depth, int time);
|
||||
|
||||
Server *getServer()
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
}
|
||||
|
||||
// 深度和限时
|
||||
void getDepthTime(int &depth, int &time)
|
||||
void getDepthTime(NineChessAi_ab::depth_t &depth, int &time)
|
||||
{
|
||||
depth = aiDepth;
|
||||
time = aiTime;
|
||||
|
@ -113,7 +113,7 @@ private:
|
|||
NineChessAi_ab ai_ab;
|
||||
|
||||
// AI的层数
|
||||
int aiDepth;
|
||||
NineChessAi_ab::depth_t aiDepth;
|
||||
|
||||
// AI的限时
|
||||
int aiTime;
|
||||
|
|
|
@ -125,7 +125,7 @@ void Client::requestNewAction()
|
|||
getActionButton->setEnabled(false);
|
||||
tcpSocket->abort();
|
||||
tcpSocket->connectToHost(hostCombo->currentText(),
|
||||
portLineEdit->text().toInt());
|
||||
portLineEdit->text().toUShort());
|
||||
}
|
||||
|
||||
void Client::readAction()
|
||||
|
@ -140,7 +140,6 @@ void Client::readAction()
|
|||
|
||||
currentAction = nextAction;
|
||||
statusLabel->setText(currentAction);
|
||||
// 发信号
|
||||
emit command(currentAction);
|
||||
getActionButton->setEnabled(true);
|
||||
|
||||
|
|
|
@ -21,6 +21,10 @@
|
|||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#if _MSC_VER >= 1600
|
||||
#pragma execution_character_set("utf-8")
|
||||
#endif
|
||||
|
||||
//#define DEBUG_MODE
|
||||
//#define DEBUG_MODE_A
|
||||
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
||||
*****************************************************************************/
|
||||
|
||||
#if _MSC_VER >= 1600
|
||||
#pragma execution_character_set("utf-8")
|
||||
#endif
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QKeyEvent>
|
||||
|
@ -42,6 +38,8 @@
|
|||
|
||||
GameController::GameController(GameScene & scene, QObject * parent) :
|
||||
QObject(parent),
|
||||
ai1(1),
|
||||
ai2(2),
|
||||
scene(scene),
|
||||
currentPiece(nullptr),
|
||||
currentRow(-1),
|
||||
|
@ -56,8 +54,6 @@ GameController::GameController(GameScene & scene, QObject * parent) :
|
|||
ruleNo_(-1),
|
||||
timeLimit(0),
|
||||
stepsLimit(50),
|
||||
ai1(1),
|
||||
ai2(2),
|
||||
score1(-2),
|
||||
score2(-2)
|
||||
{
|
||||
|
@ -316,7 +312,7 @@ void GameController::setEngine2(bool arg)
|
|||
}
|
||||
}
|
||||
|
||||
void GameController::setAiDepthTime(int depth1, int time1, int depth2, int time2)
|
||||
void GameController::setAiDepthTime(NineChessAi_ab::depth_t depth1, int time1, NineChessAi_ab::depth_t depth2, int time2)
|
||||
{
|
||||
if (isEngine1) {
|
||||
ai1.stop();
|
||||
|
@ -338,7 +334,7 @@ void GameController::setAiDepthTime(int depth1, int time1, int depth2, int time2
|
|||
}
|
||||
}
|
||||
|
||||
void GameController::getAiDepthTime(int &depth1, int &time1, int &depth2, int &time2)
|
||||
void GameController::getAiDepthTime(NineChessAi_ab::depth_t &depth1, int &time1, NineChessAi_ab::depth_t &depth2, int &time2)
|
||||
{
|
||||
ai1.getDepthTime(depth1, time1);
|
||||
ai2.getDepthTime(depth2, time2);
|
||||
|
|
|
@ -90,8 +90,8 @@ public:
|
|||
return &manualListModel;
|
||||
}
|
||||
|
||||
void setAiDepthTime(int depth1, int time1, int depth2, int time2);
|
||||
void getAiDepthTime(int &depth1, int &time1, int &depth2, int &time2);
|
||||
void setAiDepthTime(NineChessAi_ab::depth_t depth1, int time1, NineChessAi_ab::depth_t depth2, int time2);
|
||||
void getAiDepthTime(NineChessAi_ab::depth_t &depth1, int &time1, NineChessAi_ab::depth_t &depth2, int &time2);
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -231,10 +231,10 @@ private:
|
|||
int stepsLimit;
|
||||
|
||||
// 玩家1剩余时间(毫秒)
|
||||
int remainingTime1;
|
||||
long remainingTime1;
|
||||
|
||||
// 玩家2剩余时间(毫秒)
|
||||
int remainingTime2;
|
||||
long remainingTime2;
|
||||
|
||||
// 玩家1赢盘数
|
||||
int score1;
|
||||
|
|
|
@ -32,11 +32,11 @@
|
|||
|
||||
GameScene::GameScene(QObject *parent) :
|
||||
QGraphicsScene(parent),
|
||||
board(nullptr),
|
||||
pos_p1(LINE_INTERVAL * 4, LINE_INTERVAL * 6),
|
||||
pos_p1_g(LINE_INTERVAL *(-4), LINE_INTERVAL * 6),
|
||||
pos_p2(LINE_INTERVAL *(-4), LINE_INTERVAL *(-6)),
|
||||
pos_p2_g(LINE_INTERVAL * 4, LINE_INTERVAL *(-6))
|
||||
pos_p2_g(LINE_INTERVAL * 4, LINE_INTERVAL *(-6)),
|
||||
board(nullptr)
|
||||
{
|
||||
// 添加棋盘
|
||||
board = new BoardItem;
|
||||
|
|
|
@ -91,10 +91,10 @@ namespace CTSL //Concurrent Thread Safe Library
|
|||
//Function to remove an entry from the bucket, if found
|
||||
void erase(const K &key)
|
||||
{
|
||||
size_t hashValue = hashFn(key) & (hashSize - 1);
|
||||
#ifdef DISABLE_HASHBUCKET
|
||||
// std::unique_lock<std::shared_timed_mutex> lock(mutex_);
|
||||
#else
|
||||
size_t hashValue = hashFn(key) & (hashSize - 1);
|
||||
hashTable[hashValue].erase(key);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
||||
*****************************************************************************/
|
||||
|
||||
#if _MSC_VER >= 1600
|
||||
#pragma execution_character_set("utf-8")
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include "ninechess.h"
|
||||
#include "ninechessai_ab.h"
|
||||
|
@ -129,10 +125,10 @@ const int NineChess::onBoard[(N_RINGS + 2) * N_SEATS] = {
|
|||
};
|
||||
|
||||
// 着法表
|
||||
int NineChess::moveTable[N_POINTS][N_MOVE_DIRECTIONS] = { 0 };
|
||||
int NineChess::moveTable[N_POINTS][N_MOVE_DIRECTIONS] = {{0}};
|
||||
|
||||
// 成三表
|
||||
int NineChess::millTable[N_POINTS][N_DIRECTIONS][N_RINGS - 1] = { 0 };
|
||||
int NineChess::millTable[N_POINTS][N_DIRECTIONS][N_RINGS - 1] = {{{0}}};
|
||||
|
||||
NineChess::NineChess()
|
||||
{
|
||||
|
@ -1364,7 +1360,7 @@ int NineChess::isInMills(int pos, bool test)
|
|||
{
|
||||
int n = 0;
|
||||
int pos1, pos2;
|
||||
char m = test? INT32_MAX : board_[pos] & '\x30';
|
||||
int m = test? INT32_MAX : board_[pos] & '\x30';
|
||||
for (int i = 0; i < 3; i++) {
|
||||
pos1 = millTable[pos][i][0];
|
||||
pos2 = millTable[pos][i][1];
|
||||
|
@ -1633,7 +1629,7 @@ enum NineChess::Player NineChess::getWhosPiece(int c, int p)
|
|||
return NOBODY;
|
||||
}
|
||||
|
||||
void NineChess::getElapsedTimeMS(int &p1_ms, int &p2_ms)
|
||||
void NineChess::getElapsedTimeMS(long &p1_ms, long &p2_ms)
|
||||
{
|
||||
update();
|
||||
p1_ms = elapsedMS_1;
|
||||
|
|
|
@ -75,7 +75,6 @@ public:
|
|||
// 定义类型
|
||||
typedef int32_t move_t;
|
||||
|
||||
|
||||
// 位置迭代器
|
||||
// typedef typename std::vector<move_t>::iterator posIterator;
|
||||
// typedef typename std::vector<move_t>::const_iterator constPosIterator;
|
||||
|
@ -148,7 +147,7 @@ public:
|
|||
};
|
||||
|
||||
uint64_t rand64(void) {
|
||||
return rand() ^
|
||||
return (uint64_t)rand() ^
|
||||
((uint64_t)rand() << 15) ^
|
||||
((uint64_t)rand() << 30) ^
|
||||
((uint64_t)rand() << 45) ^
|
||||
|
@ -379,7 +378,7 @@ public:
|
|||
}
|
||||
|
||||
// 玩家1和玩家2的用时
|
||||
void getElapsedTimeMS(int &p1_ms, int &p2_ms);
|
||||
void getElapsedTimeMS(long &p1_ms, long &p2_ms);
|
||||
|
||||
// 获取棋局的字符提示
|
||||
const string getTips() const
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include "ninechessai_ab.h"
|
||||
#include "HashMap.h"
|
||||
#include "hashmap.h"
|
||||
|
||||
using namespace CTSL;
|
||||
|
||||
|
@ -103,7 +103,7 @@ struct NineChessAi_ab::Node *NineChessAi_ab::addNode(
|
|||
newNode->pruned = false;
|
||||
#endif
|
||||
|
||||
player = player; // Remove warning
|
||||
//player = player; // Remove warning
|
||||
|
||||
#ifdef DEBUG_AB_TREE
|
||||
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
|
||||
|
@ -190,23 +190,23 @@ void NineChessAi_ab::shuffleMovePriorityTable()
|
|||
std::shuffle(movePriorityTable3.begin(), movePriorityTable3.end(), std::default_random_engine(seed));
|
||||
std::shuffle(movePriorityTable4.begin(), movePriorityTable4.end(), std::default_random_engine(seed));
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
movePriorityTable[i + 0] = movePriorityTable0[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
movePriorityTable[i + 4] = movePriorityTable1[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
movePriorityTable[i + 12] = movePriorityTable2[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
movePriorityTable[i + 16] = movePriorityTable3[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
movePriorityTable[i + 20] = movePriorityTable4[i];
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ void NineChessAi_ab::generateLegalMoves(Node *node, move_t bestMove)
|
|||
{
|
||||
const int MOVE_PRIORITY_TABLE_SIZE = NineChess::N_RINGS * NineChess::N_SEATS;
|
||||
int pos = 0;
|
||||
size_t newCapacity = 24;
|
||||
int newCapacity = 24;
|
||||
|
||||
// 留足余量空间避免多次重新分配,此动作本身也占用 CPU/内存 开销
|
||||
switch (chessTemp.getStage()) {
|
||||
|
|
|
@ -32,11 +32,11 @@
|
|||
//#endif
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <Qdebug>
|
||||
#include <QDebug>
|
||||
#include <array>
|
||||
|
||||
#include "ninechess.h"
|
||||
#include "hashMap.h"
|
||||
#include "hashmap.h"
|
||||
|
||||
#ifdef MEMORY_POOL
|
||||
#include "MemoryPool.h"
|
||||
|
@ -62,13 +62,14 @@ public:
|
|||
struct Node
|
||||
{
|
||||
public:
|
||||
move_t move; // 着法的命令行指令,图上标示为节点前的连线
|
||||
value_t value; // 节点的值
|
||||
vector<struct Node*> children; // 子节点列表
|
||||
struct Node* parent; // 父节点
|
||||
move_t move; // 着法的命令行指令,图上标示为节点前的连线
|
||||
value_t value; // 节点的值
|
||||
#ifdef SORT_CONSIDER_PRUNED
|
||||
bool pruned; // 是否在此处剪枝
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_AB_TREE
|
||||
size_t id; // 结点编号
|
||||
string cmd;
|
||||
|
@ -278,4 +279,12 @@ private:
|
|||
char cmdline[32];
|
||||
};
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
extern HashMap<uint64_t, NineChessAi_ab::HashValue> hashmap;
|
||||
#endif /* #ifdef HASH_MAP_ENABLE */
|
||||
|
||||
#ifdef THREEFOLD_REPETITION
|
||||
extern vector<uint64_t> positions;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
||||
*****************************************************************************/
|
||||
|
||||
#if _MSC_VER >= 1600
|
||||
#pragma execution_character_set("utf-8")
|
||||
#endif
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QMap>
|
||||
#include <QMessageBox>
|
||||
|
@ -827,7 +823,8 @@ void NineChessWindow::on_actionEngine_E_triggered()
|
|||
connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
|
||||
|
||||
// 目前数据
|
||||
int depth1, depth2, time1, time2;
|
||||
NineChessAi_ab::depth_t depth1, depth2;
|
||||
int time1, time2;
|
||||
game->getAiDepthTime(depth1, time1, depth2, time2);
|
||||
spinBox_depth1->setValue(depth1);
|
||||
spinBox_depth2->setValue(depth2);
|
||||
|
@ -836,7 +833,8 @@ void NineChessWindow::on_actionEngine_E_triggered()
|
|||
|
||||
// 新设数据
|
||||
if (dialog->exec() == QDialog::Accepted) {
|
||||
int depth1_new, depth2_new, time1_new, time2_new;
|
||||
NineChessAi_ab::depth_t depth1_new, depth2_new;
|
||||
int time1_new, time2_new;
|
||||
depth1_new = spinBox_depth1->value();
|
||||
depth2_new = spinBox_depth2->value();
|
||||
time1_new = spinBox_time1->value();
|
||||
|
|
|
@ -46,7 +46,7 @@ PieceItem::PieceItem(QGraphicsItem *parent) :
|
|||
//setAcceptedMouseButtons(Qt::LeftButton);
|
||||
|
||||
// 不接受鼠标事件
|
||||
setAcceptedMouseButtons(0);
|
||||
setAcceptedMouseButtons(nullptr);
|
||||
//setAcceptHoverEvents(true);
|
||||
|
||||
// 默认模型为没有棋子
|
||||
|
@ -105,6 +105,8 @@ void PieceItem::paint(QPainter *painter,
|
|||
painter->drawPixmap(-size / 2, -size / 2, size, size,
|
||||
QPixmap(":/image/resources/image/white_piece.png"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// 如果模型要求显示序号
|
||||
|
|
|
@ -54,10 +54,10 @@ private slots:
|
|||
private:
|
||||
QLabel *statusLabel = nullptr;
|
||||
QTcpServer *tcpServer = nullptr;
|
||||
QVector<QString> actions;
|
||||
QString action;
|
||||
QNetworkSession *networkSession = nullptr;
|
||||
uint16_t port;
|
||||
QVector<QString> actions;
|
||||
QString action;
|
||||
};
|
||||
|
||||
#endif // SERVER_H
|
||||
|
|
Loading…
Reference in New Issue