Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
lib
game_playing
recordTracer.cc
Go to the documentation of this file.
1
/* recordTracer.cc
2
*/
3
#include "
osl/game_playing/recordTracer.h
"
4
#include "
osl/record/kisen.h
"
5
#include "
osl/record/csa.h
"
6
#include <iostream>
7
8
osl::game_playing::
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
18
osl::game_playing::
19
RecordTracer::RecordTracer
(
const
RecordTracer
& copy)
20
:
OpeningBookTracer
(copy),
21
moves
(copy.
moves
), state_index(copy.state_index),
verbose
(copy.
verbose
)
22
{
23
}
24
25
osl::game_playing::
26
RecordTracer::~RecordTracer
()
27
{
28
}
29
30
osl::game_playing::OpeningBookTracer
*
osl::game_playing::
31
RecordTracer::clone
()
const
32
{
33
return
new
RecordTracer
(*
this
);
34
}
35
36
void
osl::game_playing::
37
RecordTracer::update
(
Move
move)
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
55
const
osl::Move
osl::game_playing::
56
RecordTracer::selectMove
()
const
57
{
58
if
(isOutOfBook())
59
return
Move::INVALID
();
60
return
moves
.at(stateIndex());
61
}
62
63
bool
osl::game_playing::
64
RecordTracer::isOutOfBook
()
const
65
{
66
return
stateIndex() < 0;
67
}
68
void
osl::game_playing::
69
RecordTracer::popMove
()
70
{
71
state_index.pop();
72
}
73
74
const
osl::game_playing::RecordTracer
osl::game_playing::
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:
Generated on Sun Jul 21 2013 13:37:26 by
1.8.4