diff options
-rw-r--r-- | quacker/macondo.cpp | 19 | ||||
-rw-r--r-- | quacker/macondo.h | 8 | ||||
-rw-r--r-- | quacker/quacker.cpp | 2 |
3 files changed, 25 insertions, 4 deletions
diff --git a/quacker/macondo.cpp b/quacker/macondo.cpp index 476d41b..eda49e3 100644 --- a/quacker/macondo.cpp +++ b/quacker/macondo.cpp @@ -5,8 +5,10 @@ #include <QPushButton> #include <QProcess> #include <QTimer> +#include <random> -Macondo::Macondo(QWidget *parent) : QWidget(parent) { +Macondo::Macondo(TopLevel *topLevel) : QWidget() { + m_topLevel = topLevel; m_updateTimer = new QTimer(this); QGridLayout *layout = new QGridLayout(this); m_runButton = new QPushButton(tr("Run")); @@ -32,7 +34,20 @@ void Macondo::run() { void Macondo::processStarted() { m_updateTimer->start(); - m_process->write("help\n"); + std::default_random_engine rand; + std::uniform_int_distribution<int> distribution(0, 26); + // save game file with random name + char filename[] = "tmpGameXXXXXXXXXXXX.gcg"; + for (int i = 0; filename[i]; i++) { + if (filename[i] == 'X') { + filename[i] = distribution(rand) + 'A'; + } + } + m_topLevel->writeFile(filename); + std::string command = "load "; + command += filename; + command += "\n"; + m_process->write(command.c_str()); } void Macondo::updateResults() { diff --git a/quacker/macondo.h b/quacker/macondo.h index e6eb749..2490e2f 100644 --- a/quacker/macondo.h +++ b/quacker/macondo.h @@ -1,20 +1,26 @@ #include <QWidget> +#include "game.h" class QPushButton; class QProcess; class QTimer; +class TopLevel; class Macondo : public QWidget { Q_OBJECT public: - explicit Macondo(QWidget *parent = 0); + Macondo(TopLevel *topLevel); public slots: void run(); void updateResults(); void processStarted(); + void movesUpdated(Quackle::MoveList *moves); + inline void setGame(Quackle::Game *game) { m_game = game; } private: + TopLevel *m_topLevel; QPushButton *m_runButton; QTimer *m_updateTimer; std::string m_execPath; QProcess *m_process = nullptr; + Quackle::Game *m_game = nullptr; }; diff --git a/quacker/quacker.cpp b/quacker/quacker.cpp index 0270302..e9a8549 100644 --- a/quacker/quacker.cpp +++ b/quacker/quacker.cpp @@ -68,7 +68,7 @@ TopLevel::TopLevel(QWidget *parent) qRegisterMetaType<OppoThread*>("OppoThread*"); m_quackerSettings = new QuackerSettings; - m_macondo = new Macondo; + m_macondo = new Macondo(this); m_settings = new Settings; m_settings->preInitialize(); m_settings->createGUI(); |