00001
00002 #include "osl/category/analyzer/categoryMoveVector.h"
00003 #include "osl/category/analyzer/generateCategoryMoves.h"
00004 #include "osl/category/standardMoveGenerator.h"
00005 #include "osl/record/csaRecord.h"
00006 #include "osl/apply_move/applyMove.h"
00007 #include <iostream>
00008
00009 using namespace osl;
00010 using namespace osl::category;
00011 using namespace osl::category::analyzer;
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 int detailed = false;
00024
00025 void testFile(const char *file_name);
00026
00027 int main(int argc, char **argv)
00028 {
00029 const char *program_name = argv[0];
00030 bool error_flag = false;
00031 extern char *optarg;
00032 extern int optind;
00033
00034 char c;
00035 while ((c = getopt(argc, argv, "dl:vh")) != EOF)
00036 {
00037 switch(c)
00038 {
00039 case 'd': detailed = true;
00040 break;
00041 case 'l': limit = atoi(optarg);
00042 break;
00043 default: error_flag = true;
00044 }
00045 }
00046 argc -= optind;
00047 argv += optind;
00048
00049 if (error_flag || (argc < 1))
00050 usage(program_name);
00051
00052 for (int i=0; i<argc; ++i)
00053 {
00054 testFile(argv[i]);
00055 }
00056 }
00057
00058 void testState(const CategoryEnv& env)
00059 {
00060 std::cout << *env.state;
00061 CategoryMoveVector moves;
00062 if (detailed)
00063 GenerateCategoryMoves::generateAndSetDetailed<StandardMoveGenerator>(env,moves);
00064 else
00065 GenerateCategoryMoves::generateAndSet<StandardMoveGenerator>(env,moves);
00066 for (CategoryMoveVector::const_iterator p=moves.begin();
00067 p!=moves.end(); ++p)
00068 {
00069 std::cout << p->category << "\n";
00070 for (MoveLogProbVector::const_iterator q=p->moves.begin();
00071 q!=p->moves.end(); ++q)
00072 {
00073 std::cout << " " << *q << "\n";
00074 }
00075 }
00076 }
00077
00078 void testFile(const char *filename)
00079 {
00080 const Record record = CsaFile(filename).getRecord();
00081 NumEffectState state(record.getInitialState());
00082 const vector<osl::Move> moves=record.getMoves();
00083
00084 MoveStack history;
00085 CategoryEnv env(&state, limit, &history);
00086
00087 testState(env);
00088 for (size_t i=0; i<moves.size(); ++i)
00089 {
00090 const Move move = moves[i];
00091 assert(state.isValidMove(move));
00092
00093 ApplyMoveOfTurn::doMove(state, move);
00094 history.push(move);
00095
00096 testState(env);
00097 }
00098 }
00099
00100
00101
00102
00103
00104