消除W4级别的VC编译器警告
This commit is contained in:
parent
3e563edcd5
commit
c622ac0de6
|
@ -249,12 +249,12 @@
|
|||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;QT_WIDGETS_LIB;QT_CORE_LIB;QT_GUI_LIB;QT_MULTIMEDIA_LIB;QT_NETWORK_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;QT_WIDGETS_LIB;QT_CORE_LIB;QT_GUI_LIB;QT_MULTIMEDIA_LIB;QT_NETWORK_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessToFile>false</PreprocessToFile>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<ProgramDataBaseFileName>$(IntDir)vc$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
|
||||
</ClCompile>
|
||||
|
@ -289,7 +289,7 @@
|
|||
<QtMoc>
|
||||
<QTDIR>$(QTDIR)</QTDIR>
|
||||
<OutputFile>.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</OutputFile>
|
||||
<Define>_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;QT_WIDGETS_LIB;QT_CORE_LIB;QT_GUI_LIB;QT_MULTIMEDIA_LIB;QT_NETWORK_LIB;%(PreprocessorDefinitions)</Define>
|
||||
<Define>_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;QT_WIDGETS_LIB;QT_CORE_LIB;QT_GUI_LIB;QT_MULTIMEDIA_LIB;QT_NETWORK_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</Define>
|
||||
<CompilerFlavor>msvc</CompilerFlavor>
|
||||
<Include>$(Configuration)/moc_predefs.h</Include>
|
||||
<ExecutionDescription>Moc'ing %(Identity)...</ExecutionDescription>
|
||||
|
|
|
@ -25,15 +25,15 @@ AiThread::~AiThread()
|
|||
void AiThread::setAi(const NineChess &chess)
|
||||
{
|
||||
mutex.lock();
|
||||
this->chess = &chess;
|
||||
ai_ab.setChess(*(this->chess));
|
||||
this->chess_ = &chess;
|
||||
ai_ab.setChess(*(this->chess_));
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AiThread::setAi(const NineChess &chess, int depth, int time)
|
||||
{
|
||||
mutex.lock();
|
||||
this->chess = &chess;
|
||||
this->chess_ = &chess;
|
||||
ai_ab.setChess(chess);
|
||||
aiDepth = depth;
|
||||
aiTime = time;
|
||||
|
@ -54,9 +54,9 @@ void AiThread::run()
|
|||
|
||||
while (!isInterruptionRequested()) {
|
||||
mutex.lock();
|
||||
if (chess->whosTurn() == NineChess::PLAYER1)
|
||||
if (chess_->whosTurn() == NineChess::PLAYER1)
|
||||
i = 1;
|
||||
else if (chess->whosTurn() == NineChess::PLAYER2)
|
||||
else if (chess_->whosTurn() == NineChess::PLAYER2)
|
||||
i = 2;
|
||||
else
|
||||
i = 0;
|
||||
|
@ -67,7 +67,7 @@ void AiThread::run()
|
|||
continue;
|
||||
}
|
||||
|
||||
ai_ab.setChess(*chess);
|
||||
ai_ab.setChess(*chess_);
|
||||
emit calcStarted();
|
||||
mutex.unlock();
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ private:
|
|||
QWaitCondition pauseCondition;
|
||||
|
||||
// 主线程棋对象的引用
|
||||
const NineChess *chess;
|
||||
const NineChess *chess_;
|
||||
// Alpha-Beta剪枝算法类
|
||||
NineChessAi_ab ai_ab;
|
||||
// AI的层数
|
||||
|
|
|
@ -29,7 +29,7 @@ GameController::GameController(GameScene &scene, QObject *parent) : QObject(pare
|
|||
durationTime(250),
|
||||
hasSound(true),
|
||||
timeID(0),
|
||||
ruleNo(-1),
|
||||
ruleNo_(-1),
|
||||
timeLimit(0),
|
||||
stepsLimit(0),
|
||||
ai1(1),
|
||||
|
@ -81,8 +81,8 @@ const QMap<int, QStringList> GameController::getActions()
|
|||
|
||||
void GameController::gameStart()
|
||||
{
|
||||
chess.start();
|
||||
chessTemp = chess;
|
||||
chess_.start();
|
||||
chessTemp = chess_;
|
||||
// 每隔100毫秒调用一次定时器处理函数
|
||||
if (timeID == 0) {
|
||||
timeID = startTimer(100);
|
||||
|
@ -97,8 +97,8 @@ void GameController::gameReset()
|
|||
// 定时器ID为0
|
||||
timeID = 0;
|
||||
// 重置游戏
|
||||
chess.reset();
|
||||
chessTemp = chess;
|
||||
chess_.reset();
|
||||
chessTemp = chess_;
|
||||
|
||||
// 停掉线程
|
||||
ai1.stop();
|
||||
|
@ -111,7 +111,7 @@ void GameController::gameReset()
|
|||
pieceList.clear();
|
||||
currentPiece = nullptr;
|
||||
// 重新绘制棋盘
|
||||
scene.setDiagonal(chess.getRule()->hasObliqueLine);
|
||||
scene.setDiagonal(chess_.getRule()->hasObliqueLine);
|
||||
|
||||
// 绘制所有棋子,放在起始位置
|
||||
// 0: 先手第1子; 1:后手第1子
|
||||
|
@ -119,7 +119,7 @@ void GameController::gameReset()
|
|||
// ......
|
||||
PieceItem::Models md;
|
||||
PieceItem *newP;
|
||||
for (int i = 0; i < chess.getRule()->numOfChess; i++)
|
||||
for (int i = 0; i < chess_.getRule()->numOfChess; i++)
|
||||
{
|
||||
// 先手的棋子
|
||||
md = isInverted ? PieceItem::whitePiece : PieceItem::blackPiece;
|
||||
|
@ -128,7 +128,7 @@ void GameController::gameReset()
|
|||
newP->setPos(scene.pos_p1);
|
||||
newP->setNum(i + 1);
|
||||
// 如果重复三连不可用,则显示棋子序号,九连棋专用玩法
|
||||
if (!(chess.getRule()->canRepeated))
|
||||
if (!(chess_.getRule()->canRepeated))
|
||||
newP->setShowNum(true);
|
||||
pieceList.append(newP);
|
||||
scene.addItem(newP);
|
||||
|
@ -140,35 +140,35 @@ void GameController::gameReset()
|
|||
newP->setPos(scene.pos_p2);
|
||||
newP->setNum(i + 1);
|
||||
// 如果重复三连不可用,则显示棋子序号,九连棋专用玩法
|
||||
if (!(chess.getRule()->canRepeated))
|
||||
if (!(chess_.getRule()->canRepeated))
|
||||
newP->setShowNum(true);
|
||||
pieceList.append(newP);
|
||||
scene.addItem(newP);
|
||||
}
|
||||
|
||||
// 读取规则限时要求
|
||||
timeLimit = chess.getRule()->maxTime;
|
||||
timeLimit = chess_.getRule()->maxTime;
|
||||
// 如果规则不要求计时,则time1和time2表示已用时间
|
||||
if (timeLimit <= 0) {
|
||||
// 将玩家的已用时间清零
|
||||
time1 = time2 = 0;
|
||||
remainingTime1 = remainingTime2 = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 将玩家的剩余时间置为限定时间
|
||||
time1 = time2 = timeLimit * 60000;
|
||||
remainingTime1 = remainingTime2 = timeLimit * 60000;
|
||||
}
|
||||
// 更新棋谱
|
||||
manualListModel.removeRows(0, manualListModel.rowCount());
|
||||
manualListModel.insertRow(0);
|
||||
manualListModel.setData(manualListModel.index(0), chess.getCmdLine());
|
||||
manualListModel.setData(manualListModel.index(0), chess_.getCmdLine());
|
||||
currentRow = 0;
|
||||
// 发出信号通知主窗口更新LCD显示
|
||||
QTime qtime = QTime(0, 0, 0, 0).addMSecs(time1);
|
||||
QTime qtime = QTime(0, 0, 0, 0).addMSecs(remainingTime1);
|
||||
emit time1Changed(qtime.toString("mm:ss.zzz"));
|
||||
emit time2Changed(qtime.toString("mm:ss.zzz"));
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(chess.getTip());
|
||||
message = QString::fromStdString(chess_.getTip());
|
||||
emit statusBarChanged(message);
|
||||
// 播放音效
|
||||
playSound(":/sound/resources/sound/newgame.wav");
|
||||
|
@ -204,15 +204,15 @@ void GameController::setRule(int ruleNo, int stepLimited /*= -1*/, int timeLimit
|
|||
// 更新规则,原限时和限步不变
|
||||
if (ruleNo < 0 || ruleNo >= NineChess::RULENUM)
|
||||
return;
|
||||
this->ruleNo = ruleNo;
|
||||
this->ruleNo_ = ruleNo;
|
||||
|
||||
if (stepLimited != -1 && timeLimited != -1) {
|
||||
stepsLimit = stepLimited;
|
||||
timeLimit = timeLimited;
|
||||
}
|
||||
// 设置模型规则,重置游戏
|
||||
chess.setData(&NineChess::RULES[ruleNo], stepsLimit, timeLimit);
|
||||
chessTemp = chess;
|
||||
chess_.setData(&NineChess::RULES[ruleNo], stepsLimit, timeLimit);
|
||||
chessTemp = chess_;
|
||||
|
||||
// 重置游戏
|
||||
gameReset();
|
||||
|
@ -222,7 +222,7 @@ void GameController::setEngine1(bool arg)
|
|||
{
|
||||
isEngine1 = arg;
|
||||
if (arg) {
|
||||
ai1.setAi(chess);
|
||||
ai1.setAi(chess_);
|
||||
if (ai1.isRunning())
|
||||
ai1.resume();
|
||||
else
|
||||
|
@ -237,7 +237,7 @@ void GameController::setEngine2(bool arg)
|
|||
{
|
||||
isEngine2 = arg;
|
||||
if (arg) {
|
||||
ai2.setAi(chess);
|
||||
ai2.setAi(chess_);
|
||||
if (ai2.isRunning())
|
||||
ai2.resume();
|
||||
else
|
||||
|
@ -259,8 +259,8 @@ void GameController::setAiDepthTime(int depth1, int time1, int depth2, int time2
|
|||
ai2.wait();
|
||||
}
|
||||
|
||||
ai1.setAi(chess, depth1, time1);
|
||||
ai2.setAi(chess, depth2, time2);
|
||||
ai1.setAi(chess_, depth1, time1);
|
||||
ai2.setAi(chess_, depth2, time2);
|
||||
|
||||
if (isEngine1) {
|
||||
ai1.start();
|
||||
|
@ -310,12 +310,12 @@ void GameController::flip()
|
|||
ai2.wait();
|
||||
}
|
||||
|
||||
chess.mirror();
|
||||
chess.rotate(180);
|
||||
chessTemp = chess;
|
||||
chess_.mirror();
|
||||
chess_.rotate(180);
|
||||
chessTemp = chess_;
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
for (auto str : *(chess.getCmdList())) {
|
||||
for (auto str : *(chess_.getCmdList())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
// 刷新显示
|
||||
|
@ -324,8 +324,8 @@ void GameController::flip()
|
|||
else
|
||||
phaseChange(currentRow, true);
|
||||
|
||||
ai1.setAi(chess);
|
||||
ai2.setAi(chess);
|
||||
ai1.setAi(chess_);
|
||||
ai2.setAi(chess_);
|
||||
if (isEngine1) {
|
||||
ai1.start();
|
||||
}
|
||||
|
@ -346,11 +346,11 @@ void GameController::mirror()
|
|||
ai2.wait();
|
||||
}
|
||||
|
||||
chess.mirror();
|
||||
chessTemp = chess;
|
||||
chess_.mirror();
|
||||
chessTemp = chess_;
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
for (auto str : *(chess.getCmdList())) {
|
||||
for (auto str : *(chess_.getCmdList())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
qDebug() << "list: " << row;
|
||||
|
@ -360,8 +360,8 @@ void GameController::mirror()
|
|||
else
|
||||
phaseChange(currentRow, true);
|
||||
|
||||
ai1.setAi(chess);
|
||||
ai2.setAi(chess);
|
||||
ai1.setAi(chess_);
|
||||
ai2.setAi(chess_);
|
||||
if (isEngine1) {
|
||||
ai1.start();
|
||||
}
|
||||
|
@ -382,11 +382,11 @@ void GameController::turnRight()
|
|||
ai2.wait();
|
||||
}
|
||||
|
||||
chess.rotate(-90);
|
||||
chessTemp = chess;
|
||||
chess_.rotate(-90);
|
||||
chessTemp = chess_;
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
for (auto str : *(chess.getCmdList())) {
|
||||
for (auto str : *(chess_.getCmdList())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
// 刷新显示
|
||||
|
@ -395,8 +395,8 @@ void GameController::turnRight()
|
|||
else
|
||||
phaseChange(currentRow, true);
|
||||
|
||||
ai1.setAi(chess);
|
||||
ai2.setAi(chess);
|
||||
ai1.setAi(chess_);
|
||||
ai2.setAi(chess_);
|
||||
if (isEngine1) {
|
||||
ai1.start();
|
||||
}
|
||||
|
@ -417,18 +417,18 @@ void GameController::turnLeft()
|
|||
ai2.wait();
|
||||
}
|
||||
|
||||
chess.rotate(90);
|
||||
chessTemp = chess;
|
||||
chess_.rotate(90);
|
||||
chessTemp = chess_;
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
for (auto str : *(chess.getCmdList())) {
|
||||
for (auto str : *(chess_.getCmdList())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
// 刷新显示
|
||||
updateScence();
|
||||
|
||||
ai1.setAi(chess);
|
||||
ai2.setAi(chess);
|
||||
ai1.setAi(chess_);
|
||||
ai2.setAi(chess_);
|
||||
if (isEngine1) {
|
||||
ai1.start();
|
||||
}
|
||||
|
@ -442,27 +442,27 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
Q_UNUSED(event)
|
||||
static QTime qt1, qt2;
|
||||
// 玩家的已用时间
|
||||
chess.getPlayer_TimeMS(time1, time2);
|
||||
chess_.getPlayer_TimeMS(remainingTime1, remainingTime2);
|
||||
// 如果规则要求计时,则time1和time2表示倒计时
|
||||
if (timeLimit > 0)
|
||||
{
|
||||
// 玩家的剩余时间
|
||||
time1 = timeLimit * 60000 - time1;
|
||||
time2 = timeLimit * 60000 - time2;
|
||||
remainingTime1 = timeLimit * 60000 - remainingTime1;
|
||||
remainingTime2 = timeLimit * 60000 - remainingTime2;
|
||||
}
|
||||
qt1 = QTime(0, 0, 0, 0).addMSecs(time1);
|
||||
qt2 = QTime(0, 0, 0, 0).addMSecs(time2);
|
||||
qt1 = QTime(0, 0, 0, 0).addMSecs(remainingTime1);
|
||||
qt2 = QTime(0, 0, 0, 0).addMSecs(remainingTime2);
|
||||
emit time1Changed(qt1.toString("mm:ss.zzz"));
|
||||
emit time2Changed(qt2.toString("mm:ss.zzz"));
|
||||
// 如果胜负已分
|
||||
if (chess.whoWin() != NineChess::NOBODY)
|
||||
if (chess_.whoWin() != NineChess::NOBODY)
|
||||
{
|
||||
// 停止计时
|
||||
killTimer(timeID);
|
||||
// 定时器ID为0
|
||||
timeID = 0;
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(chess.getTip());
|
||||
message = QString::fromStdString(chess_.getTip());
|
||||
emit statusBarChanged(message);
|
||||
// 播放音效
|
||||
playSound(":/sound/resources/sound/win.wav");
|
||||
|
@ -503,9 +503,9 @@ bool GameController::actionPiece(QPointF pos)
|
|||
}
|
||||
|
||||
// 电脑走棋时,点击无效
|
||||
if (chess.whosTurn() == NineChess::PLAYER1 && isEngine1)
|
||||
if (chess_.whosTurn() == NineChess::PLAYER1 && isEngine1)
|
||||
return false;
|
||||
if (chess.whosTurn() == NineChess::PLAYER2 && isEngine2)
|
||||
if (chess_.whosTurn() == NineChess::PLAYER2 && isEngine2)
|
||||
return false;
|
||||
|
||||
// 在浏览历史记录时点击棋盘,则认为是悔棋
|
||||
|
@ -524,14 +524,14 @@ bool GameController::actionPiece(QPointF pos)
|
|||
|
||||
if (QMessageBox::Ok == msgBox.exec())
|
||||
{
|
||||
chess = chessTemp;
|
||||
chess_ = chessTemp;
|
||||
manualListModel.removeRows(currentRow + 1, manualListModel.rowCount() - currentRow - 1);
|
||||
// 如果再决出胜负后悔棋,则重新启动计时
|
||||
if (chess.whoWin() == NineChess::NOBODY) {
|
||||
if (chess_.whoWin() == NineChess::NOBODY) {
|
||||
// 重新启动计时
|
||||
timeID = startTimer(100);
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(chess.getTip());
|
||||
message = QString::fromStdString(chess_.getTip());
|
||||
emit statusBarChanged(message);
|
||||
}
|
||||
}
|
||||
|
@ -540,7 +540,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
}
|
||||
|
||||
// 如果未开局则开局
|
||||
if (chess.getPhase() == NineChess::GAME_NOTSTARTED)
|
||||
if (chess_.getPhase() == NineChess::GAME_NOTSTARTED)
|
||||
gameStart();
|
||||
|
||||
// 判断执行选子、落子或去子
|
||||
|
@ -548,12 +548,12 @@ bool GameController::actionPiece(QPointF pos)
|
|||
PieceItem *piece = nullptr;
|
||||
QGraphicsItem *item = scene.itemAt(pos, QTransform());
|
||||
|
||||
switch (chess.getAction())
|
||||
switch (chess_.getAction())
|
||||
{
|
||||
case NineChess::ACTION_PLACE:
|
||||
if (chess.place(c, p))
|
||||
if (chess_.place(c, p))
|
||||
{
|
||||
if (chess.getAction() == NineChess::ACTION_CAPTURE) {
|
||||
if (chess_.getAction() == NineChess::ACTION_CAPTURE) {
|
||||
// 播放成三音效
|
||||
playSound(":/sound/resources/sound/capture.wav");
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
piece = qgraphicsitem_cast<PieceItem *>(item);
|
||||
if (!piece)
|
||||
break;
|
||||
if (chess.choose(c, p)) {
|
||||
if (chess_.choose(c, p)) {
|
||||
// 播放选子音效
|
||||
playSound(":/sound/resources/sound/choose.wav");
|
||||
result = true;
|
||||
|
@ -582,7 +582,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
break;
|
||||
|
||||
case NineChess::ACTION_CAPTURE:
|
||||
if (chess.capture(c, p)) {
|
||||
if (chess_.capture(c, p)) {
|
||||
// 播放音效
|
||||
playSound(":/sound/resources/sound/remove.wav");
|
||||
result = true;
|
||||
|
@ -601,14 +601,14 @@ bool GameController::actionPiece(QPointF pos)
|
|||
if (result)
|
||||
{
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(chess.getTip());
|
||||
message = QString::fromStdString(chess_.getTip());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 将新增的棋谱行插入到ListModel
|
||||
currentRow = manualListModel.rowCount() - 1;
|
||||
int k = 0;
|
||||
// 输出命令行
|
||||
for (auto i = (chess.getCmdList())->begin(); i != (chess.getCmdList())->end(); ++i) {
|
||||
for (auto i = (chess_.getCmdList())->begin(); i != (chess_.getCmdList())->end(); ++i) {
|
||||
// 跳过已添加的,因标准list容器没有下标
|
||||
if (k++ <= currentRow)
|
||||
continue;
|
||||
|
@ -617,15 +617,15 @@ bool GameController::actionPiece(QPointF pos)
|
|||
}
|
||||
|
||||
// 播放胜利或失败音效
|
||||
if (chess.whoWin() != NineChess::NOBODY &&
|
||||
if (chess_.whoWin() != NineChess::NOBODY &&
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over."))
|
||||
playSound(":/sound/resources/sound/win.wav");
|
||||
|
||||
// AI设置
|
||||
if (&chess == &(this->chess)) {
|
||||
if (&chess_ == &(this->chess_)) {
|
||||
// 如果还未决出胜负
|
||||
if (chess.whoWin() == NineChess::NOBODY) {
|
||||
if (chess.whosTurn() == NineChess::PLAYER1) {
|
||||
if (chess_.whoWin() == NineChess::NOBODY) {
|
||||
if (chess_.whosTurn() == NineChess::PLAYER1) {
|
||||
if (isEngine1) {
|
||||
ai1.resume();
|
||||
}
|
||||
|
@ -655,24 +655,24 @@ bool GameController::actionPiece(QPointF pos)
|
|||
bool GameController::giveUp()
|
||||
{
|
||||
bool result = false;
|
||||
if (chess.whosTurn() == NineChess::PLAYER1)
|
||||
result = chess.giveup(NineChess::PLAYER1);
|
||||
else if (chess.whosTurn() == NineChess::PLAYER2)
|
||||
result = chess.giveup(NineChess::PLAYER2);
|
||||
if (chess_.whosTurn() == NineChess::PLAYER1)
|
||||
result = chess_.giveup(NineChess::PLAYER1);
|
||||
else if (chess_.whosTurn() == NineChess::PLAYER2)
|
||||
result = chess_.giveup(NineChess::PLAYER2);
|
||||
if (result)
|
||||
{
|
||||
// 将新增的棋谱行插入到ListModel
|
||||
currentRow = manualListModel.rowCount() - 1;
|
||||
int k = 0;
|
||||
// 输出命令行
|
||||
for (auto i = (chess.getCmdList())->begin(); i != (chess.getCmdList())->end(); ++i) {
|
||||
for (auto i = (chess_.getCmdList())->begin(); i != (chess_.getCmdList())->end(); ++i) {
|
||||
// 跳过已添加的,因标准list容器没有下标
|
||||
if (k++ <= currentRow)
|
||||
continue;
|
||||
manualListModel.insertRow(++currentRow);
|
||||
manualListModel.setData(manualListModel.index(currentRow), (*i).c_str());
|
||||
}
|
||||
if (chess.whoWin() != NineChess::NOBODY)
|
||||
if (chess_.whoWin() != NineChess::NOBODY)
|
||||
playSound(":/sound/resources/sound/loss.wav");
|
||||
}
|
||||
return result;
|
||||
|
@ -691,7 +691,7 @@ bool GameController::command(const QString &cmd, bool update /*= true*/)
|
|||
|
||||
// 声音
|
||||
QString sound;
|
||||
switch (chess.getAction())
|
||||
switch (chess_.getAction())
|
||||
{
|
||||
case NineChess::ACTION_CHOOSE:
|
||||
case NineChess::ACTION_PLACE:
|
||||
|
@ -705,59 +705,59 @@ bool GameController::command(const QString &cmd, bool update /*= true*/)
|
|||
}
|
||||
|
||||
// 如果未开局则开局
|
||||
if (chess.getPhase() == NineChess::GAME_NOTSTARTED) {
|
||||
if (chess_.getPhase() == NineChess::GAME_NOTSTARTED) {
|
||||
gameStart();
|
||||
}
|
||||
|
||||
if (!chess.command(cmd.toStdString().c_str()))
|
||||
if (!chess_.command(cmd.toStdString().c_str()))
|
||||
return false;
|
||||
|
||||
if (sound == ":/sound/resources/sound/drog.wav" && chess.getAction() == NineChess::ACTION_CAPTURE) {
|
||||
if (sound == ":/sound/resources/sound/drog.wav" && chess_.getAction() == NineChess::ACTION_CAPTURE) {
|
||||
sound = ":/sound/resources/sound/capture.wav";
|
||||
}
|
||||
|
||||
if (update) {
|
||||
playSound(sound);
|
||||
updateScence(chess);
|
||||
updateScence(chess_);
|
||||
}
|
||||
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(chess.getTip());
|
||||
message = QString::fromStdString(chess_.getTip());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 对于新开局
|
||||
if (chess.getCmdList()->size() <= 1) {
|
||||
if (chess_.getCmdList()->size() <= 1) {
|
||||
manualListModel.removeRows(0, manualListModel.rowCount());
|
||||
manualListModel.insertRow(0);
|
||||
manualListModel.setData(manualListModel.index(0), chess.getCmdLine());
|
||||
manualListModel.setData(manualListModel.index(0), chess_.getCmdLine());
|
||||
currentRow = 0;
|
||||
}
|
||||
// 对于当前局
|
||||
else {
|
||||
currentRow = manualListModel.rowCount() - 1;
|
||||
// 跳过已添加行,迭代器不支持+运算符,只能一个个++
|
||||
auto i = (chess.getCmdList()->begin());
|
||||
for (int r = 0; i != (chess.getCmdList())->end(); i++) {
|
||||
auto i = (chess_.getCmdList()->begin());
|
||||
for (int r = 0; i != (chess_.getCmdList())->end(); i++) {
|
||||
if (r++ > currentRow)
|
||||
break;
|
||||
}
|
||||
// 将新增的棋谱行插入到ListModel
|
||||
while (i != chess.getCmdList()->end()) {
|
||||
while (i != chess_.getCmdList()->end()) {
|
||||
manualListModel.insertRow(++currentRow);
|
||||
manualListModel.setData(manualListModel.index(currentRow), (*i++).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// 播放胜利或失败音效
|
||||
if (chess.whoWin() != NineChess::NOBODY &&
|
||||
if (chess_.whoWin() != NineChess::NOBODY &&
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over."))
|
||||
playSound(":/sound/resources/sound/win.wav");
|
||||
|
||||
// AI设置
|
||||
if (&chess == &(this->chess)) {
|
||||
if (&chess_ == &(this->chess_)) {
|
||||
// 如果还未决出胜负
|
||||
if (chess.whoWin() == NineChess::NOBODY) {
|
||||
if (chess.whosTurn() == NineChess::PLAYER1) {
|
||||
if (chess_.whoWin() == NineChess::NOBODY) {
|
||||
if (chess_.whosTurn() == NineChess::PLAYER1) {
|
||||
if (isEngine1) {
|
||||
ai1.resume();
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ bool GameController::phaseChange(int row, bool forceUpdate)
|
|||
chessTemp.command(mlist.at(i).toStdString().c_str());
|
||||
}
|
||||
// 下面这步关键,会让悔棋者承担时间损失
|
||||
chessTemp.setStartTimeb(chess.getStartTimeb());
|
||||
chessTemp.setStartTimeb(chess_.getStartTimeb());
|
||||
// 刷新棋局场景
|
||||
updateScence(chessTemp);
|
||||
return true;
|
||||
|
@ -807,12 +807,12 @@ bool GameController::phaseChange(int row, bool forceUpdate)
|
|||
|
||||
bool GameController::updateScence()
|
||||
{
|
||||
return updateScence(chess);
|
||||
return updateScence(chess_);
|
||||
}
|
||||
|
||||
bool GameController::updateScence(NineChess &chess)
|
||||
{
|
||||
const char *board = chess.getBoard();
|
||||
const int *board = chess.getBoard();
|
||||
QPointF pos;
|
||||
// chess类中的棋子代码
|
||||
int key;
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
~GameController();
|
||||
//主窗口菜单栏明细
|
||||
const QMap <int, QStringList> getActions();
|
||||
int getRuleNo() { return ruleNo; }
|
||||
int getRuleNo() { return ruleNo_; }
|
||||
int getTimeLimit() { return timeLimit; }
|
||||
int getStepsLimit() { return stepsLimit; }
|
||||
bool isAnimation() { return hasAnimation; }
|
||||
|
@ -96,7 +96,7 @@ protected:
|
|||
|
||||
private:
|
||||
// 棋对象的数据模型
|
||||
NineChess chess;
|
||||
NineChess chess_;
|
||||
// 棋对象的数据模型(临时)
|
||||
NineChess chessTemp;
|
||||
// 2个AI的线程
|
||||
|
@ -128,15 +128,15 @@ private:
|
|||
// 定时器ID
|
||||
int timeID;
|
||||
// 规则号
|
||||
int ruleNo;
|
||||
int ruleNo_;
|
||||
// 规则限时(分钟)
|
||||
int timeLimit;
|
||||
// 规则限步数
|
||||
int stepsLimit;
|
||||
// 玩家1剩余时间(毫秒)
|
||||
int time1;
|
||||
int remainingTime1;
|
||||
// 玩家2剩余时间(毫秒)
|
||||
int time2;
|
||||
int remainingTime2;
|
||||
// 用于主窗口状态栏显示的字符串
|
||||
QString message;
|
||||
// 棋谱字符串列表模型
|
||||
|
|
|
@ -107,25 +107,25 @@ const char NineChess::inBoard[(RING + 2)*SEAT] = {
|
|||
};
|
||||
|
||||
// 招法表
|
||||
char NineChess::moveTable[(RING + 2)*SEAT][4] = { 0 };
|
||||
int NineChess::moveTable[(RING + 2)*SEAT][4] = { 0 };
|
||||
|
||||
// 成三表
|
||||
char NineChess::millTable[(RING + 2)*SEAT][3][2] = { 0 };
|
||||
int NineChess::millTable[(RING + 2)*SEAT][3][2] = { 0 };
|
||||
|
||||
NineChess::NineChess()
|
||||
{
|
||||
// 单独提出board,免得每次都写data.board;
|
||||
board = data.board;
|
||||
board_ = data.board;
|
||||
// 默认选择第0号规则,即“成三棋”
|
||||
setData(&RULES[0]);
|
||||
}
|
||||
|
||||
NineChess::NineChess(const NineChess &chess)
|
||||
{
|
||||
rule = chess.rule;
|
||||
currentRule = chess.currentRule;
|
||||
data = chess.data;
|
||||
step = chess.step;
|
||||
board = data.board;
|
||||
currentStep = chess.currentStep;
|
||||
board_ = data.board;
|
||||
currentPos = chess.currentPos;
|
||||
winner = chess.winner;
|
||||
startTimeb = chess.startTimeb;
|
||||
|
@ -142,10 +142,10 @@ const NineChess & NineChess::operator=(const NineChess &chess)
|
|||
{
|
||||
if (this == &chess)
|
||||
return *this;
|
||||
rule = chess.rule;
|
||||
currentRule = chess.currentRule;
|
||||
data = chess.data;
|
||||
step = chess.step;
|
||||
board = data.board;
|
||||
currentStep = chess.currentStep;
|
||||
board_ = data.board;
|
||||
currentPos = chess.currentPos;
|
||||
winner = chess.winner;
|
||||
startTimeb = chess.startTimeb;
|
||||
|
@ -172,14 +172,14 @@ bool NineChess::setData(const struct Rule *rule, int s, int t, int step, int fla
|
|||
return false;
|
||||
|
||||
// 根据规则
|
||||
this->rule = *rule;
|
||||
this->rule.maxSteps = s;
|
||||
this->rule.maxTime = t;
|
||||
this->currentRule = *rule;
|
||||
this->currentRule.maxSteps = s;
|
||||
this->currentRule.maxTime = t;
|
||||
|
||||
// 设置棋局数据
|
||||
{
|
||||
// 设置步数
|
||||
this->step = step;
|
||||
this->currentStep = step;
|
||||
|
||||
// 局面阶段标识
|
||||
if (flags & GAME_NOTSTARTED)
|
||||
|
@ -264,7 +264,7 @@ bool NineChess::setData(const struct Rule *rule, int s, int t, int step, int fla
|
|||
// 逆时针走一步的位置
|
||||
moveTable[i*SEAT + j][1] = i * SEAT + (j + SEAT - 1) % SEAT;
|
||||
// 如果是0、2、4、6位(偶数位)或是有斜线
|
||||
if (!(j & 1) || this->rule.hasObliqueLine) {
|
||||
if (!(j & 1) || this->currentRule.hasObliqueLine) {
|
||||
if (i > 1) {
|
||||
// 向内走一步的位置
|
||||
moveTable[i*SEAT + j][2] = (i - 1)*SEAT + j;
|
||||
|
@ -289,7 +289,7 @@ bool NineChess::setData(const struct Rule *rule, int s, int t, int step, int fla
|
|||
{
|
||||
// 内外方向的“成三”
|
||||
// 如果是0、2、4、6位(偶数位)或是有斜线
|
||||
if (!(j & 1) || this->rule.hasObliqueLine) {
|
||||
if (!(j & 1) || this->currentRule.hasObliqueLine) {
|
||||
millTable[1 * SEAT + j][0][0] = 2 * SEAT + j;
|
||||
millTable[1 * SEAT + j][0][1] = 3 * SEAT + j;
|
||||
millTable[2 * SEAT + j][0][0] = 1 * SEAT + j;
|
||||
|
@ -356,7 +356,7 @@ bool NineChess::setData(const struct Rule *rule, int s, int t, int step, int fla
|
|||
cmdlist.clear();
|
||||
int i;
|
||||
for (i = 0; i < RULENUM; i++) {
|
||||
if (strcmp(this->rule.name, RULES[i].name) == 0)
|
||||
if (strcmp(this->currentRule.name, RULES[i].name) == 0)
|
||||
break;
|
||||
}
|
||||
if (sprintf(cmdline, "r%1u s%03u t%02u", i + 1, s, t) > 0) {
|
||||
|
@ -371,13 +371,12 @@ bool NineChess::setData(const struct Rule *rule, int s, int t, int step, int fla
|
|||
//return true;
|
||||
}
|
||||
|
||||
void NineChess::getData(struct Rule &rule, int &step, int &flags, const char *&board,
|
||||
int &p1_InHand, int &p2_InHand, int &num_NeedRemove)
|
||||
void NineChess::getData(struct Rule &rule, int &step, int &flags, int *&board, int &p1_InHand, int &p2_InHand, int &num_NeedRemove)
|
||||
{
|
||||
rule = this->rule;
|
||||
step = this->step;
|
||||
rule = this->currentRule;
|
||||
step = this->currentStep;
|
||||
flags = data.phase | data.turn | data.action;
|
||||
board = board;
|
||||
this->board_ = board;
|
||||
p1_InHand = data.player1_InHand;
|
||||
p2_InHand = data.player2_InHand;
|
||||
num_NeedRemove = data.num_NeedRemove;
|
||||
|
@ -389,7 +388,7 @@ bool NineChess::reset()
|
|||
return true;
|
||||
|
||||
// 步数归零
|
||||
step = 0;
|
||||
currentStep = 0;
|
||||
|
||||
// 局面阶段标识
|
||||
data.phase = GAME_NOTSTARTED;
|
||||
|
@ -402,13 +401,13 @@ bool NineChess::reset()
|
|||
winner = NOBODY;
|
||||
|
||||
// 当前棋局(3×8)
|
||||
memset(board, 0, sizeof(data.board));
|
||||
memset(board_, 0, sizeof(data.board));
|
||||
|
||||
// 盘面子数归零
|
||||
data.player1_Remain = data.player2_Remain = 0;
|
||||
|
||||
// 设置玩家盘面剩余子数和未放置子数
|
||||
data.player1_InHand = data.player2_InHand = rule.numOfChess;
|
||||
data.player1_InHand = data.player2_InHand = currentRule.numOfChess;
|
||||
|
||||
// 设置去子状态时的剩余尚待去除子数
|
||||
data.num_NeedRemove = 0;
|
||||
|
@ -429,10 +428,10 @@ bool NineChess::reset()
|
|||
cmdlist.clear();
|
||||
int i;
|
||||
for (i = 0; i < RULENUM; i++) {
|
||||
if (strcmp(this->rule.name, RULES[i].name) == 0)
|
||||
if (strcmp(this->currentRule.name, RULES[i].name) == 0)
|
||||
break;
|
||||
}
|
||||
if (sprintf(cmdline, "r%1u s%03u t%02u", i + 1, rule.maxSteps, rule.maxTime) > 0) {
|
||||
if (sprintf(cmdline, "r%1u s%03u t%02u", i + 1, currentRule.maxSteps, currentRule.maxTime) > 0) {
|
||||
cmdlist.push_back(string(cmdline));
|
||||
return true;
|
||||
}
|
||||
|
@ -478,13 +477,13 @@ bool NineChess::getPieceCP(const Players &player, const int &number, int &c, int
|
|||
else
|
||||
return false;
|
||||
|
||||
if (number > 0 && number <= rule.numOfChess)
|
||||
if (number > 0 && number <= currentRule.numOfChess)
|
||||
piece &= number;
|
||||
else
|
||||
return false;
|
||||
|
||||
for (int i = SEAT; i < SEAT*(RING + 1); i++) {
|
||||
if (board[i] == piece) {
|
||||
if (board_[i] == piece) {
|
||||
pos2cp(i, c, p);
|
||||
return true;
|
||||
}
|
||||
|
@ -499,13 +498,13 @@ bool NineChess::getCurrentPiece(Players &player, int &number)
|
|||
if (!inBoard[currentPos])
|
||||
return false;
|
||||
|
||||
if (board[currentPos] & 0x10) {
|
||||
if (board_[currentPos] & 0x10) {
|
||||
player = PLAYER1;
|
||||
number = board[currentPos] - 0x10;
|
||||
number = board_[currentPos] - 0x10;
|
||||
}
|
||||
else if (board[currentPos] & 0x20) {
|
||||
else if (board_[currentPos] & 0x20) {
|
||||
player = PLAYER2;
|
||||
number = board[currentPos] - 0x20;
|
||||
number = board_[currentPos] - 0x20;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
@ -543,36 +542,36 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/)
|
|||
return false;
|
||||
// 如果落子位置在棋盘外、已有子点或禁点,返回false
|
||||
int pos = cp2pos(c, p);
|
||||
if (!inBoard[pos] || board[pos])
|
||||
if (!inBoard[pos] || board_[pos])
|
||||
return false;
|
||||
// 时间的临时变量
|
||||
long player_ms = -1;
|
||||
|
||||
// 对于开局落子
|
||||
char piece = '\x00';
|
||||
int piece = '\x00';
|
||||
int n = 0;
|
||||
if (data.phase == GAME_OPENING) {
|
||||
// 先手下
|
||||
if (data.turn == PLAYER1)
|
||||
{
|
||||
piece = '\x11' + rule.numOfChess - data.player1_InHand;
|
||||
piece = '\x11' + currentRule.numOfChess - data.player1_InHand;
|
||||
data.player1_InHand--;
|
||||
data.player1_Remain++;
|
||||
}
|
||||
// 后手下
|
||||
else
|
||||
{
|
||||
piece = '\x21' + rule.numOfChess - data.player2_InHand;
|
||||
piece = '\x21' + currentRule.numOfChess - data.player2_InHand;
|
||||
data.player2_InHand--;
|
||||
data.player2_Remain++;
|
||||
}
|
||||
board[pos] = piece;
|
||||
board_[pos] = piece;
|
||||
move_ = pos;
|
||||
player_ms = update(time_p);
|
||||
sprintf(cmdline, "(%1u,%1u) %02u:%02u.%03u", c, p, player_ms / 60000, (player_ms % 60000) / 1000, player_ms % 1000);
|
||||
cmdlist.push_back(string(cmdline));
|
||||
currentPos = pos;
|
||||
step++;
|
||||
currentStep++;
|
||||
// 如果决出胜负
|
||||
if (win()) {
|
||||
setTip();
|
||||
|
@ -591,7 +590,7 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/)
|
|||
// 清除禁点
|
||||
cleanForbidden();
|
||||
// 设置轮到谁走
|
||||
if (rule.isDefensiveMoveFirst) {
|
||||
if (currentRule.isDefensiveMoveFirst) {
|
||||
data.turn = PLAYER2;
|
||||
}
|
||||
else {
|
||||
|
@ -613,7 +612,7 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/)
|
|||
// 如果成三
|
||||
else {
|
||||
// 设置去子数目
|
||||
data.num_NeedRemove = rule.removeMore ? n : 1;
|
||||
data.num_NeedRemove = currentRule.removeMore ? n : 1;
|
||||
// 进入去子状态
|
||||
data.action = ACTION_CAPTURE;
|
||||
}
|
||||
|
@ -624,8 +623,8 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/)
|
|||
// 对于中局落子
|
||||
else if (data.phase == GAME_MID) {
|
||||
// 如果落子不合法
|
||||
if ((data.turn == PLAYER1 && (data.player1_Remain > rule.numAtLest || !rule.canFly)) ||
|
||||
(data.turn == PLAYER2 && (data.player2_Remain > rule.numAtLest || !rule.canFly))) {
|
||||
if ((data.turn == PLAYER1 && (data.player1_Remain > currentRule.numAtLest || !currentRule.canFly)) ||
|
||||
(data.turn == PLAYER2 && (data.player2_Remain > currentRule.numAtLest || !currentRule.canFly))) {
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (pos == moveTable[currentPos][i])
|
||||
|
@ -641,10 +640,10 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/)
|
|||
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u) %02u:%02u.%03u", currentPos / SEAT, currentPos % SEAT + 1,
|
||||
c, p, player_ms / 60000, (player_ms % 60000) / 1000, player_ms % 1000);
|
||||
cmdlist.push_back(string(cmdline));
|
||||
board[pos] = board[currentPos];
|
||||
board[currentPos] = '\x00';
|
||||
board_[pos] = board_[currentPos];
|
||||
board_[currentPos] = '\x00';
|
||||
currentPos = pos;
|
||||
step++;
|
||||
currentStep++;
|
||||
n = addMills(currentPos);
|
||||
|
||||
// 中局阶段未成三
|
||||
|
@ -662,7 +661,7 @@ bool NineChess::place(int c, int p, long time_p /* = -1*/)
|
|||
// 中局阶段成三
|
||||
else {
|
||||
// 设置去子数目
|
||||
data.num_NeedRemove = rule.removeMore ? n : 1;
|
||||
data.num_NeedRemove = currentRule.removeMore ? n : 1;
|
||||
// 进入去子状态
|
||||
data.action = ACTION_CAPTURE;
|
||||
setTip();
|
||||
|
@ -691,7 +690,7 @@ bool NineChess::capture(int c, int p, long time_p /* = -1*/)
|
|||
// 对手
|
||||
char opponent = data.turn == PLAYER1 ? 0x20 : 0x10;
|
||||
// 判断去子是不是对手棋
|
||||
if (!(opponent & board[pos]))
|
||||
if (!(opponent & board_[pos]))
|
||||
return false;
|
||||
|
||||
// 如果当前子是否处于“三连”之中,且对方还未全部处于“三连”之中
|
||||
|
@ -700,10 +699,10 @@ bool NineChess::capture(int c, int p, long time_p /* = -1*/)
|
|||
}
|
||||
|
||||
// 去子(设置禁点)
|
||||
if (rule.hasForbidden && data.phase == GAME_OPENING)
|
||||
board[pos] = '\x0f';
|
||||
if (currentRule.hasForbidden && data.phase == GAME_OPENING)
|
||||
board_[pos] = '\x0f';
|
||||
else // 去子
|
||||
board[pos] = '\x00';
|
||||
board_[pos] = '\x00';
|
||||
if (data.turn == PLAYER1)
|
||||
data.player2_Remain--;
|
||||
else if (data.turn == PLAYER2)
|
||||
|
@ -714,7 +713,7 @@ bool NineChess::capture(int c, int p, long time_p /* = -1*/)
|
|||
cmdlist.push_back(string(cmdline));
|
||||
currentPos = 0;
|
||||
data.num_NeedRemove--;
|
||||
step++;
|
||||
currentStep++;
|
||||
// 去子完成
|
||||
|
||||
// 如果决出胜负
|
||||
|
@ -740,7 +739,7 @@ bool NineChess::capture(int c, int p, long time_p /* = -1*/)
|
|||
// 清除禁点
|
||||
cleanForbidden();
|
||||
// 设置轮到谁走
|
||||
if (rule.isDefensiveMoveFirst) {
|
||||
if (currentRule.isDefensiveMoveFirst) {
|
||||
data.turn = PLAYER2;
|
||||
}
|
||||
else {
|
||||
|
@ -798,7 +797,7 @@ bool NineChess::choose(int c, int p)
|
|||
else if (data.turn == PLAYER2)
|
||||
t = '\x20';
|
||||
// 判断选子是否可选
|
||||
if (board[pos] & t) {
|
||||
if (board_[pos] & t) {
|
||||
// 判断pos处的棋子是否被“闷”
|
||||
if (isSurrounded(pos)) {
|
||||
return false;
|
||||
|
@ -825,28 +824,28 @@ bool NineChess::place(int pos)
|
|||
if (data.action != ACTION_PLACE)
|
||||
return false;
|
||||
// 如果落子位置在棋盘外、已有子点或禁点,返回false
|
||||
if (!inBoard[pos] || board[pos])
|
||||
if (!inBoard[pos] || board_[pos])
|
||||
return false;
|
||||
|
||||
// 对于开局落子
|
||||
char piece = '\x00';
|
||||
int piece = '\x00';
|
||||
int n = 0;
|
||||
if (data.phase == GAME_OPENING) {
|
||||
// 先手下
|
||||
if (data.turn == PLAYER1)
|
||||
{
|
||||
piece = '\x11' + rule.numOfChess - data.player1_InHand;
|
||||
piece = '\x11' + currentRule.numOfChess - data.player1_InHand;
|
||||
data.player1_InHand--;
|
||||
data.player1_Remain++;
|
||||
}
|
||||
// 后手下
|
||||
else
|
||||
{
|
||||
piece = '\x21' + rule.numOfChess - data.player2_InHand;
|
||||
piece = '\x21' + currentRule.numOfChess - data.player2_InHand;
|
||||
data.player2_InHand--;
|
||||
data.player2_Remain++;
|
||||
}
|
||||
board[pos] = piece;
|
||||
board_[pos] = piece;
|
||||
move_ = pos;
|
||||
currentPos = pos;
|
||||
//step++;
|
||||
|
@ -868,7 +867,7 @@ bool NineChess::place(int pos)
|
|||
// 清除禁点
|
||||
cleanForbidden();
|
||||
// 设置轮到谁走
|
||||
if (rule.isDefensiveMoveFirst) {
|
||||
if (currentRule.isDefensiveMoveFirst) {
|
||||
data.turn = PLAYER2;
|
||||
}
|
||||
else {
|
||||
|
@ -890,7 +889,7 @@ bool NineChess::place(int pos)
|
|||
// 如果成三
|
||||
else {
|
||||
// 设置去子数目
|
||||
data.num_NeedRemove = rule.removeMore ? n : 1;
|
||||
data.num_NeedRemove = currentRule.removeMore ? n : 1;
|
||||
// 进入去子状态
|
||||
data.action = ACTION_CAPTURE;
|
||||
}
|
||||
|
@ -901,8 +900,8 @@ bool NineChess::place(int pos)
|
|||
// 对于中局落子
|
||||
else if (data.phase == GAME_MID) {
|
||||
// 如果落子不合法
|
||||
if ((data.turn == PLAYER1 && (data.player1_Remain > rule.numAtLest || !rule.canFly)) ||
|
||||
(data.turn == PLAYER2 && (data.player2_Remain > rule.numAtLest || !rule.canFly))) {
|
||||
if ((data.turn == PLAYER1 && (data.player1_Remain > currentRule.numAtLest || !currentRule.canFly)) ||
|
||||
(data.turn == PLAYER2 && (data.player2_Remain > currentRule.numAtLest || !currentRule.canFly))) {
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (pos == moveTable[currentPos][i])
|
||||
|
@ -914,8 +913,8 @@ bool NineChess::place(int pos)
|
|||
}
|
||||
// 移子
|
||||
move_ = (currentPos << 8) + pos;
|
||||
board[pos] = board[currentPos];
|
||||
board[currentPos] = '\x00';
|
||||
board_[pos] = board_[currentPos];
|
||||
board_[currentPos] = '\x00';
|
||||
currentPos = pos;
|
||||
//step++;
|
||||
n = addMills(currentPos);
|
||||
|
@ -935,7 +934,7 @@ bool NineChess::place(int pos)
|
|||
// 中局阶段成三
|
||||
else {
|
||||
// 设置去子数目
|
||||
data.num_NeedRemove = rule.removeMore ? n : 1;
|
||||
data.num_NeedRemove = currentRule.removeMore ? n : 1;
|
||||
// 进入去子状态
|
||||
data.action = ACTION_CAPTURE;
|
||||
//setTip();
|
||||
|
@ -961,7 +960,7 @@ bool NineChess::capture(int pos)
|
|||
// 对手
|
||||
char opponent = data.turn == PLAYER1 ? 0x20 : 0x10;
|
||||
// 判断去子是不是对手棋
|
||||
if (!(opponent & board[pos]))
|
||||
if (!(opponent & board_[pos]))
|
||||
return false;
|
||||
|
||||
// 如果当前子是否处于“三连”之中,且对方还未全部处于“三连”之中
|
||||
|
@ -970,10 +969,10 @@ bool NineChess::capture(int pos)
|
|||
}
|
||||
|
||||
// 去子(设置禁点)
|
||||
if (rule.hasForbidden && data.phase == GAME_OPENING)
|
||||
board[pos] = '\x0f';
|
||||
if (currentRule.hasForbidden && data.phase == GAME_OPENING)
|
||||
board_[pos] = '\x0f';
|
||||
else // 去子
|
||||
board[pos] = '\x00';
|
||||
board_[pos] = '\x00';
|
||||
if (data.turn == PLAYER1)
|
||||
data.player2_Remain--;
|
||||
else if (data.turn == PLAYER2)
|
||||
|
@ -1007,7 +1006,7 @@ bool NineChess::capture(int pos)
|
|||
// 清除禁点
|
||||
cleanForbidden();
|
||||
// 设置轮到谁走
|
||||
if (rule.isDefensiveMoveFirst) {
|
||||
if (currentRule.isDefensiveMoveFirst) {
|
||||
data.turn = PLAYER2;
|
||||
}
|
||||
else {
|
||||
|
@ -1059,7 +1058,7 @@ bool NineChess::choose(int pos)
|
|||
return false;
|
||||
char t = data.turn == PLAYER1 ? 0x10 : 0x20;
|
||||
// 判断选子是否可选
|
||||
if (board[pos] & t) {
|
||||
if (board_[pos] & t) {
|
||||
// 判断pos处的棋子是否被“闷”
|
||||
if (isSurrounded(pos)) {
|
||||
return false;
|
||||
|
@ -1087,7 +1086,7 @@ uint64_t NineChess::chessHash()
|
|||
*/
|
||||
uint64_t hash = 0ull;
|
||||
for (int i = SEAT; i < (RING + 1)*SEAT; i++) {
|
||||
hash |= board[i] & 0x30;
|
||||
hash |= board_[i] & 0x30;
|
||||
hash <<= 2;
|
||||
}
|
||||
if (data.turn == PLAYER2)
|
||||
|
@ -1189,7 +1188,7 @@ bool NineChess::command(const char *cmd)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool NineChess::command(int16_t move)
|
||||
bool NineChess::command(int move)
|
||||
{
|
||||
if (move < 0) {
|
||||
return capture(-move);
|
||||
|
@ -1238,7 +1237,7 @@ inline long NineChess::update(long time_p /*= -1*/)
|
|||
+ (currentTimeb.millitm - startTimeb.millitm) - playerNext_ms;
|
||||
}
|
||||
// 有限时要求则判断胜负
|
||||
if (rule.maxTime > 0)
|
||||
if (currentRule.maxTime > 0)
|
||||
win();
|
||||
return ret;
|
||||
case NineChess::GAME_NOTSTARTED:
|
||||
|
@ -1259,11 +1258,11 @@ bool NineChess::win()
|
|||
return false;
|
||||
|
||||
// 如果有时间限定
|
||||
if (rule.maxTime > 0) {
|
||||
if (currentRule.maxTime > 0) {
|
||||
// 这里不能update更新时间,否则会形成循环嵌套
|
||||
// 如果玩家1超时
|
||||
if (player1_MS > rule.maxTime * 60000) {
|
||||
player1_MS = rule.maxTime * 60000;
|
||||
if (player1_MS > currentRule.maxTime * 60000) {
|
||||
player1_MS = currentRule.maxTime * 60000;
|
||||
winner = PLAYER2;
|
||||
data.phase = GAME_OVER;
|
||||
tip = "玩家1超时,恭喜玩家2获胜!";
|
||||
|
@ -1272,8 +1271,8 @@ bool NineChess::win()
|
|||
return true;
|
||||
}
|
||||
// 如果玩家2超时
|
||||
else if (player2_MS > rule.maxTime * 60000) {
|
||||
player2_MS = rule.maxTime * 60000;
|
||||
else if (player2_MS > currentRule.maxTime * 60000) {
|
||||
player2_MS = currentRule.maxTime * 60000;
|
||||
winner = PLAYER1;
|
||||
data.phase = GAME_OVER;
|
||||
tip = "玩家2超时,恭喜玩家1获胜!";
|
||||
|
@ -1284,8 +1283,8 @@ bool NineChess::win()
|
|||
}
|
||||
|
||||
// 如果有步数限定
|
||||
if (rule.maxSteps > 0) {
|
||||
if (step > rule.maxSteps) {
|
||||
if (currentRule.maxSteps > 0) {
|
||||
if (currentStep > currentRule.maxSteps) {
|
||||
winner = DRAW;
|
||||
data.phase = GAME_OVER;
|
||||
sprintf(cmdline, "Steps over. In draw!");
|
||||
|
@ -1295,7 +1294,7 @@ bool NineChess::win()
|
|||
}
|
||||
|
||||
// 如果玩家1子数小于赛点,则玩家2获胜
|
||||
if (data.player1_Remain + data.player1_InHand < rule.numAtLest) {
|
||||
if (data.player1_Remain + data.player1_InHand < currentRule.numAtLest) {
|
||||
winner = PLAYER2;
|
||||
data.phase = GAME_OVER;
|
||||
sprintf(cmdline, "Player2 win!");
|
||||
|
@ -1303,7 +1302,7 @@ bool NineChess::win()
|
|||
return true;
|
||||
}
|
||||
// 如果玩家2子数小于赛点,则玩家1获胜
|
||||
else if (data.player2_Remain + data.player2_InHand < rule.numAtLest) {
|
||||
else if (data.player2_Remain + data.player2_InHand < currentRule.numAtLest) {
|
||||
winner = PLAYER1;
|
||||
data.phase = GAME_OVER;
|
||||
sprintf(cmdline, "Player1 win!");
|
||||
|
@ -1312,7 +1311,7 @@ bool NineChess::win()
|
|||
}
|
||||
// 如果摆满了,根据规则判断胜负
|
||||
else if (data.player1_Remain + data.player2_Remain >= SEAT * RING) {
|
||||
if (rule.isFullLose) {
|
||||
if (currentRule.isFullLose) {
|
||||
winner = PLAYER2;
|
||||
data.phase = GAME_OVER;
|
||||
sprintf(cmdline, "Player2 win!");
|
||||
|
@ -1331,7 +1330,7 @@ bool NineChess::win()
|
|||
// 如果中局被“闷”
|
||||
else if (data.phase == GAME_MID && data.action == ACTION_CHOOSE && isAllSurrounded(data.turn)) {
|
||||
// 规则要求被“闷”判负,则对手获胜
|
||||
if (rule.isNoWayLose) {
|
||||
if (currentRule.isNoWayLose) {
|
||||
if (data.turn == PLAYER1)
|
||||
{
|
||||
tip = "玩家1无子可走,恭喜玩家2获胜!";
|
||||
|
@ -1366,12 +1365,12 @@ int NineChess::isInMills(int pos)
|
|||
{
|
||||
int n = 0;
|
||||
int pos1, pos2;
|
||||
char m = board[pos] & '\x30';
|
||||
char m = board_[pos] & '\x30';
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
pos1 = millTable[pos][i][0];
|
||||
pos2 = millTable[pos][i][1];
|
||||
if (m & board[pos1] & board[pos2])
|
||||
if (m & board_[pos1] & board_[pos2])
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
|
@ -1386,14 +1385,14 @@ int NineChess::addMills(int pos)
|
|||
uint64_t mill = 0;
|
||||
int n = 0;
|
||||
int p[3], min, temp;
|
||||
char m = board[pos] & '\x30';
|
||||
char m = board_[pos] & '\x30';
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
p[0] = pos;
|
||||
p[1] = millTable[pos][i][0];
|
||||
p[2] = millTable[pos][i][1];
|
||||
// 如果成三
|
||||
if (m & board[p[1]] & board[p[2]]) {
|
||||
if (m & board_[p[1]] & board_[p[2]]) {
|
||||
// 排序
|
||||
for (int j = 0; j < 2; j++) {
|
||||
min = j;
|
||||
|
@ -1408,15 +1407,15 @@ int NineChess::addMills(int pos)
|
|||
}
|
||||
}
|
||||
// 成三
|
||||
mill = (((uint64_t)board[p[0]]) << 40)
|
||||
mill = (((uint64_t)board_[p[0]]) << 40)
|
||||
+ (((uint64_t)p[0]) << 32)
|
||||
+ (((uint64_t)board[p[1]]) << 24)
|
||||
+ (((uint64_t)board_[p[1]]) << 24)
|
||||
+ (((uint64_t)p[1]) << 16)
|
||||
+ (((uint64_t)board[p[2]]) << 8)
|
||||
+ (((uint64_t)board_[p[2]]) << 8)
|
||||
+ (uint64_t)p[2];
|
||||
|
||||
// 如果允许相同三连反复去子
|
||||
if (rule.canRepeated) {
|
||||
if (currentRule.canRepeated) {
|
||||
n++;
|
||||
}
|
||||
// 如果不允许相同三连反复去子
|
||||
|
@ -1444,7 +1443,7 @@ int NineChess::addMills(int pos)
|
|||
bool NineChess::isAllInMills(char ch)
|
||||
{
|
||||
for (int i = SEAT; i < SEAT * (RING+1); i++)
|
||||
if (board[i] & ch) {
|
||||
if (board_[i] & ch) {
|
||||
if (!isInMills(i)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1468,13 +1467,13 @@ bool NineChess::isAllInMills(enum Players player)
|
|||
bool NineChess::isSurrounded(int pos)
|
||||
{
|
||||
// 判断pos处的棋子是否被“闷”
|
||||
if ((data.turn == PLAYER1 && (data.player1_Remain > rule.numAtLest || !rule.canFly)) ||
|
||||
(data.turn == PLAYER2 && (data.player2_Remain > rule.numAtLest || !rule.canFly)))
|
||||
if ((data.turn == PLAYER1 && (data.player1_Remain > currentRule.numAtLest || !currentRule.canFly)) ||
|
||||
(data.turn == PLAYER2 && (data.player2_Remain > currentRule.numAtLest || !currentRule.canFly)))
|
||||
{
|
||||
int i, movePos;
|
||||
for (i = 0; i < 4; i++) {
|
||||
movePos = moveTable[pos][i];
|
||||
if (movePos && !board[movePos])
|
||||
if (movePos && !board_[movePos])
|
||||
break;
|
||||
}
|
||||
// 被围住
|
||||
|
@ -1491,18 +1490,18 @@ bool NineChess::isAllSurrounded(char ch)
|
|||
if (data.player1_Remain + data.player2_Remain >= SEAT * RING)
|
||||
return true;
|
||||
// 判断是否可以飞子
|
||||
if ((data.turn == PLAYER1 && (data.player1_Remain <= rule.numAtLest && rule.canFly)) ||
|
||||
(data.turn == PLAYER2 && (data.player2_Remain <= rule.numAtLest && rule.canFly)))
|
||||
if ((data.turn == PLAYER1 && (data.player1_Remain <= currentRule.numAtLest && currentRule.canFly)) ||
|
||||
(data.turn == PLAYER2 && (data.player2_Remain <= currentRule.numAtLest && currentRule.canFly)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// 查询整个棋盘
|
||||
char movePos;
|
||||
int movePos;
|
||||
for (int i = 1; i < SEAT * (RING + 1); i++) {
|
||||
if (ch & board[i]) {
|
||||
if (ch & board_[i]) {
|
||||
for (int k = 0; k < 4; k++) {
|
||||
movePos = moveTable[i][k];
|
||||
if (movePos && !board[movePos])
|
||||
if (movePos && !board_[movePos])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1525,8 +1524,8 @@ void NineChess::cleanForbidden()
|
|||
{
|
||||
for (int i = 1; i <= RING; i++)
|
||||
for (int j = 0; j < SEAT; j++) {
|
||||
if (board[i*SEAT + j] == '\x0f')
|
||||
board[i*SEAT + j] = '\x00';
|
||||
if (board_[i*SEAT + j] == '\x0f')
|
||||
board_[i*SEAT + j] = '\x00';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1604,9 +1603,9 @@ void NineChess::setTip()
|
|||
enum NineChess::Players NineChess::getWhosPiece(int c, int p)
|
||||
{
|
||||
int pos = cp2pos(c, p);
|
||||
if (board[pos] & '\x10')
|
||||
if (board_[pos] & '\x10')
|
||||
return PLAYER1;
|
||||
else if (board[pos] & '\x20')
|
||||
else if (board_[pos] & '\x20')
|
||||
return PLAYER2;
|
||||
return NOBODY;
|
||||
}
|
||||
|
@ -1620,18 +1619,18 @@ void NineChess::getPlayer_TimeMS(int &p1_ms, int &p2_ms)
|
|||
|
||||
void NineChess::mirror(bool cmdChange /*= true*/)
|
||||
{
|
||||
char ch;
|
||||
int ch;
|
||||
int i, j;
|
||||
|
||||
for (i = 1; i <= RING; i++) {
|
||||
for (j = 1; j < SEAT / 2; j++) {
|
||||
ch = board[i*SEAT + j];
|
||||
board[i*SEAT + j] = board[(i + 1)*SEAT - j];
|
||||
board[(i + 1)*SEAT - j] = ch;
|
||||
ch = board_[i*SEAT + j];
|
||||
board_[i*SEAT + j] = board_[(i + 1)*SEAT - j];
|
||||
board_[(i + 1)*SEAT - j] = ch;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t p1, p2, p3;
|
||||
uint64_t llp1, llp2, llp3;
|
||||
|
||||
if (move_ < 0) {
|
||||
i = (-move_) / SEAT;
|
||||
|
@ -1640,18 +1639,18 @@ void NineChess::mirror(bool cmdChange /*= true*/)
|
|||
move_ = -(i * SEAT + j);
|
||||
}
|
||||
else {
|
||||
p1 = move_ >> 8;
|
||||
p2 = move_ & 0x00ff;
|
||||
i = (int)p1 / SEAT;
|
||||
j = (int)p1 % SEAT;
|
||||
llp1 = move_ >> 8;
|
||||
llp2 = move_ & 0x00ff;
|
||||
i = (int)llp1 / SEAT;
|
||||
j = (int)llp1 % SEAT;
|
||||
j = (SEAT - j) % SEAT;
|
||||
p1 = i * SEAT + j;
|
||||
llp1 = i * SEAT + j;
|
||||
|
||||
i = (int)p2 / SEAT;
|
||||
j = (int)p2 % SEAT;
|
||||
i = (int)llp2 / SEAT;
|
||||
j = (int)llp2 % SEAT;
|
||||
j = (SEAT - j) % SEAT;
|
||||
p2 = i * SEAT + j;
|
||||
move_ = (int16_t)((p1 << 8) | p2);
|
||||
llp2 = i * SEAT + j;
|
||||
move_ = (int16_t)((llp1 << 8) | llp2);
|
||||
}
|
||||
|
||||
if (currentPos != 0) {
|
||||
|
@ -1661,29 +1660,29 @@ void NineChess::mirror(bool cmdChange /*= true*/)
|
|||
currentPos = i * SEAT + j;
|
||||
}
|
||||
|
||||
if (rule.canRepeated) {
|
||||
if (currentRule.canRepeated) {
|
||||
for (auto mill = data.millList.begin(); mill != data.millList.end(); mill++) {
|
||||
p1 = (*mill & 0x000000ff00000000) >> 32;
|
||||
p2 = (*mill & 0x0000000000ff0000) >> 16;
|
||||
p3 = (*mill & 0x00000000000000ff);
|
||||
llp1 = (*mill & 0x000000ff00000000) >> 32;
|
||||
llp2 = (*mill & 0x0000000000ff0000) >> 16;
|
||||
llp3 = (*mill & 0x00000000000000ff);
|
||||
|
||||
i = (int)p1 / SEAT;
|
||||
j = (int)p1 % SEAT;
|
||||
i = (int)llp1 / SEAT;
|
||||
j = (int)llp1 % SEAT;
|
||||
j = (SEAT - j) % SEAT;
|
||||
p1 = i * SEAT + j;
|
||||
llp1 = i * SEAT + j;
|
||||
|
||||
i = (int)p2 / SEAT;
|
||||
j = (int)p2 % SEAT;
|
||||
i = (int)llp2 / SEAT;
|
||||
j = (int)llp2 % SEAT;
|
||||
j = (SEAT - j) % SEAT;
|
||||
p2 = i * SEAT + j;
|
||||
llp2 = i * SEAT + j;
|
||||
|
||||
i = (int)p3 / SEAT;
|
||||
j = (int)p3 % SEAT;
|
||||
i = (int)llp3 / SEAT;
|
||||
j = (int)llp3 % SEAT;
|
||||
j = (SEAT - j) % SEAT;
|
||||
p3 = i * SEAT + j;
|
||||
llp3 = i * SEAT + j;
|
||||
|
||||
*mill &= 0xffffff00ff00ff00;
|
||||
*mill |= (p1 << 32) | (p2 << 16) | p3;
|
||||
*mill |= (llp1 << 32) | (llp2 << 16) | llp3;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1743,16 +1742,16 @@ void NineChess::mirror(bool cmdChange /*= true*/)
|
|||
|
||||
void NineChess::turn(bool cmdChange /*= true*/)
|
||||
{
|
||||
char ch;
|
||||
int ch;
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < SEAT; i++) {
|
||||
ch = board[SEAT + i];
|
||||
board[SEAT + i] = board[SEAT*RING + i];
|
||||
board[SEAT*RING + i] = ch;
|
||||
ch = board_[SEAT + i];
|
||||
board_[SEAT + i] = board_[SEAT*RING + i];
|
||||
board_[SEAT*RING + i] = ch;
|
||||
}
|
||||
|
||||
uint64_t p1, p2, p3;
|
||||
uint64_t llp1, llp2, llp3;
|
||||
|
||||
if (move_ < 0) {
|
||||
i = (-move_) / SEAT;
|
||||
|
@ -1764,23 +1763,23 @@ void NineChess::turn(bool cmdChange /*= true*/)
|
|||
move_ = -(i * SEAT + j);
|
||||
}
|
||||
else {
|
||||
p1 = move_ >> 8;
|
||||
p2 = move_ & 0x00ff;
|
||||
i = (int)p1 / SEAT;
|
||||
j = (int)p1 % SEAT;
|
||||
llp1 = move_ >> 8;
|
||||
llp2 = move_ & 0x00ff;
|
||||
i = (int)llp1 / SEAT;
|
||||
j = (int)llp1 % SEAT;
|
||||
if (i == 1)
|
||||
i = RING;
|
||||
else if (i == RING)
|
||||
i = 1;
|
||||
p1 = i * SEAT + j;
|
||||
i = (int)p2 / SEAT;
|
||||
j = (int)p2 % SEAT;
|
||||
llp1 = i * SEAT + j;
|
||||
i = (int)llp2 / SEAT;
|
||||
j = (int)llp2 % SEAT;
|
||||
if (i == 1)
|
||||
i = RING;
|
||||
else if (i == RING)
|
||||
i = 1;
|
||||
p2 = i * SEAT + j;
|
||||
move_ = (int16_t)((p1 << 8) | p2);
|
||||
llp2 = i * SEAT + j;
|
||||
move_ = (int16_t)((llp1 << 8) | llp2);
|
||||
}
|
||||
|
||||
if (currentPos != 0) {
|
||||
|
@ -1793,38 +1792,38 @@ void NineChess::turn(bool cmdChange /*= true*/)
|
|||
currentPos = i * SEAT + j;
|
||||
}
|
||||
|
||||
if (rule.canRepeated) {
|
||||
if (currentRule.canRepeated) {
|
||||
for (auto mill = data.millList.begin(); mill != data.millList.end(); mill++) {
|
||||
p1 = (*mill & 0x000000ff00000000) >> 32;
|
||||
p2 = (*mill & 0x0000000000ff0000) >> 16;
|
||||
p3 = (*mill & 0x00000000000000ff);
|
||||
llp1 = (*mill & 0x000000ff00000000) >> 32;
|
||||
llp2 = (*mill & 0x0000000000ff0000) >> 16;
|
||||
llp3 = (*mill & 0x00000000000000ff);
|
||||
|
||||
i = (int)p1 / SEAT;
|
||||
j = (int)p1 % SEAT;
|
||||
i = (int)llp1 / SEAT;
|
||||
j = (int)llp1 % SEAT;
|
||||
if (i == 1)
|
||||
i = RING;
|
||||
else if (i == RING)
|
||||
i = 1;
|
||||
p1 = i * SEAT + j;
|
||||
llp1 = i * SEAT + j;
|
||||
|
||||
i = (int)p2 / SEAT;
|
||||
j = (int)p2 % SEAT;
|
||||
i = (int)llp2 / SEAT;
|
||||
j = (int)llp2 % SEAT;
|
||||
if (i == 1)
|
||||
i = RING;
|
||||
else if (i == RING)
|
||||
i = 1;
|
||||
p2 = i * SEAT + j;
|
||||
llp2 = i * SEAT + j;
|
||||
|
||||
i = (int)p3 / SEAT;
|
||||
j = (int)p3 % SEAT;
|
||||
i = (int)llp3 / SEAT;
|
||||
j = (int)llp3 % SEAT;
|
||||
if (i == 1)
|
||||
i = RING;
|
||||
else if (i == RING)
|
||||
i = 1;
|
||||
p3 = i * SEAT + j;
|
||||
llp3 = i * SEAT + j;
|
||||
|
||||
*mill &= 0xffffff00ff00ff00;
|
||||
*mill |= (p1 << 32) | (p2 << 16) | p3;
|
||||
*mill |= (llp1 << 32) | (llp2 << 16) | llp3;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1918,44 +1917,44 @@ void NineChess::rotate(int degrees, bool cmdChange /*= true*/)
|
|||
else
|
||||
degrees /= 45;
|
||||
|
||||
char ch1, ch2;
|
||||
int ch1, ch2;
|
||||
int i, j;
|
||||
|
||||
if (degrees == 2) {
|
||||
for (i = 1; i <= RING; i++) {
|
||||
ch1 = board[i*SEAT];
|
||||
ch2 = board[i*SEAT + 1];
|
||||
ch1 = board_[i*SEAT];
|
||||
ch2 = board_[i*SEAT + 1];
|
||||
for (j = 0; j < SEAT - 2; j++) {
|
||||
board[i*SEAT + j] = board[i*SEAT + j + 2];
|
||||
board_[i*SEAT + j] = board_[i*SEAT + j + 2];
|
||||
}
|
||||
board[i*SEAT + 6] = ch1;
|
||||
board[i*SEAT + 7] = ch2;
|
||||
board_[i*SEAT + 6] = ch1;
|
||||
board_[i*SEAT + 7] = ch2;
|
||||
}
|
||||
}
|
||||
else if (degrees == 6) {
|
||||
for (i = 1; i <= RING; i++) {
|
||||
ch1 = board[i*SEAT + 7];
|
||||
ch2 = board[i*SEAT + 6];
|
||||
ch1 = board_[i*SEAT + 7];
|
||||
ch2 = board_[i*SEAT + 6];
|
||||
for (j = SEAT - 1; j >= 2 ; j--) {
|
||||
board[i*SEAT + j] = board[i*SEAT + j - 2];
|
||||
board_[i*SEAT + j] = board_[i*SEAT + j - 2];
|
||||
}
|
||||
board[i*SEAT + 1] = ch1;
|
||||
board[i*SEAT] = ch2;
|
||||
board_[i*SEAT + 1] = ch1;
|
||||
board_[i*SEAT] = ch2;
|
||||
}
|
||||
}
|
||||
else if (degrees == 4) {
|
||||
for (i = 1; i <= RING; i++) {
|
||||
for (j = 0; j < SEAT / 2; j++) {
|
||||
ch1 = board[i*SEAT + j];
|
||||
board[i*SEAT + j] = board[i*SEAT + j + 4];
|
||||
board[i*SEAT + j + 4] = ch1;
|
||||
ch1 = board_[i*SEAT + j];
|
||||
board_[i*SEAT + j] = board_[i*SEAT + j + 4];
|
||||
board_[i*SEAT + j + 4] = ch1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
uint64_t p1, p2, p3;
|
||||
uint64_t llp1, llp2, llp3;
|
||||
|
||||
if (move_ < 0) {
|
||||
i = (-move_) / SEAT;
|
||||
|
@ -1964,17 +1963,17 @@ void NineChess::rotate(int degrees, bool cmdChange /*= true*/)
|
|||
move_ = -(i * SEAT + j);
|
||||
}
|
||||
else {
|
||||
p1 = move_ >> 8;
|
||||
p2 = move_ & 0x00ff;
|
||||
i = (int)p1 / SEAT;
|
||||
j = (int)p1 % SEAT;
|
||||
llp1 = move_ >> 8;
|
||||
llp2 = move_ & 0x00ff;
|
||||
i = (int)llp1 / SEAT;
|
||||
j = (int)llp1 % SEAT;
|
||||
j = (j + SEAT - degrees) % SEAT;
|
||||
p1 = i * SEAT + j;
|
||||
i = (int)p2 / SEAT;
|
||||
j = (int)p2 % SEAT;
|
||||
llp1 = i * SEAT + j;
|
||||
i = (int)llp2 / SEAT;
|
||||
j = (int)llp2 % SEAT;
|
||||
j = (j + SEAT - degrees) % SEAT;
|
||||
p2 = i * SEAT + j;
|
||||
move_ = (int16_t)((p1 << 8) | p2);
|
||||
llp2 = i * SEAT + j;
|
||||
move_ = (int16_t)((llp1 << 8) | llp2);
|
||||
}
|
||||
|
||||
if (currentPos != 0) {
|
||||
|
@ -1984,29 +1983,29 @@ void NineChess::rotate(int degrees, bool cmdChange /*= true*/)
|
|||
currentPos = i * SEAT + j;
|
||||
}
|
||||
|
||||
if (rule.canRepeated) {
|
||||
if (currentRule.canRepeated) {
|
||||
for (auto mill = data.millList.begin(); mill != data.millList.end(); mill++) {
|
||||
p1 = (*mill & 0x000000ff00000000) >> 32;
|
||||
p2 = (*mill & 0x0000000000ff0000) >> 16;
|
||||
p3 = (*mill & 0x00000000000000ff);
|
||||
llp1 = (*mill & 0x000000ff00000000) >> 32;
|
||||
llp2 = (*mill & 0x0000000000ff0000) >> 16;
|
||||
llp3 = (*mill & 0x00000000000000ff);
|
||||
|
||||
i = (int)p1 / SEAT;
|
||||
j = (int)p1 % SEAT;
|
||||
i = (int)llp1 / SEAT;
|
||||
j = (int)llp1 % SEAT;
|
||||
j = (j + SEAT - degrees) % SEAT;
|
||||
p1 = i * SEAT + j;
|
||||
llp1 = i * SEAT + j;
|
||||
|
||||
i = (int)p2 / SEAT;
|
||||
j = (int)p2 % SEAT;
|
||||
i = (int)llp2 / SEAT;
|
||||
j = (int)llp2 % SEAT;
|
||||
j = (j + SEAT - degrees) % SEAT;
|
||||
p2 = i * SEAT + j;
|
||||
llp2 = i * SEAT + j;
|
||||
|
||||
i = (int)p3 / SEAT;
|
||||
j = (int)p3 % SEAT;
|
||||
i = (int)llp3 / SEAT;
|
||||
j = (int)llp3 % SEAT;
|
||||
j = (j + SEAT - degrees) % SEAT;
|
||||
p3 = i * SEAT + j;
|
||||
llp3 = i * SEAT + j;
|
||||
|
||||
*mill &= 0xffffff00ff00ff00;
|
||||
*mill |= (p1 << 32) | (p2 << 16) | p3;
|
||||
*mill |= (llp1 << 32) | (llp2 << 16) | llp3;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ public:
|
|||
0x21~0x2c代表后手第1~12子
|
||||
判断棋子是先手的用(board[i] & 0x10)
|
||||
判断棋子是后手的用(board[i] & 0x20) */
|
||||
char board[(NineChess::RING + 2)*NineChess::SEAT];
|
||||
int board[(NineChess::RING + 2)*NineChess::SEAT];
|
||||
|
||||
// 局面阶段标识
|
||||
enum NineChess::Phases phase;
|
||||
|
@ -109,15 +109,15 @@ public:
|
|||
enum NineChess::Actions action;
|
||||
|
||||
// 玩家1剩余未放置子数
|
||||
char player1_InHand;
|
||||
int player1_InHand;
|
||||
// 玩家2剩余未放置子数
|
||||
char player2_InHand;
|
||||
int player2_InHand;
|
||||
// 玩家1盘面剩余子数
|
||||
char player1_Remain;
|
||||
int player1_Remain;
|
||||
// 玩家1盘面剩余子数
|
||||
char player2_Remain;
|
||||
int player2_Remain;
|
||||
// 尚待去除的子数
|
||||
char num_NeedRemove;
|
||||
int num_NeedRemove;
|
||||
|
||||
/* 本打算用如下的结构体来表示“三连”
|
||||
struct Mill {
|
||||
|
@ -142,11 +142,11 @@ private:
|
|||
|
||||
// 招法表,每个位置有最多4种走法:顺时针、逆时针、向内、向外
|
||||
// 这个表跟规则有关,一旦规则改变需要重新修改
|
||||
static char moveTable[(RING + 2)*SEAT][4];
|
||||
static int moveTable[(RING + 2)*SEAT][4];
|
||||
|
||||
// 成三表,表示棋盘上各个位置有成三关系的对应位置表
|
||||
// 这个表跟规则有关,一旦规则改变需要重新修改
|
||||
static char millTable[(RING + 2)*SEAT][3][2];
|
||||
static int millTable[(RING + 2)*SEAT][3][2];
|
||||
|
||||
public:
|
||||
explicit NineChess();
|
||||
|
@ -169,11 +169,11 @@ public:
|
|||
);
|
||||
|
||||
// 获取棋局状态和棋盘数据
|
||||
void getData(struct Rule &rule, int &step, int &flags, const char *&boardsource, int &p1_InHand, int &p2_InHand, int &num_NeedRemove);
|
||||
void getData(struct Rule &rule, int &step, int &flags, int *&boardsource, int &p1_InHand, int &p2_InHand, int &num_NeedRemove);
|
||||
// 获取当前规则
|
||||
const struct Rule *getRule() const { return &rule; }
|
||||
const struct Rule *getRule() const { return ¤tRule; }
|
||||
// 获取棋盘数据
|
||||
const char *getBoard() const { return data.board; }
|
||||
const int *getBoard() const { return data.board; }
|
||||
// 获取棋子位置(c, p)
|
||||
bool getPieceCP(const Players &player, const int &number, int &c, int &p);
|
||||
// 获取当前棋子
|
||||
|
@ -181,7 +181,7 @@ public:
|
|||
// 获取当前棋子位置点
|
||||
int getCurrentPos() const { return currentPos; }
|
||||
// 获取当前步数
|
||||
int getStep() const { return step; }
|
||||
int getStep() const { return currentStep; }
|
||||
// 获取局面阶段标识
|
||||
enum Phases getPhase() const { return data.phase; }
|
||||
// 获取轮流状态标识
|
||||
|
@ -267,7 +267,7 @@ protected:
|
|||
void setTip();
|
||||
|
||||
// 下面几个函数没有算法无关判断和无关操作,节约算法时间
|
||||
bool command(int16_t move);
|
||||
bool command(int move);
|
||||
bool choose(int pos);
|
||||
bool place(int pos);
|
||||
bool capture(int pos);
|
||||
|
@ -276,18 +276,18 @@ protected:
|
|||
|
||||
private:
|
||||
// 当前使用的规则
|
||||
struct Rule rule;
|
||||
struct Rule currentRule;
|
||||
// 棋局数据
|
||||
struct ChessData data;
|
||||
// 棋局数据中的棋盘数据,单独提出来
|
||||
char *board;
|
||||
int *board_;
|
||||
// 选中的棋子在board中的位置
|
||||
char currentPos;
|
||||
int currentPos;
|
||||
// 胜负标识
|
||||
enum Players winner;
|
||||
|
||||
// 当前步数
|
||||
int step;
|
||||
int currentStep;
|
||||
// 游戏起始时间
|
||||
timeb startTimeb;
|
||||
// 当前游戏时间
|
||||
|
@ -304,7 +304,7 @@ private:
|
|||
移子:0x__??,__为移动前的位置,??为移动后的位置
|
||||
去子:0xFF??,??取位置补码,即为负数
|
||||
*/
|
||||
int16_t move_;
|
||||
int32_t move_;
|
||||
|
||||
// 招法命令行用于棋谱的显示和解析
|
||||
// 当前招法的命令行指令,即一招棋谱
|
||||
|
|
|
@ -44,7 +44,7 @@ void NineChessAi_ab::buildChildren(Node *node)
|
|||
// 对于开局落子
|
||||
if ((chessTemp.data.phase) & (NineChess::GAME_OPENING | NineChess::GAME_NOTSTARTED)) {
|
||||
for (int i = NineChess::SEAT; i < (NineChess::RING + 1)*NineChess::SEAT; i++) {
|
||||
if (!chessTemp.board[i]) {
|
||||
if (!chessTemp.board_[i]) {
|
||||
Node * newNode = new Node;
|
||||
newNode->parent = node;
|
||||
newNode->value = 0;
|
||||
|
@ -55,15 +55,15 @@ void NineChessAi_ab::buildChildren(Node *node)
|
|||
}
|
||||
// 对于中局移子
|
||||
else {
|
||||
char newPos;
|
||||
int newPos;
|
||||
for (int i = NineChess::SEAT; i < (NineChess::RING + 1)*NineChess::SEAT; i++) {
|
||||
if (!chessTemp.choose(i))
|
||||
continue;
|
||||
if ((chessTemp.data.turn == NineChess::PLAYER1 && (chessTemp.data.player1_Remain > chessTemp.rule.numAtLest || !chessTemp.rule.canFly)) ||
|
||||
(chessTemp.data.turn == NineChess::PLAYER2 && (chessTemp.data.player2_Remain > chessTemp.rule.numAtLest || !chessTemp.rule.canFly))) {
|
||||
if ((chessTemp.data.turn == NineChess::PLAYER1 && (chessTemp.data.player1_Remain > chessTemp.currentRule.numAtLest || !chessTemp.currentRule.canFly)) ||
|
||||
(chessTemp.data.turn == NineChess::PLAYER2 && (chessTemp.data.player2_Remain > chessTemp.currentRule.numAtLest || !chessTemp.currentRule.canFly))) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
newPos = chessTemp.moveTable[i][j];
|
||||
if (newPos && !chessTemp.board[newPos]) {
|
||||
if (newPos && !chessTemp.board_[newPos]) {
|
||||
Node * newNode = new Node;
|
||||
newNode->parent = node;
|
||||
newNode->value = 0;
|
||||
|
@ -74,7 +74,7 @@ void NineChessAi_ab::buildChildren(Node *node)
|
|||
}
|
||||
else {
|
||||
for (int j = NineChess::SEAT; j < (NineChess::RING + 1)*NineChess::SEAT; j++) {
|
||||
if (!chessTemp.board[j]) {
|
||||
if (!chessTemp.board_[j]) {
|
||||
Node * newNode = new Node;
|
||||
newNode->parent = node;
|
||||
newNode->value = 0;
|
||||
|
@ -91,7 +91,7 @@ void NineChessAi_ab::buildChildren(Node *node)
|
|||
// 全成三的情况
|
||||
if (chessTemp.isAllInMills(opponent)) {
|
||||
for (int i = NineChess::SEAT; i < (NineChess::RING + 1)*NineChess::SEAT; i++) {
|
||||
if (chessTemp.board[i] & opponent) {
|
||||
if (chessTemp.board_[i] & opponent) {
|
||||
Node * newNode = new Node;
|
||||
newNode->parent = node;
|
||||
newNode->value = 0;
|
||||
|
@ -102,7 +102,7 @@ void NineChessAi_ab::buildChildren(Node *node)
|
|||
}
|
||||
else {
|
||||
for (int i = NineChess::SEAT; i < (NineChess::RING + 1)*NineChess::SEAT; i++) {
|
||||
if (chessTemp.board[i] & opponent) {
|
||||
if (chessTemp.board_[i] & opponent) {
|
||||
if (!chessTemp.isInMills(i)) {
|
||||
Node * newNode = new Node;
|
||||
newNode->parent = node;
|
||||
|
@ -150,14 +150,14 @@ void NineChessAi_ab::deleteTree(Node *node)
|
|||
void NineChessAi_ab::setChess(const NineChess &chess)
|
||||
{
|
||||
// 如果规则改变,重建hashmap
|
||||
if (strcmp(this->chess.rule.name, chess.rule.name)) {
|
||||
if (strcmp(this->chess_.currentRule.name, chess.currentRule.name)) {
|
||||
mtx.lock();
|
||||
hashmap.clear();
|
||||
hashmap.reserve(maxHashCount);
|
||||
mtx.unlock();
|
||||
}
|
||||
|
||||
this->chess = chess;
|
||||
this->chess_ = chess;
|
||||
chessTemp = chess;
|
||||
chessData = &(chessTemp.data);
|
||||
requiredQuit = false;
|
||||
|
@ -217,9 +217,9 @@ int NineChessAi_ab::evaluate(Node *node)
|
|||
|
||||
// 终局评价最简单
|
||||
case NineChess::GAME_OVER:
|
||||
if (chessData->player1_Remain < chessTemp.rule.numAtLest)
|
||||
if (chessData->player1_Remain < chessTemp.currentRule.numAtLest)
|
||||
value = -15000;
|
||||
else if (chessData->player2_Remain < chessTemp.rule.numAtLest)
|
||||
else if (chessData->player2_Remain < chessTemp.currentRule.numAtLest)
|
||||
value = 15000;
|
||||
break;
|
||||
|
||||
|
@ -371,7 +371,7 @@ const char *NineChessAi_ab::bestMove()
|
|||
return "error!";
|
||||
}
|
||||
|
||||
const char *NineChessAi_ab::move2string(int16_t move)
|
||||
const char *NineChessAi_ab::move2string(int move)
|
||||
{
|
||||
int c, p;
|
||||
if (move < 0) {
|
||||
|
|
|
@ -31,8 +31,8 @@ public:
|
|||
|
||||
// 定义一个节点结构体
|
||||
struct Node {
|
||||
int16_t value; // 节点的值
|
||||
int16_t move; // 招法的命令行指令,图上标示为节点前的连线
|
||||
int value; // 节点的值
|
||||
int move; // 招法的命令行指令,图上标示为节点前的连线
|
||||
struct Node * parent; // 父节点
|
||||
list<struct Node *> children; // 子节点列表
|
||||
};
|
||||
|
@ -60,13 +60,13 @@ protected:
|
|||
// Alpha-Beta剪枝算法
|
||||
int alphaBetaPruning(int depth, int alpha, int beta, Node *node);
|
||||
// 返回招法的命令行
|
||||
const char *move2string(int16_t move);
|
||||
const char *move2string(int move);
|
||||
// 判断是否在哈希表中
|
||||
unordered_map<uint64_t, NineChessAi_ab::HashValue>::iterator findHash(uint64_t hash);
|
||||
|
||||
private:
|
||||
// 原始模型
|
||||
NineChess chess;
|
||||
NineChess chess_;
|
||||
// 演算用的模型
|
||||
NineChess chessTemp;
|
||||
NineChess::ChessData *chessData;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QHelpEvent>
|
||||
#include <QToolTip>
|
||||
#include <QPicture>
|
||||
#include <QScreen>
|
||||
#include <QDebug>
|
||||
#include <QDesktopWidget>
|
||||
#include "ninechesswindow.h"
|
||||
|
@ -69,7 +70,7 @@ NineChessWindow::NineChessWindow(QWidget *parent)
|
|||
this, SLOT(onAutoRunTimeOut()));
|
||||
|
||||
// 主窗口居中显示
|
||||
QRect deskTopRect = qApp->desktop()->availableGeometry();
|
||||
QRect deskTopRect = QGuiApplication::primaryScreen()->geometry();
|
||||
int unitw = (deskTopRect.width() - width())/2;
|
||||
int unith = (deskTopRect.height() - height())/2;
|
||||
this->move(unitw,unith);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
PieceItem::PieceItem(QGraphicsItem *parent) : QGraphicsItem(parent),
|
||||
num(0),
|
||||
deleted(false),
|
||||
deleted_(false),
|
||||
showNum(false)
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
|
@ -24,7 +24,7 @@ showNum(false)
|
|||
setAcceptedMouseButtons(0);
|
||||
//setAcceptHoverEvents(true);
|
||||
// 默认模型为没有棋子
|
||||
model = noPiece;
|
||||
model_ = noPiece;
|
||||
// 棋子尺寸
|
||||
size = PIECE_SIZE;
|
||||
// 选中子标识线宽度
|
||||
|
@ -62,11 +62,11 @@ void PieceItem::paint(QPainter *painter,
|
|||
|
||||
// 空模型不画棋子
|
||||
// 如果模型为黑色,则画黑色棋子
|
||||
if (model == blackPiece)
|
||||
if (model_ == blackPiece)
|
||||
painter->drawPixmap(-size/2, -size/2, size, size,
|
||||
QPixmap(":/image/resources/image/black_piece.png"));
|
||||
// 如果模型为白色,则画白色棋子
|
||||
else if (model == whitePiece)
|
||||
else if (model_ == whitePiece)
|
||||
painter->drawPixmap(-size/2, -size/2, size, size,
|
||||
QPixmap(":/image/resources/image/white_piece.png"));
|
||||
|
||||
|
@ -76,7 +76,7 @@ void PieceItem::paint(QPainter *painter,
|
|||
// 如果模型为黑色,用白色笔画序号
|
||||
painter->setPen(QColor(255, 255, 255));
|
||||
// 如果模型为白色,用白色笔画序号
|
||||
if (model == whitePiece)
|
||||
if (model_ == whitePiece)
|
||||
painter->setPen(QColor(0, 0, 0));
|
||||
// 字体
|
||||
QFont font;
|
||||
|
@ -105,7 +105,7 @@ void PieceItem::paint(QPainter *painter,
|
|||
}
|
||||
|
||||
// 如果模型为删除状态,则画上叉号
|
||||
if (deleted)
|
||||
if (deleted_)
|
||||
{
|
||||
QPen pen(removeLineColor, removeLineWeight, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
|
||||
painter->setPen(pen);
|
||||
|
|
|
@ -30,16 +30,16 @@ public:
|
|||
whitePiece = 0x4, // 白色棋子
|
||||
};
|
||||
|
||||
enum Models getModel() { return model; }
|
||||
void setModel(enum Models model) { this->model = model; }
|
||||
enum Models getModel() { return model_; }
|
||||
void setModel(enum Models model) { this->model_ = model; }
|
||||
int getNum() { return num; }
|
||||
void setNum(int n) { num = n; }
|
||||
bool isDeleted() { return deleted; }
|
||||
bool isDeleted() { return deleted_; }
|
||||
void setDeleted(bool deleted = true)
|
||||
{
|
||||
this->deleted = deleted;
|
||||
this->deleted_ = deleted;
|
||||
if (deleted)
|
||||
this->model = noPiece;
|
||||
this->model_ = noPiece;
|
||||
update(boundingRect());
|
||||
}
|
||||
void setShowNum(bool show = true) { this->showNum = show; }
|
||||
|
@ -51,13 +51,13 @@ protected:
|
|||
|
||||
private:
|
||||
// 棋子本质
|
||||
enum Models model;
|
||||
enum Models model_;
|
||||
// 棋子序号,黑白都从1开始
|
||||
int num;
|
||||
// 棋子尺寸
|
||||
qreal size;
|
||||
// 有无删除线
|
||||
bool deleted;
|
||||
bool deleted_;
|
||||
// 显示序号
|
||||
bool showNum;
|
||||
// 选中子标识线宽度
|
||||
|
|
Loading…
Reference in New Issue