void Controller::setTrackersToCounters(){ for(auto & tracker : trackers) { dlib::point p = tracker.second.current();//it->second.current(); CT::identifier_t best_counter_id = getBestLine(p); if(best_counter_id != -1) setTrackerToCounter(tracker.first, best_counter_id); } }
void Controller::process(std::vector<dlib::rectangle> & curObjDetected, dlib::cv_image<dlib::bgr_pixel> & cimg) { // Track newly detected faces if don't overlap with already tracked face for(uint i = 0; i < curObjDetected.size(); i++) { dlib::rectangle face = curObjDetected[i]; bool alreadytracked = false; // We check that the detected object is not tracked yey for(auto & tracker : trackers) { if(face.contains(dlib::center(tracker.second.getTracker().get_position())) || tracker.second.getTracker().get_position().contains(dlib::center(face))) { alreadytracked = true; break; } } // If the object was not detected yet we initialise a tracker on the object position if(!alreadytracked) { dlib::point p = dlib::center(face); CT::Tracker tracker(IDGenerator::instance().next(), getBestLine(p)); tracker.initTrack(cimg,face); trackers.insert(std::make_pair(tracker.getId(), tracker)); } } }
int MatFinder::runFinderOnCurrentPosition() { Board::Side sideToMove = cb_->getActiveSide(); Utils::output("Starting board is :\n" + cb_->to_string() + "\n"); Utils::output("Doing some basic evaluation on submitted position...\n"); sendCurrentPositionToEngine(); lines_.assign(Options::getMaxLines(), Line::emptyLine); sendToEngine("go depth " + to_string(Options::getPlayforMovetime())); waitBestmove(); Utils::output("Evaluation is :\n"); Utils::output(getPrettyLines()); //TODO: check if (!lines_[0].empty()) { Side winning; if ((lines_[0].getEval() < 0 && sideToMove == Side::WHITE) || (lines_[0].getEval() > 0 && sideToMove == Side::BLACK)) winning = Side::BLACK; else winning = Side::WHITE; engine_play_for_ = (winning == Side::WHITE)? Side::BLACK:Side::WHITE; } Utils::output("Engine will play for : " + Board::to_string(engine_play_for_) + "\n"); //Main loop while (true) { Line bestLine; Side active = cb_->getActiveSide(); Utils::output("[" + Board::to_string(active) + "] Depth " + to_string(addedMoves_) + "\n"); sendCurrentPositionToEngine(); Utils::output(cb_->to_string(), 2); //Thinking according to the side the engine play for int moveTime = (active == engine_play_for_ || !addedMoves_) ? Options::getPlayforMovetime() : Options::getPlayagainstMovetime(); //Compute optimal multipv int pv = updateMultiPV(); //Scaling moveTime //According to number of lines //moveTime = (int)(moveTime * ((float) // ((float)pv/(float)Options::getMaxLines()) // )); //if (moveTime <= 600) // moveTime = 600; //Acccording to depth //moveTime += 10 * addedMoves_; //Initialize vector with empty lines lines_.assign(Options::getMaxLines(), Line::emptyLine); //Increase movetime with depth sendToEngine("go depth " + to_string(moveTime)); Utils::output("[" + Board::to_string(active) + "] Thinking... (" + to_string(moveTime) + ")\n", 1); //Wait for engine to finish thinking waitBestmove(); Utils::output(getPrettyLines(), 2); bestLine = getBestLine(); if (bestLine.empty() || bestLine.isMat() || fabs(bestLine.getEval()) > Options::getMateEquiv()) { //Handle the case where we should backtrack if (addedMoves_ > 0) { Utils::output("\tBacktracking " + cb_->getUciMoves().back() + " (addedMove#" + to_string(addedMoves_) + ")\n"); /* * We did a "mistake" : a line previously unbalanced is now a * draw, we should better the backtracking by, for example, * increasing attacking time */ if (bestLine.empty()) Utils::output("\n\n\n\n DEFENDER SURVIVED \n\n\n\n ", 1); //Remove opposite side previous move addedMoves_--; cb_->undoMove(); if (active == engine_play_for_) { //Remove our previous move if we had one, since the //mat is "recorded" by engine //(not the case if starting side is not the side //the engine play for) if (addedMoves_ > 0) { addedMoves_--; cb_->undoMove(); } } continue; } else { //This is the end (hold your breath and count to ten) break; } } //If we are here, we just need to handle the next move Utils::output("[" + Board::to_string(active) + "] Chosen line : \n", 1); Utils::output("\t" + getPrettyLine(bestLine, Options::movesDisplayed) + "\n", 1); string next = bestLine.firstMove(); Utils::output("\tNext move is " + next + "\n", 3); addedMoves_++; cb_->uciApplyMove(next); } //Display info at the end of computation Utils::output("[End] Finder is done. Starting board was : \n"); Utils::output(cb_->to_string() + "\n"); if (engine_play_for_ == sideToMove) Utils::output("All lines should now be draw or mat :\n"); else Utils::output("Best line should be mat or draw.\n"); Utils::output(getPrettyLines()); Utils::output("[End] Full best line is : \n"); Utils::output("[End] " + getPrettyLine(lines_[0]) + "\n"); Utils::output("[End] " + Utils::listToString(lines_[0].getMoves()) + "\n"); return 0; }