csajapanize.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
csajapanize.cc
Go to the documentation of this file.
1 /* csajapanize.cc
2 */
3 #include "osl/record/csaString.h"
4 #include "osl/record/record.h"
5 #include "osl/record/ki2.h"
6 #include "osl/record/csaIOError.h"
7 #include "osl/misc/iconvConvert.h"
8 #include <string>
9 #include <iostream>
10 #include <sstream>
11 using namespace osl;
12 using record::SearchInfo;
13 void process(int move_number, const NumEffectState& src,
14 const vector<Move>& history,
15 const SearchInfo& info)
16 {
17 vector<Move> moves = info.moves;
18 if (moves.empty())
19 return;
20 std::ostringstream ss;
21 NumEffectState state = src;
22 for (int i=0; i<move_number; ++i)
23 state.makeMove(history[i]);
24 ss << "[(" << move_number+1 << ") "
25 << record::ki2::show(history[move_number], state)
26 << "] " << info.value << ' ';
27 state.makeMove(history[move_number]);
28 for (size_t i=0; i<moves.size(); ++i) {
29 ss << record::ki2::show(moves[i],
30 state, i ? moves[i-1] : history[move_number]);
31 state.makeMove(moves[i]);
32 }
33 std::string utf8 = misc::IconvConvert::convert("EUC-JP", "UTF-8", ss.str());
34 std::cout << utf8 << std::endl;
35
36 }
37 int main() {
38 std::string line;
39 std::string all;
40 int last_output = 0;
41 while (getline(std::cin, line)) {
42 all += line + "\n";
43 if (line[0] == '#') break;
44 try {
45 CsaString csa(all.c_str());
46 record::Record record = csa.getRecord();
47 vector<Move> moves;
48 vector<int> times;
49 vector<std::string> comments;
50 vector<SearchInfo> info;
51 record.getMoves(moves, times, comments, info);
52 if (info.empty() || info.back().moves.empty())
53 continue;
54 while (last_output < (int)info.size()) {
55 if (last_output > 0)
56 process(last_output, csa.getInitialState(),
57 moves, info[last_output]);
58 ++last_output;
59 }
60 }
61 catch (CsaIOError& e) {
62 if (last_output) {
63 std::cerr << "oops " << e.what() << ' ' << last_output << '\n';
64 std::cerr << all;
65 }
66 }
67 }
68 }