4 * Created on: 2012-03-19
8 #ifndef CPCOMMANDPARSER_H_
9 #define CPCOMMANDPARSER_H_
14 #include "CPEventListener.h"
16 class CPCommandParser
{
17 std::istream
& inputStream
;
18 std::stringstream commandStream
;
19 CPEventListener
& listener
;
21 static const std::string CN_CONNECT
;
22 static const std::string CN_BESTMOVE
;
23 static const std::string CN_ERROR
;
24 static const std::string CN_CONCEDE
;
25 static const std::string CN_INFO
;
27 static const std::string CN_INIT
;
28 static const std::string CN_STARTGAME
;
29 static const std::string CN_MOVE
;
30 static const std::string CN_FEEDBACK
;
31 static const std::string CN_SETOPTION
;
32 static const std::string CN_GETMOVE
;
33 static const std::string CN_FORCEMOVE
;
34 static const std::string CN_STOP
;
35 static const std::string CN_ENDGAME
;
36 static const std::string CN_QUIT
;
38 static const std::string UNKNOWN_LABEL
;
39 static const std::string WHITE_LABEL
;
40 static const std::string BLACK_LABEL
;
41 static const std::string ANALYST_LABEL
;
42 static const std::string DRAW_LABEL
;
43 static const std::string INFINITY_LABEL
;
45 void getCommand(std::string
& commandType
);
47 void commandConnect();
48 void commandBestMove();
50 void commandConcede();
53 void commandStartGame();
55 void commandFeedback();
56 void commandSetOption();
57 void commandGetMove();
58 void commandForceMove();
60 void commandEndGame();
63 void commandUnknown();
65 // bool match(std::string & name, CommandType type);
66 std::string
pullNextArg();
67 std::string
pullPosition();
68 std::string
pullMove();
69 CPColor
colorFromString(std::string colorString
);
70 CPRole
roleFromString(std::string roleString
);
71 CPResult
resultFromString(std::string resultString
);
72 int timeFromString(std::string timeString
);
73 std::pair
<int, int> timesFromString(std::string times
);
76 CPCommandParser(std::istream
& inputStream
, CPEventListener
& listener
);
77 std::string
nextCommand();
78 void parse(std::string
);
79 // void nextCommand(, CommandType expectedCommand);
82 #endif /* CPCOMMANDPARSER_H_ */