Changed directory structure (again)
[progcomp2012.git] / judge / manager / ai_controller.cpp
1 #include <sstream>
2
3 #include "game.h"
4 #include "stratego.h"
5
6 #include "ai_controller.h"
7
8 using namespace std;
9
10
11 /**
12  * Queries the AI program to setup its pieces. Stores the setup in a st
13  * @implements Controller::QuerySetup
14  * @param
15  * @returns A MovementResult
16  */
17
18 MovementResult AI_Controller::QuerySetup(const char * opponentName, std::string setup[])
19 {
20         switch (colour)
21         {
22                 case Piece::RED:
23                         if (!SendMessage("RED %s %d %d", opponentName, Game::theGame->theBoard.Width(), Game::theGame->theBoard.Height()))
24                                 return MovementResult::BAD_RESPONSE;
25                         break;
26                 case Piece::BLUE:
27                         if (!SendMessage("BLUE %s %d %d", opponentName, Game::theGame->theBoard.Width(), Game::theGame->theBoard.Height()))
28                                 return MovementResult::BAD_RESPONSE;
29                         break;
30                 case Piece::NONE:
31                 case Piece::BOTH:
32                         return MovementResult::COLOUR_ERROR;
33                         break;
34         }
35
36         for (int y = 0; y < 4; ++y)
37         {
38                 if (!GetMessage(setup[y], timeout))
39                         return MovementResult::BAD_RESPONSE;    
40         }
41
42         return MovementResult::OK;
43 }
44
45
46 /**
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
51  */
52 MovementResult AI_Controller::QueryMove(string & buffer)
53 {
54         if (!Running())
55                 return MovementResult::NO_MOVE; //AI has quit
56         Game::theGame->theBoard.Print(output, colour);
57
58         if (!GetMessage(buffer,timeout))
59         {
60                 return MovementResult::NO_MOVE; //AI did not respond (within the timeout). It will lose by default.
61         }
62         return MovementResult::OK; //Got the message
63 }
64

UCC git Repository :: git.ucc.asn.au