void stringMovesDo(Position* position, gchar moves[]){ guint index=0, gindex; RootMoves gmoves; gchar smove[6], sgmove[6]; gboolean found; gboolean last = FALSE; while(!last){ rootMovesGenerate(position, &gmoves); smove[0] = '\0'; sscanf(moves,"%s",smove); if(moves[strlen(smove)] == '\0' || moves[strlen(smove)] == '\n') last = TRUE; if(strlen(smove) == 0) break; moves = g_strstr_len(moves, strlen(moves), smove) + strlen(smove); found = FALSE; for(gindex = 0; gindex<gmoves.size; gindex++){ moveToString(gmoves.move[gindex].move, sgmove); if(!g_ascii_strcasecmp(smove, sgmove)){ found = TRUE; if(!moveDo(position,gmoves.move[gindex].move)){ positionPrint(position); g_error("Wrong move:%s\n",smove); } break; } } if(!found){ positionPrint(position); g_error("Can not make move (%s)!\n",smove); } index++; } }
string Gesture::getMainMovementString() { string s = ""; for (size_t i = 0; i < mainMovement.size(); i++) { string move = moveToString(mainMovement[i]); if (move != "") s += move + (i == mainMovement.size() - 1 ? "" : "_"); } return s; }
// genmove GTPResponse genmove(int stone_colour, bool verbose = false) { if (stone_colour == s.getNextToPlay()) { time_t start = time(NULL); GoMove move = GoMove::none(); std::string ai_type = args.get("ai", ""); int time_left = (stone_colour == BLACK) ? black_time_left : white_time_left; if (ai_type == "simulate") { RNG rng; PatternMatcher p; GoStateAnalyser gsa(s, rng, p); move = gsa.selectMoveForSimulation_Mogo<true>(); } else { move = ai_interface.selectMove(time_left, verbose); std::cerr << "Performing update (tree cull after move play)\n"; ai_interface.notifyPlayHasBeenMade(move); } if (!move.isResign()) { s.makeMove(move); } time_t end = time(NULL); time_left -= (end - start); // estimate time used in case we don't have time_left if (time_left < 0) { time_left = 0; } std::cerr << "Spent approx " << (end - start) << " secs thinking\n"; (stone_colour == BLACK ? black_time_left : white_time_left) = time_left; std::cerr << boardToString(s) << "\n"; return GTPResponse(GTP_SUCCESS, moveToString(move)); } else { return GTPResponse(GTP_FAILURE, "Consecutive moves of the same color are not supported."); } }
void EngineControl::SearchListener::notifyPV(int depth, int score, int time, U64 nodes, int nps, bool isMate, bool upperBound, bool lowerBound, const std::vector<Move>& pv, int multiPVIndex) { // std::lock_guard<std::mutex> L(Logger::getLogMutex()); std::string pvBuf; for (size_t i = 0; i < pv.size(); i++) { pvBuf += ' '; pvBuf += moveToString(pv[i]); } std::string bound; if (upperBound) { bound = " upperbound"; } else if (lowerBound) { bound = " lowerbound"; } os << "info depth " << depth << " score " << (isMate ? "mate " : "cp ") << score << bound << " time " << time << " nodes " << nodes << " nps " << nps; if (multiPVIndex >= 0) os << " multipv " << (multiPVIndex + 1); os << " pv" << pvBuf << std::endl; }
void *doOutput(void *details) { prodcons *fromProg; char buffer[100]; char *ourname; Action currAction; threadParameter * parameters; int haventQuit, xboardmode, protover, icsmode; parameters = (threadParameter *) details; fromProg = parameters->output; ourname = parameters->name; haventQuit = 1; xboardmode = 0; icsmode = 0; protover = 1; memset(buffer, 0, 100); fprintf(stdout,"This is " PACKAGE_STRING ". This is the last prompt you'll see\n" "If when you type a command, you get no error message, it means everything is ok\n" "'help' offers some hints > "); fflush(stdout); while (haventQuit) { getAction(fromProg, &currAction); switch (currAction.theType) { case QUIT: haventQuit = 0; break; case PRINT: if (currAction.data.message != NULL) { fprintf(stdout, "%s", currAction.data.message); fflush(stdout); free(currAction.data.message); currAction.data.message = NULL; } break; case ERROR: fprintf(stdout, "Error "); if (currAction.data.message != NULL) { fprintf(stdout, "(%s)", currAction.data.message); } fprintf(stdout, ": "); if (currAction.command != NULL) { fprintf(stdout, "%s", currAction.command); } fprintf(stdout, "\n"); fflush(stdout); break; case USERERROR: if (xboardmode) { fprintf(stdout, "tellusererror "); if (currAction.data.message != NULL) { fprintf(stdout, "(%s)", currAction.data.message); } fprintf(stdout, "\n"); fflush(stdout); } else { if (currAction.data.message != NULL) { fprintf(stderr, "Error: %s\n", currAction.data.message); } } break; case USERMESSAGE: if (xboardmode) { if (icsmode) { fprintf(stdout, "tellopponent %s\n", currAction.data.message); } else { fprintf(stdout, "telluser %s\n", currAction.data.message); } } else { fprintf(stdout, "%s\n", currAction.data.message); } fflush(stdout); if (currAction.data.message != NULL) { free(currAction.data.message); } break; case TELLICS: if ((xboardmode) && (icsmode)) { if (currAction.data.message != NULL) { fprintf(stdout, "tellics %s\n", currAction.data.message); fflush(stdout); } } if (currAction.data.message != NULL) { free(currAction.data.message); currAction.data.message = NULL; } break; case XBOARD: xboardmode = 1; fprintf(stdout, "\n"); fflush(stdout); break; case PROTOVER: if (xboardmode == 1) { protover = atoi(currAction.data.message); if (protover == 2) { fprintf(stdout, "feature ping=1 setboard=1 playother=1 usermove=1 sigint=0 sigterm=0 myname=\"%s\" variants=\"normal\" colors=0 ics=1 name=1 done=1\n", ourname); fflush(stdout); } } if (currAction.data.message != NULL) { free(currAction.data.message); currAction.data.message = NULL; } break; case MOVE: if (xboardmode == 1) { moveToString(&currAction.data.move, buffer); fprintf(stdout, "move %s\n", buffer); fflush(stdout); } else { moveToString(&currAction.data.move, buffer); printf("%s\n", buffer); } break; case ACCEPTED: break; case REJECTED: break; case NEW: break; case TIME: break; case VARIANT: break; case PLAYOTHER: break; case WHITE: break; case BLACK: break; case PING: fprintf(stdout, "pong %d\n", currAction.data.time); fflush(stdout); break; case SP_POSTLINE: if (xboardmode) { fprintf(stdout, "%d %d %d %d %s\n", currAction.data.postline.ply, currAction.data.postline.score, currAction.data.postline.time, currAction.data.postline.nodes, (currAction.data.postline.pv ? currAction.data.postline.pv:"")); } else { fprintf(stdout, "Depth: %d ply\tScore: %d\t%f secs\t%d nodes\t%s\n", currAction.data.postline.ply, currAction.data.postline.score, currAction.data.postline.time / 100.0, currAction.data.postline.nodes, (currAction.data.postline.pv ? currAction.data.postline.pv:"")); } fflush(stdout); if (currAction.data.postline.pv != NULL) free(currAction.data.postline.pv); break; case RESULT: switch (currAction.data.result.won) { case WHITEWON: strcpy(buffer, "1-0"); break; case BLACKWON: strcpy(buffer, "0-1"); break; case RESDRAW: strcpy(buffer, "1/2-1/2"); break; default: strcpy(buffer, "*"); } fprintf(stdout, "%s", buffer); if (currAction.data.result.comment != NULL) { fprintf(stdout, " {%s}", currAction.data.result.comment); free(currAction.data.result.comment); } fprintf(stdout, "\n"); fflush(stdout); break; case NAME: break; case RATING: break; case ICS: if (strcmp(currAction.data.message, "-") != 0) { icsmode = 1; } if (currAction.data.message != NULL) { free(currAction.data.message); } break; case COMPUTER: break; case UNKNOWN_COMMAND: fprintf (stdout,"that last bit i didn't understand \n"); fflush(stdout); break; case HELP: fprintf(stdout,"You want help too? So does everyone else\n" "The potato will take most IETF protocol version 2 commands which can be\n" "located at http://www.tim-mann.org/xboard/engine-intf.html\n" "Other commands can be found in the commands.txt file that should have\n" "come with this program. Brief summary:\n" "(* denotes add sp_ before the commands if you are in xboard mode)\n" "(if you don't know what xboard mode is, then ignore the line above)\n" "To make a move type 'usermove <themove>' where <themove> is in e2e4 format or\n" "'sanmove <themove>' * where <themove> is in Nf3 format\n" "To set time controls, try 'st <seconds per move>' or\n" "'level 0 <minutes/game> <second increment/move>' (but this second\n" "option won't work very easily since you have to update how much time is\n" "left before each move with 'time <time>' in hundredths of a second)\n" "To reset game, type new\n" "To set board to some FEN, 'setboard <FEN>'\n" "To analyze a position 'analyze'\n" "To solve an epd, 'epdline <epd>' * (use st before to set a time limit for it)\n" "To go through an epd test suite, 'epdsuite <epdfile>' *\n" "To quit, 'quit'\n"); fflush(stdout); break; default: ; } if (currAction.command != NULL) { free(currAction.command); currAction.command = NULL; } } return NULL; }
void printMove(int move) { char s[MOVE_STR_SIZE]; moveToString(move, s); printf( "%s\n", s); }
void EngineControl::SearchListener::notifyCurrMove(const Move& m, int moveNr) { // std::lock_guard<std::mutex> L(Logger::getLogMutex()); os << "info currmove " << moveToString(m) << " currmovenumber " << moveNr << std::endl; }
void EngineControl::startThread(int minTimeLimit, int maxTimeLimit, int maxDepth, int maxNodes) { Parameters& par = Parameters::instance(); Search::SearchTables st(tt, kt, ht, *et); sc = std::make_shared<Search>(pos, posHashList, posHashListSize, st, pd, nullptr, treeLog); sc->setListener(std::make_shared<SearchListener>(os)); sc->setStrength(par.getIntPar("Strength"), randomSeed); std::shared_ptr<MoveGen::MoveList> moves(std::make_shared<MoveGen::MoveList>()); MoveGen::pseudoLegalMoves(pos, *moves); MoveGen::removeIllegal(pos, *moves); if (searchMoves.size() > 0) moves->filter(searchMoves); onePossibleMove = false; if ((moves->size < 2) && !infinite) { onePossibleMove = true; if (!ponder) { if (maxTimeLimit > 0) { maxTimeLimit = clamp(maxTimeLimit/100, 1, 100); minTimeLimit = clamp(minTimeLimit/100, 1, 100); } else { if ((maxDepth < 0) || (maxDepth > 2)) maxDepth = 2; } } } pd.addRemoveWorkers(par.getIntPar("Threads") - 1); pd.wq.resetSplitDepth(); pd.startAll(); sc->timeLimit(minTimeLimit, maxTimeLimit); tt.nextGeneration(); bool ownBook = par.getBoolPar("OwnBook"); bool analyseMode = par.getBoolPar("UCI_AnalyseMode"); int maxPV = (infinite || analyseMode) ? par.getIntPar("MultiPV") : 1; if (analyseMode) { Evaluate eval(*et); int evScore = eval.evalPosPrint(pos) * (pos.getWhiteMove() ? 1 : -1); std::stringstream ss; ss.precision(2); ss << std::fixed << (evScore / 100.0); os << "info string Eval: " << ss.str() << std::endl; } auto f = [this,ownBook,analyseMode,moves,maxDepth,maxNodes,maxPV]() { Move m; if (ownBook && !analyseMode) { Book book(false); book.getBookMove(pos, m); } if (m.isEmpty()) m = sc->iterativeDeepening(*moves, maxDepth, maxNodes, false, maxPV); while (ponder || infinite) { // We should not respond until told to do so. Just wait until // we are allowed to respond. std::this_thread::sleep_for(std::chrono::milliseconds(10)); } Move ponderMove = getPonderMove(pos, m); std::lock_guard<std::mutex> L(threadMutex); os << "bestmove " << moveToString(m); if (!ponderMove.isEmpty()) os << " ponder " << moveToString(ponderMove); os << std::endl; if (shouldDetach) { engineThread->detach(); pd.stopAll(); pd.fhInfo.reScale(); } engineThread.reset(); sc.reset(); }; shouldDetach = true; { std::lock_guard<std::mutex> L(threadMutex); engineThread = std::make_shared<std::thread>(f); } }