00001 #include "osl/rating/featureSet.h"
00002 #include "osl/rating/ratingEnv.h"
00003 #include "osl/eval/progressEval.h"
00004 #include "osl/effect_util/sendOffPosition.h"
00005 #include "osl/effect_util/effectUtil.h"
00006 #include "osl/record/csaRecord.h"
00007 #include "osl/record/csaIOError.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 using namespace osl::rating;
00020
00026 void usage(const char *prog)
00027 {
00028 using namespace std;
00029 cerr << "Usage: " << prog << " [-v] [-f skip] csafiles\n"
00030 << endl;
00031 exit(1);
00032 }
00033
00034 size_t first_skip = 0;
00035 bool verbose = false;
00036
00037 stat::Average moves, cycles, cycles_per_move, probs, order, top_score, selected_score;
00038 int min_selected = 1000;
00039
00040 void test_file(const FeatureSet&, const char *filename);
00041
00042 int main(int argc, char **argv)
00043 {
00044 const char *program_name = argv[0];
00045 bool error_flag = false;
00046 extern char *optarg;
00047 extern int optind;
00048
00049 char c;
00050 while ((c = getopt(argc, argv, "f:vh")) != EOF)
00051 {
00052 switch(c)
00053 {
00054 case 'f': first_skip = atoi(optarg);
00055 break;
00056 case 'v': verbose = true;
00057 break;
00058 default: error_flag = true;
00059 }
00060 }
00061 argc -= optind;
00062 argv += optind;
00063
00064 if (error_flag || (argc < 1))
00065 usage(program_name);
00066
00067 eval::ProgressEval::setUp();
00068 StandardFeatureSet f;
00069
00070 for (int i=0; i<argc; ++i)
00071 {
00072 if (i % 128 == 0)
00073 std::cerr << '.';
00074 test_file(f, argv[i]);
00075 }
00076
00077 std::cout << "\n"
00078 << "average moves/position " << moves.getAverage() << "\n"
00079 << "average order " << order.getAverage() << "\n"
00080 << "average selected score " << selected_score.getAverage() << "\n"
00081 << "min selected score " << min_selected << "\n"
00082 << "average top score " << top_score.getAverage() << "\n";
00083 std::cout << "average cycles/position " << cycles.getAverage() << "\n"
00084 << "average cycles/position/move " << cycles_per_move.getAverage()
00085 << "\n";
00086 }
00087
00088
00089
00090 size_t num_positions = 0;
00091 void test_position(const FeatureSet& f, Move next_move, Move last_move, const RatingEnv& env,
00092 const NumEffectState& state)
00093 {
00094 RatedMoveVector my_moves;
00095
00096 misc::PerfMon clock;
00097 f.generateRating(state, env, 1400, my_moves);
00098
00099 const size_t consumed = clock.stop();
00100 if (my_moves.size())
00101 top_score.add(my_moves[0].rating());
00102 const RatedMove *p = my_moves.find(next_move);
00103 int count = my_moves.size();
00104 int order = p ? p - &*my_moves.begin() +1 : count;
00105 if (p) {
00106 ::order.add(order);
00107 if (p->rating() < min_selected)
00108 min_selected = p->rating();
00109 if (p->rating() < -2000) {
00110 std::cerr << state << "selected " << *p << "\n" << my_moves;
00111 }
00112 }
00113 else {
00114 ::order.add(count);
00115 }
00116 moves.add(count);
00117 cycles.add(consumed);
00118 cycles_per_move.add(consumed/count);
00119 ++num_positions;
00120
00121 }
00122
00123 void test_file(const FeatureSet& f, const char *filename)
00124 {
00125 Record rec;
00126 try {
00127 rec = CsaFile(filename).getRecord();
00128 }
00129 catch (CsaIOError& e) {
00130 std::cerr << "skip " << filename <<"\n";
00131 std::cerr << e.what() << "\n";
00132 return;
00133 }
00134 catch (...) {
00135 throw;
00136 }
00137
00138 NumEffectState state(rec.getInitialState());
00139 const osl::stl::vector<osl::Move> moves=rec.getMoves();
00140
00141 RatingEnv env;
00142 env.make(state);
00143 for (size_t i=0; i<moves.size(); ++i) {
00144 const Move move = moves[i];
00145 assert(state.isValidMove(move));
00146 if (i >= first_skip) {
00147 test_position(f, moves[i], (i>0 ? moves[i-1] : Move::PASS(alt(moves[i].player()))),
00148 env, state);
00149 }
00150 ApplyMoveOfTurn::doMove(state, move);
00151 env.update(state, move);
00152 }
00153 }
00154
00155
00156
00157
00158
00159