예제 #1
0
void
BeatBoard::SearchApiService::RpcFunc(google::protobuf::RpcController* controller,
                                     const searchapi::Request* request,
                                     searchapi::Response* response,
                                     google::protobuf::Closure* done)
{
  std::cout << __func__ << std::endl;

  std::string query = request->query();
  std::string result = "";
  bool ret = false;

  logQuery( query );
  ret = searchDB( query, result );
  if (ret)
  {
    response->set_result(result);
    std::cout << "OK: " << response->result() << std::endl;
    response->set_result_code(SEARCHAPI_RESULT_OK);
  }
  else 
  {
    result = " "; // "" does not work at protobuf serialize
    response->set_result(result);
    response->set_result_code(SEARCHAPI_RESULT_ERROR);
//    response->set_error("message wasn't set");
    std::cout << "NG: " << response->result() << std::endl;
  }
  done->Run();
}
예제 #2
0
////////////////////////////////////////////////////////////////////////////////
// limited search, no quiesce
////////////////////////////////////////////////////////////////////////////////
void Game::searchLimited(const int depth){
    m_bSearching = true;
    m_bestMove = 0;
    m_bestValue = 0;
    m_bInterrupted = false;
    m_evalCount = 0;

    // 50 move rule and repetition check
    // no need to search if the game has allready ended
    if(m_board->isEnded()){
        m_bSearching = false;
        return;
    }


    int move = searchDB();
    if(move != 0){

        m_bestMove = move;
        m_bSearching = false;

        return;
    }

    m_searchDepth = depth;
    alphaBetaLimited(m_board, depth, -ChessBoard::VALUATION_MATE, ChessBoard::VALUATION_MATE);

    char buf[32];
    Move::toDbgString(m_bestMove, buf);
    DEBUG_PRINT("\n=====\nSearch\nvalue\t%d\nevalCnt\t%d\nMove\t%s\ndepth\t%d\n\n", m_bestValue, m_evalCount, buf, depth);

    m_bSearching = false;
}
예제 #3
0
void Game::search()
{
        m_bSearching = true;
        m_bestMove = 0;
        m_bestValue = 0;
        m_bInterrupted = false;
	m_evalCount = 0;

        // 50 move rule and repetition check
        // no need to search if the game has allready ended
	if(m_board->isEnded()){
            m_bSearching = false;
            return;
        }


    	int move = searchDB();
	if(move != 0){

            m_bestMove = move;
            m_bSearching = false;

            return;
        }
	
	startTime();

	DEBUG_PRINT("Start alphabeta iterative deepening\n", 0);

        char buf[20];
        // reset principal variation for this search
        int i;
        for(i = 0; i < MAX_DEPTH; i++){

            m_arrPVMoves[i] = 0;
        }

	int reachedDepth = 0; boolean bContinue = true;
	for(m_searchDepth = 1; m_searchDepth < (MAX_DEPTH-QUIESCE_DEPTH); m_searchDepth++)
	{
            DEBUG_PRINT("Search at depth %d\n", m_searchDepth);

            bContinue = alphaBetaRoot(m_searchDepth, -ChessBoard::VALUATION_MATE, ChessBoard::VALUATION_MATE);

// todo -----------------------------------------------------------
//break; //debug


            if(bContinue){

#if DEBUG_LEVEL & 2
                DEBUG_PRINT("\n +-+-+-+-+-+-+-+-PV: ", 0);

                 for(i = 0; i < m_searchDepth; i++){

                    Move::toDbgString(m_arrPVMoves[i], buf);
                     DEBUG_PRINT(" > %s", buf);
                 }
                DEBUG_PRINT(" {%d}\n", m_bestValue);
#endif
                reachedDepth++;
                if(m_bestValue == ChessBoard::VALUATION_MATE){
                    DEBUG_PRINT("Found checkmate, stopping search\n", 0);
                    break;
                }
                // bail out if we're over 50% of time, next depth will take more than sum of previous
                if(usedTime()){
                        DEBUG_PRINT("Bailing out\n", 0);
                        break;
                }
            } else {

                if(m_bInterrupted){
                    DEBUG_PRINT("Interrupted search\n", 0);
                } else {
                    DEBUG_PRINT("No continuation, only one move\n", 0);
                }
                break;
            }
	}

//#if DEBUG_LEVEL & 3
	Move::toDbgString(m_bestMove, buf);
	DEBUG_PRINT("\n=====\nSearch\nvalue\t%d\nevalCnt\t%d\nMove\t%s\ndepth\t%d\nTime\t%ld ms\nNps\t%.2f\n", m_bestValue, m_evalCount, buf, reachedDepth, timePassed(), (double)m_evalCount / timePassed());
//#endif
        m_bSearching = false;
}
/*!
 *
 * @return
 */
QString Address::getZip() const{
    return searchDB("a_zip");
}
/*!
 *
 */
QString Address::getState() const{
    return searchDB("a_state");
}
/*!
 *
 * @return
 */
QString Address::getCity() const{
    return searchDB("a_city");
}
/*!
 *
 * @return
 */
QString Address::getStreetAddress() const{
    return searchDB("a_street_address");
}