int QGtp::openGtpSession(QString filename, int size, float komi, int handicap, int /*level*/) { _cpt = 1000; programProcess = new QProcess(); programProcess->setReadChannel(QProcess::StandardOutput); QStringList arguments; issueCmdNb = false; if(!filename.count()) { _response = "No go engine path set"; return FAIL; } if (filename.toLower().contains("gnugo")) { arguments << "--mode" << "gtp" << "--quiet" ; issueCmdNb = true; } if (filename.toLower().contains("mogo")) { arguments << "--19" << "--dontDisplay" << "1" ; } connect(programProcess, SIGNAL(readyRead()), this, SLOT(slot_readFromStdout()) ); connect(programProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slot_processExited(int , QProcess::ExitStatus )) ); qDebug("starting Go engine : %s %s", filename.toLatin1().constData(), arguments.join(" ").toLatin1().constData()); programProcess->start(filename, arguments); if (!programProcess->waitForStarted()) { _response="Could not start "+filename; return FAIL ; } //?? never know ... otherwise, I get a segfault with sprint ... if ((outFile = (char *)malloc (100)) == NULL) { _response="Yuck ! Could not allocate 100 bytes !!!" ; return FAIL ; } if (protocolVersion()==OK) { if(getLastMessage().toInt() !=2) { qDebug("Protocol version problem???"); // quit(); _response="Protocol version not supported"; // return FAIL; } if(setBoardsize(size)==FAIL) { return FAIL; } if(clearBoard()==FAIL) { // removed by frosla -> protocol changes... // return FAIL; } /* if(knownCommand("level")==FAIL) { return FAIL; } else if (getLastMessage().contains("true")) { if (setLevel(level)==FAIL) { return FAIL; } } */ if(setKomi(komi)==FAIL) { return FAIL; } if(fixedHandicap(handicap)==FAIL) { return FAIL; } } else { quit(); _response="Protocol version error"; return FAIL; } busy = false; return OK; }
int QGtp::openGtpSession(QString path, QString args, int size, float komi, int handicap) { _cpt = 1000; programProcess = new QProcess(); programProcess->setReadChannel(QProcess::StandardOutput); QStringList arguments = args.split(' ',QString::SkipEmptyParts); issueCmdNb = false; if (path.contains(QRegExp("gnugo$", Qt::CaseInsensitive))) issueCmdNb = true; // FIXME: are command numbers really gnugo-specific? connect(programProcess, SIGNAL(readyRead()), this, SLOT(slot_readFromStdout()) ); connect(programProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slot_processExited(int , QProcess::ExitStatus )) ); qDebug() << "QGtp::openGtpSession(" << path << "," << args << ")"; programProcess->start(path, arguments); if (!programProcess->waitForStarted()) { _response="Could not start "+path; return FAIL ; } //?? never know ... otherwise, I get a segfault with sprint ... if ((outFile = (char *)malloc (100)) == NULL) { _response="Yuck ! Could not allocate 100 bytes !!!" ; return FAIL ; } if (protocolVersion()==OK) { if(getLastMessage().toInt() !=2) { qDebug("Protocol version problem???"); // quit(); _response="Protocol version not supported"; // return FAIL; } if(setBoardsize(size)==FAIL) { return FAIL; } if(clearBoard()==FAIL) { // removed by frosla -> protocol changes... // return FAIL; } /* if(knownCommand("level")==FAIL) { return FAIL; } else if (getLastMessage().contains("true")) { if (setLevel(level)==FAIL) { return FAIL; } } */ if(setKomi(komi)==FAIL) { return FAIL; } if(fixedHandicap(handicap)==FAIL) { return FAIL; } } else { quit(); _response="Protocol version error"; return FAIL; } busy = false; return OK; }