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/csaRecord.h"
00010 #include "osl/record/kisen.h"
00011 #include "osl/progress/effect5x3.h"
00012 #include "osl/apply_move/applyMove.h"
00013 #include "osl/stat/average.h"
00014 #include "osl/stat/histogram.h"
00015 #include <boost/program_options.hpp>
00016 #include <iostream>
00017 #include <cmath>
00018 using namespace osl;
00019 using namespace osl::rating;
00020 namespace po = boost::program_options;
00021
00022 size_t num_kisen, opening_skip, target_limit;
00023
00024 void run(NumEffectState& state, const vector<Move>& moves);
00025 void show_statistics();
00026
00027 int main(int argc, char **argv)
00028 {
00029 std::string kisen_filename;
00030 std::vector<std::string> filenames;
00031 po::options_description options("Options");
00032 options.add_options()
00033 ("csa-file",
00034 po::value<std::vector<std::string> >(),
00035 "csa filename")
00036 ("kisen,k",
00037 po::value<std::string>(&kisen_filename),
00038 "kisen filename")
00039 ("num-kisen",
00040 po::value<size_t>(&num_kisen)->default_value(0),
00041 "number of records in kisen to be processed")
00042 ("target-limit",
00043 po::value<size_t>(&target_limit)->default_value(1000),
00044 "ignore moves whose log-probability is greater than this threshold")
00045 ("opening-skip",
00046 po::value<size_t>(&opening_skip)->default_value(20),
00047 "number of opening moves ignored in analysis");
00048 po::variables_map vm;
00049 po::positional_options_description p;
00050 p.add("csa-file", -1);
00051 try
00052 {
00053 po::store(po::command_line_parser(argc, argv).
00054 options(options).positional(p).run(), vm);
00055 notify(vm);
00056 if (vm.count("help")) {
00057 std::cout << options << std::endl;
00058 return 0;
00059 }
00060 if (vm.count("csa-file"))
00061 filenames = vm["csa-file"].as<std::vector<std::string> >();
00062 }
00063 catch (std::exception& e)
00064 {
00065 std::cerr << "error in parsing options" << std::endl
00066 << e.what() << std::endl;
00067 std::cerr << options << std::endl;
00068 throw;
00069 }
00070 if (kisen_filename != "") {
00071 std::cerr << "kisen " << kisen_filename << "\n";
00072 KisenFile kisen_file(kisen_filename.c_str());
00073 if (num_kisen == 0)
00074 num_kisen = kisen_file.size();
00075 for (size_t i=0; i<num_kisen; i++) {
00076 if (i % 16 == 0)
00077 std::cerr << '.';
00078 NumEffectState state(kisen_file.getInitialState());
00079 const osl::vector<Move> moves = kisen_file.getMoves(i);
00080 run(state, moves);
00081 }
00082 }
00083 for (size_t i=0; i<filenames.size(); ++i) {
00084 if (i % 16 == 0)
00085 std::cerr << '.';
00086 CsaFile file(filenames[i]);
00087 NumEffectState state(file.getInitialState());
00088 const osl::vector<Move> moves = file.getRecord().getMoves();
00089 run(state, moves);
00090 }
00091 std::cerr << "\n";
00092 show_statistics();
00093 }
00094
00095 CArray<stat::Average,8> top_rated, active;
00096
00097 void show(const NumEffectState& state, Move next)
00098 {
00099 static const StandardFeatureSet& feature_set = StandardFeatureSet::instance();
00100 MoveLogProbVector moves;
00101 RatingEnv env;
00102 env.make(state);
00103
00104 feature_set.generateLogProbNormalized(state, env, 2000, moves);
00105 const MoveLogProb *rm = moves.find(next);
00106 if (! rm)
00107 return;
00108 int index = rm - &*moves.begin();
00109 for (size_t i=0; i<top_rated.size(); ++i) {
00110 if (i >= moves.size())
00111 break;
00112 bool a = moves[i].getLogProb() <= (int)target_limit;
00113 active[i].add(a);
00114 if (! a)
00115 continue;
00116 bool found = index == (int)i;
00117 top_rated[i].add(found);
00118 }
00119 }
00120
00121 void run(NumEffectState& state, const vector<Move>& moves)
00122 {
00123 for (size_t i=0; i<moves.size(); ++i) {
00124 if (state.inCheck(alt(state.getTurn())))
00125 break;
00126
00127 const Move move = moves[i];
00128 if (i >= opening_skip)
00129 show(state, move);
00130 ApplyMoveOfTurn::doMove(state, move);
00131 }
00132 }
00133
00134 void show_statistics()
00135 {
00136 for (size_t i=0; i<top_rated.size(); ++i)
00137 std::cout << "top " << i
00138 << " " << top_rated[i].getAverage()*100.0
00139 << " " << active[i].getAverage()*100.0
00140 << "\n";
00141 }
00142
00143
00144
00145
00146
00147