diff options
author | pommicket <pommicket@gmail.com> | 2025-08-07 23:28:56 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-08-07 23:28:56 -0400 |
commit | ac2586a851f8c5aa30d77274f441282c29e9e56d (patch) | |
tree | 295a3afb21135bffa72aab2603731039908a66d9 /quacker/macondo.cpp | |
parent | af95032f803d6e74e704aa4ed9aafad71f389f4f (diff) |
give turn number to macondo
Diffstat (limited to 'quacker/macondo.cpp')
-rw-r--r-- | quacker/macondo.cpp | 48 |
1 files changed, 43 insertions, 5 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(); + } +} |