Skip to content

Commit

Permalink
Handle engine's errors
Browse files Browse the repository at this point in the history
In particular, open the board even if it is too large for the engine
  • Loading branch information
pzorin committed May 17, 2014
1 parent 33f5bb6 commit 2c4bfa3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
15 changes: 1 addition & 14 deletions src/board/boardwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,7 @@ BoardWindow::BoardWindow(GameData *gd, bool iAmBlack , bool iAmWhite, class Boar
{
case modeEdit :
case modeLocal :
try
{
qgoboard = new qGoBoardLocalInterface(this, tree,gameData);
}
catch(QString err)
{
QMessageBox msg(QObject::tr("Error"),
err,
QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton, QMessageBox::NoButton);
//msg.setActiveWindow();
msg.raise();
msg.exec();
return;
}
qgoboard = new qGoBoardLocalInterface(this, tree,gameData);
ui->computerBlack->setChecked(!iAmBlack);
ui->computerWhite->setChecked(!iAmWhite);
break;
Expand Down
26 changes: 18 additions & 8 deletions src/game_interfaces/qgoboardlocalinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ qGoBoardLocalInterface::qGoBoardLocalInterface(BoardWindow *bw, Tree * t, GameDa
gameData->handicap,
GNUGO_LEVEL)==FAIL)
{
throw QString(QObject::tr("Error opening program: %1")).arg(gtp->getLastMessage());
QMessageBox msg(QMessageBox::Warning,
QObject::tr("Error"),
QObject::tr("Error opening program: %1").arg(gtp->getLastMessage()),
QMessageBox::Ok);
msg.exec();
delete gtp;
gtp = NULL;
}

tree->setCurrent(tree->findLastMoveInMainBranch());
Expand Down Expand Up @@ -93,7 +99,8 @@ void qGoBoardLocalInterface::slotUndoPressed()
leaveScoreMode();
else
{
gtp->undo(0);
if (gtp)
gtp->undo(0);
qGoBoard::slotUndoPressed();
}
}
Expand All @@ -103,6 +110,8 @@ void qGoBoardLocalInterface::slotUndoPressed()
*/
void qGoBoardLocalInterface::sendMoveToInterface(StoneColor c,int x, int y)
{
if (!gtp)
return;
switch (c)
{
case stoneWhite :
Expand Down Expand Up @@ -134,6 +143,8 @@ void qGoBoardLocalInterface::sendMoveToInterface(StoneColor c,int x, int y)
*/
void qGoBoardLocalInterface::playComputer()
{
if (!gtp)
return;
if (gtp->isBusy())
return;
int result;
Expand Down Expand Up @@ -181,6 +192,8 @@ void qGoBoardLocalInterface::sendPassToInterface(StoneColor c)
{
doPass();

if (gtp)
{
// if simple pass, tell computer and move on
switch (c)
{
Expand All @@ -192,9 +205,6 @@ void qGoBoardLocalInterface::sendPassToInterface(StoneColor c)
}
else
qDebug("comp notified of white pass");
// if (win->blackPlayerType==COMPUTER)
// playComputer(c);

break;

case stoneBlack :
Expand All @@ -203,14 +213,12 @@ void qGoBoardLocalInterface::sendPassToInterface(StoneColor c)
QMessageBox::warning(boardwindow, PACKAGE, tr("Failed to pass within program \n") + gtp->getLastMessage());
return;
}

// if (win->whitePlayerType==COMPUTER)
// playComputer(c);
break;

default :
;
}
}
if (tree->getCurrent()->parent->isPassMove())
enterScoreMode();
else
Expand All @@ -219,6 +227,8 @@ void qGoBoardLocalInterface::sendPassToInterface(StoneColor c)

void qGoBoardLocalInterface::feedPositionThroughGtp()
{
if (!gtp)
return;
QStack<Move*> stack;
Move *m = tree->getCurrent();
while (m->parent != NULL)
Expand Down
4 changes: 2 additions & 2 deletions src/gtp/qgtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void QGtp::slot_readFromStdout()
answer = programProcess->readLine();
answer.chop(1); // remove the trailing '\n'
responseReceived = ((! answer.isEmpty()) &&
((answer.at(0) == '=') || (answer.at(0) != '?')));
((answer.at(0) == '=') || (answer.at(0) == '?')));
if (responseReceived)
break;
}
Expand Down Expand Up @@ -256,7 +256,7 @@ QGtp::waitResponse()
responseReceived = false;
busy=false;

return OK;
return ((answer.at(0) == '=') ? OK : FAIL );
}

/****************************
Expand Down
2 changes: 0 additions & 2 deletions src/network/boarddispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/


#include <algorithm>
#include "boarddispatch.h"
#include "boardwindow.h"
#include "messages.h"
Expand Down

0 comments on commit 2c4bfa3

Please sign in to comment.