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--) {
38 std::pair<Player,Ptype> pp=kakinoki::strToPiece(s.substr(i,3));
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");
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,
' ');
140 const Move m = kakinoki::strToMove(s, state, last_move);
143 std::ostringstream ss;
144 ss << state << misc::eucToLang(s) <<
"\n" << m;
145 std::cerr << ss.str();
155std::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,
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)
240 line = misc::sjis2euc(line);
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))
264 line = misc::sjis2euc(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);
void fill(const T_simple &value=T_simple())
bool isNormal() const
INVALID でも PASS でもない.
const Piece pieceOnBoard(Square sq) const
bool isValidMove(Move move, bool show_error=true) const
合法手かどうかを検査する. isValidMoveByRule, isAlmostValidMove をおこなう. 玉の素抜きや王手を防いでいるか, 千日手,打歩詰かどうかは検査しない.
bool isConsistent(bool show_error=true) const
void setPiece(Player player, Square sq, Ptype ptype)
bool isPieceStand() const
static bool isKakinokiFile(const std::string &filename)
KakinokiFile(const std::string &filename)
static void parseLine(SimpleState &state, Record &record, std::string s, CArray< bool, 9 > &board_parsed)
Parse kanji records such as "7六歩", the style of which is generally used to write Shogi records in Jap...
Square toSquare(const std::string &) const
Ptype toPtype(const std::string &) const
Move strToMove(const std::string &, const SimpleState &, Move last_move=Move())
std::pair< Player, Ptype > strToPiece(const std::string &)
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない.
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
NumEffectState initial_state
std::vector< Move > moves
std::string tournament_name
std::string initial_comment
std::vector< Move > moves() const
void setMoveComment(const std::string &)
CArray< std::string, 2 > player
boost::gregorian::date start_date