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