00001
00002
00003 #include "osl/game_playing/cuiClient.h"
00004 #include "osl/game_playing/gameState.h"
00005 #include "osl/game_playing/csaLogger.h"
00006 #include "osl/game_playing/moveWithComment.h"
00007
00008 osl::game_playing::
00009 CuiClient::CuiClient(ComputerPlayer *black, ComputerPlayer *white,
00010 CsaLogger *l, std::istream& i, std::ostream& o)
00011 : GameManager(black, white, l), is(i), os(o), stop_by_outside(0)
00012 {
00013 }
00014
00015 osl::game_playing::
00016 CuiClient::~CuiClient()
00017 {
00018 }
00019
00020 void osl::game_playing::
00021 CuiClient::run(const char *black, const char *white)
00022 {
00023 logger->init(black, white, state->state());
00024 run();
00025 }
00026
00027 void osl::game_playing::
00028 CuiClient::run()
00029 {
00030 try
00031 {
00032 logger->writeComment("game start");
00033 while (1)
00034 {
00035 while (! isComputer(state->state().getTurn()))
00036 {
00037 readAndProcessCommand();
00038 }
00039 int seconds;
00040 MoveWithComment best_move;
00041 if (! stop_by_outside)
00042 {
00043 best_move = computeMove(seconds);
00044 }
00045 else
00046 {
00047 best_move = MoveWithComment(Move::INVALID());
00048 logger->writeComment("forced resign");
00049 }
00050 processComputerMove(best_move, seconds);
00051 }
00052 }
00053 catch (EndGame&)
00054 {
00055 logger->writeComment("game end");
00056 }
00057 return;
00058 }
00059
00060
00061
00062
00063
00064
00065