diff --git a/AugmentedRealityGo/ARGoController.cpp b/AugmentedRealityGo/ARGoController.cpp index 9c243a9..92c4d2a 100644 --- a/AugmentedRealityGo/ARGoController.cpp +++ b/AugmentedRealityGo/ARGoController.cpp @@ -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; diff --git a/AugmentedRealityGo/ARGraphicController.cpp b/AugmentedRealityGo/ARGraphicController.cpp index 6653217..c43fd94 100644 --- a/AugmentedRealityGo/ARGraphicController.cpp +++ b/AugmentedRealityGo/ARGraphicController.cpp @@ -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; + } } diff --git a/AugmentedRealityGo/GamePlayUtils/FuegoAssistant.cpp b/AugmentedRealityGo/GamePlayUtils/FuegoAssistant.cpp index 53ee084..71dac61 100644 --- a/AugmentedRealityGo/GamePlayUtils/FuegoAssistant.cpp +++ b/AugmentedRealityGo/GamePlayUtils/FuegoAssistant.cpp @@ -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) @@ -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(); } diff --git a/AugmentedRealityGo/GamePlayUtils/FuegoAssistant.h b/AugmentedRealityGo/GamePlayUtils/FuegoAssistant.h index 85669c8..6082f2a 100644 --- a/AugmentedRealityGo/GamePlayUtils/FuegoAssistant.h +++ b/AugmentedRealityGo/GamePlayUtils/FuegoAssistant.h @@ -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); diff --git a/AugmentedRealityGo/GamePlayUtils/GoBoard.cpp b/AugmentedRealityGo/GamePlayUtils/GoBoard.cpp index cbbfc31..d955b42 100644 --- a/AugmentedRealityGo/GamePlayUtils/GoBoard.cpp +++ b/AugmentedRealityGo/GamePlayUtils/GoBoard.cpp @@ -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: "<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; } diff --git a/AugmentedRealityGo/GamePlayUtils/GoBoard.h b/AugmentedRealityGo/GamePlayUtils/GoBoard.h index 3213997..91ba69f 100644 --- a/AugmentedRealityGo/GamePlayUtils/GoBoard.h +++ b/AugmentedRealityGo/GamePlayUtils/GoBoard.h @@ -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();