GameController: position 成员变量由指针改为非指针

This commit is contained in:
Calcitem 2020-07-12 02:17:53 +08:00
parent 1c61bc7ab2
commit 89b371af93
2 changed files with 94 additions and 98 deletions

View File

@ -72,10 +72,6 @@ GameController::GameController(
scene.setBackgroundBrush(QColor(239, 239, 239)); scene.setBackgroundBrush(QColor(239, 239, 239));
#endif /* MOBILE_APP_UI */ #endif /* MOBILE_APP_UI */
if (position == nullptr) {
position = new Position();
}
resetAiPlayers(); resetAiPlayers();
createAiThreads(); createAiThreads();
@ -152,7 +148,7 @@ extern deque<int> openingBookDequeBak;
void GameController::gameStart() void GameController::gameStart()
{ {
position->start(); position.start();
// 每隔100毫秒调用一次定时器处理函数 // 每隔100毫秒调用一次定时器处理函数
if (timeID == 0) { if (timeID == 0) {
@ -180,7 +176,7 @@ void GameController::gameReset()
timeID = 0; timeID = 0;
// 重置游戏 // 重置游戏
position->reset(); position.reset();
// 停掉线程 // 停掉线程
if (!gameOptions.getAutoRestart()) { if (!gameOptions.getAutoRestart()) {
@ -249,7 +245,7 @@ void GameController::gameReset()
// 更新棋谱 // 更新棋谱
manualListModel.removeRows(0, manualListModel.rowCount()); manualListModel.removeRows(0, manualListModel.rowCount());
manualListModel.insertRow(0); manualListModel.insertRow(0);
manualListModel.setData(manualListModel.index(0), position->cmd_line()); manualListModel.setData(manualListModel.index(0), position.cmd_line());
currentRow = 0; currentRow = 0;
// 发出信号通知主窗口更新LCD显示 // 发出信号通知主窗口更新LCD显示
@ -258,22 +254,22 @@ void GameController::gameReset()
emit time2Changed(qtime.toString("hh:mm:ss")); emit time2Changed(qtime.toString("hh:mm:ss"));
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(position->get_tips()); message = QString::fromStdString(position.get_tips());
emit statusBarChanged(message); emit statusBarChanged(message);
// 更新比分 LCD 显示 // 更新比分 LCD 显示
emit nGamesPlayedChanged(QString::number(position->nPlayed, 10)); emit nGamesPlayedChanged(QString::number(position.nPlayed, 10));
emit score1Changed(QString::number(position->score[BLACK], 10)); emit score1Changed(QString::number(position.score[BLACK], 10));
emit score2Changed(QString::number(position->score[WHITE], 10)); emit score2Changed(QString::number(position.score[WHITE], 10));
emit scoreDrawChanged(QString::number(position->score_draw, 10)); emit scoreDrawChanged(QString::number(position.score_draw, 10));
// 更新胜率 LCD 显示 // 更新胜率 LCD 显示
position->nPlayed = position->score[BLACK] + position->score[WHITE] + position->score_draw; position.nPlayed = position.score[BLACK] + position.score[WHITE] + position.score_draw;
int winningRate_1 = 0, winningRate_2 = 0, winningRate_draw = 0; int winningRate_1 = 0, winningRate_2 = 0, winningRate_draw = 0;
if (position->nPlayed != 0) { if (position.nPlayed != 0) {
winningRate_1 = position->score[BLACK] * 10000 / position->nPlayed; winningRate_1 = position.score[BLACK] * 10000 / position.nPlayed;
winningRate_2 = position->score[WHITE] * 10000 / position->nPlayed; winningRate_2 = position.score[WHITE] * 10000 / position.nPlayed;
winningRate_draw = position->score_draw * 10000 / position->nPlayed; winningRate_draw = position.score_draw * 10000 / position.nPlayed;
} }
emit winningRate1Changed(QString::number(winningRate_1, 10)); emit winningRate1Changed(QString::number(winningRate_1, 10));
@ -328,7 +324,7 @@ void GameController::setRule(int ruleNo, Step stepLimited /*= -1*/, int timeLimi
} }
// 设置模型规则,重置游戏 // 设置模型规则,重置游戏
position->set_position(&RULES[ruleNo]); position.set_position(&RULES[ruleNo]);
// 重置游戏 // 重置游戏
gameReset(); gameReset();
@ -339,7 +335,7 @@ void GameController::setEngine(int color, bool arg)
isAiPlayer[color] = arg; isAiPlayer[color] = arg;
if (arg) { if (arg) {
aiThread[color]->setAi(position); aiThread[color]->setAi(&position);
if (aiThread[color]->isRunning()) if (aiThread[color]->isRunning())
aiThread[color]->resume(); aiThread[color]->resume();
else else
@ -363,8 +359,8 @@ void GameController::setAiDepthTime(int time1, int time2)
{ {
stopAndWaitAiThreads(); stopAndWaitAiThreads();
aiThread[BLACK]->setAi(position, time1); aiThread[BLACK]->setAi(&position, time1);
aiThread[WHITE]->setAi(position, time2); aiThread[WHITE]->setAi(&position, time2);
startAiThreads(); startAiThreads();
} }
@ -553,12 +549,12 @@ void GameController::flip()
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
stopAndWaitAiThreads(); stopAndWaitAiThreads();
position->mirror(position->move, position->currentSquare); position.mirror(position.move, position.currentSquare);
position->rotate(180, position->move, position->currentSquare); position.rotate(180, position.move, position.currentSquare);
// 更新棋谱 // 更新棋谱
int row = 0; int row = 0;
for (const auto &str : *(position->cmd_list())) { for (const auto &str : *(position.cmd_list())) {
manualListModel.setData(manualListModel.index(row++), str.c_str()); manualListModel.setData(manualListModel.index(row++), str.c_str());
} }
@ -568,7 +564,7 @@ void GameController::flip()
else else
phaseChange(currentRow, true); phaseChange(currentRow, true);
threadsSetAi(position); threadsSetAi(&position);
startAiThreads(); startAiThreads();
#endif // TRAINING_MODE #endif // TRAINING_MODE
} }
@ -579,12 +575,12 @@ void GameController::mirror()
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
stopAndWaitAiThreads(); stopAndWaitAiThreads();
position->mirror(position->move, position->currentSquare); position.mirror(position.move, position.currentSquare);
// 更新棋谱 // 更新棋谱
int row = 0; int row = 0;
for (const auto &str : *(position->cmd_list())) { for (const auto &str : *(position.cmd_list())) {
manualListModel.setData(manualListModel.index(row++), str.c_str()); manualListModel.setData(manualListModel.index(row++), str.c_str());
} }
@ -596,7 +592,7 @@ void GameController::mirror()
else else
phaseChange(currentRow, true); phaseChange(currentRow, true);
threadsSetAi(position); threadsSetAi(&position);
startAiThreads(); startAiThreads();
#endif // TRAINING_MODE #endif // TRAINING_MODE
} }
@ -607,12 +603,12 @@ void GameController::turnRight()
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
stopAndWaitAiThreads(); stopAndWaitAiThreads();
position->rotate(-90, position->move, position->currentSquare); position.rotate(-90, position.move, position.currentSquare);
// 更新棋谱 // 更新棋谱
int row = 0; int row = 0;
for (const auto &str : *(position->cmd_list())) { for (const auto &str : *(position.cmd_list())) {
manualListModel.setData(manualListModel.index(row++), str.c_str()); manualListModel.setData(manualListModel.index(row++), str.c_str());
} }
@ -622,7 +618,7 @@ void GameController::turnRight()
else else
phaseChange(currentRow, true); phaseChange(currentRow, true);
threadsSetAi(position); threadsSetAi(&position);
startAiThreads(); startAiThreads();
#endif #endif
} }
@ -633,18 +629,18 @@ void GameController::turnLeft()
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
stopAndWaitAiThreads(); stopAndWaitAiThreads();
position->rotate(90, position->move, position->currentSquare); position.rotate(90, position.move, position.currentSquare);
// 更新棋谱 // 更新棋谱
int row = 0; int row = 0;
for (const auto &str : *(position->cmd_list())) { for (const auto &str : *(position.cmd_list())) {
manualListModel.setData(manualListModel.index(row++), str.c_str()); manualListModel.setData(manualListModel.index(row++), str.c_str());
} }
// 刷新显示 // 刷新显示
updateScence(); updateScence();
threadsSetAi(position); threadsSetAi(&position);
startAiThreads(); startAiThreads();
#endif // TRAINING_MODE #endif // TRAINING_MODE
} }
@ -655,9 +651,9 @@ void GameController::timerEvent(QTimerEvent *event)
static QTime qt1, qt2; static QTime qt1, qt2;
// 玩家的已用时间 // 玩家的已用时间
position->update(); position.update();
remainingTime[BLACK] = position->get_elapsed_time(BLACK); remainingTime[BLACK] = position.get_elapsed_time(BLACK);
remainingTime[WHITE] = position->get_elapsed_time(WHITE); remainingTime[WHITE] = position.get_elapsed_time(WHITE);
// 如果规则要求计时则time1和time2表示倒计时 // 如果规则要求计时则time1和time2表示倒计时
if (timeLimit > 0) { if (timeLimit > 0) {
@ -673,7 +669,7 @@ void GameController::timerEvent(QTimerEvent *event)
emit time2Changed(qt2.toString("hh:mm:ss")); emit time2Changed(qt2.toString("hh:mm:ss"));
// 如果胜负已分 // 如果胜负已分
Color winner = position->get_winner(); Color winner = position.get_winner();
if (winner != NOBODY) { if (winner != NOBODY) {
// 停止计时 // 停止计时
killTimer(timeID); killTimer(timeID);
@ -683,7 +679,7 @@ void GameController::timerEvent(QTimerEvent *event)
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(position->get_tips()); message = QString::fromStdString(position.get_tips());
emit statusBarChanged(message); emit statusBarChanged(message);
// 弹框 // 弹框
@ -721,7 +717,7 @@ void GameController::timerEvent(QTimerEvent *event)
bool GameController::isAIsTurn() bool GameController::isAIsTurn()
{ {
return isAiPlayer[position->sideToMove]; return isAiPlayer[position.sideToMove];
} }
// 关键槽函数根据QGraphicsScene的信号和状态来执行选子、落子或去子 // 关键槽函数根据QGraphicsScene的信号和状态来执行选子、落子或去子
@ -760,13 +756,13 @@ bool GameController::actionPiece(QPointF pos)
manualListModel.removeRows(currentRow + 1, manualListModel.rowCount() - currentRow - 1); manualListModel.removeRows(currentRow + 1, manualListModel.rowCount() - currentRow - 1);
// 如果再决出胜负后悔棋,则重新启动计时 // 如果再决出胜负后悔棋,则重新启动计时
if (position->get_winner() == NOBODY) { if (position.get_winner() == NOBODY) {
// 重新启动计时 // 重新启动计时
timeID = startTimer(100); timeID = startTimer(100);
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(position->get_tips()); message = QString::fromStdString(position.get_tips());
emit statusBarChanged(message); emit statusBarChanged(message);
#ifndef MOBILE_APP_UI #ifndef MOBILE_APP_UI
} }
@ -777,7 +773,7 @@ bool GameController::actionPiece(QPointF pos)
} }
// 如果未开局则开局 // 如果未开局则开局
if (position->get_phase() == PHASE_READY) if (position.get_phase() == PHASE_READY)
gameStart(); gameStart();
// 判断执行选子、落子或去子 // 判断执行选子、落子或去子
@ -785,15 +781,15 @@ bool GameController::actionPiece(QPointF pos)
PieceItem *piece = nullptr; PieceItem *piece = nullptr;
QGraphicsItem *item = scene.itemAt(pos, QTransform()); QGraphicsItem *item = scene.itemAt(pos, QTransform());
switch (position->get_action()) { switch (position.get_action()) {
case ACTION_PLACE: case ACTION_PLACE:
if (position->_placePiece(file, rank)) { if (position._placePiece(file, rank)) {
if (position->get_action() == ACTION_REMOVE) { if (position.get_action() == ACTION_REMOVE) {
// 播放成三音效 // 播放成三音效
playSound(GAME_SOUND_MILL, position->side_to_move()); playSound(GAME_SOUND_MILL, position.side_to_move());
} else { } else {
// 播放移动棋子音效 // 播放移动棋子音效
playSound(GAME_SOUND_DROG, position->side_to_move()); playSound(GAME_SOUND_DROG, position.side_to_move());
} }
result = true; result = true;
break; break;
@ -806,24 +802,24 @@ bool GameController::actionPiece(QPointF pos)
piece = qgraphicsitem_cast<PieceItem *>(item); piece = qgraphicsitem_cast<PieceItem *>(item);
if (!piece) if (!piece)
break; break;
if (position->_selectPiece(file, rank)) { if (position._selectPiece(file, rank)) {
// 播放选子音效 // 播放选子音效
playSound(GAME_SOUND_SELECT, position->side_to_move()); playSound(GAME_SOUND_SELECT, position.side_to_move());
result = true; result = true;
} else { } else {
// 播放禁止音效 // 播放禁止音效
playSound(GAME_SOUND_BANNED, position->side_to_move()); playSound(GAME_SOUND_BANNED, position.side_to_move());
} }
break; break;
case ACTION_REMOVE: case ACTION_REMOVE:
if (position->_removePiece(file, rank)) { if (position._removePiece(file, rank)) {
// 播放音效 // 播放音效
playSound(GAME_SOUND_REMOVE, position->side_to_move()); playSound(GAME_SOUND_REMOVE, position.side_to_move());
result = true; result = true;
} else { } else {
// 播放禁止音效 // 播放禁止音效
playSound(GAME_SOUND_BANNED, position->side_to_move()); playSound(GAME_SOUND_BANNED, position.side_to_move());
} }
break; break;
@ -834,7 +830,7 @@ bool GameController::actionPiece(QPointF pos)
if (result) { if (result) {
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(position->get_tips()); message = QString::fromStdString(position.get_tips());
emit statusBarChanged(message); emit statusBarChanged(message);
// 将新增的棋谱行插入到ListModel // 将新增的棋谱行插入到ListModel
@ -842,7 +838,7 @@ bool GameController::actionPiece(QPointF pos)
int k = 0; int k = 0;
// 输出命令行 // 输出命令行
for (const auto & i : *(position->cmd_list())) { for (const auto & i : *(position.cmd_list())) {
// 跳过已添加的因标准list容器没有下标 // 跳过已添加的因标准list容器没有下标
if (k++ <= currentRow) if (k++ <= currentRow)
continue; continue;
@ -852,7 +848,7 @@ bool GameController::actionPiece(QPointF pos)
// 播放胜利或失败音效 // 播放胜利或失败音效
#ifndef DONOT_PLAY_WIN_SOUND #ifndef DONOT_PLAY_WIN_SOUND
Color winner = position->get_winner(); Color winner = position.get_winner();
if (winner != NOBODY && if (winner != NOBODY &&
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) (manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over."))
playSound(GAME_SOUND_WIN, winner); playSound(GAME_SOUND_WIN, winner);
@ -860,8 +856,8 @@ bool GameController::actionPiece(QPointF pos)
// AI设置 // AI设置
// 如果还未决出胜负 // 如果还未决出胜负
if (position->get_winner() == NOBODY) { if (position.get_winner() == NOBODY) {
resumeAiThreads(position->sideToMove); resumeAiThreads(position.sideToMove);
} }
// 如果已经决出胜负 // 如果已经决出胜负
else { else {
@ -879,7 +875,7 @@ bool GameController::actionPiece(QPointF pos)
bool GameController::giveUp() bool GameController::giveUp()
{ {
bool result = position->giveup(position->sideToMove); bool result = position.giveup(position.sideToMove);
if (!result) { if (!result) {
return false; return false;
@ -892,7 +888,7 @@ bool GameController::giveUp()
int k = 0; int k = 0;
// 输出命令行 // 输出命令行
for (const auto & i : *(position->cmd_list())) { for (const auto & i : *(position.cmd_list())) {
// 跳过已添加的因标准list容器没有下标 // 跳过已添加的因标准list容器没有下标
if (k++ <= currentRow) if (k++ <= currentRow)
continue; continue;
@ -900,8 +896,8 @@ bool GameController::giveUp()
manualListModel.setData(manualListModel.index(currentRow), i.c_str()); manualListModel.setData(manualListModel.index(currentRow), i.c_str());
} }
if (position->get_winner() != NOBODY) if (position.get_winner() != NOBODY)
playSound(GAME_SOUND_GIVE_UP, position->side_to_move()); playSound(GAME_SOUND_GIVE_UP, position.side_to_move());
#endif // TRAINING_MODE #endif // TRAINING_MODE
@ -926,7 +922,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
// 声音 // 声音
sound_t soundType = GAME_SOUND_NONE; sound_t soundType = GAME_SOUND_NONE;
switch (position->get_action()) { switch (position.get_action()) {
case ACTION_SELECT: case ACTION_SELECT:
case ACTION_PLACE: case ACTION_PLACE:
soundType = GAME_SOUND_DROG; soundType = GAME_SOUND_DROG;
@ -940,45 +936,45 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
#endif #endif
// 如果未开局则开局 // 如果未开局则开局
if (position->get_phase() == PHASE_READY) { if (position.get_phase() == PHASE_READY) {
gameStart(); gameStart();
} }
if (!position->command(cmd.toStdString().c_str())) if (!position.command(cmd.toStdString().c_str()))
return false; return false;
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
if (soundType == GAME_SOUND_DROG && position->get_action() == ACTION_REMOVE) { if (soundType == GAME_SOUND_DROG && position.get_action() == ACTION_REMOVE) {
soundType = GAME_SOUND_MILL; soundType = GAME_SOUND_MILL;
} }
if (update) { if (update) {
playSound(soundType, position->side_to_move()); playSound(soundType, position.side_to_move());
updateScence(position); updateScence(&position);
} }
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(position->get_tips()); message = QString::fromStdString(position.get_tips());
emit statusBarChanged(message); emit statusBarChanged(message);
// 对于新开局 // 对于新开局
if (position->cmd_list()->size() <= 1) { if (position.cmd_list()->size() <= 1) {
manualListModel.removeRows(0, manualListModel.rowCount()); manualListModel.removeRows(0, manualListModel.rowCount());
manualListModel.insertRow(0); manualListModel.insertRow(0);
manualListModel.setData(manualListModel.index(0), position->cmd_line()); manualListModel.setData(manualListModel.index(0), position.cmd_line());
currentRow = 0; currentRow = 0;
} }
// 对于当前局 // 对于当前局
else { else {
currentRow = manualListModel.rowCount() - 1; currentRow = manualListModel.rowCount() - 1;
// 跳过已添加行,迭代器不支持+运算符,只能一个个++ // 跳过已添加行,迭代器不支持+运算符,只能一个个++
auto i = (position->cmd_list()->begin()); auto i = (position.cmd_list()->begin());
for (int r = 0; i != (position->cmd_list())->end(); i++) { for (int r = 0; i != (position.cmd_list())->end(); i++) {
if (r++ > currentRow) if (r++ > currentRow)
break; break;
} }
// 将新增的棋谱行插入到ListModel // 将新增的棋谱行插入到ListModel
while (i != position->cmd_list()->end()) { while (i != position.cmd_list()->end()) {
manualListModel.insertRow(++currentRow); manualListModel.insertRow(++currentRow);
manualListModel.setData(manualListModel.index(currentRow), (*i++).c_str()); manualListModel.setData(manualListModel.index(currentRow), (*i++).c_str());
} }
@ -986,7 +982,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
// 播放胜利或失败音效 // 播放胜利或失败音效
#ifndef DONOT_PLAY_WIN_SOUND #ifndef DONOT_PLAY_WIN_SOUND
Color winner = position->get_winner(); Color winner = position.get_winner();
if (winner != NOBODY && if (winner != NOBODY &&
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) { (manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) {
playSound(GAME_SOUND_WIN, winner); playSound(GAME_SOUND_WIN, winner);
@ -996,8 +992,8 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
// AI设置 // AI设置
// 如果还未决出胜负 // 如果还未决出胜负
if (position->get_winner() == NOBODY) { if (position.get_winner() == NOBODY) {
resumeAiThreads(position->sideToMove); resumeAiThreads(position.sideToMove);
} }
// 如果已经决出胜负 // 如果已经决出胜负
else { else {
@ -1069,7 +1065,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
#ifdef MESSAGEBOX_ENABLE #ifdef MESSAGEBOX_ENABLE
// 弹框 // 弹框
message = QString::fromStdString(position->get_tips()); message = QString::fromStdString(position.get_tips());
QMessageBox::about(NULL, "游戏结果", message); QMessageBox::about(NULL, "游戏结果", message);
#endif #endif
} }
@ -1105,14 +1101,14 @@ bool GameController::phaseChange(int row, bool forceUpdate)
for (int i = 0; i <= row; i++) { for (int i = 0; i <= row; i++) {
loggerDebug("%s\n", mlist.at(i).toStdString().c_str()); loggerDebug("%s\n", mlist.at(i).toStdString().c_str());
position->command(mlist.at(i).toStdString().c_str()); position.command(mlist.at(i).toStdString().c_str());
} }
// 下面这步关键,会让悔棋者承担时间损失 // 下面这步关键,会让悔棋者承担时间损失
position->set_start_time(static_cast<int>(position->start_timeb())); position.set_start_time(static_cast<int>(position.start_timeb()));
// 刷新棋局场景 // 刷新棋局场景
updateScence(position); updateScence(&position);
#endif // TRAINING_MODE #endif // TRAINING_MODE
return true; return true;
@ -1121,7 +1117,7 @@ bool GameController::phaseChange(int row, bool forceUpdate)
bool GameController::updateScence() bool GameController::updateScence()
{ {
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
return updateScence(position); return updateScence(&position);
#else #else
return true; return true;
#endif #endif
@ -1196,7 +1192,7 @@ bool GameController::updateScence(Position *p)
deletedPiece = piece; deletedPiece = piece;
#ifdef GAME_PLACING_SHOW_REMOVED_PIECES #ifdef GAME_PLACING_SHOW_REMOVED_PIECES
if (position->get_phase() == PHASE_MOVING) { if (position.get_phase() == PHASE_MOVING) {
#endif #endif
QPropertyAnimation *animation = new QPropertyAnimation(piece, "pos"); QPropertyAnimation *animation = new QPropertyAnimation(piece, "pos");
animation->setDuration(durationTime); animation->setDuration(durationTime);
@ -1264,12 +1260,12 @@ bool GameController::updateScence(Position *p)
emit scoreDrawChanged(QString::number(p->score_draw, 10)); emit scoreDrawChanged(QString::number(p->score_draw, 10));
// 更新胜率 LCD 显示 // 更新胜率 LCD 显示
position->nPlayed = position->score[BLACK] + position->score[WHITE] + position->score_draw; position.nPlayed = position.score[BLACK] + position.score[WHITE] + position.score_draw;
int winningRate_1 = 0, winningRate_2 = 0, winningRate_draw = 0; int winningRate_1 = 0, winningRate_2 = 0, winningRate_draw = 0;
if (position->nPlayed != 0) { if (position.nPlayed != 0) {
winningRate_1 = position->score[BLACK] * 10000 / position->nPlayed; winningRate_1 = position.score[BLACK] * 10000 / position.nPlayed;
winningRate_2 = position->score[WHITE] * 10000 / position->nPlayed; winningRate_2 = position.score[WHITE] * 10000 / position.nPlayed;
winningRate_draw = position->score_draw * 10000 / position->nPlayed; winningRate_draw = position.score_draw * 10000 / position.nPlayed;
} }
emit winningRate1Changed(QString::number(winningRate_1, 10)); emit winningRate1Changed(QString::number(winningRate_1, 10));
@ -1295,7 +1291,7 @@ void GameController::showTestWindow()
void GameController::humanGiveUp() void GameController::humanGiveUp()
{ {
if (position->get_winner() == NOBODY) { if (position.get_winner() == NOBODY) {
giveUp(); giveUp();
} }
} }
@ -1346,16 +1342,16 @@ void GameController::saveScore()
textStream << "" << endl; textStream << "" << endl;
position->nPlayed = position->score[BLACK] + position->score[WHITE] + position->score_draw; position.nPlayed = position.score[BLACK] + position.score[WHITE] + position.score_draw;
if (position->nPlayed == 0) { if (position.nPlayed == 0) {
goto out; goto out;
} }
textStream << "Sum\t" + QString::number(position->nPlayed) << endl; textStream << "Sum\t" + QString::number(position.nPlayed) << endl;
textStream << "Black\t" + QString::number(position->score[BLACK]) + "\t" + QString::number(position->score[BLACK] * 10000 / position->nPlayed) << endl; textStream << "Black\t" + QString::number(position.score[BLACK]) + "\t" + QString::number(position.score[BLACK] * 10000 / position.nPlayed) << endl;
textStream << "White\t" + QString::number(position->score[WHITE]) + "\t" + QString::number(position->score[WHITE] * 10000 / position->nPlayed) << endl; textStream << "White\t" + QString::number(position.score[WHITE]) + "\t" + QString::number(position.score[WHITE] * 10000 / position.nPlayed) << endl;
textStream << "Draw\t" + QString::number(position->score_draw) + "\t" + QString::number(position->score_draw * 10000 / position->nPlayed) << endl; textStream << "Draw\t" + QString::number(position.score_draw) + "\t" + QString::number(position.score_draw * 10000 / position.nPlayed) << endl;
out: out:
file.flush(); file.flush();

View File

@ -133,7 +133,7 @@ public:
Position *getPosition() Position *getPosition()
{ {
return position; return &position;
} }
signals: signals:
@ -345,7 +345,7 @@ protected:
private: private:
// 棋对象的数据模型 // 棋对象的数据模型
Position *position {nullptr}; Position position;
// 测试 // 测试
Test *gameTest; Test *gameTest;