AdvancedSearchDialog::AdvancedSearchDialog(QWidget * parent) : QDialog (parent) { setupUi(this); dialogLayout = this->layout(); metrics = new QFontMetrics(this->font()); // the list of expressions expressions = new QList<ExpressionWidget*>(); // a area for holding the objects expressionsLayout = new QVBoxLayout(); expressionsLayout->setSpacing(0); expressionsLayout->setMargin(0); expressionsLayout->setObjectName(QString::fromUtf8("expressionsLayout")); expressionsFrame->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); expressionsFrame->setLayout(expressionsLayout); // we now add the first expression widgets to the dialog via a vertical // layout reset();//addNewExpression(); connect (this->addExprButton, SIGNAL(clicked()), this, SLOT(addNewExpression())); connect (this->resetButton, SIGNAL(clicked()), this, SLOT(reset())); connect(this->executeButton, SIGNAL(clicked()), this, SLOT(prepareSearch())); }
Results FindWords(const char * board, unsigned width, unsigned height) { Results results = {}; results.Score = 0; results.Count = 0; std::queue<BoardState> queue; std::unordered_set<std::string> foundWords; prepareSearch(queue, board, width, height); // process the queue while (!queue.empty()) { BoardState node = queue.front(); queue.pop(); char sym = board[node.nextIndex]; // only append the character if that path is correct if (node.visited_nodes[node.nextIndex] == empty) { node.word += sym; } // handle the 'q'-> 'qu' case by making a copy of current 'q' node, marking it and pushing it to the queue if (sym == 'q' && node.visited_nodes[node.nextIndex] == empty) { processQnode(node, queue); } node.visited_nodes[node.nextIndex] = used; // if we matched the word, we just add it to the results, but it may be a part of a longer word so continue match_t match = matchPath(node); if (node.word.length() >= MIN_WORD_SIZE && match == full_match) { foundWords.insert(node.word); } if (match == full_match || match == partial_match) { processNeighbourNodes(width, height, node, queue); } } combineResults(results, foundWords); return results; }
// The SearchLineEdit class is adapted from code presented by Girish // Ramakrishnan in a Qt Labs post: // // http://labs.qt.nokia.com/2007/06/06/lineedit-with-a-clear-button SearchLineEdit::SearchLineEdit(QWidget *parent): QLineEdit(parent) { previousResultButton = new QToolButton(this); previousResultButton->setIcon(style()->standardIcon(QStyle::SP_ArrowLeft)); previousResultButton->setCursor(Qt::ArrowCursor); previousResultButton->setStyleSheet(QString::fromUtf8("QToolButton { border: none; padding: 0px; }")); connect(previousResultButton, SIGNAL(clicked()), this, SLOT(handlePreviousResult())); nextResultButton = new QToolButton(this); nextResultButton->setIcon(style()->standardIcon(QStyle::SP_ArrowRight)); nextResultButton->setCursor(Qt::ArrowCursor); nextResultButton->setStyleSheet(QString::fromUtf8("QToolButton { border: none; padding: 0px; }")); connect(nextResultButton, SIGNAL(clicked()), this, SLOT(handleNextResult())); clearButton = new QToolButton(this); clearButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); clearButton->setCursor(Qt::ArrowCursor); clearButton->setStyleSheet(QString::fromUtf8("QToolButton { border: none; padding: 0px; }")); connect(clearButton, SIGNAL(clicked()), this, SLOT(clearSearch())); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); setStyleSheet(QString::fromUtf8("QLineEdit { padding-right: %1px; } ").arg( nextResultButton->sizeHint().width() + previousResultButton->sizeHint().width() + clearButton->sizeHint().width() + frameWidth + 1)); QSize msz = minimumSizeHint(); setMinimumSize(qMax(msz.width(), nextResultButton->sizeHint().width() + previousResultButton->sizeHint().width() + clearButton->sizeHint().width() + frameWidth * 2 + 2), qMax(msz.height(), clearButton->sizeHint().height() + frameWidth * 2 + 2)); connect(this, SIGNAL(returnPressed()), this, SLOT(prepareSearch())); setPlaceholderText(QString::fromUtf8("Search")); }
Move Engine::IterativeDeepening(int mode, uint64_t wtime, uint64_t btime, uint64_t winc, uint64_t binc, bool print) { int status = pos.getGameStatus(); if(status==STATUS_WHITEMATED || status == STATUS_BLACKMATED || status == STATUS_STALEMATE) { return CONS_NULLMOVE; } vector<Move> moves; pos.generateMoves(moves); if (moves.size() == 1) //only 1 legal move return moves.at(0); //init prepareSearch(); timeMode = mode; AllocatedTime = 1; uint64_t mytime = 1; uint64_t opptime = 1; if (mode == MODE_MOVETIME) { AllocatedTime = wtime; } else { if (pos.turn == COLOR_WHITE) { mytime = wtime; opptime = btime; } else { mytime = btime; opptime = wtime; } AllocatedTime = max((uint64_t)1, mytime / 15); } if(mode==MODE_DEPTH) { MAXDEPTH = wtime; } else { MAXDEPTH = 100; } if (opptime < mytime / 4 && timeMode == MODE_DEFAULT) { AllocatedTime = max((uint64_t)1, mytime / 4); //if opponent is in time trouble lets take our sweet time } #ifdef BLITZKRIEG_DEBUG if(print) cout << "Allocated Time: " << AllocatedTime << endl; #endif vector<Move> line; line.reserve(128); int score = AlphaBeta(1,CONS_NEGINF,CONS_INF,&line,false,false); //int score = think(1,CONS_NEGINF,CONS_INF,&line); //PrincipalVariation = line; int val = 0; int lastscore = 0; timer.Start(); int takeback = 0; int initialmovenumber = pos.movelist.size(); Move bestmove = line.at(line.size()-1); /*for (int i = 0;i < 128;i++) { PrincipalVariation[i] = CONS_NULLMOVE; }*/ //cout << "takeback set " << takeback << " " << PrincipalVariation.size() << endl; takeback = setjmp(env); if(takeback!=0) { while(pos.movelist.size()>initialmovenumber) { pos.takebackMove(); takeback--; } if (print) { cout << "info string "; //cout << "Eval time: " << evaltime.time << ", Sort time: " << sorttime.time << ", Quisc time: " << quisctime.time << ", movegen time: " << movegentime.time << ", Timer: " << timer.ElapsedMilliseconds(); cout << "Nodes: " << nodes << ", Pruned nodes: " << prunednodes << ": " << ((double)(prunednodes * 100) / nodes) << "%, Futility nodes: " << futilitynodes << ": " << ((double)(futilitynodes * 100) / nodes) << "%"; cout << ", Avg. beta: " << ((double)betacutoff_sum / betacutoff_counter); cout << ", First beta: " << ((double)(firstbetacutoffcount*100) / betacutoff_counter) << "%"; cout << ", Latemove researches: " << latemoveresearch; cout << ", PV researches: " << pvresearch; //cout << ", Bad null: " << badavoidnull; cout << ", Aspiration Resets: " << aspirationresets; cout << ", Nullcutoffs: " << nullcutoffs; /*cout << ", Avg. alpha first: " << ((double)alphafirst_sum / alpha_counter); cout << ", Avg. alpha last: " << ((double)alphalast_sum / alpha_counter);*/ cout << ", Fake Hits: " << ((double)(Table.hits * 100) / nodes); cout << ", TT hits: " << tthitcount << ": " << ((double)(tthitcount * 100) / nodes) << "%" << endl; Table.hits = 0; } /*if (PvSize < 0) { cout << "info string ERROR: pv size is 0\n"; return CONS_NULLMOVE; }*/ ply = 0; return bestmove; } incheck[0] = pos.underCheck(pos.turn); for (int i = 2;i <= MAXDEPTH;i++) { //mr = think(i,CONS_NEGINF,CONS_INF); //mr = think(i,score - 100,score + 100); //aspiration search //if(mr.eval <= score-150 || mr.eval >= score+150) //{ // cout << "Aspiration fail " << mr.eval << endl; // mr = think(i,CONS_NEGINF,CONS_INF); //} //int low = 8; //int high = 8; /*PvSize = -1; PvPly = -1;*/ int delta = 32; int alpha = max(score - delta, int(CONS_NEGINF)); int beta = min(score + delta, int(CONS_INF)); while (true) { //line = deque<Move>(); ply = 0; //PvSize = -1; line.clear(); val = AlphaBeta(i, alpha, beta, &line, true, true); checkup(); //cout << "asp. " << alpha << " " << beta << endl; /*for (int i = 0;i < 2;i++) { for (int j = 0;j < 100;j++) { KillerScores[i][j] = CONS_NEGINF; } }*/ if (val <= alpha) { beta = (alpha + beta) / 2; alpha = max(score - delta, int(CONS_NEGINF)); //cout << "val is " << val << endl; //low = low << 1; } else if (val >= beta) { alpha = (alpha + beta) / 2; beta = min(score + delta, int(CONS_INF)); //cout << "val is " << val << endl; //high = high << 1; } else break; delta += delta / 2; aspirationresets++; } lastscore = score; score = val; assert(score > CONS_NEGINF && score < CONS_INF); timer.Stop(); if (print) { cout << "info score cp " << score << " depth " << i << " seldepth " << SelectiveDepth << " nodes " << nodes << " nps " << getNPS(nodes, timer.ElapsedMilliseconds()) << " time " << timer.ElapsedMilliseconds() << " pv "; for (int j = line.size() - 1;j >= 0;j--) { cout << line.at(j).toString() << " "; } cout << endl; /*for (int j = 0;j < 128;j++) { if (PrincipalVariation[j].isNullMove()) break; cout << PrincipalVariation[j].toString() << " "; }*/ } PrincipalVariation = line; bestmove = line.at(line.size()-1); if (timeMode == MODE_DEFAULT) { if (score > lastscore + 100 || score < lastscore - 100) //score changed? allocate more time { AllocatedTime = min(AllocatedTime + mytime / 30, max((uint64_t)1, mytime / 4)); } } } if (print) { cout << "Nodes: " << nodes << endl; cout << "info string Eval time: " << evaltime.ElapsedMilliseconds() << ", Sort time: " << sorttime.ElapsedMilliseconds() << ", Quisc time: " << quisctime.ElapsedMilliseconds() << ", movegen time: " << movegentime.ElapsedMilliseconds() << endl; } /*if (PvSize < 0) { cout << "info string ERROR: principal variation size is 0\n"; return CONS_NULLMOVE; }*/ //Move bestmove = PrincipalVariation[0]; ply = 0; return bestmove; }