6 #include "ai_controller.h"
12 * Queries the AI program to setup its pieces. Stores the setup in a st
13 * @implements Controller::QuerySetup
15 * @returns A MovementResult
18 MovementResult AI_Controller::QuerySetup(const char * opponentName, std::string setup[])
23 if (!SendMessage("RED %s %d %d", opponentName, Game::theGame->theBoard.Width(), Game::theGame->theBoard.Height()))
24 return MovementResult::BAD_RESPONSE;
27 if (!SendMessage("BLUE %s %d %d", opponentName, Game::theGame->theBoard.Width(), Game::theGame->theBoard.Height()))
28 return MovementResult::BAD_RESPONSE;
32 return MovementResult::COLOUR_ERROR;
36 for (int y = 0; y < 4; ++y)
38 if (!GetMessage(setup[y], timeout))
39 return MovementResult::BAD_RESPONSE;
42 return MovementResult::OK;
47 * Queries the AI program to make a move
48 * @implements Controller::QueryMove
49 * @param buffer String which stores the AI program's response
50 * @returns A MovementResult which will be MovementResult::OK if a move was made, or MovementResult::NO_MOVE if the AI did not respond
52 MovementResult AI_Controller::QueryMove(string & buffer)
55 return MovementResult::NO_MOVE; //AI has quit
56 Game::theGame->theBoard.Print(output, colour);
58 if (!GetMessage(buffer,timeout))
60 return MovementResult::NO_MOVE; //AI did not respond (within the timeout). It will lose by default.
62 return MovementResult::OK; //Got the message