00001 /* recordTracer.cc 00002 */ 00003 #include "osl/game_playing/recordTracer.h" 00004 #include "osl/record/kisen.h" 00005 #include "osl/record/csa.h" 00006 #include <iostream> 00007 00008 osl::game_playing:: 00009 RecordTracer::RecordTracer(const vector<Move>& m, bool v) 00010 : moves(m), verbose(v) 00011 { 00012 state_index.push(moves.empty() ? -1 : 0); 00013 if (verbose && (! moves.empty())) 00014 std::cerr << "book: expect " << record::csa::show(moves[0]) 00015 << "\n"; 00016 } 00017 00018 osl::game_playing:: 00019 RecordTracer::RecordTracer(const RecordTracer& copy) 00020 : OpeningBookTracer(copy), 00021 moves(copy.moves), state_index(copy.state_index), verbose(copy.verbose) 00022 { 00023 } 00024 00025 osl::game_playing:: 00026 RecordTracer::~RecordTracer() 00027 { 00028 } 00029 00030 osl::game_playing::OpeningBookTracer* osl::game_playing:: 00031 RecordTracer::clone() const 00032 { 00033 return new RecordTracer(*this); 00034 } 00035 00036 void osl::game_playing:: 00037 RecordTracer::update(Move move) 00038 { 00039 if ((! isOutOfBook()) 00040 && (move == moves.at(stateIndex()))) 00041 { 00042 const size_t next_index = stateIndex()+1; 00043 if (next_index < moves.size()) 00044 { 00045 state_index.push(next_index); 00046 if (verbose) 00047 std::cerr << "book: expect " << record::csa::show(moves[next_index]) 00048 << "\n"; 00049 return; 00050 } 00051 } 00052 state_index.push(-1); 00053 } 00054 00055 const osl::Move osl::game_playing:: 00056 RecordTracer::selectMove() const 00057 { 00058 if (isOutOfBook()) 00059 return Move::INVALID(); 00060 return moves.at(stateIndex()); 00061 } 00062 00063 bool osl::game_playing:: 00064 RecordTracer::isOutOfBook() const 00065 { 00066 return stateIndex() < 0; 00067 } 00068 void osl::game_playing:: 00069 RecordTracer::popMove() 00070 { 00071 state_index.pop(); 00072 } 00073 00074 const osl::game_playing::RecordTracer osl::game_playing:: 00075 RecordTracer::kisenRecord(const char *filename, int id, 00076 unsigned int num_moves, bool verbose) 00077 { 00078 KisenFile kisen(filename); 00079 vector<Move> moves = kisen.getMoves(id); 00080 if (moves.size() > num_moves) 00081 moves.resize(num_moves); 00082 return RecordTracer(moves, verbose); 00083 } 00084 00085 /* ------------------------------------------------------------------------- */ 00086 // ;;; Local Variables: 00087 // ;;; mode:c++ 00088 // ;;; c-basic-offset:2 00089 // ;;; End: