Example #1
0
  // 評価関数ファイルを読み込む
  void load_eval()
  {
    {
      // KK
      std::ifstream ifsKK(KK_BIN, std::ios::binary);
      if (ifsKK) ifsKK.read(reinterpret_cast<char*>(kk), sizeof(kk));
      else goto Error;

      // KKP
      std::ifstream ifsKKP(KKP_BIN, std::ios::binary);
      if (ifsKKP) ifsKKP.read(reinterpret_cast<char*>(kkp), sizeof(kkp));
      else goto Error;

      // KPP
      std::ifstream ifsKPP(KPP_BIN, std::ios::binary);
      if (ifsKPP) ifsKPP.read(reinterpret_cast<char*>(kpp), sizeof(kpp));
      else goto Error;
    }
    
    return;

  Error:;
    // 評価関数ファイルの読み込みに失敗した場合、思考を開始しないように抑制したほうがいいと思う。
    cout << "\ninfo string Error! open evaluation file failed.\n";
    exit(EXIT_FAILURE);
  }
void Position::init_evaluate()
{
	int iret=0;
	FILE *fp;
	const char *fname ="評価ベクトル";

	do {
		// KK
		std::ifstream ifsKK("KK_synthesized.bin", std::ios::binary);
		if (ifsKK) ifsKK.read(reinterpret_cast<char*>(KK), sizeof(KK));
		else { iret=-1; fname="KK_synthesized.bin"; continue;}

		// KKP
		std::ifstream ifsKKP("KKP_synthesized.bin", std::ios::binary);
		if (ifsKKP) ifsKKP.read(reinterpret_cast<char*>(KKP), sizeof(KKP));
		else { iret=-1; fname="KKP_synthesized.bin"; continue;}

		// KPP
		std::ifstream ifsKPP("KPP_synthesized.bin", std::ios::binary);
		if (ifsKPP) ifsKPP.read(reinterpret_cast<char*>(KPP), sizeof(KPP));
		else { iret=-1; fname="KPP_synthesized.bin"; continue;}
	} while (0);

	if (iret < 0) {
		std::cerr << "Can't load " << fname << "." << std::endl;
#if defined(CSADLL) || defined(CSA_DIRECT)
		::MessageBox(NULL, "評価ベクトルがロードできません\n終了します", "Error!", MB_OK);
#endif	// defined(CSA_DLL) || defined(CSA_DIRECT)
		exit(1);
	}

	int i;
	for ( i = 0; i < 31; i++) { p_value[i]       = 0; }

	p_value[15+pawn]       = DPawn;
	p_value[15+lance]      = DLance;
	p_value[15+knight]     = DKnight;
	p_value[15+silver]     = DSilver;
	p_value[15+gold]       = DGold;
	p_value[15+bishop]     = DBishop;
	p_value[15+rook]       = DRook;
	p_value[15+king]       = DKing;
	p_value[15+pro_pawn]   = DProPawn;
	p_value[15+pro_lance]  = DProLance;
	p_value[15+pro_knight] = DProKnight;
	p_value[15+pro_silver] = DProSilver;
	p_value[15+horse]      = DHorse;
	p_value[15+dragon]     = DDragon;

	p_value[15-pawn]          = p_value[15+pawn];
	p_value[15-lance]         = p_value[15+lance];
	p_value[15-knight]        = p_value[15+knight];
	p_value[15-silver]        = p_value[15+silver];
	p_value[15-gold]          = p_value[15+gold];
	p_value[15-bishop]        = p_value[15+bishop];
	p_value[15-rook]          = p_value[15+rook];
	p_value[15-king]          = p_value[15+king];
	p_value[15-pro_pawn]      = p_value[15+pro_pawn];
	p_value[15-pro_lance]     = p_value[15+pro_lance];
	p_value[15-pro_knight]    = p_value[15+pro_knight];
	p_value[15-pro_silver]    = p_value[15+pro_silver];
	p_value[15-horse]         = p_value[15+horse];
	p_value[15-dragon]        = p_value[15+dragon];
}