5#include <boost/algorithm/string/classification.hpp>
6#include <boost/algorithm/string/split.hpp>
7#include <boost/algorithm/string/trim.hpp>
19 const std::string& line,
22 std::istringstream is(line);
37 if (s ==
"%PASS" || s ==
"<PASS>" || s ==
"PASS") {
39 }
else if (s[0] ==
'+' || s[0] ==
'-') {
49 info.
moves.push_back(move);
63 std::cerr <<
"drop illegal move in comment " << s << std::endl;
71 bool parse_move_comment)
75 if (s.substr(1,2) ==
"* ")
79 else if (s.substr(1,2) ==
"**" && parse_move_comment)
85 if (s.find(
"$START_TIME:") == 0) {
86 const std::string YYMMDD = s.substr(12,10);
88 std::vector<std::string> e;
89 boost::algorithm::split(e, YYMMDD, boost::algorithm::is_any_of(
"/"));
92 start_date = boost::gregorian::date(stoi(e[0]), stoi(e[1]), stoi(e[2]));
93 assert(!start_date.is_special());
110 std::cerr <<
"Illegal csa line " << s << std::endl;
120 if (s.find(
"%TORYO") == 0 || s.find(
"%ILLEGAL_MOVE") == 0)
123 else if (s.find(
"%SENNICHITE") == 0)
125 else if (s.find(
"%KACHI") == 0)
128 else if (s.find(
"%JISHOGI") == 0 || s.find(
"%HIKIWAKE") == 0)
130 else if (s.find(
"%+ILLEGAL_ACTION") == 0)
132 else if (s.find(
"%-ILLEGAL_ACTION") == 0)
136 throw CsaIOError(
"unknown character in csaParseLine "+s);
143 std::ifstream ifs(filename);
145 const std::string msg =
"CsaFile::CsaFile file cannot read ";
146 std::cerr << msg << filename <<
"\n";
164read(std::istream& is)
170 while (std::getline(is, line))
174 && (line[line.size()-1] == 13))
175 line.erase(line.size()-1);
177 std::vector<std::string> elements;
178 boost::algorithm::split(elements, line, boost::algorithm::is_any_of(
","));
179 for (
auto& e: elements) {
180 boost::algorithm::trim(e);
181 boost::algorithm::trim_left(e);
186 if (*std::min_element(board_parsed.
begin(), board_parsed.
end()) ==
false)
187 throw CsaIOError(
"incomplete position description in csaParseLine");
188 assert(record.record.initial_state.isConsistent());
static const Move PASS(Player P)
static const Move INVALID()
bool isNormal() const
INVALID でも PASS でもない.
bool inCheck(Player P) const
Pの玉が王手状態
bool isValidMove(Move move, bool show_error=true) const
合法手かどうかを検査する. isValidMoveByRule, isAlmostValidMove をおこなう. 玉の素抜きや王手を防いでいるか, 千日手,打歩詰かどうかは検査しない.
static bool parseLine(SimpleState &, RecordMinimal &, std::string element, CArray< bool, 9 > &)
CsaFile(std::istream &is)
void read(std::istream &)
static void parseLine(SimpleState &, Record &, std::string element, bool parse_move_comment=true)
static SearchInfo makeInfo(const SimpleState &initial, const std::string &line, Move last_move)
const std::string show(Move)
Player charToPlayer(char c)
const Move strToMove(const std::string &s, const SimpleState &st)
const Move strToMove(const std::string &, const NumEffectState &)
const std::string show(Move)
constexpr Player alt(Player player)
static void addWithNewLine(std::string &a, const std::string &b)
std::string initial_comment
void setMoveInfo(const SearchInfo &)
void setDate(const std::string &date_str)
void setMoveComment(const std::string &)
CArray< std::string, 2 > player
std::vector< Move > moves