00001
00004 #include "osl/record/csaString.h"
00005 #include "osl/state/hashEffectState.h"
00006 #include "osl/container/moveLogProbSet.h"
00007 #include "osl/apply_move/applyMove.h"
00008
00009 #include "osl/category/standardMoveGenerator.h"
00010 #include "osl/category/categoryListUtil.h"
00011 #include "osl/misc/perfmon.h"
00012 #include <iostream>
00013 using namespace osl;
00014 using namespace osl::category;
00015 using namespace osl::misc;
00016
00017 int moveCount;
00018 int maxLevel;
00019
00020 MoveStack history;
00021 int limit = 800;
00022
00023 template<Player P ,typename State>
00024 void nextMoves(State& state, int level);
00025
00026 template<class State, Player P>
00027 struct DoUndoHelper
00028 {
00029 State& state;
00030 int level;
00031 Move move;
00032
00033 DoUndoHelper(State& s, int level)
00034 : state(s), level(level), move(Move::INVALID())
00035 {
00036 }
00037 void operator()(Position p)
00038 {
00039 history.push(move);
00040 assert(move.isNormal());
00041 nextMoves<P,State>(state, level);
00042 history.pop();
00043 }
00044 };
00045
00046 template <Player P, typename State>
00047 void nextMoves(State& state,int level)
00048 {
00049 typedef typename State::effect_state_t effect_t;
00050 if (level>maxLevel)
00051 return;
00052 const Position opKingPosition
00053 =state.template getKingPosition<PlayerTraits<P>::opponent>();
00054 if (state.hasEffectBy(P,opKingPosition))
00055 return;
00056
00057 MoveLogProbSet moves;
00058 CategoryEnv env(&state, limit, &history);
00059 CategoryListUtil::gatherAllMoves<StandardMoveGenerator>(env, moves);
00060
00061 typedef DoUndoHelper<State,PlayerTraits<P>::opponent> helper_t;
00062 helper_t helper(state, level+1);
00063
00064 for (MoveLogProbSet::const_iterator p=moves.begin(); p!=moves.end(); ++p)
00065 {
00066 const Move move = p->getMove();
00067 moveCount++;
00068 helper.move = move;
00069 ApplyMove<P>::doUndoMove(state, move, helper);
00070 }
00071 }
00072
00073 int main(int argc,char **argv)
00074 {
00075
00076 bool hashMode=false;
00077 int level=3;
00078 extern char *optarg;
00079
00080 char c;
00081 while ((c = getopt(argc, argv, "l:L:h")) != EOF)
00082 {
00083 switch(c)
00084 {
00085 case 'l': level=atoi(optarg);
00086 break;
00087 case 'L': limit=atoi(optarg);
00088 break;
00089 case 'h': hashMode=true;
00090 break;
00091 default:
00092 std::cerr << "unknown option\n";
00093 std::cerr << "Usage: " << argv[0] << "[-l depth] [-L limit] [-hE]\n";
00094 return 1;
00095 }
00096 }
00097 SimpleState state=CsaString(
00098 "P1-KY * * * -KY * -FU-KE * \n"
00099 "P2 * * * * -OU * * * * \n"
00100 "P3 * * * -FU-FU+RY * * -KY\n"
00101 "P4-FU * * -GI * * * * * \n"
00102 "P5 * * * * * * * * * \n"
00103 "P6+FU * * +RY * * +FU * * \n"
00104 "P7 * +FU * +FU+FU+FU * * * \n"
00105 "P8 * * +OU * -TO * * * * \n"
00106 "P9+KY * * * * * * +KE * \n"
00107 "P+00KI00GI00GI00GI00KE00KE00FU00FU00FU00KI\n"
00108 "P-00KA00KA00KI00FU00FU00FU00FU00KI\n"
00109 "-\n").getInitialState();
00110 maxLevel=level;
00111 moveCount=0;
00112 PerfMon clock;
00113
00114 Move lastMove=Move(Position(4,4),Position(4,3),PROOK,
00115 PTYPE_EMPTY,false,BLACK);
00116 history.push(lastMove);
00117 if(hashMode)
00118 {
00119 std::cerr << "hashMode" << std::endl;
00120 HashEffectState hState(state);
00121
00122 nextMoves<WHITE,HashEffectState>(hState,0);
00123 }
00124 else
00125 {
00126 std::cerr << "effectMode" << std::endl;
00127 NumEffectState neState(state);
00128 nextMoves<WHITE,NumEffectState>(neState,0);
00129 }
00130 clock.stop("total", moveCount+1);
00131 std::cerr << "maxLevel=" << maxLevel << ",moveCount=" << moveCount
00132 << std::endl;
00133
00134 }
00135
00136
00137
00138