diff options
Diffstat (limited to 'quacker')
-rw-r--r-- | quacker/macondo.cpp | 30 | ||||
-rw-r--r-- | quacker/macondo.h | 12 | ||||
-rw-r--r-- | quacker/macondobackend.cpp | 12 | ||||
-rw-r--r-- | quacker/macondobackend.h | 28 | ||||
-rw-r--r-- | quacker/quacker.cpp | 3 |
5 files changed, 55 insertions, 30 deletions
diff --git a/quacker/macondo.cpp b/quacker/macondo.cpp index 8c53beb..c089b42 100644 --- a/quacker/macondo.cpp +++ b/quacker/macondo.cpp @@ -1,33 +1,49 @@ #include "macondo.h" #include "macondobackend.h" +#include "movebox.h" #include "quacker.h" #include <QGridLayout> #include <QPushButton> Macondo::Macondo(Quackle::Game *game) : QWidget() { + m_game = game; QGridLayout *layout = new QGridLayout(this); + m_moveBox = new MoveBox; m_simulateButton = new QPushButton(tr("Simulate")); - layout->addWidget(m_simulateButton, 0, 0); layout->setAlignment(Qt::AlignTop); + layout->addWidget(m_simulateButton, 0, 0); + layout->addWidget(m_moveBox, 1, 0); const char *home = getenv("HOME"); // TODO: configurable path std::string execPath = home ? home : "/"; execPath += "/apps/macondo/macondo"; - MacondoBackend::InitOptions initOptions(execPath); - m_backend = new MacondoBackend(game, initOptions); + initOptions = std::make_unique<MacondoInitOptions>(execPath); + m_backend = new MacondoBackend(game, *initOptions); connect(m_simulateButton, SIGNAL(clicked()), this, SLOT(simulate())); - connect(m_backend, SIGNAL(gotSimMoves(const std::vector<Quackle::Move> &)), this, SLOT(gotSimMoves(const std::vector<Quackle::Move> &))); + connect(m_backend, SIGNAL(gotSimMoves(const Quackle::MoveList &)), this, SLOT(gotSimMoves(const Quackle::MoveList &))); } +Macondo::~Macondo() {} + void Macondo::simulate() { - MacondoBackend::SimulateOptions options; + MacondoSimulateOptions options; m_backend->simulate(options); + m_moveBox->positionChanged(&m_game->currentPosition()); +} + + +void Macondo::setGame(Quackle::Game *game) { + delete m_backend; + m_backend = new MacondoBackend(game, *initOptions); + m_game = game; } -void Macondo::gotSimMoves(const std::vector<Quackle::Move> &moves) { - printf("got %zu moves\n",moves.size()); +void Macondo::gotSimMoves(const Quackle::MoveList &moves) { + m_moveBox->movesChanged(&moves); + /*printf("got %zu moves\n",moves.size()); for (const Quackle::Move &move: moves) { std::cout << move << std::endl; } + */ } diff --git a/quacker/macondo.h b/quacker/macondo.h index 82505d5..18441b5 100644 --- a/quacker/macondo.h +++ b/quacker/macondo.h @@ -7,18 +7,21 @@ class QPushButton; class QTimer; namespace Quackle { class Game; - class Move; + class MoveList; } class MacondoBackend; - +struct MacondoInitOptions; +class MoveBox; class Macondo : public QWidget { Q_OBJECT public: Macondo(Quackle::Game *); + ~Macondo(); + void setGame(Quackle::Game *); public slots: void simulate(); private slots: - void gotSimMoves(const std::vector<Quackle::Move> &moves); + void gotSimMoves(const Quackle::MoveList &moves); private: enum class Command { None, @@ -26,9 +29,12 @@ private: Solve, }; QPushButton *m_simulateButton; + Quackle::Game *m_game; MacondoBackend *m_backend; int m_viewingPlyNumber = 0; Command m_command = Command::None; + MoveBox *m_moveBox; + std::unique_ptr<MacondoInitOptions> initOptions; }; #endif diff --git a/quacker/macondobackend.cpp b/quacker/macondobackend.cpp index 33b8a78..d109d53 100644 --- a/quacker/macondobackend.cpp +++ b/quacker/macondobackend.cpp @@ -55,7 +55,7 @@ static string trimLeft(const string &s) { } -MacondoBackend::MacondoBackend(Quackle::Game *game, const InitOptions &options) { +MacondoBackend::MacondoBackend(Quackle::Game *game, const MacondoInitOptions &options) { m_execPath = options.execPath; m_game = game; m_updateTimer = new QTimer(this); @@ -64,7 +64,7 @@ MacondoBackend::MacondoBackend(Quackle::Game *game, const InitOptions &options) m_updateTimer->start(); } -void MacondoBackend::simulate(const SimulateOptions &) { +void MacondoBackend::simulate(const MacondoSimulateOptions &) { if (m_process) return; printf("running macondo %s\n", m_execPath.c_str()); m_process = new QProcess(this); @@ -142,6 +142,7 @@ static Quackle::Move extractSimMove(const string &play) { const string &winString = words[3 + !plays7]; const string &equityString = words[4 + !plays7]; Quackle::Move move = Quackle::Move::createExchangeMove(QUACKLE_ALPHABET_PARAMETERS->encode(tiles), false); + move.setPrettyTiles(QUACKLE_ALPHABET_PARAMETERS->encode(tiles)); move.win = parseWinRate(winString); move.equity = parseEquity(equityString); return move; @@ -165,6 +166,7 @@ static Quackle::Move extractSimMove(const string &play) { i++; } Quackle::Move move = Quackle::Move::createPlaceMove(placement, QUACKLE_ALPHABET_PARAMETERS->encode(dotDescription)); + move.setPrettyTiles(QUACKLE_ALPHABET_PARAMETERS->encode(description)); move.score = parseScore(scoreString); move.win = parseWinRate(winString); move.equity = parseEquity(equityString); @@ -174,8 +176,8 @@ static Quackle::Move extractSimMove(const string &play) { } // extract Quackle::Move from Macondo's sim output -static vector<Quackle::Move> extractSimMoves(QByteArray &processOutput) { - vector<Quackle::Move> moves; +static Quackle::MoveList extractSimMoves(QByteArray &processOutput) { + Quackle::MoveList moves; QByteArray playsStartIdentifier("Play Leave Score Win% Equity"); QByteArray playsEndIdentifier("Iterations:"); int start = processOutput.indexOf(playsStartIdentifier) + playsStartIdentifier.length(); @@ -212,7 +214,7 @@ void MacondoBackend::timer() { m_process->write("sim show\n"); } { - vector<Quackle::Move> moves = extractSimMoves(m_processOutput); + Quackle::MoveList moves = extractSimMoves(m_processOutput); if (!moves.empty()) { // at this point the GCG is definitely fully loaded removeTempGCG(); diff --git a/quacker/macondobackend.h b/quacker/macondobackend.h index 6e88521..f61ae11 100644 --- a/quacker/macondobackend.h +++ b/quacker/macondobackend.h @@ -6,29 +6,31 @@ namespace Quackle { class Game; class Move; + class MoveList; } class QTimer; +struct MacondoInitOptions { + inline MacondoInitOptions(std::string execPath) { + this->execPath = execPath; + } + std::string execPath; +}; +struct MacondoSimulateOptions { + inline MacondoSimulateOptions() {} +}; + class MacondoBackend: public QObject { Q_OBJECT public: - struct InitOptions { - inline InitOptions(std::string execPath) { - this->execPath = execPath; - } - std::string execPath; - }; - MacondoBackend(Quackle::Game *game, const InitOptions &); - struct SimulateOptions { - inline SimulateOptions() {} - }; - void simulate(const SimulateOptions &); + MacondoBackend(Quackle::Game *game, const MacondoInitOptions &); + void simulate(const MacondoSimulateOptions &); ~MacondoBackend(); std::string getSimResults(); signals: - void gotSimMoves(const std::vector<Quackle::Move> &moves); -protected slots: + void gotSimMoves(const Quackle::MoveList &moves); +private slots: void processStarted(); void processFinished(int, QProcess::ExitStatus); void timer(); diff --git a/quacker/quacker.cpp b/quacker/quacker.cpp index 3502c3a..c386968 100644 --- a/quacker/quacker.cpp +++ b/quacker/quacker.cpp @@ -1295,8 +1295,7 @@ void TopLevel::loadFile(const QString &filename) QTextStream stream(&file); delete m_game; m_game = logania->read(stream, QuackleIO::Logania::MaintainBoardPreparation); - delete m_macondo; - m_macondo = new Macondo(m_game); + m_macondo->setGame(m_game); file.close(); |