X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=judge%2Fmanager%2Fgame.cpp;h=486920d3acaadb35f55d235939b1a77b8f6c4811;hb=fe14abf80ad8503eb8984f3a8e7139243d6a1e19;hp=3df968cc9dad319282197be3d522b19788d35cf0;hpb=e1153eebe8cfd0c881cef2ff8fca63f130e736b3;p=progcomp2012.git diff --git a/judge/manager/game.cpp b/judge/manager/game.cpp index 3df968c..486920d 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,26 @@ MovementResult Game::Play() #endif //BUILD_GRAPHICS turn = Piece::RED; + + 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 +542,24 @@ MovementResult Game::Play() turn = Piece::BLUE; + + 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;