parent
4b0569ea65
commit
d6574b0fcb
|
@ -284,7 +284,7 @@ void AIAlgorithm::deleteTree(Node *node)
|
|||
#endif
|
||||
}
|
||||
|
||||
void AIAlgorithm::setGame(const Game &game)
|
||||
void AIAlgorithm::setGame(const Game &g)
|
||||
{
|
||||
// 如果规则改变,重建hashmap
|
||||
if (strcmp(rule.name, rule.name) != 0) {
|
||||
|
@ -301,8 +301,8 @@ void AIAlgorithm::setGame(const Game &game)
|
|||
history.clear();
|
||||
}
|
||||
|
||||
this->game_ = game;
|
||||
tempGame = game;
|
||||
this->game = g;
|
||||
tempGame = g;
|
||||
position = &(tempGame.position);
|
||||
requiredQuit = false;
|
||||
deleteTree(root);
|
||||
|
@ -339,8 +339,8 @@ int AIAlgorithm::search(depth_t depth)
|
|||
#ifdef THREEFOLD_REPETITION
|
||||
static int nRepetition = 0;
|
||||
|
||||
if (game_.getPhase() == PHASE_MOVING) {
|
||||
hash_t hash = game_.getHash();
|
||||
if (game.getPhase() == PHASE_MOVING) {
|
||||
hash_t hash = game.getHash();
|
||||
|
||||
if (std::find(history.begin(), history.end(), hash) != history.end()) {
|
||||
nRepetition++;
|
||||
|
@ -353,7 +353,7 @@ int AIAlgorithm::search(depth_t depth)
|
|||
}
|
||||
}
|
||||
|
||||
if (game_.getPhase() == PHASE_PLACING) {
|
||||
if (game.getPhase() == PHASE_PLACING) {
|
||||
history.clear();
|
||||
}
|
||||
#endif // THREEFOLD_REPETITION
|
||||
|
@ -690,7 +690,7 @@ const char* AIAlgorithm::bestMove()
|
|||
i++;
|
||||
}
|
||||
|
||||
player_t side = game_.position.sideToMove;
|
||||
player_t side = game.position.sideToMove;
|
||||
|
||||
#ifdef ENDGAME_LEARNING
|
||||
// 检查是否明显劣势
|
||||
|
@ -707,9 +707,9 @@ const char* AIAlgorithm::bestMove()
|
|||
|
||||
if (isMostWeak) {
|
||||
Endgame endgame;
|
||||
endgame.type = game_.position.sideToMove == PLAYER_1 ?
|
||||
endgame.type = game.position.sideToMove == PLAYER_1 ?
|
||||
ENDGAME_PLAYER_2_WIN : ENDGAME_PLAYER_1_WIN;
|
||||
hash_t endgameHash = this->game_.getHash(); // TODO: 减少重复计算哈希
|
||||
hash_t endgameHash = this->game.getHash(); // TODO: 减少重复计算哈希
|
||||
recordEndgameHash(endgameHash, endgame);
|
||||
loggerDebug("Record 0x%08I32x to Endgame Hashmap\n", endgameHash);
|
||||
}
|
||||
|
@ -730,7 +730,7 @@ const char* AIAlgorithm::bestMove()
|
|||
|
||||
// 自动认输
|
||||
if (isMostLose) {
|
||||
sprintf(cmdline, "Player%d give up!", game_.position.sideId);
|
||||
sprintf(cmdline, "Player%d give up!", game.position.sideId);
|
||||
return cmdline;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ protected:
|
|||
|
||||
private:
|
||||
// 原始模型
|
||||
Game game_;
|
||||
Game game;
|
||||
|
||||
// 演算用的模型
|
||||
Game tempGame;
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
|
||||
AiThread::AiThread(int id, QObject *parent) :
|
||||
QThread(parent),
|
||||
waiting_(false),
|
||||
game_(nullptr),
|
||||
waiting(false),
|
||||
game(nullptr),
|
||||
depth(2),
|
||||
timeLimit(3600)
|
||||
{
|
||||
|
@ -61,12 +61,12 @@ AiThread::~AiThread()
|
|||
wait();
|
||||
}
|
||||
|
||||
void AiThread::setAi(const Game &game)
|
||||
void AiThread::setAi(const Game &g)
|
||||
{
|
||||
mutex.lock();
|
||||
|
||||
this->game_ = &game;
|
||||
ai.setGame(*(this->game_));
|
||||
this->game = &g;
|
||||
ai.setGame(*(this->game));
|
||||
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
// 新下一盘前清除哈希表 (注意可能同时存在每步之前清除)
|
||||
|
@ -78,11 +78,11 @@ void AiThread::setAi(const Game &game)
|
|||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AiThread::setAi(const Game &game, depth_t d, int tl)
|
||||
void AiThread::setAi(const Game &g, depth_t d, int tl)
|
||||
{
|
||||
mutex.lock();
|
||||
this->game_ = &game;
|
||||
ai.setGame(game);
|
||||
this->game = &g;
|
||||
ai.setGame(g);
|
||||
depth = d;
|
||||
timeLimit = tl;
|
||||
mutex.unlock();
|
||||
|
@ -108,15 +108,15 @@ void AiThread::run()
|
|||
while (!isInterruptionRequested()) {
|
||||
mutex.lock();
|
||||
|
||||
i = Player::toId(game_->position.sideToMove);
|
||||
i = Player::toId(game->position.sideToMove);
|
||||
|
||||
if (i != id || waiting_) {
|
||||
if (i != id || waiting) {
|
||||
pauseCondition.wait(&mutex);
|
||||
mutex.unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
ai.setGame(*game_);
|
||||
ai.setGame(*game);
|
||||
emit calcStarted();
|
||||
mutex.unlock();
|
||||
|
||||
|
@ -152,7 +152,7 @@ void AiThread::act()
|
|||
return;
|
||||
|
||||
mutex.lock();
|
||||
waiting_ = false;
|
||||
waiting = false;
|
||||
ai.quit();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
@ -160,14 +160,14 @@ void AiThread::act()
|
|||
void AiThread::pause()
|
||||
{
|
||||
mutex.lock();
|
||||
waiting_ = true;
|
||||
waiting = true;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AiThread::resume()
|
||||
{
|
||||
mutex.lock();
|
||||
waiting_ = false;
|
||||
waiting = false;
|
||||
pauseCondition.wakeAll();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ void AiThread::stop()
|
|||
if (!isInterruptionRequested()) {
|
||||
requestInterruption();
|
||||
mutex.lock();
|
||||
waiting_ = false;
|
||||
waiting = false;
|
||||
ai.quit();
|
||||
pauseCondition.wakeAll();
|
||||
mutex.unlock();
|
||||
|
|
|
@ -108,13 +108,13 @@ private:
|
|||
QMutex mutex;
|
||||
|
||||
// 线程等待标识,这里没用到,留着以后扩展用
|
||||
bool waiting_;
|
||||
bool waiting;
|
||||
|
||||
// 等待条件,这里没用到,留着以后扩展用
|
||||
QWaitCondition pauseCondition;
|
||||
|
||||
// 主线程棋对象的引用
|
||||
const Game *game_;
|
||||
const Game *game;
|
||||
|
||||
// AI 算法类
|
||||
AIAlgorithm ai;
|
||||
|
|
|
@ -71,7 +71,7 @@ Game &Game::operator= (const Game &game)
|
|||
currentTime = game.currentTime;
|
||||
elapsedSeconds[1] = game.elapsedSeconds[1];
|
||||
elapsedSeconds[2] = game.elapsedSeconds[2];
|
||||
move_ = game.move_;
|
||||
move = game.move;
|
||||
memcpy(cmdline, game.cmdline, sizeof(cmdline));
|
||||
cmdlist = game.cmdlist;
|
||||
tips = game.tips;
|
||||
|
@ -320,7 +320,7 @@ bool Game::place(int location, int8_t updateCmdlist)
|
|||
|
||||
updateHash(location);
|
||||
|
||||
move_ = static_cast<move_t>(location);
|
||||
move = static_cast<move_t>(location);
|
||||
|
||||
if (updateCmdlist) {
|
||||
seconds = update();
|
||||
|
@ -400,7 +400,7 @@ bool Game::place(int location, int8_t updateCmdlist)
|
|||
}
|
||||
|
||||
// 移子
|
||||
move_ = static_cast<move_t>((currentLocation << 8) + location);
|
||||
move = static_cast<move_t>((currentLocation << 8) + location);
|
||||
|
||||
if (updateCmdlist) {
|
||||
seconds = update();
|
||||
|
@ -515,7 +515,7 @@ bool Game::capture(int location, int8_t updateCmdlist)
|
|||
|
||||
position.nPiecesOnBoard[position.opponentId]--;
|
||||
|
||||
move_ = static_cast<move_t>(-location);
|
||||
move = static_cast<move_t>(-location);
|
||||
|
||||
if (updateCmdlist) {
|
||||
seconds = update();
|
||||
|
@ -744,18 +744,18 @@ bool Game::command(const char *cmd)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Game::command(int move)
|
||||
bool Game::command(int m)
|
||||
{
|
||||
if (move < 0) {
|
||||
return capture(-move);
|
||||
if (m < 0) {
|
||||
return capture(-m);
|
||||
}
|
||||
|
||||
if (move & 0x1f00) {
|
||||
if (choose(move >> 8)) {
|
||||
return place(move & 0x00ff);
|
||||
if (m & 0x1f00) {
|
||||
if (choose(m >> 8)) {
|
||||
return place(m & 0x00ff);
|
||||
}
|
||||
} else {
|
||||
return place(move & 0x00ff);
|
||||
return place(m & 0x00ff);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -288,7 +288,7 @@ public: /* TODO: move to private */
|
|||
| / | \ |
|
||||
29 ----- 28 ----- 27
|
||||
*/
|
||||
move_t move_{};
|
||||
move_t move{};
|
||||
|
||||
// 选中的棋子在board中的位置
|
||||
int currentLocation{};
|
||||
|
|
|
@ -50,13 +50,13 @@ private slots:
|
|||
void displayError(QAbstractSocket::SocketError socketError);
|
||||
void enableGetActionButton();
|
||||
void sessionOpened();
|
||||
void setPort(uint16_t port)
|
||||
void setPort(uint16_t p)
|
||||
{
|
||||
this->port_ = port;
|
||||
this->port = p;
|
||||
}
|
||||
uint16_t getPort()
|
||||
{
|
||||
return port_;
|
||||
return port;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -71,7 +71,7 @@ private:
|
|||
|
||||
QNetworkSession *networkSession = nullptr;
|
||||
|
||||
uint16_t port_ {};
|
||||
uint16_t port {};
|
||||
};
|
||||
|
||||
#endif // CLIENT_H
|
||||
|
|
|
@ -47,7 +47,7 @@ GameController::GameController(GameScene & scene, QObject * parent) :
|
|||
durationTime(500),
|
||||
hasSound(true),
|
||||
timeID(0),
|
||||
ruleNo_(-1),
|
||||
ruleIndex(-1),
|
||||
timeLimit(0),
|
||||
stepsLimit(50)
|
||||
{
|
||||
|
@ -122,8 +122,8 @@ const QMap<int, QStringList> GameController::getActions()
|
|||
|
||||
void GameController::gameStart()
|
||||
{
|
||||
game_.start();
|
||||
tempGame = game_;
|
||||
game.start();
|
||||
tempGame = game;
|
||||
|
||||
// 每隔100毫秒调用一次定时器处理函数
|
||||
if (timeID == 0) {
|
||||
|
@ -141,14 +141,14 @@ void GameController::gameReset()
|
|||
timeID = 0;
|
||||
|
||||
// 棋未下完,则算对手得分
|
||||
if (game_.getPhase() == PHASE_MOVING &&
|
||||
game_.whoWin() == PLAYER_NOBODY) {
|
||||
if (game.getPhase() == PHASE_MOVING &&
|
||||
game.whoWin() == PLAYER_NOBODY) {
|
||||
giveUp();
|
||||
}
|
||||
|
||||
// 重置游戏
|
||||
game_.reset();
|
||||
tempGame = game_;
|
||||
game.reset();
|
||||
tempGame = game;
|
||||
|
||||
// 停掉线程
|
||||
if (!options.getAutoRestart()) {
|
||||
|
@ -218,7 +218,7 @@ void GameController::gameReset()
|
|||
// 更新棋谱
|
||||
manualListModel.removeRows(0, manualListModel.rowCount());
|
||||
manualListModel.insertRow(0);
|
||||
manualListModel.setData(manualListModel.index(0), game_.getCmdLine());
|
||||
manualListModel.setData(manualListModel.index(0), game.getCmdLine());
|
||||
currentRow = 0;
|
||||
|
||||
// 发出信号通知主窗口更新LCD显示
|
||||
|
@ -227,13 +227,13 @@ void GameController::gameReset()
|
|||
emit time2Changed(qtime.toString("hh:mm:ss"));
|
||||
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(game_.getTips());
|
||||
message = QString::fromStdString(game.getTips());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 更新比分 LCD 显示
|
||||
emit score1Changed(QString::number(game_.score[1], 10));
|
||||
emit score2Changed(QString::number(game_.score[2], 10));
|
||||
emit scoreDrawChanged(QString::number(game_.score_draw, 10));
|
||||
emit score1Changed(QString::number(game.score[1], 10));
|
||||
emit score2Changed(QString::number(game.score[2], 10));
|
||||
emit scoreDrawChanged(QString::number(game.score_draw, 10));
|
||||
|
||||
// 播放音效
|
||||
//playSound(":/sound/resources/sound/newgame.wav");
|
||||
|
@ -270,7 +270,7 @@ void GameController::setRule(int ruleNo, step_t stepLimited /*= -1*/, int timeLi
|
|||
// 更新规则,原限时和限步不变
|
||||
if (ruleNo < 0 || ruleNo >= N_RULES)
|
||||
return;
|
||||
this->ruleNo_ = ruleNo;
|
||||
this->ruleIndex = ruleNo;
|
||||
|
||||
if (stepLimited != UINT16_MAX && timeLimited != -1) {
|
||||
stepsLimit = stepLimited;
|
||||
|
@ -278,8 +278,8 @@ void GameController::setRule(int ruleNo, step_t stepLimited /*= -1*/, int timeLi
|
|||
}
|
||||
|
||||
// 设置模型规则,重置游戏
|
||||
game_.setPosition(&RULES[ruleNo], stepsLimit, timeLimit);
|
||||
tempGame = game_;
|
||||
game.setPosition(&RULES[ruleNo], stepsLimit, timeLimit);
|
||||
tempGame = game;
|
||||
|
||||
// 重置游戏
|
||||
gameReset();
|
||||
|
@ -290,7 +290,7 @@ void GameController::setEngine(int id, bool arg)
|
|||
isAiPlayer[id] = arg;
|
||||
|
||||
if (arg) {
|
||||
ai[id]->setAi(game_);
|
||||
ai[id]->setAi(game);
|
||||
if (ai[id]->isRunning())
|
||||
ai[id]->resume();
|
||||
else
|
||||
|
@ -321,8 +321,8 @@ void GameController::setAiDepthTime(depth_t depth1, int time1, depth_t depth2, i
|
|||
ai[2]->wait();
|
||||
}
|
||||
|
||||
ai[1]->setAi(game_, depth1, time1);
|
||||
ai[2]->setAi(game_, depth2, time2);
|
||||
ai[1]->setAi(game, depth1, time1);
|
||||
ai[2]->setAi(game, depth2, time2);
|
||||
|
||||
if (isAiPlayer[1]) {
|
||||
ai[1]->start();
|
||||
|
@ -402,13 +402,13 @@ void GameController::flip()
|
|||
ai[2]->wait();
|
||||
}
|
||||
|
||||
game_.position.board.mirror(game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation);
|
||||
game_.position.board.rotate(180, game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation);
|
||||
tempGame = game_;
|
||||
game.position.board.mirror(game.cmdlist, game.cmdline, game.move, game.currentLocation);
|
||||
game.position.board.rotate(180, game.cmdlist, game.cmdline, game.move, game.currentLocation);
|
||||
tempGame = game;
|
||||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
for (const auto &str : *(game_.getCmdList())) {
|
||||
for (const auto &str : *(game.getCmdList())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
|
||||
|
@ -418,8 +418,8 @@ void GameController::flip()
|
|||
else
|
||||
phaseChange(currentRow, true);
|
||||
|
||||
ai[1]->setAi(game_);
|
||||
ai[2]->setAi(game_);
|
||||
ai[1]->setAi(game);
|
||||
ai[2]->setAi(game);
|
||||
|
||||
if (isAiPlayer[1]) {
|
||||
ai[1]->start();
|
||||
|
@ -442,13 +442,13 @@ void GameController::mirror()
|
|||
ai[2]->wait();
|
||||
}
|
||||
|
||||
game_.position.board.mirror(game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation);
|
||||
tempGame = game_;
|
||||
game.position.board.mirror(game.cmdlist, game.cmdline, game.move, game.currentLocation);
|
||||
tempGame = game;
|
||||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
|
||||
for (const auto &str : *(game_.getCmdList())) {
|
||||
for (const auto &str : *(game.getCmdList())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
|
||||
|
@ -460,8 +460,8 @@ void GameController::mirror()
|
|||
else
|
||||
phaseChange(currentRow, true);
|
||||
|
||||
ai[1]->setAi(game_);
|
||||
ai[2]->setAi(game_);
|
||||
ai[1]->setAi(game);
|
||||
ai[2]->setAi(game);
|
||||
|
||||
if (isAiPlayer[1]) {
|
||||
ai[1]->start();
|
||||
|
@ -484,13 +484,13 @@ void GameController::turnRight()
|
|||
ai[2]->wait();
|
||||
}
|
||||
|
||||
game_.position.board.rotate(-90, game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation);
|
||||
tempGame = game_;
|
||||
game.position.board.rotate(-90, game.cmdlist, game.cmdline, game.move, game.currentLocation);
|
||||
tempGame = game;
|
||||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
|
||||
for (const auto &str : *(game_.getCmdList())) {
|
||||
for (const auto &str : *(game.getCmdList())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
|
||||
|
@ -500,8 +500,8 @@ void GameController::turnRight()
|
|||
else
|
||||
phaseChange(currentRow, true);
|
||||
|
||||
ai[1]->setAi(game_);
|
||||
ai[2]->setAi(game_);
|
||||
ai[1]->setAi(game);
|
||||
ai[2]->setAi(game);
|
||||
|
||||
if (isAiPlayer[1]) {
|
||||
ai[1]->start();
|
||||
|
@ -524,20 +524,20 @@ void GameController::turnLeft()
|
|||
ai[2]->wait();
|
||||
}
|
||||
|
||||
game_.position.board.rotate(90, game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation);
|
||||
tempGame = game_;
|
||||
game.position.board.rotate(90, game.cmdlist, game.cmdline, game.move, game.currentLocation);
|
||||
tempGame = game;
|
||||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
for (const auto &str : *(game_.getCmdList())) {
|
||||
for (const auto &str : *(game.getCmdList())) {
|
||||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
|
||||
// 刷新显示
|
||||
updateScence();
|
||||
|
||||
ai[1]->setAi(game_);
|
||||
ai[2]->setAi(game_);
|
||||
ai[1]->setAi(game);
|
||||
ai[2]->setAi(game);
|
||||
if (isAiPlayer[1]) {
|
||||
ai[1]->start();
|
||||
}
|
||||
|
@ -552,9 +552,9 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
static QTime qt1, qt2;
|
||||
|
||||
// 玩家的已用时间
|
||||
game_.update();
|
||||
remainingTime[1] = game_.getElapsedTime(1);
|
||||
remainingTime[2] = game_.getElapsedTime(2);
|
||||
game.update();
|
||||
remainingTime[1] = game.getElapsedTime(1);
|
||||
remainingTime[2] = game.getElapsedTime(2);
|
||||
|
||||
// 如果规则要求计时,则time1和time2表示倒计时
|
||||
if (timeLimit > 0) {
|
||||
|
@ -570,7 +570,7 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
emit time2Changed(qt2.toString("hh:mm:ss"));
|
||||
|
||||
// 如果胜负已分
|
||||
if (game_.whoWin() != PLAYER_NOBODY) {
|
||||
if (game.whoWin() != PLAYER_NOBODY) {
|
||||
// 停止计时
|
||||
killTimer(timeID);
|
||||
|
||||
|
@ -578,7 +578,7 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
timeID = 0;
|
||||
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(game_.getTips());
|
||||
message = QString::fromStdString(game.getTips());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 弹框
|
||||
|
@ -615,7 +615,7 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
|
||||
bool GameController::isAIsTurn()
|
||||
{
|
||||
return isAiPlayer[game_.position.sideId];
|
||||
return isAiPlayer[game.position.sideId];
|
||||
}
|
||||
|
||||
// 关键槽函数,根据QGraphicsScene的信号和状态来执行选子、落子或去子
|
||||
|
@ -648,17 +648,17 @@ bool GameController::actionPiece(QPointF pos)
|
|||
|
||||
if (QMessageBox::Ok == msgBox.exec()) {
|
||||
#endif /* !MOBILE_APP_UI */
|
||||
game_ = tempGame;
|
||||
game = tempGame;
|
||||
manualListModel.removeRows(currentRow + 1, manualListModel.rowCount() - currentRow - 1);
|
||||
|
||||
// 如果再决出胜负后悔棋,则重新启动计时
|
||||
if (game_.whoWin() == PLAYER_NOBODY) {
|
||||
if (game.whoWin() == PLAYER_NOBODY) {
|
||||
|
||||
// 重新启动计时
|
||||
timeID = startTimer(100);
|
||||
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(game_.getTips());
|
||||
message = QString::fromStdString(game.getTips());
|
||||
emit statusBarChanged(message);
|
||||
#ifndef MOBILE_APP_UI
|
||||
}
|
||||
|
@ -669,7 +669,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
}
|
||||
|
||||
// 如果未开局则开局
|
||||
if (game_.getPhase() == PHASE_NOTSTARTED)
|
||||
if (game.getPhase() == PHASE_NOTSTARTED)
|
||||
gameStart();
|
||||
|
||||
// 判断执行选子、落子或去子
|
||||
|
@ -677,10 +677,10 @@ bool GameController::actionPiece(QPointF pos)
|
|||
PieceItem *piece = nullptr;
|
||||
QGraphicsItem *item = scene.itemAt(pos, QTransform());
|
||||
|
||||
switch (game_.getAction()) {
|
||||
switch (game.getAction()) {
|
||||
case ACTION_PLACE:
|
||||
if (game_._place(r, s)) {
|
||||
if (game_.getAction() == ACTION_CAPTURE) {
|
||||
if (game._place(r, s)) {
|
||||
if (game.getAction() == ACTION_CAPTURE) {
|
||||
// 播放成三音效
|
||||
playSound(":/sound/resources/sound/capture.wav");
|
||||
} else {
|
||||
|
@ -698,7 +698,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
piece = qgraphicsitem_cast<PieceItem *>(item);
|
||||
if (!piece)
|
||||
break;
|
||||
if (game_.choose(r, s)) {
|
||||
if (game.choose(r, s)) {
|
||||
// 播放选子音效
|
||||
playSound(":/sound/resources/sound/choose.wav");
|
||||
result = true;
|
||||
|
@ -709,7 +709,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
break;
|
||||
|
||||
case ACTION_CAPTURE:
|
||||
if (game_._capture(r, s)) {
|
||||
if (game._capture(r, s)) {
|
||||
// 播放音效
|
||||
playSound(":/sound/resources/sound/remove.wav");
|
||||
result = true;
|
||||
|
@ -726,7 +726,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
|
||||
if (result) {
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(game_.getTips());
|
||||
message = QString::fromStdString(game.getTips());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 将新增的棋谱行插入到ListModel
|
||||
|
@ -734,7 +734,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
int k = 0;
|
||||
|
||||
// 输出命令行
|
||||
for (const auto & i : *(game_.getCmdList())) {
|
||||
for (const auto & i : *(game.getCmdList())) {
|
||||
// 跳过已添加的,因标准list容器没有下标
|
||||
if (k++ <= currentRow)
|
||||
continue;
|
||||
|
@ -744,16 +744,16 @@ bool GameController::actionPiece(QPointF pos)
|
|||
|
||||
// 播放胜利或失败音效
|
||||
#ifndef DONOT_PLAY_WIN_SOUND
|
||||
if (game_.whoWin() != PLAYER_NOBODY &&
|
||||
if (game.whoWin() != PLAYER_NOBODY &&
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over."))
|
||||
playSound(":/sound/resources/sound/win.wav");
|
||||
#endif
|
||||
|
||||
// AI设置
|
||||
if (&game_ == &(this->game_)) {
|
||||
if (&game == &(this->game)) {
|
||||
// 如果还未决出胜负
|
||||
if (game_.whoWin() == PLAYER_NOBODY) {
|
||||
if (game_.position.sideToMove == PLAYER_1) {
|
||||
if (game.whoWin() == PLAYER_NOBODY) {
|
||||
if (game.position.sideToMove == PLAYER_1) {
|
||||
if (isAiPlayer[1]) {
|
||||
ai[1]->resume();
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
ai[2]->stop();
|
||||
|
||||
// 弹框
|
||||
//message = QString::fromStdString(game_.getTips());
|
||||
//message = QString::fromStdString(game.getTips());
|
||||
//QMessageBox::about(NULL, "游戏结果", message);
|
||||
}
|
||||
}
|
||||
|
@ -785,7 +785,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
|
||||
bool GameController::giveUp()
|
||||
{
|
||||
bool result = game_.giveup(game_.position.sideToMove);
|
||||
bool result = game.giveup(game.position.sideToMove);
|
||||
|
||||
if (!result) {
|
||||
return false;
|
||||
|
@ -796,7 +796,7 @@ bool GameController::giveUp()
|
|||
int k = 0;
|
||||
|
||||
// 输出命令行
|
||||
for (const auto & i : *(game_.getCmdList())) {
|
||||
for (const auto & i : *(game.getCmdList())) {
|
||||
// 跳过已添加的,因标准list容器没有下标
|
||||
if (k++ <= currentRow)
|
||||
continue;
|
||||
|
@ -804,7 +804,7 @@ bool GameController::giveUp()
|
|||
manualListModel.setData(manualListModel.index(currentRow), i.c_str());
|
||||
}
|
||||
|
||||
if (game_.whoWin() != PLAYER_NOBODY)
|
||||
if (game.whoWin() != PLAYER_NOBODY)
|
||||
playSound(":/sound/resources/sound/loss.wav");
|
||||
|
||||
return result;
|
||||
|
@ -825,7 +825,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
// 声音
|
||||
QString sound;
|
||||
|
||||
switch (game_.getAction()) {
|
||||
switch (game.getAction()) {
|
||||
case ACTION_CHOOSE:
|
||||
case ACTION_PLACE:
|
||||
sound = ":/sound/resources/sound/drog.wav";
|
||||
|
@ -838,44 +838,44 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
}
|
||||
|
||||
// 如果未开局则开局
|
||||
if (game_.getPhase() == PHASE_NOTSTARTED) {
|
||||
if (game.getPhase() == PHASE_NOTSTARTED) {
|
||||
gameStart();
|
||||
}
|
||||
|
||||
if (!game_.command(cmd.toStdString().c_str()))
|
||||
if (!game.command(cmd.toStdString().c_str()))
|
||||
return false;
|
||||
|
||||
if (sound == ":/sound/resources/sound/drog.wav" && game_.getAction() == ACTION_CAPTURE) {
|
||||
if (sound == ":/sound/resources/sound/drog.wav" && game.getAction() == ACTION_CAPTURE) {
|
||||
sound = ":/sound/resources/sound/capture.wav";
|
||||
}
|
||||
|
||||
if (update) {
|
||||
playSound(sound);
|
||||
updateScence(game_);
|
||||
updateScence(game);
|
||||
}
|
||||
|
||||
// 发信号更新状态栏
|
||||
message = QString::fromStdString(game_.getTips());
|
||||
message = QString::fromStdString(game.getTips());
|
||||
emit statusBarChanged(message);
|
||||
|
||||
// 对于新开局
|
||||
if (game_.getCmdList()->size() <= 1) {
|
||||
if (game.getCmdList()->size() <= 1) {
|
||||
manualListModel.removeRows(0, manualListModel.rowCount());
|
||||
manualListModel.insertRow(0);
|
||||
manualListModel.setData(manualListModel.index(0), game_.getCmdLine());
|
||||
manualListModel.setData(manualListModel.index(0), game.getCmdLine());
|
||||
currentRow = 0;
|
||||
}
|
||||
// 对于当前局
|
||||
else {
|
||||
currentRow = manualListModel.rowCount() - 1;
|
||||
// 跳过已添加行,迭代器不支持+运算符,只能一个个++
|
||||
auto i = (game_.getCmdList()->begin());
|
||||
for (int r = 0; i != (game_.getCmdList())->end(); i++) {
|
||||
auto i = (game.getCmdList()->begin());
|
||||
for (int r = 0; i != (game.getCmdList())->end(); i++) {
|
||||
if (r++ > currentRow)
|
||||
break;
|
||||
}
|
||||
// 将新增的棋谱行插入到ListModel
|
||||
while (i != game_.getCmdList()->end()) {
|
||||
while (i != game.getCmdList()->end()) {
|
||||
manualListModel.insertRow(++currentRow);
|
||||
manualListModel.setData(manualListModel.index(currentRow), (*i++).c_str());
|
||||
}
|
||||
|
@ -883,17 +883,17 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
|
||||
// 播放胜利或失败音效
|
||||
#ifndef DONOT_PLAY_WIN_SOUND
|
||||
if (game_.whoWin() != PLAYER_NOBODY &&
|
||||
if (game.whoWin() != PLAYER_NOBODY &&
|
||||
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) {
|
||||
playSound(":/sound/resources/sound/win.wav");
|
||||
}
|
||||
#endif
|
||||
|
||||
// AI设置
|
||||
if (&game_ == &(this->game_)) {
|
||||
if (&game == &(this->game)) {
|
||||
// 如果还未决出胜负
|
||||
if (game_.whoWin() == PLAYER_NOBODY) {
|
||||
if (game_.position.sideToMove == PLAYER_1) {
|
||||
if (game.whoWin() == PLAYER_NOBODY) {
|
||||
if (game.position.sideToMove == PLAYER_1) {
|
||||
if (isAiPlayer[1]) {
|
||||
ai[1]->resume();
|
||||
}
|
||||
|
@ -926,7 +926,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
|
||||
#ifdef MESSAGEBOX_ENABLE
|
||||
// 弹框
|
||||
message = QString::fromStdString(game_.getTips());
|
||||
message = QString::fromStdString(game.getTips());
|
||||
QMessageBox::about(NULL, "游戏结果", message);
|
||||
#endif
|
||||
}
|
||||
|
@ -963,7 +963,7 @@ bool GameController::phaseChange(int row, bool forceUpdate)
|
|||
}
|
||||
|
||||
// 下面这步关键,会让悔棋者承担时间损失
|
||||
tempGame.setStartTime(game_.getStartTimeb());
|
||||
tempGame.setStartTime(game.getStartTimeb());
|
||||
|
||||
// 刷新棋局场景
|
||||
updateScence(tempGame);
|
||||
|
@ -973,12 +973,12 @@ bool GameController::phaseChange(int row, bool forceUpdate)
|
|||
|
||||
bool GameController::updateScence()
|
||||
{
|
||||
return updateScence(game_);
|
||||
return updateScence(game);
|
||||
}
|
||||
|
||||
bool GameController::updateScence(Game &game)
|
||||
bool GameController::updateScence(Game &g)
|
||||
{
|
||||
const int *board = game.getBoardLocations();
|
||||
const int *board = g.getBoardLocations();
|
||||
QPointF pos;
|
||||
|
||||
// game类中的棋子代码
|
||||
|
@ -1032,10 +1032,10 @@ bool GameController::updateScence(Game &game)
|
|||
if (j == (Board::N_SEATS) * (Board::N_RINGS + 1)) {
|
||||
// 判断是被吃掉的子,还是未安放的子
|
||||
if (key & 0x10) {
|
||||
pos = (key - 0x11 < nTotalPieces / 2 - game.getPiecesInHandCount(1)) ?
|
||||
pos = (key - 0x11 < nTotalPieces / 2 - g.getPiecesInHandCount(1)) ?
|
||||
scene.pos_p2_g : scene.pos_p1;
|
||||
} else {
|
||||
pos = (key - 0x21 < nTotalPieces / 2 - game.getPiecesInHandCount(2)) ?
|
||||
pos = (key - 0x21 < nTotalPieces / 2 - g.getPiecesInHandCount(2)) ?
|
||||
scene.pos_p1_g : scene.pos_p2;
|
||||
}
|
||||
|
||||
|
@ -1062,7 +1062,7 @@ bool GameController::updateScence(Game &game)
|
|||
}
|
||||
|
||||
// 添加摆棋阶段禁子点
|
||||
if (rule.hasForbiddenLocations && game.getPhase() == PHASE_PLACING) {
|
||||
if (rule.hasForbiddenLocations && g.getPhase() == PHASE_PLACING) {
|
||||
for (int j = Board::LOCATION_BEGIN; j < Board::LOCATION_END; j++) {
|
||||
if (board[j] == 0x0F) {
|
||||
pos = scene.rs2pos(j / Board::N_SEATS, j % Board::N_SEATS + 1);
|
||||
|
@ -1081,7 +1081,7 @@ bool GameController::updateScence(Game &game)
|
|||
}
|
||||
|
||||
// 走棋阶段清除禁子点
|
||||
if (rule.hasForbiddenLocations && game.getPhase() != PHASE_PLACING) {
|
||||
if (rule.hasForbiddenLocations && g.getPhase() != PHASE_PLACING) {
|
||||
while (nTotalPieces < pieceList.size()) {
|
||||
delete pieceList.at(nTotalPieces);
|
||||
pieceList.removeAt(nTotalPieces);
|
||||
|
@ -1089,9 +1089,9 @@ bool GameController::updateScence(Game &game)
|
|||
}
|
||||
|
||||
// 选中当前棋子
|
||||
int ipos = game.getCurrentLocation();
|
||||
int ipos = g.getCurrentLocation();
|
||||
if (ipos) {
|
||||
key = board[game.getCurrentLocation()];
|
||||
key = board[g.getCurrentLocation()];
|
||||
ipos = key & 0x10 ? (key - 0x11) * 2 : (key - 0x21) * 2 + 1;
|
||||
if (ipos >= 0 && ipos < nTotalPieces) {
|
||||
currentPiece = pieceList.at(ipos);
|
||||
|
@ -1107,9 +1107,9 @@ bool GameController::updateScence(Game &game)
|
|||
animationGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
|
||||
// 更新比分 LCD 显示
|
||||
emit score1Changed(QString::number(game.score[1], 10));
|
||||
emit score2Changed(QString::number(game.score[2], 10));
|
||||
emit scoreDrawChanged(QString::number(game.score_draw, 10));
|
||||
emit score1Changed(QString::number(g.score[1], 10));
|
||||
emit score2Changed(QString::number(g.score[2], 10));
|
||||
emit scoreDrawChanged(QString::number(g.score_draw, 10));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -55,9 +55,9 @@ public:
|
|||
//主窗口菜单栏明细
|
||||
const QMap <int, QStringList> getActions();
|
||||
|
||||
int getRuleNo()
|
||||
int getRuleIndex()
|
||||
{
|
||||
return ruleNo_;
|
||||
return ruleIndex;
|
||||
}
|
||||
|
||||
int getTimeLimit()
|
||||
|
@ -196,7 +196,7 @@ protected:
|
|||
|
||||
private:
|
||||
// 棋对象的数据模型
|
||||
Game game_;
|
||||
Game game;
|
||||
|
||||
// 棋对象的数据模型(临时)
|
||||
Game tempGame;
|
||||
|
@ -241,7 +241,7 @@ private:
|
|||
int timeID;
|
||||
|
||||
// 规则号
|
||||
int ruleNo_;
|
||||
int ruleIndex;
|
||||
|
||||
// 规则限时(分钟)
|
||||
int timeLimit;
|
||||
|
|
|
@ -114,9 +114,9 @@ MillGameWindow::MillGameWindow(QWidget * parent) :
|
|||
|
||||
MillGameWindow::~MillGameWindow()
|
||||
{
|
||||
if (game) {
|
||||
game->disconnect();
|
||||
game->deleteLater();
|
||||
if (gameController) {
|
||||
gameController->disconnect();
|
||||
gameController->deleteLater();
|
||||
}
|
||||
|
||||
qDeleteAll(ruleActionList);
|
||||
|
@ -154,14 +154,14 @@ bool MillGameWindow::eventFilter(QObject *watched, QEvent *event)
|
|||
void MillGameWindow::initialize()
|
||||
{
|
||||
// 初始化函数,仅执行一次
|
||||
if (game)
|
||||
if (gameController)
|
||||
return;
|
||||
|
||||
// 开辟一个新的游戏控制器
|
||||
game = new GameController(*scene, this);
|
||||
gameController = new GameController(*scene, this);
|
||||
|
||||
// 添加新菜单栏动作
|
||||
QMap <int, QStringList> actions = game->getActions();
|
||||
QMap <int, QStringList> actions = gameController->getActions();
|
||||
|
||||
for (auto i = actions.constBegin(); i != actions.constEnd(); i++) {
|
||||
// QMap的key存放int索引值,value存放规则名称和规则提示
|
||||
|
@ -185,7 +185,7 @@ void MillGameWindow::initialize()
|
|||
// 关联主窗口动作信号和控制器的槽
|
||||
|
||||
connect(ui.actionGiveUp_G, SIGNAL(triggered()),
|
||||
game, SLOT(giveUp()));
|
||||
gameController, SLOT(giveUp()));
|
||||
|
||||
#ifdef MOBILE_APP_UI
|
||||
connect(ui.pushButton_giveUp, SIGNAL(released()),
|
||||
|
@ -193,71 +193,71 @@ void MillGameWindow::initialize()
|
|||
#endif
|
||||
|
||||
connect(ui.actionEngine1_T, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setEngine1(bool)));
|
||||
gameController, SLOT(setEngine1(bool)));
|
||||
|
||||
connect(ui.actionEngine2_R, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setEngine2(bool)));
|
||||
gameController, SLOT(setEngine2(bool)));
|
||||
|
||||
connect(ui.
|
||||
actionSound_S, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setSound(bool)));
|
||||
gameController, SLOT(setSound(bool)));
|
||||
|
||||
connect(ui.actionAnimation_A, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setAnimation(bool)));
|
||||
gameController, SLOT(setAnimation(bool)));
|
||||
|
||||
connect(ui.actionGiveUpIfMostLose_G, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setGiveUpIfMostLose(bool)));
|
||||
gameController, SLOT(setGiveUpIfMostLose(bool)));
|
||||
|
||||
connect(ui.actionAutoRestart_A, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setAutoRestart(bool)));
|
||||
gameController, SLOT(setAutoRestart(bool)));
|
||||
|
||||
connect(ui.actionRandomMove_R, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setRandomMove(bool)));
|
||||
gameController, SLOT(setRandomMove(bool)));
|
||||
|
||||
connect(ui.actionLearnEndgame_E, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setLearnEndgame(bool)));
|
||||
gameController, SLOT(setLearnEndgame(bool)));
|
||||
|
||||
// 视图上下翻转
|
||||
connect(ui.actionFlip_F, &QAction::triggered,
|
||||
game, &GameController::flip);
|
||||
gameController, &GameController::flip);
|
||||
|
||||
// 视图左右镜像
|
||||
connect(ui.actionMirror_M, &QAction::triggered,
|
||||
game, &GameController::mirror);
|
||||
gameController, &GameController::mirror);
|
||||
|
||||
// 视图须时针旋转90°
|
||||
connect(ui.actionTurnRight_R, &QAction::triggered,
|
||||
game, &GameController::turnRight);
|
||||
gameController, &GameController::turnRight);
|
||||
|
||||
// 视图逆时针旋转90°
|
||||
connect(ui.actionTurnLeftt_L, &QAction::triggered,
|
||||
game, &GameController::turnLeft);
|
||||
gameController, &GameController::turnLeft);
|
||||
|
||||
// 关联控制器的信号和主窗口控件的槽
|
||||
|
||||
// 更新LCD,显示玩家1赢盘数
|
||||
connect(game, SIGNAL(score1Changed(QString)),
|
||||
connect(gameController, SIGNAL(score1Changed(QString)),
|
||||
ui.scoreLcdNumber_1, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD,显示玩家2赢盘数
|
||||
connect(game, SIGNAL(score2Changed(QString)),
|
||||
connect(gameController, SIGNAL(score2Changed(QString)),
|
||||
ui.scoreLcdNumber_2, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD,显示和棋数
|
||||
connect(game, SIGNAL(scoreDrawChanged(QString)),
|
||||
connect(gameController, SIGNAL(scoreDrawChanged(QString)),
|
||||
ui.scoreLcdNumber_draw, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD1,显示玩家1用时
|
||||
connect(game, SIGNAL(time1Changed(QString)),
|
||||
connect(gameController, SIGNAL(time1Changed(QString)),
|
||||
ui.lcdNumber_1, SLOT(display(QString)));
|
||||
|
||||
// 更新LCD2,显示玩家2用时
|
||||
connect(game, SIGNAL(time2Changed(QString)),
|
||||
connect(gameController, SIGNAL(time2Changed(QString)),
|
||||
ui.lcdNumber_2, SLOT(display(QString)));
|
||||
|
||||
// 关联场景的信号和控制器的槽
|
||||
connect(scene, SIGNAL(mouseReleased(QPointF)),
|
||||
game, SLOT(actionPiece(QPointF)));
|
||||
gameController, SLOT(actionPiece(QPointF)));
|
||||
|
||||
// 为状态栏添加一个正常显示的标签
|
||||
auto *statusBarlabel = new QLabel(this);
|
||||
|
@ -267,7 +267,7 @@ void MillGameWindow::initialize()
|
|||
ui.statusBar->addWidget(statusBarlabel);
|
||||
|
||||
// 更新状态栏
|
||||
connect(game, SIGNAL(statusBarChanged(QString)),
|
||||
connect(gameController, SIGNAL(statusBarChanged(QString)),
|
||||
statusBarlabel, SLOT(setText(QString)));
|
||||
|
||||
// 默认第2号规则
|
||||
|
@ -275,13 +275,13 @@ void MillGameWindow::initialize()
|
|||
ruleActionList.at(ruleNo)->setChecked(true);
|
||||
|
||||
// 重置游戏规则
|
||||
game->setRule(ruleNo);
|
||||
gameController->setRule(ruleNo);
|
||||
|
||||
// 更新规则显示
|
||||
ruleInfo();
|
||||
|
||||
// 关联列表视图和字符串列表模型
|
||||
ui.listView->setModel(game->getManualListModel());
|
||||
ui.listView->setModel(gameController->getManualListModel());
|
||||
|
||||
// 因为QListView的rowsInserted在setModel之后才能启动,
|
||||
// 第一次需手动初始化选中listView第一项
|
||||
|
@ -372,8 +372,8 @@ void MillGameWindow::ctxMenu(const QPoint &pos)
|
|||
|
||||
void MillGameWindow::ruleInfo()
|
||||
{
|
||||
int s = game->getStepsLimit();
|
||||
int t = game->getTimeLimit();
|
||||
int s = gameController->getStepsLimit();
|
||||
int t = gameController->getTimeLimit();
|
||||
|
||||
QString tl(" 不限时");
|
||||
QString sl(" 不限步");
|
||||
|
@ -406,8 +406,8 @@ void MillGameWindow::on_actionLimited_T_triggered()
|
|||
* 还要写与主窗口的接口,费劲
|
||||
* 于是手写QDialog界面
|
||||
*/
|
||||
int gStep = game->getStepsLimit();
|
||||
int gTime = game->getTimeLimit();
|
||||
int gStep = gameController->getStepsLimit();
|
||||
int gTime = gameController->getTimeLimit();
|
||||
|
||||
// 定义新对话框
|
||||
auto *dialog = new QDialog(this);
|
||||
|
@ -470,7 +470,7 @@ void MillGameWindow::on_actionLimited_T_triggered()
|
|||
int dTime = comboBox_time->currentData().toInt();
|
||||
if (gStep != dStep || gTime != dTime) {
|
||||
// 重置游戏规则
|
||||
game->setRule(ruleNo, static_cast<step_t>(dStep), dTime);
|
||||
gameController->setRule(ruleNo, static_cast<step_t>(dStep), dTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -497,7 +497,7 @@ void MillGameWindow::actionRules_triggered()
|
|||
ruleNo = action->data().toInt();
|
||||
|
||||
// 如果游戏规则没变化,则返回
|
||||
if (ruleNo == game->getRuleNo())
|
||||
if (ruleNo == gameController->getRuleIndex())
|
||||
return;
|
||||
|
||||
// 取消AI设定
|
||||
|
@ -505,7 +505,7 @@ void MillGameWindow::actionRules_triggered()
|
|||
ui.actionEngine2_R->setChecked(false);
|
||||
|
||||
// 重置游戏规则
|
||||
game->setRule(ruleNo);
|
||||
gameController->setRule(ruleNo);
|
||||
|
||||
// 更新规则显示
|
||||
ruleInfo();
|
||||
|
@ -539,7 +539,7 @@ void MillGameWindow::on_actionNew_N_triggered()
|
|||
ui.actionAutoRun_A->setChecked(false);
|
||||
|
||||
// 重置游戏规则
|
||||
game->gameReset();
|
||||
gameController->gameReset();
|
||||
|
||||
// 重设AI设定
|
||||
if (ui.actionEngine2_R->isChecked()) {
|
||||
|
@ -592,7 +592,7 @@ void MillGameWindow::on_actionOpen_O_triggered()
|
|||
cmd = textStream.readLine();
|
||||
|
||||
// 读取并显示棋谱时,不必刷新棋局场景
|
||||
if (!(game->command(cmd, false))) {
|
||||
if (!(gameController->command(cmd, false))) {
|
||||
// 定义新对话框
|
||||
QMessageBox msgBox(QMessageBox::Warning, tr("文件错误"), tr("不是正确的棋谱文件"), QMessageBox::Ok);
|
||||
msgBox.exec();
|
||||
|
@ -601,11 +601,11 @@ void MillGameWindow::on_actionOpen_O_triggered()
|
|||
|
||||
while (!textStream.atEnd()) {
|
||||
cmd = textStream.readLine();
|
||||
game->command(cmd, false);
|
||||
gameController->command(cmd, false);
|
||||
}
|
||||
|
||||
// 最后刷新棋局场景
|
||||
game->updateScence();
|
||||
gameController->updateScence();
|
||||
}
|
||||
|
||||
void MillGameWindow::on_actionSave_S_triggered()
|
||||
|
@ -685,7 +685,7 @@ void MillGameWindow::on_actionInvert_I_toggled(bool arg1)
|
|||
}
|
||||
|
||||
// 让控制器改变棋子颜色
|
||||
game->setInvert(arg1);
|
||||
gameController->setInvert(arg1);
|
||||
}
|
||||
|
||||
// 前后招的公共槽
|
||||
|
@ -749,7 +749,7 @@ void MillGameWindow::on_actionRowChange()
|
|||
}
|
||||
|
||||
// 更新局面
|
||||
game->phaseChange(currentRow);
|
||||
gameController->phaseChange(currentRow);
|
||||
|
||||
#if 0
|
||||
// 下面的代码全部取消,改用QTimer的方式实现
|
||||
|
@ -818,7 +818,7 @@ void MillGameWindow::onAutoRunTimeOut(QPrivateSignal signal)
|
|||
}
|
||||
|
||||
// 更新局面
|
||||
game->phaseChange(currentRow);
|
||||
gameController->phaseChange(currentRow);
|
||||
}
|
||||
|
||||
// 自动运行
|
||||
|
@ -830,7 +830,7 @@ void MillGameWindow::on_actionAutoRun_A_toggled(bool arg1)
|
|||
ui.gameView->setEnabled(false);
|
||||
|
||||
// 启动定时器
|
||||
autoRunTimer.start(game->getDurationTime() * 10 + 50);
|
||||
autoRunTimer.start(gameController->getDurationTime() * 10 + 50);
|
||||
} else {
|
||||
// 关闭定时器
|
||||
autoRunTimer.stop();
|
||||
|
@ -852,7 +852,7 @@ void MillGameWindow::on_actionInternet_I_triggered()
|
|||
ui.actionLocal_L->setChecked(false);
|
||||
ui.actionInternet_I->setChecked(true);
|
||||
|
||||
game->showNetworkWindow();
|
||||
gameController->showNetworkWindow();
|
||||
}
|
||||
|
||||
void MillGameWindow::on_actionEngine_E_triggered()
|
||||
|
@ -928,7 +928,7 @@ void MillGameWindow::on_actionEngine_E_triggered()
|
|||
// 目前数据
|
||||
depth_t depth1, depth2;
|
||||
int time1, time2;
|
||||
game->getAiDepthTime(depth1, time1, depth2, time2);
|
||||
gameController->getAiDepthTime(depth1, time1, depth2, time2);
|
||||
spinBox_depth1->setValue(depth1);
|
||||
spinBox_depth2->setValue(depth2);
|
||||
spinBox_time1->setValue(time1);
|
||||
|
@ -950,7 +950,7 @@ void MillGameWindow::on_actionEngine_E_triggered()
|
|||
time1 != time1_new ||
|
||||
time2 != time2_new) {
|
||||
// 重置AI
|
||||
game->setAiDepthTime(depth1_new, time1_new, depth2_new, time2_new);
|
||||
gameController->setAiDepthTime(depth1_new, time1_new, depth2_new, time2_new);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ private:
|
|||
GameScene *scene {nullptr};
|
||||
|
||||
// 控制器
|
||||
GameController *game {nullptr};
|
||||
GameController *gameController {nullptr};
|
||||
|
||||
// 动态增加的菜单栏动作列表
|
||||
QList <QAction *> ruleActionList;
|
||||
|
|
|
@ -49,7 +49,7 @@ PieceItem::PieceItem(QGraphicsItem *parent) :
|
|||
//setAcceptHoverEvents(true);
|
||||
|
||||
// 默认模型为没有棋子
|
||||
model_ = noPiece;
|
||||
model = noPiece;
|
||||
|
||||
// 棋子尺寸
|
||||
size = PIECE_SIZE;
|
||||
|
@ -95,7 +95,7 @@ void PieceItem::paint(QPainter *painter,
|
|||
|
||||
// 空模型不画棋子
|
||||
|
||||
switch (model_) {
|
||||
switch (model) {
|
||||
case blackPiece:
|
||||
// 如果模型为黑色,则画黑色棋子
|
||||
#ifdef MOBILE_APP_UI
|
||||
|
@ -126,11 +126,11 @@ void PieceItem::paint(QPainter *painter,
|
|||
// 如果模型要求显示序号
|
||||
if (showNum) {
|
||||
// 如果模型为黑色,用白色笔画序号
|
||||
if (model_ == blackPiece)
|
||||
if (model == blackPiece)
|
||||
painter->setPen(QColor(255, 255, 255));
|
||||
|
||||
// 如果模型为白色,用白色笔画序号
|
||||
if (model_ == whitePiece)
|
||||
if (model == whitePiece)
|
||||
painter->setPen(QColor(0, 0, 0));
|
||||
|
||||
// 字体
|
||||
|
@ -162,7 +162,7 @@ void PieceItem::paint(QPainter *painter,
|
|||
}
|
||||
|
||||
// 如果模型为删除状态,则画上叉号
|
||||
if (deleted_) {
|
||||
if (deleted) {
|
||||
QPen pen(removeLineColor, removeLineWeight, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
|
||||
painter->setPen(pen);
|
||||
|
||||
|
|
|
@ -69,12 +69,12 @@ public:
|
|||
|
||||
enum Models getModel()
|
||||
{
|
||||
return model_;
|
||||
return model;
|
||||
}
|
||||
|
||||
void setModel(enum Models model)
|
||||
void setModel(enum Models m)
|
||||
{
|
||||
this->model_ = model;
|
||||
this->model = m;
|
||||
}
|
||||
|
||||
int getNum()
|
||||
|
@ -89,15 +89,15 @@ public:
|
|||
|
||||
bool isDeleted()
|
||||
{
|
||||
return deleted_;
|
||||
return deleted;
|
||||
}
|
||||
|
||||
void setDeleted(bool deleted = true)
|
||||
void setDeleted(bool del = true)
|
||||
{
|
||||
this->deleted_ = deleted;
|
||||
deleted = del;
|
||||
|
||||
if (deleted)
|
||||
this->model_ = noPiece;
|
||||
this->model = noPiece;
|
||||
|
||||
update(boundingRect());
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ protected:
|
|||
|
||||
private:
|
||||
// 棋子本质
|
||||
enum Models model_;
|
||||
enum Models model;
|
||||
|
||||
// 棋子序号,黑白都从1开始
|
||||
int num = 1;
|
||||
|
@ -123,7 +123,7 @@ private:
|
|||
int size;
|
||||
|
||||
// 有无删除线
|
||||
bool deleted_ {false};
|
||||
bool deleted {false};
|
||||
|
||||
// 显示序号
|
||||
bool showNum {false};
|
||||
|
|
|
@ -31,7 +31,7 @@ Server::Server(QWidget *parent, uint16_t port)
|
|||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
statusLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
|
||||
this->port_ = port;
|
||||
this->port = port;
|
||||
|
||||
QNetworkConfigurationManager manager;
|
||||
|
||||
|
@ -110,9 +110,9 @@ void Server::sessionOpened()
|
|||
|
||||
tcpServer = new QTcpServer(this);
|
||||
|
||||
if (!tcpServer->listen(QHostAddress::LocalHost, port_)) {
|
||||
port_++;
|
||||
if (!tcpServer->listen(QHostAddress::LocalHost, port_)) {
|
||||
if (!tcpServer->listen(QHostAddress::LocalHost, port)) {
|
||||
port++;
|
||||
if (!tcpServer->listen(QHostAddress::LocalHost, port)) {
|
||||
QMessageBox::critical(this, tr("Server"),
|
||||
tr("Unable to start the server: %1.")
|
||||
.arg(tcpServer->errorString()));
|
||||
|
@ -150,9 +150,9 @@ void Server::sessionOpened()
|
|||
.arg(ipAddress).arg(tcpServer->serverPort()));
|
||||
}
|
||||
|
||||
void Server::setAction(const QString &action)
|
||||
void Server::setAction(const QString &a)
|
||||
{
|
||||
actions.push(action);
|
||||
actions.push(a);
|
||||
}
|
||||
|
||||
void Server::sendAction()
|
||||
|
@ -162,10 +162,10 @@ void Server::sendAction()
|
|||
out.setVersion(QDataStream::Qt_5_10);
|
||||
|
||||
if (!actions.empty()) {
|
||||
action_ = actions.front();
|
||||
action = actions.front();
|
||||
}
|
||||
|
||||
out << action_;
|
||||
out << action;
|
||||
|
||||
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
|
||||
|
||||
|
|
|
@ -39,13 +39,13 @@ class Server : public QDialog
|
|||
public:
|
||||
explicit Server(QWidget *parent = nullptr, uint16_t port = 33333);
|
||||
void setAction(const QString &action);
|
||||
void setPort(uint16_t port)
|
||||
void setPort(uint16_t p)
|
||||
{
|
||||
this->port_ = port;
|
||||
port = p;
|
||||
}
|
||||
uint16_t getPort()
|
||||
{
|
||||
return port_;
|
||||
return port;
|
||||
}
|
||||
|
||||
private slots:
|
||||
|
@ -56,9 +56,9 @@ private:
|
|||
QLabel *statusLabel = nullptr;
|
||||
QTcpServer *tcpServer = nullptr;
|
||||
QNetworkSession *networkSession = nullptr;
|
||||
uint16_t port_;
|
||||
uint16_t port;
|
||||
std::queue<QString> actions;
|
||||
QString action_;
|
||||
QString action;
|
||||
};
|
||||
|
||||
#endif // SERVER_H
|
||||
|
|
Loading…
Reference in New Issue