All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
annotate.cc
Go to the documentation of this file.
1 /* annotate.cc
2  */
3 #include "osl/annotate/facade.h"
4 #include "osl/record/kakinoki.h"
5 #include "osl/record/record.h"
6 #include "osl/record/ki2.h"
7 #include "osl/record/psn.h"
8 #include <boost/program_options.hpp>
9 #include <iostream>
10 #include <iomanip>
11 #include <sstream>
12 #include <string>
13 
14 namespace po = boost::program_options;
15 using namespace osl;
16 
17 void analyze_root(const NumEffectState& state, const vector<Move>& moves, int move_number);
18 int main(int argc, char **argv)
19 {
20  po::options_description options;
21  std::string filename;
22  size_t start, end;
23  options.add_options()
24  ("filename,f", po::value<std::string>(&filename),
25  "specify .kif or .ki2 file to be analyzed")
26  ("start,s", po::value<size_t>(&start)->default_value(35),
27  "skip first moves")
28  ("end,e", po::value<size_t>(&end)->default_value(350),
29  "skip first moves")
30  ("help,h", "Show help message");
31  po::variables_map vm;
32  try
33  {
34  po::store(po::parse_command_line(argc, argv, options), vm);
35  po::notify(vm);
36  if (vm.count("help")) {
37  std::cerr << "Usage: " << argv[0] << " [options] files" << std::endl;
38  std::cout << options << std::endl;
39  return 1;
40  }
41  }
42  catch (std::exception& e)
43  {
44  std::cerr << "error in parsing options" << std::endl
45  << e.what() << std::endl;
46  std::cerr << options << std::endl;
47  return 1;
48  }
49  if (filename.empty())
50  return 1;
51  vector<Move> moves;
52  NumEffectState state;
53  try
54  {
55  if (filename.find(".kif") == filename.size()-4)
56  {
57  KakinokiFile file(filename);
58  moves = file.getRecord().getMoves();
59  state = file.getRecord().getInitialState();
60  }
61  else if (filename.find(".ki2") == filename.size()-4)
62  {
63  Ki2File file(filename);
64  moves = file.getRecord().getMoves();
65  state = file.getRecord().getInitialState();
66  }
67  }
68  catch (KakinokiIOError&)
69  {
70  return 1;
71  }
72 
73  for (size_t i=0; i<moves.size(); ++i)
74  {
75  state.makeMove(moves[i]);
76  if (i+1 < start)
77  continue;
78  std::cerr << i+1 << "\n";
79  analyze_root(state, moves, i+1);
80  if (i+1 >= end)
81  break;
82  }
83 }
84 
85 void analyze_root(const NumEffectState& src, const vector<Move>& moves, int move_number)
86 {
87  std::ostringstream ret;
88  ret << "[(" << move_number << ") ";
89  NumEffectState s;
90  if (move_number)
91  {
92  for (int i=0; i<move_number-1; ++i)
93  s.makeMove(moves[i]);
94  ret << record::ki2::show(moves[move_number-1], s) << "]\n";
95  s.makeMove(moves[move_number-1]);
96  }
97 
99  annotate::analyze(src, moves, move_number-1, result);
100  if (result == annotate::AnalysesResult())
101  return;
102  ret << result;
103  std::cout << ret.str() << std::endl;
104 }
105 
106 // ;;; Local Variables:
107 // ;;; mode:c++
108 // ;;; c-basic-offset:2
109 // ;;; End: