All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
progress/show-state.cc
Go to the documentation of this file.
1 /* show-state.cc
2  */
3 
6 #include "osl/record/csaRecord.h"
8 #include <stdexcept>
9 #include <iostream>
10 #include <iomanip>
11 #include <cstdlib>
12 #include <cstdio>
13 #include <unistd.h>
14 
15 using namespace osl;
16 using namespace osl::progress;
17 
18 void usage(const char *prog)
19 {
20  using namespace std;
21  cerr << "Usage: " << prog << " [-a] csa-filename"
22  << endl;
23  exit(1);
24 }
25 
26 void show(const char *filename);
27 
28 bool show_all_states = false;
29 int main(int argc, char **argv)
30 {
31  const char *program_name = argv[0];
32  bool error_flag = false;
33 
34  // extern char *optarg;
35  extern int optind;
36  char c;
37  while ((c = getopt(argc, argv, "at:f:vh")) != EOF)
38  {
39  switch(c)
40  {
41  case 'a': show_all_states = true;
42  break;
43  default: error_flag = true;
44  }
45  }
46  argc -= optind;
47  argv += optind;
48 
49  if (error_flag)
50  usage(program_name);
51 
53 
54  for (int i=0; i<argc; ++i)
55  {
56  show(argv[i]);
57  }
58 }
59 
60 void show(const NumEffectState& state)
61 {
62  std::cout << state;
63  const int progress_black = Effect5x3::makeProgress(BLACK,state);
64  const int progress_white = Effect5x3::makeProgress(WHITE,state);
65  std::cout << "black " << progress_black << "\n";
66  std::cout << "white " << progress_white << "\n";
67  std::cout << "total " << progress_black + progress_white << "\n";
68  std::cout << "test " << progress::ml::NewProgress(state).progress16().value() << "\n";
69 }
70 
71 void show(const char *filename)
72 {
73  std::cout << filename << "\n";
74  CsaFile file(filename);
75  const vector<osl::Move> moves = file.getRecord().getMoves();
76  NumEffectState state(file.getInitialState());
77  for (unsigned int i=0; i<moves.size(); i++)
78  {
79  if (show_all_states)
80  show(state);
81  const Move m = moves[i];
82  state.makeMove(m);
83  }
84  show(state);
85 }
86 
87 /* ------------------------------------------------------------------------- */
88 // ;;; Local Variables:
89 // ;;; mode:c++
90 // ;;; c-basic-offset:2
91 // ;;; End: