summaryrefslogtreecommitdiff
path: root/quacker/macondo.cpp
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-08-15 12:13:27 -0400
committerpommicket <pommicket@gmail.com>2025-08-15 12:13:27 -0400
commit0c53cb08d8032687887802f1352c6409326e5d6a (patch)
tree17d3a85235b5a8ff9d8f743075db69dabf1b9743 /quacker/macondo.cpp
parent1bc6551758fd772d48d24ffdd3c49840f9fe371d (diff)
Start endgame solving
Diffstat (limited to 'quacker/macondo.cpp')
-rw-r--r--quacker/macondo.cpp40
1 files changed, 37 insertions, 3 deletions
diff --git a/quacker/macondo.cpp b/quacker/macondo.cpp
index a07eb4a..f92f89b 100644
--- a/quacker/macondo.cpp
+++ b/quacker/macondo.cpp
@@ -1,6 +1,9 @@
/*
TODO:
- configurable execPath
+- detect Macondo crashing?
+- stop Macondo solve when game position changes
+- configurable max plies
*/
#include "macondo.h"
@@ -12,16 +15,20 @@ TODO:
Macondo::Macondo(Quackle::Game *game) : View() {
m_game = game;
- QGridLayout *layout = new QGridLayout(this);
m_useMacondo = new QCheckBox(tr("Use Macondo for 'Simulate'"));
- layout->setAlignment(Qt::AlignTop);
- layout->addWidget(m_useMacondo, 0, 0);
const char *home = getenv("HOME");
std::string execPath = home ? home : "/";
execPath += "/apps/macondo/macondo";
initOptions = std::make_unique<MacondoInitOptions>(execPath);
m_backend = new MacondoBackend(game, *initOptions);
connect(m_backend, SIGNAL(gotSimMoves(const Quackle::MoveList &)), this, SLOT(gotSimMoves(const Quackle::MoveList &)));
+ m_solve = new QPushButton(tr("Solve"));
+ m_solve->setDisabled(true);
+ QGridLayout *layout = new QGridLayout(this);
+ layout->setAlignment(Qt::AlignTop);
+ layout->addWidget(m_useMacondo, 0, 0);
+ layout->addWidget(m_solve, 1, 0);
+ connect(m_solve, SIGNAL(clicked()), this, SLOT(solve()));
}
Macondo::~Macondo() {
@@ -36,6 +43,21 @@ void Macondo::simulate() {
m_backend->simulate(options, m_movesFromKibitzer);
}
+void Macondo::solve() {
+ bool wasSolving = m_isSolving;
+ if (m_backend->isRunning())
+ stop();
+ clearMoves();
+ if (wasSolving) {
+ m_solve->setText(tr("Solve"));
+ } else {
+ MacondoSolveOptions options;
+ m_backend->solve(options);
+ m_solve->setText(tr("Stop"));
+ m_isSolving = true;
+ }
+}
+
void Macondo::gameChanged(Quackle::Game *game) {
delete m_backend;
m_backend = new MacondoBackend(game, *initOptions);
@@ -45,6 +67,7 @@ void Macondo::gameChanged(Quackle::Game *game) {
void Macondo::stop() {
m_backend->stop();
m_anyUpdates = false;
+ m_isSolving = false;
}
bool Macondo::useForSimulation() const {
@@ -60,5 +83,16 @@ void Macondo::positionChanged(const Quackle::GamePosition *position) {
if (!m_backend->isRunning()) {
// perhaps new moves were generated
m_movesFromKibitzer = position->moves();
+ }
+ int tilesLeft = position->unseenBag().size();
+ if (!position->gameOver() && tilesLeft <= 7) {
+ m_solve->setText(tr("Solve endgame"));
+ m_solve->setDisabled(false);
+ } else if (!position->gameOver() && tilesLeft <= 10) {
+ m_solve->setText(tr("Solve pre-endgame"));
+ m_solve->setDisabled(false);
+ } else {
+ m_solve->setText(tr("Solve"));
+ m_solve->setDisabled(true);
}
}