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'))
72 if (record.
moves().size() > 0)
73 last_move = record.
moves().back();
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.";
138 const int x = position.
x(), y = position.
y();
139 return StandardCharacters::suji[x] + StandardCharacters::dan[y];
152 return StandardCharacters().kanji(ptype);
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)) {
271 const std::string
osl:: 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++)
295 const std::string
osl:: 298 std::vector<char> threatmate(last-first,
false);
299 return show(first, last, &*threatmate.begin(), &*threatmate.end(), initial, prev);
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
bool isOnBoardByOwner() const
piece がプレイヤーPの持ち物でかつボード上にある駒の場合は true.
CArray< std::string, 2 > player
GeneralMask< mask_int_t > mask_t
bool isMajor(Ptype ptype)
#define K_BLACK_SIGN
Define Kanji characters by using EUC-JP codes.
std::string tournament_name
const Piece pieceAt(Square sq) const
bool isNormal() const
INVALID でも PASS でもない.
NumEffectState initial_state
int y() const
将棋としてのY座標を返す.
void setVerbose(bool verbose)
const Move strToMove(const std::string &, const NumEffectState &state, const Move &last_move) const
Convert a Japanese string (one token) to a move object.
int x() const
将棋としてのX座標を返す.
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない. ...
const Piece pieceOf(int num) const
const PtypeTable Ptype_Table
Ki2File(const std::string &filename, bool verbose=false)
const Square from() const
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
const std::string show(Square)
constexpr int sign(Player player)
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
const Square square() const
std::vector< Move > moves() const
int getIndex(Ptype) const
const std::string showPromote(bool)
Parse kanji records such as "7六歩", the style of which is generally used to write Shogi records in ...
const mask_t allEffectAt(Player P, Square target) const
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
const mask_t getMask(int num) const
void setDate(const std::string &date_str)
static ParseResult parseLine(NumEffectState &, Record &, KanjiMove &, std::string element)
std::vector< Move > moves
bool isPieceStand() const
const PieceMask promotedPieces() const
std::string sjis2euc(const std::string &str)
Convert character encoding from Shift_JIS to EUC-JP.
bool isInvalid() const
state に apply 可能でない場合にtrue