From 28a909f695d545bcb25d2b9a1744086a93a2280f Mon Sep 17 00:00:00 2001 From: X1aomu Date: Sun, 2 Dec 2018 12:21:15 +0800 Subject: [PATCH 01/12] gui: set fixed window size --- main.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/main.cc b/main.cc index 561bb6e..9fa9485 100644 --- a/main.cc +++ b/main.cc @@ -9,6 +9,7 @@ int main(int argc, char *argv[]) MainWindow w; w.show(); + w.setFixedSize(w.sizeHint()); return a.exec(); } From 7ab7080a406aa45fc4f87d06e5c92dfdbf720abd Mon Sep 17 00:00:00 2001 From: X1aomu Date: Mon, 3 Dec 2018 16:40:14 +0800 Subject: [PATCH 02/12] keep the GUI responsive when AI is moving --- core/players/ai.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/players/ai.cc b/core/players/ai.cc index 126f1d0..d367750 100644 --- a/core/players/ai.cc +++ b/core/players/ai.cc @@ -3,8 +3,9 @@ #include #include #include -#include -#include + +#include +#include #include "core/gameplay.h" @@ -14,7 +15,13 @@ void Ai::slotNextMove(const GamePlay::CheckerBoard &game, GamePlay::PlayerColor if (m_game == nullptr) return; - std::this_thread::sleep_for(std::chrono::milliseconds(200)); + // 设置延时,同时不失去主进程的响应 + QTimer t; + QEventLoop eventLoop; + t.setSingleShot(true); + connect(&t, &QTimer::timeout, &eventLoop, &QEventLoop::quit); + t.start(500); + eventLoop.exec(); std::vector availPositions; for (size_t row = 0; row != GamePlay::kBoardRows; ++row) From 10e7d1fbe083c9612e5a5825aab686124a1298e9 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Mon, 3 Dec 2018 18:32:15 +0800 Subject: [PATCH 03/12] improve user interaction experience Add timeout for changing stone's color and increase AI's moving timeout. --- core/players/ai.cc | 3 ++- ui/checkerboard/boardgrid.cc | 19 +++++++++++++++++-- ui/checkerboard/boardgrid.h | 2 ++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/players/ai.cc b/core/players/ai.cc index d367750..7e9fca6 100644 --- a/core/players/ai.cc +++ b/core/players/ai.cc @@ -19,8 +19,9 @@ void Ai::slotNextMove(const GamePlay::CheckerBoard &game, GamePlay::PlayerColor QTimer t; QEventLoop eventLoop; t.setSingleShot(true); + t.setTimerType(Qt::PreciseTimer); connect(&t, &QTimer::timeout, &eventLoop, &QEventLoop::quit); - t.start(500); + t.start(1000); eventLoop.exec(); std::vector availPositions; diff --git a/ui/checkerboard/boardgrid.cc b/ui/checkerboard/boardgrid.cc index eaa53c1..d45c937 100644 --- a/ui/checkerboard/boardgrid.cc +++ b/ui/checkerboard/boardgrid.cc @@ -3,11 +3,13 @@ #include #include #include +#include BoardGrid::BoardGrid(GamePlay::Position position, GamePlay::PlayerColor role, QWidget *parent) : QPushButton(parent), m_position(position), - m_playerColor(role) + m_playerColor(role), + m_updateTimer(new QTimer(this)) { QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); sizePolicy.setHorizontalStretch(0); @@ -19,6 +21,10 @@ BoardGrid::BoardGrid(GamePlay::Position position, GamePlay::PlayerColor role, QW setFocusPolicy(Qt::NoFocus); // 连接信号 connect(this, &QPushButton::clicked, this, &BoardGrid::slotOnClicked); + + m_updateTimer->setSingleShot(true); + m_updateTimer->setTimerType(Qt::PreciseTimer); + connect(m_updateTimer, &QTimer::timeout, this, [&](){ update(); }); } BoardGrid::~BoardGrid() @@ -28,8 +34,17 @@ BoardGrid::~BoardGrid() void BoardGrid::setStoneColor(GamePlay::PlayerColor role) { + auto old = m_playerColor; m_playerColor = role; - update(); + if (old != role && old != GamePlay::Unknown && role != GamePlay::Unknown) + { + m_updateTimer->setInterval(400); + } + else + { + m_updateTimer->setInterval(0); + } + m_updateTimer->start(); } void BoardGrid::slotOnClicked() diff --git a/ui/checkerboard/boardgrid.h b/ui/checkerboard/boardgrid.h index fddba6d..0b0aa6a 100644 --- a/ui/checkerboard/boardgrid.h +++ b/ui/checkerboard/boardgrid.h @@ -4,6 +4,7 @@ #include "core/gameplay.h" #include +#include /// \brief 棋盘格子。 /// @@ -45,6 +46,7 @@ public slots: GamePlay::Position m_position; GamePlay::PlayerColor m_playerColor; bool m_hovered = false; + QTimer* m_updateTimer; }; #endif // PIECEGIRD_H From d96e65beeb94c131d9f6203d78735643044889a6 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Mon, 3 Dec 2018 18:38:25 +0800 Subject: [PATCH 04/12] fix a deep bug the program may crash after stoping battling between AI and AI --- core/gameplay.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/gameplay.cc b/core/gameplay.cc index dbe1a44..03037e1 100644 --- a/core/gameplay.cc +++ b/core/gameplay.cc @@ -126,6 +126,8 @@ size_t GamePlay::tryMove(GamePlay::Position pos, PlayerColor playerColor, bool r bool GamePlay::playerCanMove(GamePlay::PlayerColor playerColor) { + if (!m_running) + return false; for (size_t row = 0; row != kBoardRows; ++row) { for (size_t col = 0; col != kBoardColumns; ++col) From d4a3e7407f83e84303c27f0c2d88c760795d0122 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Mon, 3 Dec 2018 20:31:30 +0800 Subject: [PATCH 05/12] fix: fix random engine problem under MS Windows --- core/players/ai.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/players/ai.cc b/core/players/ai.cc index 7e9fca6..66a820f 100644 --- a/core/players/ai.cc +++ b/core/players/ai.cc @@ -39,9 +39,9 @@ void Ai::slotNextMove(const GamePlay::CheckerBoard &game, GamePlay::PlayerColor if (availPositions.empty()) return; - std::random_device r; - std::default_random_engine randomEngine(r()); + std::mt19937 rng; + rng.seed(time(nullptr)); std::uniform_int_distribution randomDist(0, availPositions.size() - 1); - emit sigMoved(availPositions.at(randomDist(randomEngine))); + emit sigMoved(availPositions.at(randomDist(rng))); } From 9b7141a1f2ba167c600bf57ef4df36bc4fbae265 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Mon, 3 Dec 2018 22:48:44 +0800 Subject: [PATCH 06/12] fix: work on problem which is described in d96e65b --- core/battle.cc | 40 ++++++++++++++++------------------------ core/battle.h | 9 +++++---- core/players/ai.cc | 17 +++++++++++++++++ core/players/ai.h | 4 ++++ ui/mainwindow.cc | 9 ++++++--- ui/mainwindow.h | 2 +- 6 files changed, 49 insertions(+), 32 deletions(-) diff --git a/core/battle.cc b/core/battle.cc index eff2e14..9c0448f 100644 --- a/core/battle.cc +++ b/core/battle.cc @@ -16,7 +16,7 @@ Battle::Battle(QObject *parent) Battle::~Battle() { - cleanup(); + } bool Battle::isBattleRunning() @@ -29,7 +29,7 @@ Battle::PlayerColor Battle::currentPlayerColor() return m_gamePlay.getCurrentPlayerColor(); } -VirtualPlayer *Battle::getPlayer(Battle::PlayerColor playerColor) +std::shared_ptr Battle::getPlayer(Battle::PlayerColor playerColor) { if (playerColor == PlayerColor::Black) { @@ -44,59 +44,51 @@ VirtualPlayer *Battle::getPlayer(Battle::PlayerColor playerColor) void Battle::startNewBattle(Battle::PlayerType blackPlayerType, Battle::PlayerType whitePlayerType, QString blackPlayerName, QString whitePlayerName) { - cleanup(); + endBattle(); switch (blackPlayerType) { case Human: - m_playerBlack = new class Human(blackPlayerName, this); + m_playerBlack = std::make_shared(blackPlayerName, this); break; case Ai: - m_playerBlack = new class Ai(blackPlayerName, this); - dynamic_cast(m_playerBlack)->setGame(&m_gamePlay); + m_playerBlack = std::make_shared(blackPlayerName, this); + dynamic_cast(*m_playerBlack).setGame(&m_gamePlay); break; } switch (whitePlayerType) { case Human: - m_playerWhile = new class Human(whitePlayerName, this); + m_playerWhile = std::make_shared(whitePlayerName, this); break; case Ai: - m_playerWhile = new class Ai(whitePlayerName, this); - dynamic_cast(m_playerWhile)->setGame(&m_gamePlay); + m_playerWhile = std::make_shared(whitePlayerName, this); + dynamic_cast(*m_playerWhile).setGame(&m_gamePlay); break; } // 连接信号 - connect(m_playerBlack, &VirtualPlayer::sigMoved, &m_gamePlay, &GamePlay::slotMove); - connect(m_playerWhile, &VirtualPlayer::sigMoved, &m_gamePlay, &GamePlay::slotMove); + connect(m_playerBlack.get(), &VirtualPlayer::sigMoved, &m_gamePlay, &GamePlay::slotMove); + connect(m_playerWhile.get(), &VirtualPlayer::sigMoved, &m_gamePlay, &GamePlay::slotMove); m_gamePlay.slotStartNewGame(); emit sigBattleStarted(); + emit sigChanged(); } void Battle::endBattle() { m_gamePlay.reset(); - cleanup(); emit sigChanged(); } void Battle::slotHumanMove(GamePlay::Position position) { - VirtualPlayer* playerToMove = m_gamePlay.getCurrentPlayerColor() == PlayerColor::Black ? m_playerBlack : m_playerWhile; - if (class Human* humanPlayer = dynamic_cast(playerToMove)) + auto playerToMove = m_gamePlay.getCurrentPlayerColor() == PlayerColor::Black ? m_playerBlack : m_playerWhile; + if (class Human* humanPlayer = dynamic_cast(playerToMove.get())) { humanPlayer->slotMoveTo(position); } } -void Battle::cleanup() -{ - delete m_playerBlack; - delete m_playerWhile; - m_playerBlack = nullptr; - m_playerWhile = nullptr; -} - void Battle::gamePlayCheckerBoardChangedHandler(GamePlay::CheckerBoard currentBoard) { emit sigCheckerBoardChanged(currentBoard); @@ -105,6 +97,8 @@ void Battle::gamePlayCheckerBoardChangedHandler(GamePlay::CheckerBoard currentBo void Battle::gamePlayPlayerChangedHandler(Battle::PlayerColor playerColor) { + emit sigPlayerChanged(playerColor); + emit sigChanged(); // 通知玩家下子 if (playerColor == PlayerColor::Black) { @@ -114,8 +108,6 @@ void Battle::gamePlayPlayerChangedHandler(Battle::PlayerColor playerColor) { m_playerWhile->slotNextMove(m_gamePlay.getCheckerBoard(), playerColor); } - emit sigPlayerChanged(playerColor); - emit sigChanged(); } void Battle::gamePlayGameOverHandler(Battle::PlayerColor winner) diff --git a/core/battle.h b/core/battle.h index 5f34246..b4dff40 100644 --- a/core/battle.h +++ b/core/battle.h @@ -1,6 +1,8 @@ #ifndef ROUND_H #define ROUND_H +#include + #include "core/gameplay.h" #include "core/players/virtualplayer.h" @@ -38,7 +40,7 @@ class Battle : public QObject /// \param playerColor 玩家颜色, /// 需为 #GamePlay::Black 或 #GamePlay::White 。 /// \return 下子方 \p playerColor 对应的玩家。如果没有对战则为 nullptr。 - VirtualPlayer *getPlayer(PlayerColor playerColor); + std::shared_ptr getPlayer(PlayerColor playerColor); /// \brief 开始对战。 /// \param blackPlayerType 黑方的玩家类型。 @@ -87,10 +89,9 @@ public slots: private: GamePlay m_gamePlay; - VirtualPlayer *m_playerBlack; - VirtualPlayer *m_playerWhile; + std::shared_ptr m_playerBlack; + std::shared_ptr m_playerWhile; - void cleanup(); void gamePlayCheckerBoardChangedHandler(GamePlay::CheckerBoard currentBoard); void gamePlayPlayerChangedHandler(PlayerColor playerColor); void gamePlayGameOverHandler(PlayerColor winner); diff --git a/core/players/ai.cc b/core/players/ai.cc index 66a820f..55d0e00 100644 --- a/core/players/ai.cc +++ b/core/players/ai.cc @@ -3,17 +3,29 @@ #include #include #include +#include #include #include #include "core/gameplay.h" +Ai::~Ai() +{ + // 善后,让本对象析构之前所有的 slotNextMove 执行完毕 + std::lock_guard lock(m_processing); +} + void Ai::slotNextMove(const GamePlay::CheckerBoard &game, GamePlay::PlayerColor playerColor) { Q_UNUSED(game); + m_processing.lock(); + if (m_game == nullptr) + { + m_processing.unlock(); return; + } // 设置延时,同时不失去主进程的响应 QTimer t; @@ -37,11 +49,16 @@ void Ai::slotNextMove(const GamePlay::CheckerBoard &game, GamePlay::PlayerColor } if (availPositions.empty()) + { + m_processing.unlock(); return; + } std::mt19937 rng; rng.seed(time(nullptr)); std::uniform_int_distribution randomDist(0, availPositions.size() - 1); + m_processing.unlock(); + emit sigMoved(availPositions.at(randomDist(rng))); } diff --git a/core/players/ai.h b/core/players/ai.h index f57794a..a6beea2 100644 --- a/core/players/ai.h +++ b/core/players/ai.h @@ -1,6 +1,8 @@ #ifndef AI_H #define AI_H +#include + #include "core/players/virtualplayer.h" #include "core/gameplay.h" @@ -13,6 +15,7 @@ class Ai : public VirtualPlayer public: using VirtualPlayer::VirtualPlayer; + ~Ai() override; /// \brief 设置游戏 void setGame(GamePlay* game); @@ -28,6 +31,7 @@ public slots: private: GamePlay* m_game; + std::mutex m_processing; }; inline void Ai::setGame(GamePlay *game) diff --git a/ui/mainwindow.cc b/ui/mainwindow.cc index d4b7348..8c12c40 100644 --- a/ui/mainwindow.cc +++ b/ui/mainwindow.cc @@ -57,7 +57,7 @@ void MainWindow::initSignalsAndSlots() // battle and mainwindow connect(m_battle, &Battle::sigBattleEnded, this, &MainWindow::showWinnerInfo); - connect(m_battle, &Battle::sigChanged, this, &MainWindow::updateStatusBar); + connect(m_battle, &Battle::sigChanged, this, &MainWindow::battleChangedHandler); } void MainWindow::startNewGame() @@ -82,16 +82,19 @@ void MainWindow::showWinnerInfo(GamePlay::PlayerColor winner) mb->show(); } -void MainWindow::updateStatusBar() +void MainWindow::battleChangedHandler() { if (m_battle->isBattleRunning()) { + m_startGame->setEnabled(false); + m_stopGame->setEnabled(true); QString currentPlayerName = m_battle->getPlayer(m_battle->currentPlayerColor())->getName(); statusBar()->showMessage("请 " + currentPlayerName + " 下子", 0); } else { - + m_startGame->setEnabled(true); + m_stopGame->setEnabled(false); statusBar()->showMessage("开始一场新游戏", 0); } } diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 8410a30..cbdaa64 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -36,7 +36,7 @@ private slots: /// 这个函数弹出一个对话框并显示出胜利方,其中包含一些必要的信息,比如胜者的昵称等。 void showWinnerInfo(GamePlay::PlayerColor winner); /// \brief 更新状态栏。 - void updateStatusBar(); + void battleChangedHandler(); private: // 游戏 From e80b3108f3ed5fb49d4fdf2e0b79606be40d8448 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Mon, 3 Dec 2018 22:54:31 +0800 Subject: [PATCH 07/12] improve user interaction experience Decrease timeout of changing stone's color. --- ui/checkerboard/boardgrid.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/checkerboard/boardgrid.cc b/ui/checkerboard/boardgrid.cc index d45c937..8a64d3b 100644 --- a/ui/checkerboard/boardgrid.cc +++ b/ui/checkerboard/boardgrid.cc @@ -38,7 +38,7 @@ void BoardGrid::setStoneColor(GamePlay::PlayerColor role) m_playerColor = role; if (old != role && old != GamePlay::Unknown && role != GamePlay::Unknown) { - m_updateTimer->setInterval(400); + m_updateTimer->setInterval(300); } else { From d48a298805c14ddcb1566f2017419bbd307ddec2 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Mon, 3 Dec 2018 23:40:23 +0800 Subject: [PATCH 08/12] fix: base class should have virtual destructor --- core/players/virtualplayer.cc | 5 +++++ core/players/virtualplayer.h | 1 + 2 files changed, 6 insertions(+) diff --git a/core/players/virtualplayer.cc b/core/players/virtualplayer.cc index bb75561..77e3717 100644 --- a/core/players/virtualplayer.cc +++ b/core/players/virtualplayer.cc @@ -5,3 +5,8 @@ VirtualPlayer::VirtualPlayer(QString name, QObject *parent) { } + +VirtualPlayer::~VirtualPlayer() +{ + +} diff --git a/core/players/virtualplayer.h b/core/players/virtualplayer.h index ef7738b..bca449d 100644 --- a/core/players/virtualplayer.h +++ b/core/players/virtualplayer.h @@ -20,6 +20,7 @@ class VirtualPlayer : public QObject /// \param name 名字。 /// \param parent 父控件。 explicit VirtualPlayer(QString name, QObject *parent = nullptr); + virtual ~VirtualPlayer(); /// \brief 获取名字。 /// \return 玩家的名字。 From 719d42a0f6d556097e45adb206baa4fbbf8882f7 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Tue, 2 Apr 2019 20:22:46 +0800 Subject: [PATCH 09/12] fix: solved problem that d96e65b and 9b7141a had tried to sovle --- core/battle.cc | 8 ++++++-- core/battle.h | 3 +++ core/players/ai.cc | 13 +------------ core/players/ai.h | 1 - core/players/virtualplayer.h | 3 +++ 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/core/battle.cc b/core/battle.cc index 9c0448f..c6d302e 100644 --- a/core/battle.cc +++ b/core/battle.cc @@ -6,6 +6,8 @@ Battle::Battle(QObject *parent) : QObject(parent), m_gamePlay(this), + m_blackAiPlayer(std::make_shared("", this)), + m_whiteAiPlayer(std::make_shared("", this)), m_playerBlack(nullptr), m_playerWhile(nullptr) { @@ -51,7 +53,8 @@ void Battle::startNewBattle(Battle::PlayerType blackPlayerType, Battle::PlayerTy m_playerBlack = std::make_shared(blackPlayerName, this); break; case Ai: - m_playerBlack = std::make_shared(blackPlayerName, this); + m_playerBlack = m_blackAiPlayer; + m_playerBlack->setName(blackPlayerName); dynamic_cast(*m_playerBlack).setGame(&m_gamePlay); break; } @@ -60,7 +63,8 @@ void Battle::startNewBattle(Battle::PlayerType blackPlayerType, Battle::PlayerTy m_playerWhile = std::make_shared(whitePlayerName, this); break; case Ai: - m_playerWhile = std::make_shared(whitePlayerName, this); + m_playerWhile = m_whiteAiPlayer; + m_playerWhile->setName(whitePlayerName); dynamic_cast(*m_playerWhile).setGame(&m_gamePlay); break; } diff --git a/core/battle.h b/core/battle.h index b4dff40..eb124db 100644 --- a/core/battle.h +++ b/core/battle.h @@ -5,6 +5,7 @@ #include "core/gameplay.h" #include "core/players/virtualplayer.h" +#include "core/players/ai.h" #include @@ -89,6 +90,8 @@ public slots: private: GamePlay m_gamePlay; + std::shared_ptr m_blackAiPlayer; + std::shared_ptr m_whiteAiPlayer; std::shared_ptr m_playerBlack; std::shared_ptr m_playerWhile; diff --git a/core/players/ai.cc b/core/players/ai.cc index 55d0e00..20ec854 100644 --- a/core/players/ai.cc +++ b/core/players/ai.cc @@ -12,20 +12,14 @@ Ai::~Ai() { - // 善后,让本对象析构之前所有的 slotNextMove 执行完毕 - std::lock_guard lock(m_processing); } void Ai::slotNextMove(const GamePlay::CheckerBoard &game, GamePlay::PlayerColor playerColor) { - Q_UNUSED(game); - m_processing.lock(); + Q_UNUSED(game) if (m_game == nullptr) - { - m_processing.unlock(); return; - } // 设置延时,同时不失去主进程的响应 QTimer t; @@ -49,16 +43,11 @@ void Ai::slotNextMove(const GamePlay::CheckerBoard &game, GamePlay::PlayerColor } if (availPositions.empty()) - { - m_processing.unlock(); return; - } std::mt19937 rng; rng.seed(time(nullptr)); std::uniform_int_distribution randomDist(0, availPositions.size() - 1); - m_processing.unlock(); - emit sigMoved(availPositions.at(randomDist(rng))); } diff --git a/core/players/ai.h b/core/players/ai.h index a6beea2..1903c37 100644 --- a/core/players/ai.h +++ b/core/players/ai.h @@ -31,7 +31,6 @@ public slots: private: GamePlay* m_game; - std::mutex m_processing; }; inline void Ai::setGame(GamePlay *game) diff --git a/core/players/virtualplayer.h b/core/players/virtualplayer.h index bca449d..4f126d0 100644 --- a/core/players/virtualplayer.h +++ b/core/players/virtualplayer.h @@ -25,6 +25,9 @@ class VirtualPlayer : public QObject /// \brief 获取名字。 /// \return 玩家的名字。 QString getName() { return m_name; } + /// \brief 设置名字。 + /// \return 玩家的名字。 + void setName(const QString &name) { m_name = name; } public slots: /// \brief 通知玩家下子。 From 551021022dd65c634c4f350ef432496c43d6a804 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Wed, 3 Apr 2019 17:04:30 +0800 Subject: [PATCH 10/12] chore(cmake): migrate to cmake build system --- .gitignore | 19 ++++++++++++++++ CMakeLists.txt | 36 +++++++++++++++++++++++++++++ QReversi.pro | 61 -------------------------------------------------- 3 files changed, 55 insertions(+), 61 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 QReversi.pro diff --git a/.gitignore b/.gitignore index 5291a38..0354e69 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,22 @@ target_wrapper.* # QtCreator CMake CMakeLists.txt.user* + +# CMake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +# CMake automoc +/*_autogen + +# compilation database +compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e4312c5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.1...3.14) + +if(${CMAKE_VERSION} VERSION_LESS 3.12) + cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) +endif() + +project(QReversi) + +find_package(Qt5Widgets REQUIRED) + +set(CMAKE_CXX_STANDARD 11) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) + +set(SOURCES + main.cc + core/battle.cc + core/gameplay.cc + core/players/ai.cc + core/players/human.cc + core/players/virtualplayer.cc + ui/mainwindow.cc + ui/newgamedialog.cc + ui/checkerboard/boardlayout.cc + ui/checkerboard/checkerboardwidget.cc + ui/checkerboard/boardgrid.cc + ui/newgamedialog.ui + resources.qrc +) + +add_executable(qreversi ${SOURCES}) +target_link_libraries(qreversi Qt5::Widgets) diff --git a/QReversi.pro b/QReversi.pro deleted file mode 100644 index 16bd137..0000000 --- a/QReversi.pro +++ /dev/null @@ -1,61 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2018-11-05T23:17:01 -# -#------------------------------------------------- - -QT += core gui - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = QReversi -TEMPLATE = app - -# The following define makes your compiler emit warnings if you use -# any feature of Qt which has been marked as deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -CONFIG += c++11 - -SOURCES += \ - main.cc \ - core/players/ai.cc \ - core/players/human.cc \ - core/players/virtualplayer.cc \ - core/battle.cc \ - core/gameplay.cc \ - ui/mainwindow.cc \ - ui/checkerboard/boardlayout.cc \ - ui/checkerboard/checkerboardwidget.cc \ - ui/checkerboard/boardgrid.cc \ - ui/newgamedialog.cc - -HEADERS += \ - ui/mainwindow.h \ - ui/checkerboard/boardlayout.h \ - ui/checkerboard/checkerboardwidget.h \ - core/players/ai.h \ - core/players/human.h \ - core/players/virtualplayer.h \ - core/battle.h \ - core/gameplay.h \ - ui/checkerboard/boardgrid.h \ - ui/newgamedialog.h - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - -FORMS += \ - ui/newgamedialog.ui - -RESOURCES += \ - resources.qrc From ced7346772555e5bc0e5231f11d2f6646145e133 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Wed, 3 Apr 2019 18:45:07 +0800 Subject: [PATCH 11/12] chore(travis-ci): add Travis CI --- .travis.yml | 14 ++++++++++++++ README.md | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..66b7e37 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: cpp + +dist: xenial + +addons: + apt: + update: true + +before_install: + - sudo apt-get install -y qt5-default + +script: + - cmake . + - make -j2 diff --git a/README.md b/README.md index ea9d61d..cdc7a9a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # QReversi +[![Build Status](https://travis-ci.org/X1aomu/QReversi.svg?branch=master)](https://travis-ci.org/X1aomu/QReversi) + A Qt-based reversi game From 1ee06129e17ea43c424db5291d028ffd958ec8b5 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Wed, 3 Apr 2019 18:56:01 +0800 Subject: [PATCH 12/12] doc(README.md): add release badge --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cdc7a9a..6d5b6d5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # QReversi -[![Build Status](https://travis-ci.org/X1aomu/QReversi.svg?branch=master)](https://travis-ci.org/X1aomu/QReversi) +[![Build Status](https://travis-ci.org/X1aomu/QReversi.svg)](https://travis-ci.org/X1aomu/QReversi) +[![GitHub release](https://img.shields.io/github/X1aomu/QReversi.svg)](https://github.com/X1aomu/QReversi/releases) A Qt-based reversi game