summaryrefslogtreecommitdiff
path: root/quacker/macondo.cpp
blob: a07eb4a1b2b8f84406a5b6854b93f399c295280d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
TODO:
- configurable execPath
*/

#include "macondo.h"
#include "macondobackend.h"

#include <QGridLayout>
#include <QPushButton>
#include <QCheckBox>

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 &)));
}

Macondo::~Macondo() {
	delete m_backend;
}

void Macondo::simulate() {
	if (m_backend->isRunning())
		stop();
	clearMoves();
	MacondoSimulateOptions options;
	m_backend->simulate(options, m_movesFromKibitzer);
}

void Macondo::gameChanged(Quackle::Game *game) {
	delete m_backend;
	m_backend = new MacondoBackend(game, *initOptions);
	m_game = game;
}

void Macondo::stop() {
	m_backend->stop();
	m_anyUpdates = false;
}

bool Macondo::useForSimulation() const {
	return m_useMacondo->isChecked();
}

void Macondo::gotSimMoves(const Quackle::MoveList &moves) {
	m_moves = moves;
	m_anyUpdates = true;
}

void Macondo::positionChanged(const Quackle::GamePosition *position) {
	if (!m_backend->isRunning()) {
		// perhaps new moves were generated
		m_movesFromKibitzer = position->moves();
	}
}