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