Go to the documentation of this file.00001
00002
00003 #include "osl/annotate/facade.h"
00004 #include "osl/record/kakinoki.h"
00005 #include "osl/record/record.h"
00006 #include "osl/record/ki2.h"
00007 #include "osl/record/psn.h"
00008 #include <boost/program_options.hpp>
00009 #include <iostream>
00010 #include <iomanip>
00011 #include <sstream>
00012 #include <string>
00013
00014 namespace po = boost::program_options;
00015 using namespace osl;
00016
00017 void analyze_root(const NumEffectState& state, const vector<Move>& moves, int move_number);
00018 int main(int argc, char **argv)
00019 {
00020 po::options_description options;
00021 std::string filename;
00022 size_t start, end;
00023 options.add_options()
00024 ("filename,f", po::value<std::string>(&filename),
00025 "specify .kif or .ki2 file to be analyzed")
00026 ("start,s", po::value<size_t>(&start)->default_value(35),
00027 "skip first moves")
00028 ("end,e", po::value<size_t>(&end)->default_value(350),
00029 "skip first moves")
00030 ("help,h", "Show help message");
00031 po::variables_map vm;
00032 try
00033 {
00034 po::store(po::parse_command_line(argc, argv, options), vm);
00035 po::notify(vm);
00036 if (vm.count("help")) {
00037 std::cerr << "Usage: " << argv[0] << " [options] files" << std::endl;
00038 std::cout << options << std::endl;
00039 return 1;
00040 }
00041 }
00042 catch (std::exception& e)
00043 {
00044 std::cerr << "error in parsing options" << std::endl
00045 << e.what() << std::endl;
00046 std::cerr << options << std::endl;
00047 return 1;
00048 }
00049 if (filename.empty())
00050 return 1;
00051 vector<Move> moves;
00052 NumEffectState state;
00053 try
00054 {
00055 if (filename.find(".kif") == filename.size()-4)
00056 {
00057 KakinokiFile file(filename);
00058 moves = file.getRecord().getMoves();
00059 state = file.getRecord().getInitialState();
00060 }
00061 else if (filename.find(".ki2") == filename.size()-4)
00062 {
00063 Ki2File file(filename);
00064 moves = file.getRecord().getMoves();
00065 state = file.getRecord().getInitialState();
00066 }
00067 }
00068 catch (KakinokiIOError&)
00069 {
00070 return 1;
00071 }
00072
00073 for (size_t i=0; i<moves.size(); ++i)
00074 {
00075 state.makeMove(moves[i]);
00076 if (i+1 < start)
00077 continue;
00078 std::cerr << i+1 << "\n";
00079 analyze_root(state, moves, i+1);
00080 if (i+1 >= end)
00081 break;
00082 }
00083 }
00084
00085 void analyze_root(const NumEffectState& src, const vector<Move>& moves, int move_number)
00086 {
00087 std::ostringstream ret;
00088 ret << "[(" << move_number << ") ";
00089 NumEffectState s;
00090 if (move_number)
00091 {
00092 for (int i=0; i<move_number-1; ++i)
00093 s.makeMove(moves[i]);
00094 ret << record::ki2::show(moves[move_number-1], s) << "]\n";
00095 s.makeMove(moves[move_number-1]);
00096 }
00097
00098 annotate::AnalysesResult result;
00099 annotate::analyze(src, moves, move_number-1, result);
00100 if (result == annotate::AnalysesResult())
00101 return;
00102 ret << result;
00103 std::cout << ret.str() << std::endl;
00104 }
00105
00106
00107
00108
00109