/**
* Queries the AI program to setup its pieces
+ * @param opponentName - string containing the name/id of the opponent AI program
* @returns the result of the response
*/
-Board::MovementResult Controller::Setup(const char * opponentName)
+MovementResult Controller::Setup(const char * opponentName)
{
int y;
switch (colour)
if (!GetMessage(line, 2.5))
{
fprintf(stderr, "Timeout on setup\n");
- return Board::BAD_RESPONSE;
+ return MovementResult::BAD_RESPONSE;
}
if ((int)(line.size()) != Board::theBoard.Width())
{
fprintf(stderr, "Bad length of \"%s\" on setup\n", line.c_str());
- return Board::BAD_RESPONSE;
+ return MovementResult::BAD_RESPONSE;
}
for (int x = 0; x < (int)(line.size()); ++x)
if (usedUnits[type] > Piece::maxUnits[(int)type])
{
fprintf(stderr, "Too many units of type %c\n", Piece::tokens[(int)(type)]);
- return Board::BAD_RESPONSE;
+ return MovementResult::BAD_RESPONSE;
}
Board::theBoard.AddPiece(x, y+ii, type, colour);
if (usedUnits[(int)Piece::FLAG] <= 0)
{
- return Board::BAD_RESPONSE; //You need to include a flag!
+ return MovementResult::BAD_RESPONSE; //You need to include a flag!
}
- return Board::OK;
+ return MovementResult::OK;
}
* Queries the AI program to respond to a state of Board::theBoard
* @returns The result of the response and/or move if made
*/
-Board::MovementResult Controller::MakeMove(string & buffer)
+MovementResult Controller::MakeMove(string & buffer)
{
if (!Running())
- return Board::NO_MOVE; //AI has quit
+ return MovementResult::NO_MOVE; //AI has quit
Board::theBoard.Print(output, colour);
buffer.clear();
if (!GetMessage(buffer,2))
{
- return Board::NO_MOVE; //AI did not respond. It will lose by default.
+ return MovementResult::NO_MOVE; //AI did not respond. It will lose by default.
}
int x; int y; string direction="";
else
{
fprintf(stderr, "BAD_RESPONSE \"%s\"\n", buffer.c_str());
- return Board::BAD_RESPONSE; //AI gave bogus direction - it will lose by default.
+ return MovementResult::BAD_RESPONSE; //AI gave bogus direction - it will lose by default.
}
int multiplier = 1;
if (s.peek() != EOF)
s >> multiplier;
- Board::MovementResult moveResult = Board::theBoard.MovePiece(x, y, dir, multiplier, colour);
- switch (moveResult)
+ MovementResult moveResult = Board::theBoard.MovePiece(x, y, dir, multiplier, colour);
+
+ s.clear(); s.str("");
+
+ //I stored the ranks in the wrong order; rank 1 is the marshal, 2 is the general etc...
+ //So I am reversing them in the output... great work
+ s << (Piece::BOMB - moveResult.attackerRank) << " " << (Piece::BOMB - moveResult.defenderRank) << "\n";
+ switch (moveResult.type)
{
- case Board::OK:
+ case MovementResult::OK:
buffer += " OK";
break;
- case Board::VICTORY:
+ case MovementResult::VICTORY:
buffer += " FLAG";
break;
- case Board::KILLS:
- buffer += " KILLS";
+ case MovementResult::KILLS:
+ buffer += " KILLS ";
+ buffer += s.str();
+
break;
- case Board::DIES:
- buffer += " DIES";
+ case MovementResult::DIES:
+ buffer += " DIES ";
+ buffer += s.str();
break;
- case Board::BOTH_DIE:
- buffer += " BOTHDIE";
+ case MovementResult::BOTH_DIE:
+ buffer += " BOTHDIE ";
+ buffer += s.str();
break;
default:
buffer += " ILLEGAL";
}
if (!Board::LegalResult(moveResult))
- return Board::OK; //HACK - Legal results returned!
+ return MovementResult::OK; //HACK - Legal results returned!
else
return moveResult;