00001
00002 #include "osl/category/standardMoveGenerator.h"
00003 #include "osl/category/categoryListUtil.h"
00004 #include "osl/container/moveLogProbSet.h"
00005 #include "osl/record/csaRecord.h"
00006 #include "osl/apply_move/applyMove.h"
00007 #include <iostream>
00008 #include <cmath>
00009
00010 using namespace osl;
00011 using namespace osl::category;
00012
00013 void usage(const char *prog)
00014 {
00015 using namespace std;
00016 cerr << "Usage: " << prog << " [-d] [-l limit] csa_files\n"
00017 << endl;
00018 exit(1);
00019 }
00020
00022 int limit = 800;
00023
00024 void testFile(const char *file_name);
00025
00026 int main(int argc, char **argv)
00027 {
00028 const char *program_name = argv[0];
00029 bool error_flag = false;
00030 extern char *optarg;
00031 extern int optind;
00032
00033 char c;
00034 while ((c = getopt(argc, argv, "l:vh")) != EOF)
00035 {
00036 switch(c)
00037 {
00038 case 'l': limit = atoi(optarg);
00039 break;
00040 default: error_flag = true;
00041 }
00042 }
00043 argc -= optind;
00044 argv += optind;
00045
00046 if (error_flag || (argc < 1))
00047 usage(program_name);
00048
00049 for (int i=0; i<argc; ++i)
00050 {
00051 testFile(argv[i]);
00052 }
00053 }
00054
00055 void testState(const CategoryEnv& env)
00056 {
00057 std::cout << *env.state;
00058 MoveLogProbSet moves;
00059 CategoryListUtil::gatherAllMoves<StandardMoveGenerator,MoveLogProbSet>
00060 (env, moves);
00061
00062 for (MoveLogProbSet::const_iterator p=moves.begin(); p!=moves.end(); ++p)
00063 {
00064 std::cout << p->getMove() << " " << p->getLogProb()
00065 << " " << pow(0.5, (p->getLogProb()/100.0)) << "\n";
00066 }
00067 }
00068
00069 void testFile(const char *filename)
00070 {
00071 const Record record = CsaFile(filename).getRecord();
00072 NumEffectState state(record.getInitialState());
00073 const vector<osl::Move> moves=record.getMoves();
00074
00075 MoveStack history;
00076 CategoryEnv env(&state, limit, &history);
00077
00078 testState(env);
00079 for (size_t i=0; i<moves.size(); ++i)
00080 {
00081 const Move move = moves[i];
00082 assert(state.isValidMove(move));
00083
00084 ApplyMoveOfTurn::doMove(state, move);
00085 history.push(move);
00086
00087 testState(env);
00088 }
00089 }
00090
00091
00092
00093
00094
00095