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