00001
00002
00003 #include "osl/progress/effect5x3.h"
00004 #include "osl/progress/effect5x3d.h"
00005 #include "osl/record/csaString.h"
00006 #include "osl/record/csaRecord.h"
00007 #include "osl/misc/perfmon.h"
00008 #include "osl/apply_move/applyMove.h"
00009
00010 #include <iostream>
00011 #include <fstream>
00012
00013 using namespace osl;
00014
00015 void usage(const char *program_name)
00016 {
00017 std::cerr << program_name << " csafiles\n";
00018 exit(1);
00019 }
00020
00021 size_t skip_first = 0;
00022 void run(const char *filename);
00023 void finish();
00024
00025 int main(int argc, char **argv)
00026 {
00027 const char *program_name = argv[0];
00028 bool error_flag = false;
00029
00030 extern char *optarg;
00031 extern int optind;
00032 char c;
00033 while ((c = getopt(argc, argv, "s:vh")) != EOF)
00034 {
00035 switch(c)
00036 {
00037 case 's': skip_first = atoi(optarg);
00038 break;
00039 default: error_flag = true;
00040 }
00041 }
00042 argc -= optind;
00043 argv += optind;
00044
00045 if (error_flag || (argc < 1))
00046 usage(program_name);
00047
00048 try
00049 {
00050 for (int i=0; i<argc; ++i)
00051 {
00052 run(argv[i]);
00053 }
00054 finish();
00055 }
00056 catch (std::exception& e)
00057 {
00058 std::cerr << e.what() << "\n";
00059 return 1;
00060 }
00061 catch (...)
00062 {
00063 throw;
00064 }
00065 }
00066
00067 unsigned long long total_cycles=0;
00068 unsigned long long total_cycles_naive=0;
00069 unsigned long long positions = 0;
00070 void run(const char *filename)
00071 {
00072 Record rec=CsaFile(filename).getRecord();
00073 NumEffectState state(rec.getInitialState());
00074 const vector<osl::Move> moves=rec.getMoves();
00075
00076 size_t i=0;
00077 progress::Effect5x3 progress(state);
00078 while (true)
00079 {
00080 if (i >= moves.size())
00081 break;
00082 const Move move = moves[i++];
00083 ApplyMoveOfTurn::doMove(state, move);
00084 if (i >= skip_first) {
00085 misc::PerfMon clock;
00086 progress.update(state, move);
00087 total_cycles += clock.stop();
00088 ++positions;
00089 }
00090 }
00091 }
00092
00093 void finish()
00094 {
00095 std::cerr << "p " << total_cycles << " / " << positions << " = "
00096 << total_cycles/(double)positions << "\n";
00097 }
00098
00099
00100
00101
00102
00103