summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-08-07 23:28:56 -0400
committerpommicket <pommicket@gmail.com>2025-08-07 23:28:56 -0400
commitac2586a851f8c5aa30d77274f441282c29e9e56d (patch)
tree295a3afb21135bffa72aab2603731039908a66d9
parentaf95032f803d6e74e704aa4ed9aafad71f389f4f (diff)
give turn number to macondo
-rw-r--r--quacker/macondo.cpp48
-rw-r--r--quacker/macondo.h17
-rw-r--r--quacker/quacker.cpp5
3 files changed, 58 insertions, 12 deletions
diff --git a/quacker/macondo.cpp b/quacker/macondo.cpp
index eda49e3..70687ef 100644
--- a/quacker/macondo.cpp
+++ b/quacker/macondo.cpp
@@ -7,7 +7,7 @@
#include <QTimer>
#include <random>
-Macondo::Macondo(TopLevel *topLevel) : QWidget() {
+Macondo::Macondo(TopLevel *topLevel) : View() {
m_topLevel = topLevel;
m_updateTimer = new QTimer(this);
QGridLayout *layout = new QGridLayout(this);
@@ -30,10 +30,30 @@ void Macondo::run() {
QStringList args;
m_process->start(m_execPath.c_str(), args);
connect(m_process, SIGNAL(started()), this, SLOT(processStarted()));
+ connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus)));
}
void Macondo::processStarted() {
m_updateTimer->start();
+ loadGCG();
+}
+
+void Macondo::killProcess() {
+ if (m_process) {
+ m_process->kill();
+ }
+}
+
+void Macondo::processFinished(int, QProcess::ExitStatus) {
+ delete m_process;
+ m_process = nullptr;
+}
+
+Macondo::~Macondo() {
+ killProcess();
+}
+
+void Macondo::loadGCG() {
std::default_random_engine rand;
std::uniform_int_distribution<int> distribution(0, 26);
// save game file with random name
@@ -44,10 +64,10 @@ void Macondo::processStarted() {
}
}
m_topLevel->writeFile(filename);
- std::string command = "load ";
- command += filename;
- command += "\n";
- m_process->write(command.c_str());
+ std::stringstream commands;
+ commands << "load " << filename << "\n"
+ << "turn " << plyNumber << "\n";
+ m_process->write(commands.str().c_str());
}
void Macondo::updateResults() {
@@ -58,3 +78,21 @@ void Macondo::updateResults() {
printf("%s", data.constData());
fflush(stdout);
}
+
+void Macondo::positionChanged(const Quackle::GamePosition *position) {
+ int playerIndex = 0, numPlayers = position->players().size();
+ for (const Quackle::Player &player: position->players()) {
+ if (player.id() == position->playerOnTurn().id()) {
+ break;
+ }
+ playerIndex++;
+ }
+ if (playerIndex >= numPlayers) {
+ throw "couldn't find player in player list";
+ }
+ plyNumber = (position->turnNumber() - 1) * numPlayers
+ + playerIndex;
+ if (m_process && m_process->state() != QProcess::Starting) {
+ loadGCG();
+ }
+}
diff --git a/quacker/macondo.h b/quacker/macondo.h
index 2490e2f..d72a03d 100644
--- a/quacker/macondo.h
+++ b/quacker/macondo.h
@@ -1,26 +1,31 @@
+#include <QProcess>
#include <QWidget>
-#include "game.h"
+
+#include "view.h"
+
class QPushButton;
-class QProcess;
class QTimer;
class TopLevel;
-class Macondo : public QWidget {
+class Macondo : public View {
Q_OBJECT
public:
Macondo(TopLevel *topLevel);
+ ~Macondo();
public slots:
void run();
void updateResults();
void processStarted();
- void movesUpdated(Quackle::MoveList *moves);
- inline void setGame(Quackle::Game *game) { m_game = game; }
+ void processFinished(int, QProcess::ExitStatus);
+ virtual void positionChanged(const Quackle::GamePosition *position);
private:
+ void loadGCG();
+ void killProcess();
TopLevel *m_topLevel;
QPushButton *m_runButton;
QTimer *m_updateTimer;
std::string m_execPath;
QProcess *m_process = nullptr;
- Quackle::Game *m_game = nullptr;
+ int plyNumber = 0;
};
diff --git a/quacker/quacker.cpp b/quacker/quacker.cpp
index e9a8549..af50d2f 100644
--- a/quacker/quacker.cpp
+++ b/quacker/quacker.cpp
@@ -68,7 +68,6 @@ TopLevel::TopLevel(QWidget *parent)
qRegisterMetaType<OppoThread*>("OppoThread*");
m_quackerSettings = new QuackerSettings;
- m_macondo = new Macondo(this);
m_settings = new Settings;
m_settings->preInitialize();
m_settings->createGUI();
@@ -2002,6 +2001,10 @@ void TopLevel::createWidgets()
m_history = new History;
plugIntoHistoryMatrix(m_history);
+ m_macondo = new Macondo(this);
+ plugIntoMatrix(m_macondo);
+ plugIntoPositionMatrix(m_macondo);
+
m_tabWidget = new QTabWidget;
m_tabWidget->addTab(m_history, tr("Histor&y"));
m_tabWidget->addTab(m_choicesWidget, tr("&Choices"));