void PerftModule::run()
{
  ChessBoard board;
  loadBoardFromFEN(&board, this->fenString_);

#ifdef WIN32
  SYSTEMTIME startSystemTime, endSystemTime;
  FILETIME start, end;
#else
  struct timeval start, end;
#endif

  for(int i = 0; i <= this->depth_; ++i) {
    moveGenTime = 0.0;
    moveProcessTime = 0.0;
    moveUnprocessTime = 0.0;

#ifdef WIN32
    GetSystemTime(&startSystemTime);
    SystemTimeToFileTime(&startSystemTime, &start);
#else
    gettimeofday(&start, NULL);
#endif
        
    int perftNum;
    if (verbose_) {
      perftNum = perft<true>(&board, i, i, this->divide_);
    }
    else {
      perftNum = perft<false>(&board, i, i, this->divide_);
    }

#ifdef WIN32
    GetSystemTime(&endSystemTime);
    SystemTimeToFileTime(&endSystemTime, &end);
    __int64 nanoSecondsDiff = ((__int64) (end.dwHighDateTime - 
					  start.dwHighDateTime)) << 32;
    nanoSecondsDiff += end.dwLowDateTime - start.dwLowDateTime;
    double diff = nanoSecondsDiff / (10000000.0);
#else
    gettimeofday(&end, NULL);
    double diff = (end.tv_sec - start.tv_sec);
    diff += (end.tv_usec - start.tv_usec) / (1000.0 * 1000.0);
#endif

    std::cout << std::fixed << std::setprecision(4) << i << "   " << diff << "   " << perftNum;
    if (verbose_) {
      std::cout << " (movegen: " 
		<< this->moveGenTime 
		<< ", process: " 
		<< this->moveProcessTime 
		<< ", unprocess: " 
		<< this->moveUnprocessTime << ")";
    }
    std::cout << std::endl;
  }
}
Exemple #2
0
void
EvalModule::run() {
  ChessBoard board;
  loadBoardFromFEN(&board, fenString_);
  board.whiteHasCastled = true;
  board.blackHasCastled = true;

  evaluateBoard<true>(&board, &std::cout);
}
Exemple #3
0
bool loadOpeningBook(const std::string& file) {
	cerr << "loading opening book " << file << "..." << endl;

	//std::ofstream openBookData("openbookdata.txt");

	bool isFirst = true;

	std::ifstream inputStream(file.c_str());
	if (!inputStream) {
		cerr << "could not load opening book " << file << endl;
		return false;
	}

	while (!inputStream.eof()) {
		ChessBoard nextBoard;
		ChessBoard nextBoard2;
		memset(&nextBoard, 0, sizeof(ChessBoard));
		/*
		memset(&nextBoard2, 0, sizeof(ChessBoard));*/
		std::string fenString;
		std::getline(inputStream, fenString);

		if (fenString == "#END#")
			break;

		if (!loadBoardFromFEN(&nextBoard, fenString)) {
			cerr << "ERROR: opening book contains invalid FEN: " << fenString << endl;
			std::string burnString;
			std::getline(inputStream, burnString);
			continue;
		}

		loadBoardFromFEN(&nextBoard2, fenString);

		HASHKEY zobristKey = nextBoard.zobristHashKey;

		std::string coordString;
		std::getline(inputStream, coordString);

		std::stringstream coordInputStream(coordString);
		while(!coordInputStream.eof()) {
			std::string indivCoordString;
			coordInputStream >> indivCoordString;
			
			if (indivCoordString == "")
				continue;
			
			std::string::size_type openBrace = indivCoordString.find("{");
			std::string::size_type closeBrace = indivCoordString.find("}");
			std::string movePart = indivCoordString.substr(0, openBrace);
			std::string bracePart = indivCoordString.substr(openBrace + 1, (closeBrace - openBrace) - 1);

			//cerr << "move: " << movePart << " with weight of " << bracePart << endl;

			//cerr << "converting " << movePart << " to string from " << coordString << endl;
			int move = CoordStringToMove(&nextBoard, movePart);
			int weight = string_to_int(bracePart);

			Coord theCoord;
			theCoord.move = move;
			theCoord.weight = weight;

			//openBookData << board_to_string(&nextBoard) << endl << movePart << " vs " << MoveToString(move) << endl;

			openingBook.insert(std::pair<HASHKEY, Coord>(zobristKey, theCoord));
		}
	}

	cerr << "finished loading opening book " << file << endl;
	return true;
}