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