7#include <boost/algorithm/string/trim.hpp>
15 boost::algorithm::trim(line);
17 if (line.empty() || line.at(0) ==
'*')
21 std::string date_str(line.substr(10));
23 const static std::string spaces[] = {
" ",
K_SPACE};
24 for (
const auto& space: spaces) {
25 const std::string::size_type pos_space = date_str.find(space);
26 if (pos_space != std::string::npos)
27 date_str = date_str.substr(0, pos_space);
36 const std::string player_name(line.substr(6));
42 const std::string player_name(line.substr(6));
57 for (
size_t i = 0; ; ) {
58 if (i < line.size() &&
59 (line.at(i) ==
' ' || line.at(i) ==
'\t'))
74 const Move move = kmove.
strToMove(move_str, state, last_move);
76 if (move_str.find(
K_RESIGN) != move_str.npos)
84 if (i+1 >= line.size())
86 move_str.append(line.substr(i,2));
95 std::ifstream is(filename);
98 const std::string msg =
"Ki2File::Ki2File file cannot read ";
99 std::cerr << msg << filename <<
"\n";
108 while (std::getline(is, line))
118 const std::string msg =
"ERROR: Komaochi (handicapped game) records are not available: ";
119 std::cerr << msg <<
"\n";
124 const std::string msg =
"ERROR: An illegal move found in a record.";
135 using namespace record;
138 const int x = position.
x(), y = position.
y();
139 return StandardCharacters::suji[x] + StandardCharacters::dan[y];
144 using namespace record;
152 return StandardCharacters().kanji(ptype);
178 mask_t pieces = state.
allEffectAt(player, ptype, to);
187 while (pieces.any()) {
189 if (p.
ptype() == ptype)
199 const int count = pieces.countBit();
202 int my_x = 0, my_y = 0;
203 while (pieces.any()) {
206 if (p.
ptype() != ptype)
208 int index_x = 1, index_y = 1;
210 index_x = ((p.
square().
x() - to.x()) *
sign(player) > 0)
213 index_y = ((p.
square().
y() - to.y()) *
sign(player) > 0)
216 my_x = index_x, my_y = index_y;
220 if (y_count[my_y] == 1) {
221 if (from.
y() == to.y())
223 else if ((to.y() - from.
y())*
sign(player) > 0)
228 else if (x_count[my_x] == 1) {
229 if (from.
x() == to.x()) {
241 else if ((to.x() - from.
x())*
sign(player) > 0)
246 else if (from.
x() == to.x()) {
247 if ((to.y() - from.
y())*
sign(player) > 0)
253 if ((to.x() - from.
x())*
sign(player) > 0)
257 if ((to.y() - from.
y())*
sign(player) > 0)
265 || to.canPromote(player) || from.
canPromote(player)) {
273 const char *threatmate_first,
const char *threatmate_last,
279 std::string ret =
show(*first, state, prev);
280 if (threatmate_first != threatmate_last
281 && *threatmate_first++)
283 for (; first+1 != last; ++first) {
287 ret +=
show(*(first+1), state, *first);
288 if (threatmate_first != threatmate_last
289 && *threatmate_first++)
298 std::vector<char> threatmate(last-first,
false);
299 return show(first, last, &*threatmate.begin(), &*threatmate.end(), initial, prev);
bool isInvalid() const
state に apply 可能でない場合にtrue
bool isNormal() const
INVALID でも PASS でもない.
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
const Square from() const
const PieceMask promotedPieces() const
const mask_t allEffectAt(Player P, Square target) const
const mask_t getMask(int num) const
const Square square() const
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
int getIndex(Ptype) const
const Piece pieceOf(int num) const
const Piece pieceAt(Square sq) const
bool isPieceStand() const
int y() const
将棋としてのY座標を返す.
int x() const
将棋としてのX座標を返す.
static ParseResult parseLine(NumEffectState &, Record &, KanjiMove &, std::string element)
Ki2File(const std::string &filename, bool verbose=false)
Parse kanji records such as "7六歩", the style of which is generally used to write Shogi records in Jap...
const Move strToMove(const std::string &, const NumEffectState &state, const Move &last_move) const
Convert a Japanese string (one token) to a move object.
void setVerbose(bool verbose)
#define K_BLACK_SIGN
Define Kanji characters by using EUC-JP codes.
const std::string showPromote(bool)
const std::string show(Square)
std::string sjis2euc(const std::string &str)
Convert character encoding from Shift_JIS to EUC-JP.
const PtypeTable Ptype_Table
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
constexpr int sign(Player player)
bool isMajor(Ptype ptype)
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない.
NumEffectState initial_state
std::vector< Move > moves
std::string tournament_name
std::vector< Move > moves() const
void setDate(const std::string &date_str)
CArray< std::string, 2 > player