X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=judge%2Fmanager%2Fgame.cpp;h=8d3eef0c398c7ab46ee64eaa144c8caf4e9b933f;hb=38c6e9b9fc245ca5e6e6cee2806cb64dcbd34e35;hp=3df968cc9dad319282197be3d522b19788d35cf0;hpb=e1153eebe8cfd0c881cef2ff8fca63f130e736b3;p=progcomp2012.git diff --git a/judge/manager/game.cpp b/judge/manager/game.cpp index 3df968c..8d3eef0 100644 --- a/judge/manager/game.cpp +++ b/judge/manager/game.cpp @@ -442,9 +442,24 @@ void Game::PrintEndMessage(const MovementResult & result) } } +/** Checks for victory by attrition (destroying all mobile pieces) + * + * @returns OK for no victory, + * DRAW if both players have no pieces, or + * VICTORY_ATTRITION if the current player has won by attrition + */ +MovementResult Game::CheckVictoryAttrition() +{ + if (theBoard.MobilePieces(Piece::OppositeColour(turn)) == 0) + { + if (theBoard.MobilePieces(turn) == 0) + return MovementResult::DRAW; + else + return MovementResult::VICTORY_ATTRITION; + } + return MovementResult::OK; - - +} MovementResult Game::Play() { @@ -483,22 +498,27 @@ MovementResult Game::Play() #endif //BUILD_GRAPHICS turn = Piece::RED; + blue->Pause(); + red->Continue(); + if (!Board::HaltResult(result)) + { + result = CheckVictoryAttrition(); + } + if (Board::HaltResult(result)) + break; + logMessage( "%d RED: ", turnCount); result = red->MakeMove(buffer); red->Message(buffer); blue->Message(buffer); logMessage( "%s\n", buffer.c_str()); - if (Board::HaltResult(result)) - break; - if (theBoard.MobilePieces(Piece::BLUE) == 0) + if (!Board::HaltResult(result)) { - if (theBoard.MobilePieces(Piece::RED) == 0) - result = MovementResult::DRAW; - else - result = MovementResult::VICTORY_ATTRITION; - break; + result = CheckVictoryAttrition(); } + if (Board::HaltResult(result)) + break; if (stallTime >= 0) Wait(stallTime); @@ -523,12 +543,25 @@ MovementResult Game::Play() turn = Piece::BLUE; + red->Pause(); + blue->Continue(); + if (!Board::HaltResult(result)) + { + result = CheckVictoryAttrition(); + } + if (Board::HaltResult(result)) + break; + logMessage( "%d BLU: ", turnCount); result = blue->MakeMove(buffer); blue->Message(buffer); red->Message(buffer); logMessage( "%s\n", buffer.c_str()); + if (!Board::HaltResult(result)) + { + result = CheckVictoryAttrition(); + } if (Board::HaltResult(result)) break;