Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
FutaAlice committed Mar 18, 2018
1 parent 00d91cb commit 691c1a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/futahex2/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ void app::onOpen()
Record rec(_rec);
_rec.clear();
changeBoardsize(rec.boardsize());
setAIColor(AIColorSetting::None);
setPlayerColor(PlayerColorSetting::Auto);
for (auto record_data : rec)
{
auto pos = record_data.pos();
Expand Down Expand Up @@ -330,14 +332,25 @@ void app::onSave()

void app::onRestart()
{
auto size = _pBoard ? _pBoard->boardsize() : 11;
changeBoardsize(size);
changeBoardsize(_pBoard ? 0 : 11);
}

void app::onAIMove()
{
if (!_pBoard)
return;

if (aiThinking)
{
const char *err = "AI is busy. This operation will be ignored";
debug(Level::Warning) << err;
QMessageBox message(QMessageBox::NoIcon, "Warning",
err, QMessageBox::Ok);
message.exec();
return;
}
aiThinking = true;

Color color = _pBoard->color();

EngineCfg cfg;
Expand Down Expand Up @@ -366,6 +379,7 @@ void app::onAIMove()
cout << result << endl;
auto *data = static_cast<CallbackParams *>(opaque);
data->pApp->setPiece(result.row, result.col);
data->pApp->aiThinking = false;
delete data;
return NULL;
}, static_cast<void *>(new CallbackParams(pEngine, this)));
Expand All @@ -375,6 +389,10 @@ void app::onTakeBack()
{
if (_rec.empty())
return;

setAIColor(AIColorSetting::None);
setPlayerColor(PlayerColorSetting::Auto);

pos_t pos = _rec.back().pos();
resetPiece(pos.row, pos.col);
_rec.pop_back();
Expand Down
1 change: 1 addition & 0 deletions src/futahex2/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class app : public QMainWindow
public:
app(QWidget *parent = Q_NULLPTR);
static const int w { 720 };
bool aiThinking { false };

public slots:
void setPiece(int row, int col);
Expand Down

0 comments on commit 691c1a5

Please sign in to comment.