00001 #include "osl/eval/see.h"
00002 #include "osl/eval/pieceEval.h"
00003 #include "osl/effect_util/pin.h"
00004 #include "osl/record/csaRecord.h"
00005 #include "osl/record/csaIOError.h"
00006 #include "osl/move_generator/legalMoves.h"
00007 #include "osl/container/moveVector.h"
00008 #include "osl/apply_move/applyMove.h"
00009 #include "osl/stat/average.h"
00010 #include "osl/misc/perfmon.h"
00011
00012 #include <boost/format.hpp>
00013 #include <string>
00014 #include <iostream>
00015 #include <iomanip>
00016 #include <cmath>
00017 #include <cstdio>
00018 using namespace osl;
00019
00025 void usage(const char *prog)
00026 {
00027 using namespace std;
00028 cerr << "Usage: " << prog << " [-v] [-f skip] [-o] csafiles\n"
00029 << endl;
00030 exit(1);
00031 }
00032
00033 size_t first_skip = 0;
00034 bool verbose = false;
00035 bool old = false;
00036
00037 stat::Average moves, cycles, cycles_per_move;
00038
00039 void test_file(const char *filename);
00040
00041 int main(int argc, char **argv)
00042 {
00043 const char *program_name = argv[0];
00044 bool error_flag = false;
00045 extern char *optarg;
00046 extern int optind;
00047
00048 char c;
00049 while ((c = getopt(argc, argv, "f:ovh")) != EOF)
00050 {
00051 switch(c)
00052 {
00053 case 'f': first_skip = atoi(optarg);
00054 break;
00055 case 'v': verbose = true;
00056 break;
00057 case 'o': old = true;
00058 break;
00059 default: error_flag = true;
00060 }
00061 }
00062 argc -= optind;
00063 argv += optind;
00064
00065 if (error_flag || (argc < 1))
00066 usage(program_name);
00067
00068 for (int i=0; i<argc; ++i)
00069 {
00070 if (i % 128 == 0)
00071 std::cerr << '.';
00072 test_file(argv[i]);
00073 }
00074
00075 std::cout << "average cycles/position " << cycles.getAverage() << "\n"
00076 << "average cycles/position/move " << cycles_per_move.getAverage()
00077 << "\n";
00078 }
00079
00080
00081
00082 size_t num_positions = 0;
00083 void test_position(const NumEffectState& state)
00084 {
00085 MoveVector moves;
00086 LegalMoves::generate(state, moves);
00087 const PieceMask my_pin = effect_util::Pin::make(state, state.getTurn());
00088 const PieceMask op_pin = effect_util::Pin::make(state, alt(state.getTurn()));
00089
00090 misc::PerfMon clock;
00091 for (size_t i=0; i<moves.size(); ++i) {
00092 if (old)
00093 PieceEval::computeDiffAfterMoveForRP(state, moves[i]);
00094 else
00095 See::see(state, moves[i], my_pin, op_pin);
00096 }
00097 const size_t consumed = clock.stop();
00098 cycles.add(consumed);
00099 cycles_per_move.add(consumed/moves.size());
00100 ++num_positions;
00101 }
00102
00103 void test_file(const char *filename)
00104 {
00105 Record rec;
00106 try {
00107 rec = CsaFile(filename).getRecord();
00108 }
00109 catch (CsaIOError& e) {
00110 std::cerr << "skip " << filename <<"\n";
00111 std::cerr << e.what() << "\n";
00112 return;
00113 }
00114 catch (...) {
00115 throw;
00116 }
00117
00118 NumEffectState state(rec.getInitialState());
00119 const osl::stl::vector<osl::Move> moves=rec.getMoves();
00120
00121 for (size_t i=0; i<moves.size(); ++i) {
00122 const Move move = moves[i];
00123 assert(state.isValidMove(move));
00124 if (i >= first_skip) {
00125 test_position(state);
00126 }
00127 ApplyMoveOfTurn::doMove(state, move);
00128 }
00129 }
00130
00131
00132
00133
00134
00135