5 #include <boost/algorithm/string/split.hpp> 6 #include <boost/algorithm/string/trim.hpp> 24 throw CsaIOError(
"not a csa PlayerCharacter "+std::string(1,c));
33 return Square::STAND();
40 for(
int i=0;i<16;i++){
42 return static_cast<Ptype>(i);
44 throw CsaIOError(
"unknown std::string in csa::strToPtype "+s);
51 return Move::DeclareWin();
53 return Move::INVALID();
55 return Move::PASS(state.
turn());
61 if(fromPos==Square::STAND()){
63 throw CsaIOError(
"drop with promote ?! in csa::strToMove "+s);
64 return Move(toPos,ptype,pl);
70 bool isPromote=(p0.
ptype()!=ptype);
72 throw CsaIOError(
"bad promotion in csa::strToMove "+s);
73 return Move(fromPos,toPos,ptype,
74 capturePtype,isPromote,pl);
82 assert(buf.size() >= offset+1);
83 buf[offset] = (player==
BLACK) ?
'+' :
'-';
90 assert(buf.capacity() >= 7);
92 if (move == Move::DeclareWin())
93 return buf =
"%KACHI";
95 return buf =
"%TORYO";
108 assert(buf.size() >= offset+2);
115 const int x = pos.
x();
116 const int y = pos.
y();
117 buf[offset+0] = x +
'0';
118 buf[offset+1] = y +
'0';
125 assert(buf.size() >= offset+2);
127 buf[0+offset] = name[0];
128 buf[1+offset] = name[1];
136 std::string buf(
"+7776FU");
137 return show(move, buf);
143 std::string ret =
show(move);
156 std::string buf(
"+");
157 return show(player, buf);
163 std::string buf(
"00");
164 return show(position, buf);
170 std::string buf(
"OU");
171 return show(ptype, buf);
191 std::ostringstream out;
192 for (; first != last; ++first) {
203 std::ifstream is(filename);
205 const std::string msg =
"CsaFileMinimal::CsaFileMinimal file open failed ";
206 std::cerr << msg << filename <<
"\n";
226 while (std::getline(is, line))
230 && (line[line.size()-1] == 13))
231 line.erase(line.size()-1);
233 std::vector<std::string> elements;
234 boost::algorithm::split(elements, line, boost::algorithm::is_any_of(
","));
235 for (
auto& e: elements) {
236 boost::algorithm::trim(e);
237 boost::algorithm::trim_left(e);
241 if (*std::min_element(board_parsed.
begin(), board_parsed.
end()) ==
false)
242 throw CsaIOError(
"incomplete position description in csaParseLine");
250 while (! s.empty() && isspace(s[s.size()-1]))
251 s.resize(s.size()-1);
258 board_parsed.
fill(
true);
264 for(
int i=2;i<=(int)s.length()-4;i+=4){
266 if(s.substr(i+2,2) ==
"AL"){
277 if(isdigit(s.at(1))){
278 const int y=s.at(1)-
'0';
279 board_parsed[y-1] =
true;
280 for(
unsigned int x=9,i=2;i<s.length();i+=3,x--){
281 if (s.at(i) !=
'+' && s.at(i) !=
'-' && s.find(
" *",i)!=i) {
285 std::cerr <<
"possible typo for empty square " << s <<
"\n";
287 if (s.at(i) !=
'+' && s.at(i) !=
'-')
continue;
308 std::cerr <<
"Illegal move " << m << std::endl;
311 record.
moves.push_back(m);
327 std::istringstream is(s);
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
void setPieceAll(Player player)
void setPiece(Player player, Square sq, Ptype ptype)
const Piece pieceAt(Square sq) const
bool isNormal() const
INVALID でも PASS でもない.
NumEffectState initial_state
int y() const
将棋としてのY座標を返す.
int x() const
将棋としてのX座標を返す.
const char * getCsaName(Ptype ptype) const
bool isConsistent(bool showError=true) const
bool isValidMove(Move move, bool show_error=true) const
合法手かどうかを検査する. isValidMoveByRule, isAlmostValidMove をおこなう. 玉の素抜きや王手を防いで...
const PtypeTable Ptype_Table
const Square from() const
Player charToPlayer(char c)
const PieceTable Piece_Table
const Square strToPos(const std::string &s)
virtual ~CsaFileMinimal()
Ptype capturePtype() const
RecordMinimal load() const
void fill(const T_simple &value=T_simple())
const Move strToMove(const std::string &s, const SimpleState &st)
const std::string show(Move)
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Ptype getPtypeOf(int num) const
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
CsaString(const std::string &)
const std::string fancyShow(Move)
std::vector< Move > moves
bool isPieceStand() const
static bool parseLine(SimpleState &, RecordMinimal &, std::string element, CArray< bool, 9 > &)
Ptype strToPtype(const std::string &s)
bool isInvalid() const
state に apply 可能でない場合にtrue
void setTurn(Player player)