blob: 3feb80d3903b40771e5e71a2e5370454131a4c9e (
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
65
66
67
68
69
70
71
|
#ifndef MACONDO_BACKEND_H
#define MACONDO_BACKEND_H
#include <QProcess>
#include "game.h"
class QTimer;
struct MacondoInitOptions {
inline MacondoInitOptions(std::string execPath) {
this->execPath = execPath;
}
std::string execPath;
};
struct MacondoSimulateOptions {
inline MacondoSimulateOptions() {}
};
struct MacondoEndgameOptions {
inline MacondoEndgameOptions() {}
};
struct MacondoPreEndgameOptions {
inline MacondoPreEndgameOptions() {}
};
class MacondoBackend: public QObject {
Q_OBJECT
public:
MacondoBackend(Quackle::Game *game, const MacondoInitOptions &);
~MacondoBackend();
void simulate(const MacondoSimulateOptions &options, const Quackle::MoveList &moves);
void solveEndgame(const MacondoEndgameOptions &options);
void solvePreEndgame(const MacondoPreEndgameOptions &options);
std::string getSimResults();
inline bool isRunning() const { return m_command != Command::None; }
// stop current Macondo analysis
void stop();
signals:
void gotMoves(const Quackle::MoveList &moves);
void statusMessage(const QString &message);
private slots:
void processStarted();
void processFinished(int, QProcess::ExitStatus);
void timer();
private:
enum class Command {
None,
Simulate,
SolvePreEndgame,
SolveEndgame,
};
void startProcess();
void loadGCG();
void killProcess();
void removeTempGCG();
const char *updateDots(bool);
std::string m_execPath;
std::string m_tempGCG;
QProcess *m_process = nullptr;
QTimer *m_updateTimer = nullptr;
int m_solveStatusDots = 3;
int m_preEndgamePlaysToAnalyze = 0;
// is simulation being run right now? (i.e. has process been started & game been loaded?)
bool m_runningSimulation = false;
Quackle::Game *m_game;
QByteArray m_processOutput;
QByteArray m_processStderr;
Command m_command = Command::None;
Quackle::MoveList m_movesToLoad;
};
#endif
|