qGoBoardLocalInterface::qGoBoardLocalInterface(BoardWindow *bw, Tree * t, GameData *gd) : qGoBoard(bw, t, gd) { this->setObjectName("qGoBoardLocalInterface"); boardwindow->getUi()->board->clearData(); // If we have handicap, but not from a loaded file, we have to set the handicap move if (gameData->handicap && gameData->fileName.isEmpty()) setHandicap(gameData->handicap); QSettings settings; // value 1 = no sound, 0 all games, 2 my games playSound = (settings.value("SOUND") != 1); // Set up computer interface. gtp = new QGtp() ; connect (gtp, SIGNAL(signal_computerPlayed(int, int)), SLOT(slot_playComputer(int, int))); connect (gtp, SIGNAL(computerResigned()), SLOT(slot_resignComputer())); connect (gtp, SIGNAL(computerPassed()), SLOT(slot_passComputer())); if (gtp->openGtpSession(settings.value("COMPUTER_PATH").toString(), gameData->board_size, gameData->komi, gameData->handicap, GNUGO_LEVEL)==FAIL) { throw QString(QObject::tr("Error opening program: %1")).arg(gtp->getLastMessage()); } tree->setCurrent(tree->findLastMoveInMainBranch()); boardwindow->getBoardHandler()->updateMove(tree->getCurrent()); feedPositionThroughGtp(); }
// Read from stdout void QGtp::slot_readFromStdout() { int number; int pos; while (programProcess->canReadLine()) { answer = programProcess->readLine(); answer.chop(1); // remove the trailing '\n' responseReceived = ((! answer.isEmpty()) && ((answer.at(0) == '=') || (answer.at(0) == '?'))); if (responseReceived) break; } if (!responseReceived) return; _response = answer; qDebug("** QGtp::slot_readFromStdout(): %s" , _response.toLatin1().constData()); // do we have any answer after the command number ? pos = _response.indexOf(" "); number = _response.mid(1,pos).toInt(); if (pos < 1) _response = ""; else _response = _response.right(_response.length() - pos - 1); int i = moveRequests.indexOf(number); if (i == -1) return; // Otherwise we have an answer to a move request. // This is the one case in which we currently do not busy-wait. busy=false; moveRequests.removeAt(i); if (_response == "resign") { emit computerResigned(); return; } else if (_response.contains("Pass",Qt::CaseInsensitive)) { emit computerPassed(); return; } int x = _response[0].unicode() - QChar::fromLatin1('A').unicode() + 1; // skip 'J' if (x > 8) x--; int y; if (_response[2] >= '0' && _response[2] <= '9') y = _response.mid(1,2).toInt(); else y = _response[1].digitValue(); emit signal_computerPlayed( x, y ); }