Skip to content

Commit

Permalink
fixed overlapping virtual move bug
Browse files Browse the repository at this point in the history
  • Loading branch information
spchuang committed Jul 8, 2013
1 parent 5c073f7 commit d197410
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
9 changes: 6 additions & 3 deletions AugmentedRealityGo/ARGoController.cpp
Expand Up @@ -100,10 +100,13 @@ void ARGoController::startAR()
}else if(command == "komi"){

}else if(command == "play"){
if(arguments.size() == 3)
board.addVirtualStone(arguments[2], arguments[1]);
else
if(arguments.size() == 3){
if(!board.addVirtualStone(arguments[2], arguments[1])){
response = "? invalid play move";
}
}else{
response = "? invalid play move";
}

}else if(command == "genmove"){
char color;
Expand Down
8 changes: 6 additions & 2 deletions AugmentedRealityGo/ARGraphicController.cpp
Expand Up @@ -485,8 +485,12 @@ void ARGraphicController::keyFunc(unsigned char key, int x, int y)

if(board->checkNewBoardState(newRealBoardStones, newMoveColor)){

board->addRealStone(board->newMoveIndex, newMoveColor);
genMove = false;
if(!board->addRealStone(board->newMoveIndex, newMoveColor)){
//not a valid move
fprintf(stderr, "ERROR: Invalid move\n");
}else{
genMove = false;
}
}


Expand Down
10 changes: 7 additions & 3 deletions AugmentedRealityGo/GamePlayUtils/FuegoAssistant.cpp
Expand Up @@ -144,7 +144,7 @@ bool FuegoAssistant::estimateTerritory(int color)

}

void FuegoAssistant::addMove(std::string move, int color){
bool FuegoAssistant::addMove(std::string move, int color){
//realStones[stone_index] = color;
string command;
if(color == COLOR_BLACK)
Expand All @@ -157,9 +157,13 @@ void FuegoAssistant::addMove(std::string move, int color){
string readLine;
do{
getline(readFromFuego, readLine);
}while(readLine[0]!='=');

}while(readLine[0]!='=' && readLine[0]!='?');

if(readLine[0] == '?'){
return false;
}

return true;
//getBookPositions();
}

Expand Down
2 changes: 1 addition & 1 deletion AugmentedRealityGo/GamePlayUtils/FuegoAssistant.h
Expand Up @@ -27,7 +27,7 @@ class FuegoAssistant
void clear_board();
void genMove(std::string color);

void addMove(std::string move, int color);
bool addMove(std::string move, int color);
void showBoard();
bool sendCommandWithEmptyResponse(std::string command, std::string& readLine);

Expand Down
17 changes: 11 additions & 6 deletions AugmentedRealityGo/GamePlayUtils/GoBoard.cpp
Expand Up @@ -45,24 +45,29 @@ void GoBoard::changeTurn()
newMoveIsMade = true;
}

void GoBoard::addVirtualStone(std::string move, std::string color)
bool GoBoard::addVirtualStone(std::string move, std::string color)
{
//check if this is valid move first
if(!fuego->addMove(move, helper::convert_string_color(color)))
return false;
int stone_index = helper::convert_string_move(move);
//std::cout<<"#add virtual stone at: "<<stone_index<<std::endl;
if(color == "black" || color =="b")
virtualStones[stone_index] = COLOR_BLACK;
else if(color =="white"|| color =="w")
virtualStones[stone_index] = COLOR_WHITE;
fuego->addMove(move, helper::convert_string_color(color));

changeTurn();
return true;
}

void GoBoard::addRealStone(int stone_index, int color){

bool GoBoard::addRealStone(int stone_index, int color){
//check if this is valid move first
if(!fuego->addMove(helper::convert_index_move(stone_index), color))
return false;
realStones[stone_index] = color;

fuego->addMove(helper::convert_index_move(stone_index), color);
changeTurn();
return true;
}


Expand Down
4 changes: 2 additions & 2 deletions AugmentedRealityGo/GamePlayUtils/GoBoard.h
Expand Up @@ -26,8 +26,8 @@ class GoBoard

//add stones
void changeTurn();
void addVirtualStone(std::string move, std::string color);
void addRealStone(int stone_index, int color);
bool addVirtualStone(std::string move, std::string color);
bool addRealStone(int stone_index, int color);

//return the color of current turn
int getMoveTurnColor();
Expand Down

0 comments on commit d197410

Please sign in to comment.