Go to the documentation of this file.00001
00002
00003 #include "osl/rating/featureSet.h"
00004 #include "osl/rating/ratingEnv.h"
00005 #include "osl/effect_util/effectUtil.h"
00006 #include "osl/state/numEffectState.h"
00007 #include "osl/stl/vector.h"
00008 #include "osl/record/csa.h"
00009 #include "osl/record/kisen.h"
00010 #include "osl/progress/effect5x3.h"
00011 #include "osl/stat/average.h"
00012 #include "osl/stat/histogram.h"
00013 #include <iostream>
00014 #include <cmath>
00015 using namespace osl;
00016 using namespace osl::rating;
00017
00018 int verbose = 0;
00019 const char *kisen_filename="0.kif";
00020 size_t num_kisen = 4096;
00021 double verbose_limit = 0;
00022
00023 void show(const NumEffectState&, Move, const progress::Effect5x3& progress);
00024 void show_statistics();
00025
00026 int main()
00027 {
00028 KisenFile kisen_file(kisen_filename);
00029 for (size_t i=0; i<num_kisen; i++) {
00030 if (i % 16 == 0)
00031 std::cerr << '.';
00032 NumEffectState state(kisen_file.getInitialState());
00033 const osl::vector<Move> moves = kisen_file.getMoves(i);
00034 RatingEnv env;
00035 env.make(state);
00036 progress::Effect5x3 progress(state);
00037 for (size_t i=0; i<moves.size(); ++i) {
00038 if (state.inCheck(alt(state.turn())))
00039 break;
00040
00041 const Move move = moves[i];
00042 show(state, move, progress);
00043 state.makeMove(move);
00044 env.update(state, move);
00045 progress.update(state, move);
00046 }
00047 }
00048 std::cerr << "\n";
00049 show_statistics();
00050 }
00051
00052 vector<double> rating_to_probability(const RatedMoveVector& moves)
00053 {
00054 double sum = 0;
00055 for (size_t i=0; i<moves.size(); ++i)
00056 sum += pow(10, moves[i].rating()/400.0);
00057 vector<double> result(moves.size());
00058 for (size_t i=0; i<moves.size(); ++i)
00059 result[i] = pow(10, moves[i].rating()/400.0) / sum;
00060 return result;
00061 }
00062
00063 stat::Average top_rated[16];
00064 stat::Histogram histogram(1,10,0,true);
00065
00066 void show(const NumEffectState& state, Move next, const progress::Effect5x3& progress)
00067 {
00068 static const StandardFeatureSet& feature_set = StandardFeatureSet::instance();
00069 RatedMoveVector moves;
00070 RatingEnv env;
00071 env.make(state);
00072
00073 feature_set.generateRating(state, env, 2000, moves);
00074 vector<double> probability = rating_to_probability(moves);
00075 const RatedMove *rm = moves.find(next);
00076 top_rated[progress.progress16().value()].add(rm && rm == &moves[0]);
00077 if (rm)
00078 histogram.add(-log10(probability[rm - &moves[0]]));
00079 if (verbose || (rm && probability[rm - &moves[0]] < verbose_limit)) {
00080 std::cout << state;
00081 if (verbose > 1) {
00082 for (size_t i=0; i<probability.size(); ++i) {
00083 std::cout << record::csa::show(moves[i].move()) << " " << probability[i] << "\n";
00084 }
00085 }
00086 std::cout << "max " << probability.front() << " min " << probability.back()
00087 << " selected " << record::csa::show(next) << " ";
00088 if (rm)
00089 std::cout << probability[rm - &moves[0]] << "\n";
00090 else
00091 std::cout << "move-not-found?!\n";
00092 std::cout << "\n";
00093 }
00094 }
00095
00096 void show_statistics()
00097 {
00098 for (int i=0; i<16; ++i)
00099 std::cout << "top " << i << " " << top_rated[i].getAverage() << "\n";
00100 }
00101
00102
00103
00104
00105
00106