X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=manager%2Fstratego.cpp;h=d84819f55b089cac36444817de8296921f77f7bb;hp=37df4d2f3b997a5c0f8c9c83e7add42267ad16d0;hb=fe470c015d73d07c44f0e951a2bb205d95763f22;hpb=4a3c0478160e7e9b637a12e7cf22f8da61b66ad2 diff --git a/manager/stratego.cpp b/manager/stratego.cpp index 37df4d2..d84819f 100644 --- a/manager/stratego.cpp +++ b/manager/stratego.cpp @@ -92,7 +92,7 @@ Board::~Board() /** * Print textual representation of the board to a stream * @param stream - the stream to print information to - * @param reveal - Pieces matching this colour will have their identify revealed, other pieces will be shown as '#' or '*' for RED or BLUE respectively. + * @param reveal - Pieces matching this colour will have their identify revealed, other pieces will be shown as '#' */ void Board::Print(FILE * stream, const Piece::Colour & reveal) { @@ -107,26 +107,89 @@ void Board::Print(FILE * stream, const Piece::Colour & reveal) } else if (piece->colour != Piece::NONE && (piece->colour == reveal || reveal == Piece::BOTH)) { + fprintf(stream, "%c", Piece::tokens[piece->type]); + + } else { switch (piece->colour) { case Piece::RED: + case Piece::BLUE: fprintf(stream, "#"); + break; + case Piece::NONE: + fprintf(stream, "+"); + break; + case Piece::BOTH: + fprintf(stream, "$"); + break; + } + } + } + fprintf(stream, "\n"); + } + +} + +/** + * Print textual representation of the board to a stream + * @param stream - the stream to print information to + * @param reveal - Pieces matching this colour will have their identify revealed, other pieces will be shown as '#' + */ +void Board::PrintPretty(FILE * stream, const Piece::Colour & reveal) +{ + for (int y=0; y < height; ++y) + { + for (int x=0; x < width; ++x) + { + Piece * piece = board[x][y]; + if (piece == NULL) + { + fprintf(stream, "."); + } + else if (piece->colour != Piece::NONE && (piece->colour == reveal || reveal == Piece::BOTH)) + { + switch (piece->colour) + { + case Piece::RED: + fprintf(stream, "%c[%d;%d;%dm",0x1B,1,31,40); + break; + case Piece::BLUE: + fprintf(stream, "%c[%d;%d;%dm",0x1B,1,34,40); + break; + default: + break; + } + fprintf(stream, "%c", Piece::tokens[piece->type]); + + } + else + { + switch (piece->colour) + { + case Piece::RED: + fprintf(stream, "%c[%d;%d;%dm",0x1B,1,31,41); + break; case Piece::BLUE: - fprintf(stream, "*"); + fprintf(stream, "%c[%d;%d;%dm",0x1B,1,34,44); break; case Piece::NONE: - fprintf(stream, "+"); + fprintf(stream, "%c[%d;%d;%dm",0x1B,1,37,47); break; case Piece::BOTH: - fprintf(stream, "$"); //Should never see these! + //Should never see this + fprintf(stream, "%c[%d;%d;%dm",0x1B,1,33,43); break; - } + + } + fprintf(stream, "#"); + } + fprintf(stream, "%c[%d;%d;%dm",0x1B,0,7,0); } fprintf(stream, "\n"); }