File: show_progress.cc

package info (click to toggle)
gpsshogi 0.7.0-3.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 111,280 kB
  • sloc: cpp: 80,962; perl: 12,610; ruby: 3,929; javascript: 1,631; makefile: 1,202; sh: 473; tcl: 166; ansic: 67
file content (134 lines) | stat: -rw-r--r-- 2,826 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * show_progress
 */

#include "osl/progress/progressAnalyzer.h"
#include "osl/record/record.h"
#include "osl/record/csa.h"
#include "osl/record/kisen.h"
#include "osl/effectUtil.h"
#include "osl/numEffectState.h"
#include "osl/progress.h"
#include "osl/applyMove.h"

#include <iostream>
#include <cstdlib>
#include <unistd.h>

using namespace osl;
using namespace osl::progress;

void usage(const char *prog)
{
  using namespace std;
  cerr << "Usage: " << prog << " [-r] [-N atmost-N-games] [-S skip] [-k kisenFileName] csa-filenames "
       << "-r raw output\n"
       << endl;
  exit(1);
}

class StandardProgressAnazyzer : public ProgressAnazyzer
{
public:
  explicit StandardProgressAnazyzer(bool raw_output) 
    : ProgressAnazyzer(raw_output)
  {
  }
  void processRecord(osl::vector<Move> const& moves)
  {
    NumEffectState state((SimpleState(HIRATE)));
    Progress progress(state);
    for (size_t i=0; i<moves.size(); ++i)
    {
      if (EffectUtil::isKingInCheck(alt(state.turn()), state))
      {
	// ʬμ֤β => ľμ꤬ˡ
	std::cerr << "e"; // state;
	break;
      }
      ApplyMoveOfTurn::doMove(progress, state, moves[i]);
      state.doMove(moves[i]);
      const int cur = progress.getVal();
      processMove(cur);
    }
    endRecond(moves.size());
  }
};

int main(int argc, char **argv)
{
  const char *program_name = argv[0];
  const char *kisenFilename = 0;
  bool error_flag = false;
  bool raw_output=false;
  size_t num_records = 1;
  size_t skip = 0;

  extern char *optarg;
  extern int optind;
  char c;
  while ((c = getopt(argc, argv, "N:S:rk:vh")) != EOF)
  {
    switch(c)
    {
    case 'k': kisenFilename = optarg;
      break;
    case 'N': num_records = atoi(optarg);
      break;
    case 'S': skip = atoi(optarg);
      break;
    case 'r': raw_output = true;
      break;
    default:	error_flag = true;
    }
  }
  argc -= optind;
  argv += optind;

  if (error_flag)
    usage(program_name);

  try
  {
    nice(20);
    size_t record_processed = 0;

    StandardProgressAnazyzer analyzer(raw_output);
      
    //ǽ Kisenե
    if (kisenFilename)
    {
      KisenFile kisenFile(kisenFilename);
	  
      for (size_t i=skip; i<kisenFile.size(); i++)
      {
	if (++record_processed > num_records)
	  break;
	const vector<Move> moves=kisenFile.getMoves(i);
	analyzer.processRecord(moves);
      }
    }

    // CSAե
    for (int i=0; i<argc; ++i)
    {
      if (++record_processed > num_records)
	break;
      CsaFile file(argv [i]);
      const vector<Move> moves=file.getRecord().getMoves();

      analyzer.processRecord(moves);
    }
  }

  catch (std::exception& e)
  {
    std::cerr << e.what() << "\n";
    return 1;
  }
}

// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End: