bool GMToolProcessInMessenger::isValidGmCommand( std::string tstr ) { // 각 명령어의 유효성 검사 typedef boost::tokenizer<boost::char_separator<char> > stokenizer; boost::char_separator<char> sep(" ", NULL, boost::drop_empty_tokens); stokenizer tok(tstr, sep); std::vector<std::string> vecstr(tok.begin(), tok.end()); if (vecstr[0] == GM_CMD_JEWELRYE) { if (vecstr.size() != 3) return false; if (vecstr[1] != "0" && vecstr[1] != "1" && vecstr[1] != "2" && vecstr[1] != "3" && vecstr[1] != "4" && vecstr[1] != "all") return false; int percent = atoi(vecstr[2].c_str()); if (percent < 1 || percent > 10000) return false; } else if(vecstr[0] == GM_CMD_EVENTAOUTOMATON) { if (vecstr.size() != 3) return false; if (vecstr[1] != "on" && vecstr[1] != "off") return false; } else { return false; } return true; }
GTPResponse GTP::gtp_save_sgf(vecstr args){ int limit = -1; if(args.size() == 0) return GTPResponse(true, "save_sgf <filename> [work limit]"); std::ifstream infile(args[0].c_str()); if(infile) { infile.close(); return GTPResponse(false, "File " + args[0] + " already exists"); } std::ofstream outfile(args[0].c_str()); if(!outfile) return GTPResponse(false, "Opening file " + args[0] + " for writing failed"); if(args.size() > 1) limit = from_str<unsigned int>(args[1]); SGFPrinter<Move> sgf(outfile); sgf.game(Board::name); sgf.program(gtp_name(vecstr()).response, gtp_version(vecstr()).response); sgf.size(hist->get_size()); sgf.end_root(); Side s = Side::P1; for(auto m : hist){ sgf.move(s, m); s = ~s; } agent->gen_sgf(sgf, limit); sgf.end(); outfile.close(); return true; }