9 #include <boost/algorithm/string/split.hpp> 10 #include <boost/algorithm/string/replace.hpp> 11 #include <boost/algorithm/string/classification.hpp> 12 #include <boost/date_time/gregorian/gregorian.hpp> 24 static const KanjiMove& Kanji_Move = KanjiMove::instance();
26 "",
K_K1,
K_K2,
K_K3,
K_K4,
K_K5,
K_K6,
K_K7,
K_K8,
K_K9,
K_K10 30 if (s.size() < 1+3*9+1+2)
32 const int y = std::find(n_str.
begin(), n_str.
end(), s.substr(s.size()-2))
34 if (! (1 <= y && y <= 9))
36 board_parsed[y-1] =
true;
37 for (
unsigned int x=9,i=1;i<s.length()&&x>0;i+=3,x--) {
44 if (s.find(
K_TESUU "--") == 0) {
46 if (std::find(board_parsed.
begin(), board_parsed.
end(),
true)
47 == board_parsed.
end()) {
49 board_parsed.
fill(
true);
51 if (*std::min_element(board_parsed.
begin(), board_parsed.
end()) ==
false)
52 throw KakinokiIOError(
"incomplete position description in kakinokiParseLine");
63 if (s.find(
K_WHITE K_COLON) == 0) {
67 if (s.find(
K_KISEN K_COLON) == 0)
73 boost::gregorian::date date =
80 std::string piece_str = s.substr(s.find(K_COLON)+2);
81 boost::algorithm::replace_all(piece_str,
K_SPACE,
" ");
82 std::vector<std::string> pieces;
83 boost::algorithm::split(pieces, piece_str,
84 boost::algorithm::is_any_of(
" "));
90 for (
const auto& e: pieces) {
91 if (e.empty())
continue;
96 n = std::find(n_str.
begin(),n_str.
end(),e.substr(2,2))
99 n = n * ((e.substr(2,2) ==
K_K10) ? 1 : 10)
100 + (std::find(n_str.
begin(),n_str.
end(),e.substr(4,2))
102 for (
int i=0; i<n; ++i)
103 state.
setPiece(player, Square::STAND(), ptype);
111 if (record.
moves().empty())
119 if (record.
moves().empty())
126 ? Record::WhiteWin : Record::BlackWin);
132 size_t p = s.find(
'(');
134 s.replace(p, 1, 1,
' ');
137 s.replace(p, 1, 1,
' ');
143 std::ostringstream ss;
145 std::cerr << ss.str();
155 std::pair<osl::Player,osl::Ptype>
osl:: 158 static const KanjiMove& Kanji_Move = KanjiMove::instance();
159 if (s.size() != 3 || (s[0] !=
'v' && s[0] !=
' '))
163 return std::make_pair(pl, ptype);
169 static const KanjiMove& Kanji_Move = KanjiMove::instance();
170 std::istringstream is(s);
171 int move_number, from_number;
172 std::string move_string;
173 is >> move_number >> move_string;
176 if (move_string.substr(0,2) ==
K_ONAZI)
179 to = Kanji_Move.
toSquare(move_string.substr(0,4));
185 if (move_string.substr(cur,2) ==
K_NARU)
187 assert(move_string.size() >= cur+4);
188 ptype = Kanji_Move.
toPtype(move_string.substr(cur,4));
193 ptype = Kanji_Move.
toPtype(move_string.substr(cur,2));
196 if (move_string.size() >= cur+2 && move_string.substr(cur,2)
201 if (! (is >> from_number))
203 from =
Square(from_number / 10, from_number % 10);
206 bool is_promote =
false;
207 if (move_string.size() >= cur+2 && move_string.substr(cur,2) ==
K_NARU)
211 return Move(to, ptype, state.
turn());
213 return Move(from, to, is_promote ?
promote(ptype) : ptype,
214 captured, is_promote, state.
turn());
220 std::ifstream is(filename);
223 const std::string msg =
"KakinokiFile::KakinokiFile file cannot read ";
224 std::cerr << msg << filename <<
"\n";
231 while (std::getline(is, line))
235 && (line[line.size()-1] == 13))
236 line.erase(line.size()-1);
237 if (line.length()==0)
244 if (! line.empty() && line[0] ==
'#' 245 && line.find(
"separator") != line.npos)
247 parseLine(work, record, line, board_parsed);
260 std::ifstream is(filename.c_str());
262 if (! is || ! getline(is, line))
265 return line.find(
"Kifu for Windows") != line.npos
266 || line.find(
"KIFU") != line.npos
269 || (line.find(
"#") == 0 && line.find(
K_KIFU) != line.npos);
std::string initial_comment
CArray< std::string, 2 > player
Square toSquare(const std::string &) const
std::string tournament_name
void setPiece(Player player, Square sq, Ptype ptype)
bool isNormal() const
INVALID でも PASS でもない.
NumEffectState initial_state
const Piece pieceOnBoard(Square sq) const
bool isConsistent(bool show_error=true) const
KakinokiFile(const std::string &filename)
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない. ...
bool isValidMove(Move move, bool show_error=true) const
合法手かどうかを検査する. isValidMoveByRule, isAlmostValidMove をおこなう. 玉の素抜きや王手を防いで...
std::pair< Player, Ptype > strToPiece(const std::string &)
static void parseLine(SimpleState &state, Record &record, std::string s, CArray< bool, 9 > &board_parsed)
Move strToMove(const std::string &, const SimpleState &, Move last_move=Move())
std::string eucToLang(const std::string &src)
std::vector< Move > moves() const
void fill(const T_simple &value=T_simple())
const Move strToMove(const std::string &s, const SimpleState &st)
Parse kanji records such as "7六歩", the style of which is generally used to write Shogi records in ...
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
static bool isKakinokiFile(const std::string &filename)
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
boost::gregorian::date start_date
Ptype toPtype(const std::string &) const
std::vector< Move > moves
void setMoveComment(const std::string &)
bool isPieceStand() const
std::string sjis2euc(const std::string &str)
Convert character encoding from Shift_JIS to EUC-JP.