summaryrefslogtreecommitdiff
path: root/quacker
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-08-24 15:55:08 -0400
committerpommicket <pommicket@gmail.com>2025-08-24 15:55:08 -0400
commitd862a46709d4cf4fabcaeeb0cb6a7bbc4fb4da26 (patch)
tree21c1c4c5903c1d3091f6d2b88e83772c017a2d4a /quacker
parentc4db2f06cbfd002d8ef89f783787f7910bee5bb9 (diff)
fix windows line endings maybe?
Diffstat (limited to 'quacker')
-rw-r--r--quacker/macondo.cpp8
-rw-r--r--quacker/macondobackend.cpp44
-rw-r--r--quacker/macondobackend.h3
3 files changed, 45 insertions, 10 deletions
diff --git a/quacker/macondo.cpp b/quacker/macondo.cpp
index 49f8959..84f7bda 100644
--- a/quacker/macondo.cpp
+++ b/quacker/macondo.cpp
@@ -22,6 +22,10 @@ TODO:
#include "customqsettings.h"
+static bool isWindows() {
+ return QOperatingSystemVersion::currentType() == QOperatingSystemVersion::Windows;
+}
+
// Convenience wrapper around an hbox containing a label and another widget.
class LabelLayout: public QHBoxLayout {
public:
@@ -39,7 +43,7 @@ Macondo::Macondo(Quackle::Game *game) : View() {
m_useMacondo = new QCheckBox(tr("Use Macondo for 'Simulate'"));
m_useMacondo->setChecked(settings.value("macondo/useForSimulate", false).toBool());
QString execExt = "";
- if (QOperatingSystemVersion::currentType() == QOperatingSystemVersion::Windows) {
+ if (isWindows()) {
execExt = ".exe";
}
QString defaultExecPath = QCoreApplication::applicationDirPath() + "/macondo/macondo" + execExt;
@@ -147,7 +151,7 @@ void Macondo::setExecPath(const std::string &path) {
void Macondo::chooseExecPath() {
QString filter;
- if (QOperatingSystemVersion::currentType() == QOperatingSystemVersion::Windows) {
+ if (isWindows()) {
filter = tr("Executable files (*.exe)");
}
QString path = QFileDialog::getOpenFileName(this, tr("Select Macondo executable..."), QString(), filter);
diff --git a/quacker/macondobackend.cpp b/quacker/macondobackend.cpp
index ce48290..50ea1b0 100644
--- a/quacker/macondobackend.cpp
+++ b/quacker/macondobackend.cpp
@@ -5,6 +5,7 @@
#include "game.h"
#include <QFile>
+#include <QOperatingSystemVersion>
#include <QProcess>
#include <QTimer>
#include <QTextStream>
@@ -12,6 +13,10 @@
#include <random>
#include <climits>
+static bool isWindows() {
+ return QOperatingSystemVersion::currentType() == QOperatingSystemVersion::Windows;
+}
+
// These "markers" are special parts of Macondo's standard output/error which we're looking for.
// We can change these whenever Macondo's output format changes.
static const QByteArray simPlaysStartMarker("Play Leave Score Win% Equity");
@@ -417,17 +422,40 @@ const char *MacondoBackend::updateDots(bool anythingNew) {
return dots;
}
+
+void MacondoBackend::send(const QByteArray &data) {
+ if (isWindows()) {
+ QByteArray copy;
+ copy.replace("\n", "\r\n");
+ m_process->write(copy);
+ } else {
+ m_process->write(data);
+ }
+}
+
+QByteArray MacondoBackend::receiveStdout() {
+ QByteArray data = m_process->readAllStandardOutput();
+ data.replace("\r\n", "\n");
+ return data;
+}
+
+QByteArray MacondoBackend::receiveStderr() {
+ QByteArray data = m_process->readAllStandardError();
+ data.replace("\r\n", "\n");
+ return data;
+}
+
void MacondoBackend::timer() {
bool anyNewOutput = false;
if (m_process) {
- QByteArray data = m_process->readAllStandardError();
+ QByteArray data = receiveStderr();
if (data.size()) {
anyNewOutput = true;
emit newLogOutput(data);
}
//fprintf(stderr,"%.*s",data.size(), data.constData());
m_processStderr.append(data);
- data = m_process->readAllStandardOutput();
+ data = receiveStdout();
m_processOutput.append(data);
if (data.size()) {
anyNewOutput = true;
@@ -441,7 +469,7 @@ void MacondoBackend::timer() {
break;
case Command::Simulate:
if (m_runningSimulation) {
- m_process->write("sim show\n");
+ send("sim show\n");
}
{
Quackle::MoveList moves = extractSimMoves(m_processOutput);
@@ -503,7 +531,7 @@ void MacondoBackend::timer() {
removeTempGCG();
// give Macondo a bit more time to write out the full sequence
QThread::msleep(60);
- m_processOutput.append(m_process->readAllStandardOutput());
+ m_processOutput.append(receiveStdout());
Quackle::Move move;
if (extractEndgameMove(m_processOutput, move)) {
Quackle::MoveList list;
@@ -584,7 +612,7 @@ void MacondoBackend::processStarted() {
}
commands << "sim\n";
- m_process->write(commands.str().c_str());
+ send(commands.str().c_str());
m_runningSimulation = true;
}
break;
@@ -607,7 +635,7 @@ void MacondoBackend::processStarted() {
command << "-opprack " << m_preEndgameOptions.opponentRack << " ";
}
command << "\n";
- m_process->write(command.str().c_str());
+ send(command.str().c_str());
}
break;
case Command::SolveEndgame:
@@ -618,7 +646,7 @@ void MacondoBackend::processStarted() {
command << "-prevent-slowroll " << (m_endgameOptions.preventSlowRoll ? "true" : "false") << " ";
command << "-plies " << m_endgameOptions.maxPlies << " ";
command << "\n";
- m_process->write(command.str().c_str());
+ send(command.str().c_str());
}
break;
}
@@ -654,7 +682,7 @@ void MacondoBackend::loadGCG() {
commands << "set lexicon " << lexicon << "\n"
<< "load " << filename << "\n"
<< "turn " << getPlyNumber(m_game->currentPosition()) << "\n";
- m_process->write(commands.str().c_str());
+ send(commands.str().c_str());
}
void MacondoBackend::killProcess() {
diff --git a/quacker/macondobackend.h b/quacker/macondobackend.h
index 28ba65c..93032b7 100644
--- a/quacker/macondobackend.h
+++ b/quacker/macondobackend.h
@@ -56,6 +56,9 @@ private slots:
void processFinished(int, QProcess::ExitStatus);
void timer();
private:
+ void send(const QByteArray &);
+ QByteArray receiveStdout();
+ QByteArray receiveStderr();
Quackle::Move createPlaceMove(const std::string &placement, const std::string &tiles);
Quackle::Move extractSimMove(const std::string &play);
Quackle::MoveList extractSimMoves(QByteArray &processOutput);