X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=home%2Fprogcomp%2Fjudge%2Fmanager%2Fai_controller.cpp;fp=home%2Fprogcomp%2Fjudge%2Fmanager%2Fai_controller.cpp;h=40ee3df44e60bbfc9b73ae71557ccb27ac745d0e;hp=0000000000000000000000000000000000000000;hb=e3b15cd5dea739f7523920d83bda592db95a7b93;hpb=7f7bc05439b70b3139086086608996de3c9ae2ed;ds=sidebyside diff --git a/home/progcomp/judge/manager/ai_controller.cpp b/home/progcomp/judge/manager/ai_controller.cpp new file mode 100644 index 0000000..40ee3df --- /dev/null +++ b/home/progcomp/judge/manager/ai_controller.cpp @@ -0,0 +1,64 @@ +#include + +#include "game.h" +#include "stratego.h" + +#include "ai_controller.h" + +using namespace std; + + +/** + * Queries the AI program to setup its pieces. Stores the setup in a st + * @implements Controller::QuerySetup + * @param + * @returns A MovementResult + */ + +MovementResult AI_Controller::QuerySetup(const char * opponentName, std::string setup[]) +{ + switch (colour) + { + case Piece::RED: + if (!SendMessage("RED %s %d %d", opponentName, Game::theGame->theBoard.Width(), Game::theGame->theBoard.Height())) + return MovementResult::BAD_RESPONSE; + break; + case Piece::BLUE: + if (!SendMessage("BLUE %s %d %d", opponentName, Game::theGame->theBoard.Width(), Game::theGame->theBoard.Height())) + return MovementResult::BAD_RESPONSE; + break; + case Piece::NONE: + case Piece::BOTH: + return MovementResult::COLOUR_ERROR; + break; + } + + for (int y = 0; y < 4; ++y) + { + if (!GetMessage(setup[y], timeout)) + return MovementResult::BAD_RESPONSE; + } + + return MovementResult::OK; +} + + +/** + * Queries the AI program to make a move + * @implements Controller::QueryMove + * @param buffer String which stores the AI program's response + * @returns A MovementResult which will be MovementResult::OK if a move was made, or MovementResult::NO_MOVE if the AI did not respond + */ +MovementResult AI_Controller::QueryMove(string & buffer) +{ + if (!Running()) + return MovementResult::NO_MOVE; //AI has quit + Game::theGame->theBoard.Print(output, colour); + + if (!GetMessage(buffer,timeout)) + { + return MovementResult::NO_MOVE; //AI did not respond (within the timeout). It will lose by default. + } + return MovementResult::OK; //Got the message +} +