00001
00002
00003 #include "osl/state/numEffectState.h"
00004 #include "osl/effect_util/effectUtil.h"
00005 #include "osl/container/moveVector.h"
00006 #include "osl/apply_move/applyMove.h"
00007 #include "osl/record/csa.h"
00008 #include "osl/move_generator/legalMoves.h"
00009 #include <boost/random/mersenne_twister.hpp>
00010
00011 #include <string>
00012 #include <sys/time.h>
00013 using namespace osl;
00014
00019 void showState(const NumEffectState& state)
00020 {
00021 std::cout << state << std::endl;
00022 #if 0
00023 KanjiPrint printer(std::cout);
00024 printer.print(state);
00025 #endif
00026 }
00027
00031 Move selectMove(const NumEffectState& state, const MoveVector& moves)
00032 {
00033 static boost::mt11213b generator(random());
00034 return moves[generator() % moves.size()];
00035 #if 0
00036 boost::uniform_int<boost::mt11213b> random(generator, 0, moves.size());
00037 return moves[random()];
00038 #endif
00039 }
00040
00044 bool isMated(const NumEffectState& state)
00045 {
00046 return EffectUtil::isKingInCheck(alt(state.getTurn()), state);
00047 }
00048
00049 int main()
00050 {
00051 srandom(time(0));
00052
00053 NumEffectState state((SimpleState(HIRATE)));
00054 std::string line;
00055 while (true)
00056 {
00057
00058 MoveVector moves;
00059 LegalMoves::generate(state, moves);
00060 if (moves.empty())
00061 {
00062 std::cerr << "make masita\n";
00063 break;
00064 }
00065 const Move my_move = selectMove(state, moves);
00066 assert(state.isValidMove(my_move));
00067 ApplyMoveOfTurn::doMove(state, my_move);
00068
00069 showState(state);
00070 csaShow(std::cout, my_move);
00071 std::cout << "\n";
00072
00073 if (isMated(state))
00074 {
00075 std::cerr << "checkmate!";
00076 break;
00077 }
00078
00079
00080 if (! std::getline(std::cin, line))
00081 break;
00082
00083 const Move op_move=record::csa::strToMove(line, state);
00084 if (! state.isValidMove(op_move))
00085 break;
00086
00087 ApplyMoveOfTurn::doMove(state, op_move);
00088
00089 showState(state);
00090 csaShow(std::cout, op_move);
00091 std::cout << "\n";
00092 }
00093 }
00094
00095
00096
00097
00098
00099
00100
00101