将 QDebug 替换为自己定义的 loggerDebug 函数

This commit is contained in:
CalciteM 2019-09-07 19:19:45 +08:00
parent 1e3e994920
commit a1125087bc
15 changed files with 68 additions and 68 deletions

3
.gitignore vendored
View File

@ -325,3 +325,6 @@ CMakeLists.txt.user*
# Text files # Text files
*.txt *.txt
# Other files
user*

View File

@ -21,6 +21,8 @@
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#include "debug.h"
#if _MSC_VER >= 1600 #if _MSC_VER >= 1600
#pragma execution_character_set("utf-8") #pragma execution_character_set("utf-8")
#endif #endif

View File

@ -13,6 +13,7 @@ TARGET = MillGame
TEMPLATE = app TEMPLATE = app
CONFIG += warn_off CONFIG += warn_off
CONFIG += console
INCLUDEPATH += include INCLUDEPATH += include
INCLUDEPATH += src/base INCLUDEPATH += src/base
@ -39,6 +40,7 @@ HEADERS += \
include/version.h \ include/version.h \
include/version.h.template \ include/version.h.template \
src/base/HashNode.h \ src/base/HashNode.h \
src/base/debug.h \
src/base/hashMap.h \ src/base/hashMap.h \
src/base/MemoryPool.h \ src/base/MemoryPool.h \
src/base/MemoryPool.tcc \ src/base/MemoryPool.tcc \

View File

@ -443,6 +443,7 @@
</CustomBuild> </CustomBuild>
<ClInclude Include="src\ai\search.h" /> <ClInclude Include="src\ai\search.h" />
<ClInclude Include="src\ai\zobrist.h" /> <ClInclude Include="src\ai\zobrist.h" />
<ClInclude Include="src\base\debug.h" />
<ClInclude Include="src\base\hashmap.h" /> <ClInclude Include="src\base\hashmap.h" />
<ClInclude Include="src\base\HashNode.h" /> <ClInclude Include="src\base\HashNode.h" />
<ClInclude Include="src\base\MemoryPool.h" /> <ClInclude Include="src\base\MemoryPool.h" />

View File

@ -93,6 +93,9 @@
<ClInclude Include="src\ai\search.h"> <ClInclude Include="src\ai\search.h">
<Filter>ai</Filter> <Filter>ai</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\base\debug.h">
<Filter>base</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt"> <CustomBuild Include="debug\moc_predefs.h.cbt">

View File

@ -20,7 +20,6 @@
*****************************************************************************/ *****************************************************************************/
#include <cmath> #include <cmath>
#include <QDebug>
#include <QTime> #include <QTime>
#include <array> #include <array>
#include <random> #include <random>
@ -95,7 +94,7 @@ MillGameAi_ab::depth_t MillGameAi_ab::changeDepth(depth_t originalDepth)
} }
#endif /* GAME_MOVING_FIXED_DEPTH */ #endif /* GAME_MOVING_FIXED_DEPTH */
qDebug() << "Depth:" << newDepth; loggerDebug("Depth: %d\n", newDepth);
return newDepth; return newDepth;
} }
@ -740,7 +739,7 @@ int MillGameAi_ab::alphaBetaPruning(depth_t depth)
alphaBetaPruning(i, -INF_VALUE, INF_VALUE, rootNode); alphaBetaPruning(i, -INF_VALUE, INF_VALUE, rootNode);
} }
qDebug() << "IDS Time: " << time1.elapsed() / 1000.0 << "s"; loggerDebug("IDS Time: %0.3fs\n", time1.elapsed() / 1000.0);
#endif /* IDS_SUPPORT */ #endif /* IDS_SUPPORT */
#ifdef HASH_MAP_ENABLE #ifdef HASH_MAP_ENABLE
@ -751,7 +750,7 @@ int MillGameAi_ab::alphaBetaPruning(depth_t depth)
value = alphaBetaPruning(d, -INF_VALUE /* alpha */, INF_VALUE /* beta */, rootNode); value = alphaBetaPruning(d, -INF_VALUE /* alpha */, INF_VALUE /* beta */, rootNode);
qDebug() << "Total Time: " << time1.elapsed() / 1000.0 << "s\n"; loggerDebug("Total Time: %0.3fs\n", time1.elapsed() / 1000.0);
// 生成了 Alpha-Beta 树 // 生成了 Alpha-Beta 树
@ -886,7 +885,6 @@ MillGameAi_ab::value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t al
if (chessContext->turn == MillGame::PLAYER2) { if (chessContext->turn == MillGame::PLAYER2) {
// 是否需对后手扣分 // TODO: 先后手都处理 // 是否需对后手扣分 // TODO: 先后手都处理
node->value += 1; node->value += 1;
// qDebug() << ">>>>>>>>>>>>>>> New soccer = " << node->value;
} }
} }
#endif #endif
@ -1032,18 +1030,19 @@ const char* MillGameAi_ab::bestMove()
return "error!"; return "error!";
} }
qDebug() << "31 ----- 24 ----- 25"; loggerDebug("\n");
qDebug() << "| \\ | / |"; loggerDebug("31 ----- 24 ----- 25\n");
qDebug() << "| 23 -- 16 -- 17 |"; loggerDebug("| \\ | / |\n");
qDebug() << "| | \\ | / | |"; loggerDebug("| 23 -- 16 -- 17 |\n");
qDebug() << "| | 15-08-09 | |"; loggerDebug("| | \\ | / | |\n");
qDebug() << "30-22-14 10-18-26"; loggerDebug("| | 15-08-09 | |\n");
qDebug() << "| | 13-12-11 | |"; loggerDebug("30-22-14 10-18-26\n");
qDebug() << "| | / | \\ | |"; loggerDebug("| | 13-12-11 | |\n");
qDebug() << "| 21 -- 20 -- 19 |"; loggerDebug("| | / | \\ | |\n");
qDebug() << "| / | \\ |"; loggerDebug("| 21 -- 20 -- 19 |\n");
qDebug() << "29 ----- 28 ----- 27"; loggerDebug("| / | \\ |\n");
qDebug() << ""; loggerDebug("29 ----- 28 ----- 27\n");
loggerDebug("\n");
int i = 0; int i = 0;
string moves = "moves"; string moves = "moves";
@ -1054,9 +1053,9 @@ const char* MillGameAi_ab::bestMove()
&& !child->pruned && !child->pruned
#endif #endif
) { ) {
qDebug("[%.2d] %d\t%s\t%d *", i, child->move, move2string(child->move), child->value); loggerDebug("[%.2d] %d\t%s\t%d *\n", i, child->move, move2string(child->move), child->value);
} else { } else {
qDebug("[%.2d] %d\t%s\t%d", i, child->move, move2string(child->move), child->value); loggerDebug("[%.2d] %d\t%s\t%d\n", i, child->move, move2string(child->move), child->value);
} }
i++; i++;
@ -1071,23 +1070,22 @@ const char* MillGameAi_ab::bestMove()
bestMovesSize = bestMoves.size(); bestMovesSize = bestMoves.size();
if (bestMovesSize == 0) { if (bestMovesSize == 0) {
qDebug() << "Not any child value is equal to root value"; loggerDebug("Not any child value is equal to root value\n");
for (auto child : rootNode->children) { for (auto child : rootNode->children) {
bestMoves.push_back(child); bestMoves.push_back(child);
} }
} }
qDebug() << "Evaluated: " << evaluatedNodeCount << "/" << nodeCount << " = " loggerDebug("Evaluated: %llu / %llu = %llu%%\n", evaluatedNodeCount, nodeCount, evaluatedNodeCount * 100 / nodeCount);
<< evaluatedNodeCount * 100 / nodeCount << "%";
nodeCount = 0; nodeCount = 0;
evaluatedNodeCount = 0; evaluatedNodeCount = 0;
#ifdef HASH_MAP_ENABLE #ifdef HASH_MAP_ENABLE
#ifdef HASH_MAP_DEBUG #ifdef HASH_MAP_DEBUG
qDebug() << "Hash hit count:" << hashHitCount; loggerDebug(""Hash hit count: %llu\n", hashHitCount);
#endif #endif
#endif #endif
//qDebug() << "sizeof(Node) = " << sizeof(Node);
if (bestMoves.empty()) { if (bestMoves.empty()) {
return nullptr; return nullptr;
@ -1194,9 +1192,6 @@ int MillGameAi_ab::recordHash(value_t value, depth_t depth, HashType type, MillG
if (findHash(hash, hashValue) && if (findHash(hash, hashValue) &&
hashValue.type != hashfEMPTY && hashValue.type != hashfEMPTY &&
hashValue.depth > depth) { hashValue.depth > depth) {
#ifdef DEBUG_MODE
qDebug() << "Skip recordHash coz depth";
#endif
return -1; return -1;
} }
@ -1260,22 +1255,18 @@ void MillGameAi_ab::recordOpeningBookToHashMap()
recordBookHash(hash, hashValue); // 暂时使用直接覆盖策略 recordBookHash(hash, hashValue); // 暂时使用直接覆盖策略
} }
//qDebug("Record %d items to Opening Book\n", openingBook.size());
openingBook.clear(); openingBook.clear();
} }
void MillGameAi_ab::recordOpeningBookHashMapToFile() void MillGameAi_ab::recordOpeningBookHashMapToFile()
{ {
const QString bookFileName = "opening-book.txt"; const QString bookFileName = "opening-book.txt";
qDebug() << "Dump Opening Book to file...";
bookHashMap.dump(bookFileName); bookHashMap.dump(bookFileName);
} }
void MillGameAi_ab::loadOpeningBookFileToHashMap() void MillGameAi_ab::loadOpeningBookFileToHashMap()
{ {
const QString bookFileName = "opening-book.txt"; const QString bookFileName = "opening-book.txt";
qDebug() << "Loading Opening Book from file...";
bookHashMap.load(bookFileName); bookHashMap.load(bookFileName);
} }
#endif // BOOK_LEARNING #endif // BOOK_LEARNING

View File

@ -32,7 +32,6 @@
//#endif //#endif
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <QDebug>
#include <array> #include <array>
#include "millgame.h" #include "millgame.h"
@ -129,7 +128,7 @@ public:
void quit() void quit()
{ {
qDebug() << "Timeout\n"; loggerDebug("Timeout\n");
requiredQuit = true; requiredQuit = true;
} }

17
src/base/debug.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef DEBUG_H
#define DEBUG_H
#include <cstdio>
#include <QDebug>
//#define QT_NO_DEBUG_OUTPUT
#define CSTYLE_DEBUG_OUTPUT
#ifdef CSTYLE_DEBUG_OUTPUT
#define loggerDebug printf
#else
#define loggerDebug qDebug
#endif /* CSTYLE_DEBUG_OUTPUT */
#endif /* DEBUG_H */

View File

@ -20,8 +20,6 @@
*****************************************************************************/ *****************************************************************************/
#include <QTimer> #include <QTimer>
#include <QDebug>
#include "thread.h" #include "thread.h"
AiThread::AiThread(int id, QObject *parent) : AiThread::AiThread(int id, QObject *parent) :
@ -103,7 +101,7 @@ void AiThread::run()
// 设一个标识1号线程只管玩家12号线程只管玩家2 // 设一个标识1号线程只管玩家12号线程只管玩家2
int i = 0; int i = 0;
qDebug() << "Thread" << id << "start"; loggerDebug("Thread %d start\n", id);
while (!isInterruptionRequested()) { while (!isInterruptionRequested()) {
mutex.lock(); mutex.lock();
@ -122,21 +120,17 @@ void AiThread::run()
if (ai_ab.alphaBetaPruning(aiDepth) == 3) { if (ai_ab.alphaBetaPruning(aiDepth) == 3) {
// 三次重复局面和 // 三次重复局面和
qDebug() << "Draw\n"; loggerDebug("Draw\n\n");
strCommand = "draw"; strCommand = "draw";
QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand); QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand);
} else { } else {
strCommand = ai_ab.bestMove(); strCommand = ai_ab.bestMove();
if (strCommand && strcmp(strCommand, "error!") != 0) { if (strCommand && strcmp(strCommand, "error!") != 0) {
qDebug() << "Computer:" << strCommand << "\n"; loggerDebug("Computer: %s\n\n", strCommand);
QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand); QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand);
} }
} }
#ifdef DEBUG_MODE
qDebug() << "Thread" << id << "run" << ++iTemp << "times";
#endif
emit calcFinished(); emit calcFinished();
// 执行完毕后继续判断 // 执行完毕后继续判断
@ -147,7 +141,7 @@ void AiThread::run()
mutex.unlock(); mutex.unlock();
} }
qDebug() << "Thread" << id << "quit"; loggerDebug("Thread %d quit\n", id);
} }
void AiThread::act() void AiThread::act()

View File

@ -22,7 +22,6 @@
#include <algorithm> #include <algorithm>
#include "millgame.h" #include "millgame.h"
#include "search.h" #include "search.h"
#include <QDebug>
// 对静态常量数组的定义要放在类外,不要放在头文件 // 对静态常量数组的定义要放在类外,不要放在头文件
// 预定义的4套规则 // 预定义的4套规则
@ -448,17 +447,17 @@ void MillGame::createMoveTable()
#if 0 #if 0
int sum = 0; int sum = 0;
for (int i = 0; i < N_POINTS; i++) { for (int i = 0; i < N_POINTS; i++) {
printf("/* %d */ {", i); loggerDebug("/* %d */ {", i);
for (int j = 0; j < N_MOVE_DIRECTIONS; j++) { for (int j = 0; j < N_MOVE_DIRECTIONS; j++) {
if (j == N_MOVE_DIRECTIONS - 1) if (j == N_MOVE_DIRECTIONS - 1)
printf("%d", moveTable[i][j]); loggerDebug("%d", moveTable[i][j]);
else else
printf("%d, ", moveTable[i][j]); loggerDebug("%d, ", moveTable[i][j]);
sum += moveTable[i][j]; sum += moveTable[i][j];
} }
printf("},\n"); loggerDebug("},\n");
} }
qDebug() << "sum = " << sum; loggerDebug("sum = %d\n");
#endif #endif
} }
@ -2493,12 +2492,12 @@ void MillGame::constructHash()
#if 0 #if 0
// 预留末8位后续填充局面特征标志 // 预留末8位后续填充局面特征标志
for (int p = 0; p < N_POINTS; p++) { for (int p = 0; p < N_POINTS; p++) {
//qDebug("{\n"); //loggerDebug("{\n");
for (int t = MillGame::POINT_TYPE_EMPTY; t <= MillGame::POINT_TYPE_FORBIDDEN; t++) { for (int t = MillGame::POINT_TYPE_EMPTY; t <= MillGame::POINT_TYPE_FORBIDDEN; t++) {
context.zobrist[p][t] = rand56(); context.zobrist[p][t] = rand56();
//qDebug("%llX, ", context.zobrist[p][t]); //loggerDebug("%llX, ", context.zobrist[p][t]);
} }
//qDebug("},\n"); //loggerDebug("},\n");
} }
#endif #endif
} }

View File

@ -25,7 +25,6 @@
#include <QApplication> #include <QApplication>
#include <QTimer> #include <QTimer>
#include <QSound> #include <QSound>
#include <QDebug>
#include <QMessageBox> #include <QMessageBox>
#include <QAbstractButton> #include <QAbstractButton>
#include <QPropertyAnimation> #include <QPropertyAnimation>
@ -443,7 +442,7 @@ void GameController::mirror()
manualListModel.setData(manualListModel.index(row++), str.c_str()); manualListModel.setData(manualListModel.index(row++), str.c_str());
} }
qDebug() << "list: " << row; loggerDebug("list: %d\n", row);
// 刷新显示 // 刷新显示
if (currentRow == row - 1) if (currentRow == row - 1)
@ -590,7 +589,6 @@ void GameController::timerEvent(QTimerEvent *event)
time1 = ti - time2; time1 = ti - time2;
// 用于显示时间的临时变量多出的50毫秒用于消除计时器误差产生的跳动 // 用于显示时间的临时变量多出的50毫秒用于消除计时器误差产生的跳动
t = QTime(0, 0, 0, 50).addMSecs(time1); t = QTime(0, 0, 0, 50).addMSecs(time1);
//qDebug() << t;
emit time1Changed(t.toString("hh:mm:ss")); emit time1Changed(t.toString("hh:mm:ss"));
} }
else if (timeWhos == 2) else if (timeWhos == 2)
@ -598,7 +596,6 @@ void GameController::timerEvent(QTimerEvent *event)
time2 = ti - time1; time2 = ti - time1;
// 用于显示时间的临时变量多出的50毫秒用于消除计时器误差产生的跳动 // 用于显示时间的临时变量多出的50毫秒用于消除计时器误差产生的跳动
t = QTime(0, 0, 0, 50).addMSecs(time2); t = QTime(0, 0, 0, 50).addMSecs(time2);
//qDebug() << t;
emit time2Changed(t.toString("hh:mm:ss")); emit time2Changed(t.toString("hh:mm:ss"));
} }
#endif #endif
@ -934,10 +931,8 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
if (isAiPlayer1) if (isAiPlayer1)
{ {
ai1.getServer()->setAction(cmd); ai1.getServer()->setAction(cmd);
qDebug() << "isEngine1: AI(1) set Action: " << cmd;
} else if (isAiPlayer2) { } else if (isAiPlayer2) {
ai1.getServer()->setAction(cmd); // 注意: 同样是AI1 ai1.getServer()->setAction(cmd); // 注意: 同样是AI1
qDebug() << "isEngine2: AI(1) set Action: " << cmd;
} }
return true; return true;
@ -954,10 +949,11 @@ bool GameController::stageChange(int row, bool forceUpdate)
currentRow = row; currentRow = row;
int rows = manualListModel.rowCount(); int rows = manualListModel.rowCount();
QStringList mlist = manualListModel.stringList(); QStringList mlist = manualListModel.stringList();
qDebug() << "rows:" << rows << " current:" << row;
loggerDebug("rows: %d current: %d\n", rows, row);
for (int i = 0; i <= row; i++) { for (int i = 0; i <= row; i++) {
qDebug() << mlist.at(i); loggerDebug("%s\n", mlist.at(i).toStdString().c_str());
chessTemp.command(mlist.at(i).toStdString().c_str()); chessTemp.command(mlist.at(i).toStdString().c_str());
} }

View File

@ -23,7 +23,6 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QKeyEvent> #include <QKeyEvent>
#include <QDebug>
#include "gamescene.h" #include "gamescene.h"
#include "pieceitem.h" #include "pieceitem.h"

View File

@ -20,7 +20,6 @@
*****************************************************************************/ *****************************************************************************/
#include <QMatrix> #include <QMatrix>
#include <QDebug>
#include "gameview.h" #include "gameview.h"
@ -119,7 +118,6 @@ void GameView::resizeEvent(QResizeEvent *event)
sy = sx; sy = sx;
// 缩放视图适合场景大小 // 缩放视图适合场景大小
scale(sx, sy); scale(sx, sy);
//qDebug() << "scale :" << sx;
#endif #endif
// 使用如下形式,更简洁 // 使用如下形式,更简洁

View File

@ -39,7 +39,6 @@
#include <QToolTip> #include <QToolTip>
#include <QPicture> #include <QPicture>
#include <QScreen> #include <QScreen>
#include <QDebug>
#include <QDesktopWidget> #include <QDesktopWidget>
#include "gamewindow.h" #include "gamewindow.h"
@ -130,7 +129,7 @@ void MillGameWindow::closeEvent(QCloseEvent *event)
// 取消自动运行 // 取消自动运行
ui.actionAutoRun_A->setChecked(false); ui.actionAutoRun_A->setChecked(false);
//qDebug() << "closed"; loggerDebug("closed\n");
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
@ -164,7 +163,6 @@ void MillGameWindow::initialize()
QMap <int, QStringList> actions = game->getActions(); QMap <int, QStringList> actions = game->getActions();
for (auto i = actions.constBegin(); i != actions.constEnd(); i++) { for (auto i = actions.constBegin(); i != actions.constEnd(); i++) {
// qDebug() << i.key() << i.value();
// QMap的key存放int索引值value存放规则名称和规则提示 // QMap的key存放int索引值value存放规则名称和规则提示
auto *ruleAction = new QAction(i.value().at(0), this); auto *ruleAction = new QAction(i.value().at(0), this);
ruleAction->setToolTip(i.value().at(1)); ruleAction->setToolTip(i.value().at(1));
@ -280,7 +278,6 @@ void MillGameWindow::initialize()
// 因为QListView的rowsInserted在setModel之后才能启动 // 因为QListView的rowsInserted在setModel之后才能启动
// 第一次需手动初始化选中listView第一项 // 第一次需手动初始化选中listView第一项
//qDebug() << ui.listView->model();
ui.listView->setCurrentIndex(ui.listView->model()->index(0, 0)); ui.listView->setCurrentIndex(ui.listView->model()->index(0, 0));
// 初始局面、前一步、后一步、最终局面的槽 // 初始局面、前一步、后一步、最终局面的槽

View File

@ -34,7 +34,6 @@
#include <QListView> #include <QListView>
#include <QMouseEvent> #include <QMouseEvent>
#include <QDebug>
#include "config.h" #include "config.h"