Skip to content

Commit

Permalink
fix bug: display wrong winner when play at forbidden point
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd committed Jun 3, 2017
1 parent 2ed6d43 commit 182f3ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
22 changes: 7 additions & 15 deletions ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@ AI::AI() {
}

AI::~AI() {
if (tree != NULL)
delete tree;
if (vb != NULL)
delete vb;
if (tree != NULL) delete tree;
if (vb != NULL) delete vb;
}

void AI::think(int *row, int *col) {
if (backgroundThread != NULL) {
stopBackgroundThread = true;
backgroundThread->join();
delete backgroundThread;
backgroundThread = NULL;
}
stopBGThread();

#ifdef DEBUG_MCTS_PROCESS
int batch = 100;
Expand All @@ -54,16 +47,15 @@ void AI::think(int *row, int *col) {
#endif
}

bool AI::play(int row, int col, bool triggerBackgroundThread ) {
int AI::play(int row, int col, bool triggerBackgroundThread ) {
// stop background thinking to avoid memory corruption.
stopBGThread();
bool hasSomeoneWin = tree->play(row, col);
int result = tree->play(row, col);

if (triggerBackgroundThread) {
if (triggerBackgroundThread)
startBGThread();
}

return hasSomeoneWin;
return result;
}

void AI::startBGThread() {
Expand Down
5 changes: 3 additions & 2 deletions ai.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class AI {
/* think of a play, and return it. */
void think(int *Row, int *Col);

/* plays a new point, returns true if someone wins after this move.
/* plays a new point
* return value: 1: self-winning, -1: opp-winning, 0 no winning
* triggerBackgroundThread: true: start bg thread */
bool play(int row, int col, bool triggerBackgroundThread);
int play(int row, int col, bool triggerBackgroundThread);

/* resets AI for a new game */
void reset(int level, int rule);
Expand Down

0 comments on commit 182f3ec

Please sign in to comment.