将 QDebug 替换为自己定义的 loggerDebug 函数
This commit is contained in:
parent
1e3e994920
commit
a1125087bc
|
@ -325,3 +325,6 @@ CMakeLists.txt.user*
|
|||
|
||||
# Text files
|
||||
*.txt
|
||||
|
||||
# Other files
|
||||
user*
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#if _MSC_VER >= 1600
|
||||
#pragma execution_character_set("utf-8")
|
||||
#endif
|
||||
|
|
|
@ -13,6 +13,7 @@ TARGET = MillGame
|
|||
TEMPLATE = app
|
||||
|
||||
CONFIG += warn_off
|
||||
CONFIG += console
|
||||
|
||||
INCLUDEPATH += include
|
||||
INCLUDEPATH += src/base
|
||||
|
@ -39,6 +40,7 @@ HEADERS += \
|
|||
include/version.h \
|
||||
include/version.h.template \
|
||||
src/base/HashNode.h \
|
||||
src/base/debug.h \
|
||||
src/base/hashMap.h \
|
||||
src/base/MemoryPool.h \
|
||||
src/base/MemoryPool.tcc \
|
||||
|
|
|
@ -443,6 +443,7 @@
|
|||
</CustomBuild>
|
||||
<ClInclude Include="src\ai\search.h" />
|
||||
<ClInclude Include="src\ai\zobrist.h" />
|
||||
<ClInclude Include="src\base\debug.h" />
|
||||
<ClInclude Include="src\base\hashmap.h" />
|
||||
<ClInclude Include="src\base\HashNode.h" />
|
||||
<ClInclude Include="src\base\MemoryPool.h" />
|
||||
|
|
|
@ -93,6 +93,9 @@
|
|||
<ClInclude Include="src\ai\search.h">
|
||||
<Filter>ai</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\base\debug.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="debug\moc_predefs.h.cbt">
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <cmath>
|
||||
#include <QDebug>
|
||||
#include <QTime>
|
||||
#include <array>
|
||||
#include <random>
|
||||
|
@ -95,7 +94,7 @@ MillGameAi_ab::depth_t MillGameAi_ab::changeDepth(depth_t originalDepth)
|
|||
}
|
||||
#endif /* GAME_MOVING_FIXED_DEPTH */
|
||||
|
||||
qDebug() << "Depth:" << newDepth;
|
||||
loggerDebug("Depth: %d\n", newDepth);
|
||||
|
||||
return newDepth;
|
||||
}
|
||||
|
@ -740,7 +739,7 @@ int MillGameAi_ab::alphaBetaPruning(depth_t depth)
|
|||
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 */
|
||||
|
||||
#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);
|
||||
|
||||
qDebug() << "Total Time: " << time1.elapsed() / 1000.0 << "s\n";
|
||||
loggerDebug("Total Time: %0.3fs\n", time1.elapsed() / 1000.0);
|
||||
|
||||
// 生成了 Alpha-Beta 树
|
||||
|
||||
|
@ -886,7 +885,6 @@ MillGameAi_ab::value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t al
|
|||
if (chessContext->turn == MillGame::PLAYER2) {
|
||||
// 是否需对后手扣分 // TODO: 先后手都处理
|
||||
node->value += 1;
|
||||
// qDebug() << ">>>>>>>>>>>>>>> New soccer = " << node->value;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1032,18 +1030,19 @@ const char* MillGameAi_ab::bestMove()
|
|||
return "error!";
|
||||
}
|
||||
|
||||
qDebug() << "31 ----- 24 ----- 25";
|
||||
qDebug() << "| \\ | / |";
|
||||
qDebug() << "| 23 -- 16 -- 17 |";
|
||||
qDebug() << "| | \\ | / | |";
|
||||
qDebug() << "| | 15-08-09 | |";
|
||||
qDebug() << "30-22-14 10-18-26";
|
||||
qDebug() << "| | 13-12-11 | |";
|
||||
qDebug() << "| | / | \\ | |";
|
||||
qDebug() << "| 21 -- 20 -- 19 |";
|
||||
qDebug() << "| / | \\ |";
|
||||
qDebug() << "29 ----- 28 ----- 27";
|
||||
qDebug() << "";
|
||||
loggerDebug("\n");
|
||||
loggerDebug("31 ----- 24 ----- 25\n");
|
||||
loggerDebug("| \\ | / |\n");
|
||||
loggerDebug("| 23 -- 16 -- 17 |\n");
|
||||
loggerDebug("| | \\ | / | |\n");
|
||||
loggerDebug("| | 15-08-09 | |\n");
|
||||
loggerDebug("30-22-14 10-18-26\n");
|
||||
loggerDebug("| | 13-12-11 | |\n");
|
||||
loggerDebug("| | / | \\ | |\n");
|
||||
loggerDebug("| 21 -- 20 -- 19 |\n");
|
||||
loggerDebug("| / | \\ |\n");
|
||||
loggerDebug("29 ----- 28 ----- 27\n");
|
||||
loggerDebug("\n");
|
||||
|
||||
int i = 0;
|
||||
string moves = "moves";
|
||||
|
@ -1054,9 +1053,9 @@ const char* MillGameAi_ab::bestMove()
|
|||
&& !child->pruned
|
||||
#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 {
|
||||
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++;
|
||||
|
@ -1071,23 +1070,22 @@ const char* MillGameAi_ab::bestMove()
|
|||
bestMovesSize = bestMoves.size();
|
||||
|
||||
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) {
|
||||
bestMoves.push_back(child);
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Evaluated: " << evaluatedNodeCount << "/" << nodeCount << " = "
|
||||
<< evaluatedNodeCount * 100 / nodeCount << "%";
|
||||
loggerDebug("Evaluated: %llu / %llu = %llu%%\n", evaluatedNodeCount, nodeCount, evaluatedNodeCount * 100 / nodeCount);
|
||||
|
||||
nodeCount = 0;
|
||||
evaluatedNodeCount = 0;
|
||||
|
||||
#ifdef HASH_MAP_ENABLE
|
||||
#ifdef HASH_MAP_DEBUG
|
||||
qDebug() << "Hash hit count:" << hashHitCount;
|
||||
loggerDebug(""Hash hit count: %llu\n", hashHitCount);
|
||||
#endif
|
||||
#endif
|
||||
//qDebug() << "sizeof(Node) = " << sizeof(Node);
|
||||
|
||||
if (bestMoves.empty()) {
|
||||
return nullptr;
|
||||
|
@ -1194,9 +1192,6 @@ int MillGameAi_ab::recordHash(value_t value, depth_t depth, HashType type, MillG
|
|||
if (findHash(hash, hashValue) &&
|
||||
hashValue.type != hashfEMPTY &&
|
||||
hashValue.depth > depth) {
|
||||
#ifdef DEBUG_MODE
|
||||
qDebug() << "Skip recordHash coz depth";
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1260,22 +1255,18 @@ void MillGameAi_ab::recordOpeningBookToHashMap()
|
|||
recordBookHash(hash, hashValue); // 暂时使用直接覆盖策略
|
||||
}
|
||||
|
||||
//qDebug("Record %d items to Opening Book\n", openingBook.size());
|
||||
|
||||
openingBook.clear();
|
||||
}
|
||||
|
||||
void MillGameAi_ab::recordOpeningBookHashMapToFile()
|
||||
{
|
||||
const QString bookFileName = "opening-book.txt";
|
||||
qDebug() << "Dump Opening Book to file...";
|
||||
bookHashMap.dump(bookFileName);
|
||||
}
|
||||
|
||||
void MillGameAi_ab::loadOpeningBookFileToHashMap()
|
||||
{
|
||||
const QString bookFileName = "opening-book.txt";
|
||||
qDebug() << "Loading Opening Book from file...";
|
||||
bookHashMap.load(bookFileName);
|
||||
}
|
||||
#endif // BOOK_LEARNING
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
//#endif
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <QDebug>
|
||||
#include <array>
|
||||
|
||||
#include "millgame.h"
|
||||
|
@ -129,7 +128,7 @@ public:
|
|||
|
||||
void quit()
|
||||
{
|
||||
qDebug() << "Timeout\n";
|
||||
loggerDebug("Timeout\n");
|
||||
requiredQuit = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
|
@ -20,8 +20,6 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
#include "thread.h"
|
||||
|
||||
AiThread::AiThread(int id, QObject *parent) :
|
||||
|
@ -103,7 +101,7 @@ void AiThread::run()
|
|||
// 设一个标识,1号线程只管玩家1,2号线程只管玩家2
|
||||
int i = 0;
|
||||
|
||||
qDebug() << "Thread" << id << "start";
|
||||
loggerDebug("Thread %d start\n", id);
|
||||
|
||||
while (!isInterruptionRequested()) {
|
||||
mutex.lock();
|
||||
|
@ -122,21 +120,17 @@ void AiThread::run()
|
|||
|
||||
if (ai_ab.alphaBetaPruning(aiDepth) == 3) {
|
||||
// 三次重复局面和
|
||||
qDebug() << "Draw\n";
|
||||
loggerDebug("Draw\n\n");
|
||||
strCommand = "draw";
|
||||
QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand);
|
||||
} else {
|
||||
strCommand = ai_ab.bestMove();
|
||||
if (strCommand && strcmp(strCommand, "error!") != 0) {
|
||||
qDebug() << "Computer:" << strCommand << "\n";
|
||||
loggerDebug("Computer: %s\n\n", strCommand);
|
||||
QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MODE
|
||||
qDebug() << "Thread" << id << "run" << ++iTemp << "times";
|
||||
#endif
|
||||
|
||||
emit calcFinished();
|
||||
|
||||
// 执行完毕后继续判断
|
||||
|
@ -147,7 +141,7 @@ void AiThread::run()
|
|||
mutex.unlock();
|
||||
}
|
||||
|
||||
qDebug() << "Thread" << id << "quit";
|
||||
loggerDebug("Thread %d quit\n", id);
|
||||
}
|
||||
|
||||
void AiThread::act()
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <algorithm>
|
||||
#include "millgame.h"
|
||||
#include "search.h"
|
||||
#include <QDebug>
|
||||
|
||||
// 对静态常量数组的定义要放在类外,不要放在头文件
|
||||
// 预定义的4套规则
|
||||
|
@ -448,17 +447,17 @@ void MillGame::createMoveTable()
|
|||
#if 0
|
||||
int sum = 0;
|
||||
for (int i = 0; i < N_POINTS; i++) {
|
||||
printf("/* %d */ {", i);
|
||||
loggerDebug("/* %d */ {", i);
|
||||
for (int j = 0; j < N_MOVE_DIRECTIONS; j++) {
|
||||
if (j == N_MOVE_DIRECTIONS - 1)
|
||||
printf("%d", moveTable[i][j]);
|
||||
loggerDebug("%d", moveTable[i][j]);
|
||||
else
|
||||
printf("%d, ", moveTable[i][j]);
|
||||
loggerDebug("%d, ", moveTable[i][j]);
|
||||
sum += moveTable[i][j];
|
||||
}
|
||||
printf("},\n");
|
||||
loggerDebug("},\n");
|
||||
}
|
||||
qDebug() << "sum = " << sum;
|
||||
loggerDebug("sum = %d\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -2493,12 +2492,12 @@ void MillGame::constructHash()
|
|||
#if 0
|
||||
// 预留末8位后续填充局面特征标志
|
||||
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++) {
|
||||
context.zobrist[p][t] = rand56();
|
||||
//qDebug("%llX, ", context.zobrist[p][t]);
|
||||
//loggerDebug("%llX, ", context.zobrist[p][t]);
|
||||
}
|
||||
//qDebug("},\n");
|
||||
//loggerDebug("},\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <QApplication>
|
||||
#include <QTimer>
|
||||
#include <QSound>
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QAbstractButton>
|
||||
#include <QPropertyAnimation>
|
||||
|
@ -443,7 +442,7 @@ void GameController::mirror()
|
|||
manualListModel.setData(manualListModel.index(row++), str.c_str());
|
||||
}
|
||||
|
||||
qDebug() << "list: " << row;
|
||||
loggerDebug("list: %d\n", row);
|
||||
|
||||
// 刷新显示
|
||||
if (currentRow == row - 1)
|
||||
|
@ -590,7 +589,6 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
time1 = ti - time2;
|
||||
// 用于显示时间的临时变量,多出的50毫秒用于消除计时器误差产生的跳动
|
||||
t = QTime(0, 0, 0, 50).addMSecs(time1);
|
||||
//qDebug() << t;
|
||||
emit time1Changed(t.toString("hh:mm:ss"));
|
||||
}
|
||||
else if (timeWhos == 2)
|
||||
|
@ -598,7 +596,6 @@ void GameController::timerEvent(QTimerEvent *event)
|
|||
time2 = ti - time1;
|
||||
// 用于显示时间的临时变量,多出的50毫秒用于消除计时器误差产生的跳动
|
||||
t = QTime(0, 0, 0, 50).addMSecs(time2);
|
||||
//qDebug() << t;
|
||||
emit time2Changed(t.toString("hh:mm:ss"));
|
||||
}
|
||||
#endif
|
||||
|
@ -934,10 +931,8 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
|||
if (isAiPlayer1)
|
||||
{
|
||||
ai1.getServer()->setAction(cmd);
|
||||
qDebug() << "isEngine1: AI(1) set Action: " << cmd;
|
||||
} else if (isAiPlayer2) {
|
||||
ai1.getServer()->setAction(cmd); // 注意: 同样是AI1
|
||||
qDebug() << "isEngine2: AI(1) set Action: " << cmd;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -954,10 +949,11 @@ bool GameController::stageChange(int row, bool forceUpdate)
|
|||
currentRow = row;
|
||||
int rows = manualListModel.rowCount();
|
||||
QStringList mlist = manualListModel.stringList();
|
||||
qDebug() << "rows:" << rows << " current:" << row;
|
||||
|
||||
loggerDebug("rows: %d current: %d\n", rows, row);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QDebug>
|
||||
|
||||
#include "gamescene.h"
|
||||
#include "pieceitem.h"
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <QMatrix>
|
||||
#include <QDebug>
|
||||
|
||||
#include "gameview.h"
|
||||
|
||||
|
@ -119,7 +118,6 @@ void GameView::resizeEvent(QResizeEvent *event)
|
|||
sy = sx;
|
||||
// 缩放视图适合场景大小
|
||||
scale(sx, sy);
|
||||
//qDebug() << "scale :" << sx;
|
||||
#endif
|
||||
|
||||
// 使用如下形式,更简洁
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include <QToolTip>
|
||||
#include <QPicture>
|
||||
#include <QScreen>
|
||||
#include <QDebug>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
#include "gamewindow.h"
|
||||
|
@ -130,7 +129,7 @@ void MillGameWindow::closeEvent(QCloseEvent *event)
|
|||
// 取消自动运行
|
||||
ui.actionAutoRun_A->setChecked(false);
|
||||
|
||||
//qDebug() << "closed";
|
||||
loggerDebug("closed\n");
|
||||
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
@ -164,7 +163,6 @@ void MillGameWindow::initialize()
|
|||
QMap <int, QStringList> actions = game->getActions();
|
||||
|
||||
for (auto i = actions.constBegin(); i != actions.constEnd(); i++) {
|
||||
// qDebug() << i.key() << i.value();
|
||||
// QMap的key存放int索引值,value存放规则名称和规则提示
|
||||
auto *ruleAction = new QAction(i.value().at(0), this);
|
||||
ruleAction->setToolTip(i.value().at(1));
|
||||
|
@ -280,7 +278,6 @@ void MillGameWindow::initialize()
|
|||
|
||||
// 因为QListView的rowsInserted在setModel之后才能启动,
|
||||
// 第一次需手动初始化选中listView第一项
|
||||
//qDebug() << ui.listView->model();
|
||||
ui.listView->setCurrentIndex(ui.listView->model()->index(0, 0));
|
||||
|
||||
// 初始局面、前一步、后一步、最终局面的槽
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
|
||||
#include <QListView>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue