All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
recordTracer.cc
Go to the documentation of this file.
1 /* recordTracer.cc
2  */
4 #include "osl/record/kisen.h"
5 #include "osl/record/csa.h"
6 #include <iostream>
7 
9 RecordTracer::RecordTracer(const vector<Move>& m, bool v)
10  : moves(m), verbose(v)
11 {
12  state_index.push(moves.empty() ? -1 : 0);
13  if (verbose && (! moves.empty()))
14  std::cerr << "book: expect " << record::csa::show(moves[0])
15  << "\n";
16 }
17 
20  : OpeningBookTracer(copy),
21  moves(copy.moves), state_index(copy.state_index), verbose(copy.verbose)
22 {
23 }
24 
27 {
28 }
29 
32 {
33  return new RecordTracer(*this);
34 }
35 
38 {
39  if ((! isOutOfBook())
40  && (move == moves.at(stateIndex())))
41  {
42  const size_t next_index = stateIndex()+1;
43  if (next_index < moves.size())
44  {
45  state_index.push(next_index);
46  if (verbose)
47  std::cerr << "book: expect " << record::csa::show(moves[next_index])
48  << "\n";
49  return;
50  }
51  }
52  state_index.push(-1);
53 }
54 
57 {
58  if (isOutOfBook())
59  return Move::INVALID();
60  return moves.at(stateIndex());
61 }
62 
65 {
66  return stateIndex() < 0;
67 }
70 {
71  state_index.pop();
72 }
73 
75 RecordTracer::kisenRecord(const char *filename, int id,
76  unsigned int num_moves, bool verbose)
77 {
78  KisenFile kisen(filename);
79  vector<Move> moves = kisen.getMoves(id);
80  if (moves.size() > num_moves)
81  moves.resize(num_moves);
82  return RecordTracer(moves, verbose);
83 }
84 
85 /* ------------------------------------------------------------------------- */
86 // ;;; Local Variables:
87 // ;;; mode:c++
88 // ;;; c-basic-offset:2
89 // ;;; End: