Skip to content

Commit

Permalink
バグ修正
Browse files Browse the repository at this point in the history
  • Loading branch information
TukamotoRyuzo committed Dec 25, 2016
1 parent 90f21c6 commit ae3cac6
Show file tree
Hide file tree
Showing 18 changed files with 5,907 additions and 5,718 deletions.
3 changes: 0 additions & 3 deletions yomita/yomita.sln
Expand Up @@ -6,9 +6,6 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yomita", "yomita\yomita.vcxproj", "{70D62DC5-76BE-4831-BEEB-7A48283445A0}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Expand Down
4 changes: 3 additions & 1 deletion yomita/yomita/src/benchmark.cpp
Expand Up @@ -71,6 +71,7 @@ void benchmark(Board& b)
//"startpos moves 7g7f 8c8d 2g2f 8d8e 8h7g 3c3d 7i8h 4a3b 6i7h 2b7g+ 8h7g 3a2b 3i3h 7a6b 4g4f 5a4b 4i5h 7c7d 3h4g 2b3c 5i6h 6b7c 4g5f 7c6d 6g6f 7d7e 6f6e 7e7f 7g7f 6d7c 5h6g 6c6d 6e6d 7c6d P*6e 6d7c",
//"startpos moves 7g7f 3c3d 2g2f 8c8d 2f2e 8d8e 6i7h 4a3b 2e2d 2c2d 2h2d 8e8f 8g8f 8b8f 2d3d 2b3c 3d3f 8f8d 3f2f 3a2b P*8g 5a5b 5i5h 7c7d 3i3h 7a7b 3g3f",
//"startpos moves 2g2f 3c3d 2f2e 2b3c 9g9f 8c8d 3i4h 7a6b 3g3f 4a3b 4h3g 8d8e 6i7h 3a2b 3g4f 7c7d 5i6h 3c4b 7g7f 5c5d 6h6i 6b5c 5g5f 5a4a 3f3e 3d3e 4f3e 8e8f 8g8f 4c4d 2h3h 8b8f P*8g",
//"startpos moves 7g7f 3c3d 2g2f 8c8d 2f2e 8d8e 6i7h 4a3b 2e2d 2c2d 2h2d 8e8f 8g8f 8b8f 2d3d 2b3c 5i5h 5a5b 3g3f 8f7f 8h7g 3c7g+ 8i7g B*5e P*2b 2a3c 2b2a+ 3a4b P*2c 3b2c 3d8d 3c4e 7i6h",
"startpos moves 2g2f 3c3d 2f2e 2b3c 7g7f 3a2b 5g5f 3c8h+ 7i8h B*5g 3g3f 1c1d 3i4h 5g1c+ B*7i 1c1b 5i6h 2b1c 6h7h 1b2b 7i4f 4c4d 4f5e 8b4b 8g8f 2b3b 8h8g 3b5d 4h3g 5d4e 5e7g 4e5f 4i5h 5c5d 3g4f 5f7d 3f3e 3d3e 4f3e 7d6d 4g4f 5d5e 2e2d 2c2d 3e2d 6d5d 2d1c+ P*2g 2h3h 1a1c P*3d 2g2h+ 3h2h S*2g S*6e 5d3f 2h4h P*2h P*5d 2h2i+ 5d5c+", // 250付近n
//"startpos moves 7g7f 3c3d 2g2f 8c8d 2f2e 8d8e 6i7h 4a3b 2e2d 2c2d 2h2d 8e8f 8g8f 8b8f 2d3d 2b3c 5i6h 3a2b 3g3f 8f8b 2i3g 3c8h+ 7i8h 2b3c P*8c 8b8c P*8d 8c8b 3d3e 8b8d B*6f 8d8b P*8c",

Expand All @@ -83,6 +84,7 @@ void benchmark(Board& b)

// ここに探索時の持ち時間など 探索深さでもいい
string str_go =
//"go infinite";
" depth 20";
//" btime 0 wtime 0 byoyomi 10000";

Expand All @@ -100,7 +102,7 @@ void benchmark(Board& b)
{
istringstream is(positions[i]);
USI::position(b, is);
//cout << b << endl;
cout << b << endl;
is.clear(stringstream::goodbit);
is.str(str_go);
USI::go(b, is);
Expand Down
10 changes: 5 additions & 5 deletions yomita/yomita/src/board.cpp
Expand Up @@ -412,15 +412,15 @@ bool Board::pseudoLegal(const Move move) const
// 両王手に対して持ち駒を打つ手を生成することはできない。
if (checkers)
{
std::cout << "pseudoLegal 2" << std::endl;
//std::cout << "pseudoLegal 2" << std::endl;
COUNT(2);
return false;
}

// 玉と、王手した駒との間に駒を打っていない。
if (!(mask(to) & bbBetween(check_square, kingSquare(self))))
{
std::cout << "pseudoLegal 3" << std::endl;
//std::cout << "pseudoLegal 3" << std::endl;
COUNT(3);
return false;
}
Expand All @@ -438,7 +438,7 @@ bool Board::pseudoLegal(const Move move) const
// 取った駒がtoにある駒である
// ※レアケース。ハッシュミスが起こるとこの条件に引っかかることもありえる。
// 置換表のサイズをケチると結構簡単に起こりえる。
if (isCapture(move) && capturePiece(move) != piece(to))
if (capturePiece(move) != piece(to))
{
COUNT(24);
return false;
Expand Down Expand Up @@ -513,7 +513,7 @@ bool Board::pseudoLegal(const Move move) const
// 両王手なので玉が動かなければならない。
if (target)
{
std::cout << "pseudoLegal 10" << std::endl;
//std::cout << "pseudoLegal 10" << std::endl;
COUNT(10);
return false;
}
Expand All @@ -523,7 +523,7 @@ bool Board::pseudoLegal(const Move move) const
// 移動合いもしくは王手駒を取る手以外はだめ。
if (!(target & to))
{
std::cout << "pseudoLegal 11" << std::endl;
//std::cout << "pseudoLegal 11" << std::endl;
COUNT(11);
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions yomita/yomita/src/book.cpp
Expand Up @@ -171,11 +171,18 @@ void MemoryBook::store(const std::string filename, const std::string sfen, const
// 定跡ファイルの読み込み(book.db)など。MemoryBookに読み出す
int MemoryBook::read(const std::string filename)
{
static bool allready = false;

if (allready)
return 0;

vector<string> lines;

if (readAllLines(filename, lines))
return 1; // 読み込み失敗

allready = true;

uint64_t num_sum = 0;
string sfen;

Expand Down
12 changes: 7 additions & 5 deletions yomita/yomita/src/config.h
Expand Up @@ -52,8 +52,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// 読み込み方が対応するだけで、生成には対応しない。
//#define GENERATED_SFEN_BY_FILESQ

// なんらかの評価関数バイナリを使う場合のdefine。
#if defined EVAL_KPP || defined EVAL_KPPT || defined EVAL_PPT
#define USE_EVAL
#endif

// 進行度を使うときに定義する。
#ifdef USE_EVAL
#define USE_PROGRESS
#endif

// 評価関数バイナリが入っているディレクトリと、学習時に生成したバイナリを保存するディレクトリ
#ifdef EVAL_KPP
Expand All @@ -74,11 +81,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define EVAL_TYPE "komadoku_only"
#endif

// なんらかの評価関数バイナリを使う場合のdefine。
#if defined EVAL_KPP || defined EVAL_KPPT || defined EVAL_PPT
#define USE_EVAL
#endif

// 評価関数で手番を考慮しているときとそうでないときのdefine。
#if defined EVAL_KPPT || defined EVAL_PPT
#define USE_EVAL_TURN
Expand Down
77 changes: 75 additions & 2 deletions yomita/yomita/src/eval_kppt.cpp
Expand Up @@ -38,7 +38,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif

#ifdef USE_GATHER
static const __m256i MASK[9] = {
static const __m256i MASK[9] =
{
_mm256_setzero_si256(),
_mm256_set_epi32(0, 0, 0, 0, 0, 0, 0, -1),
_mm256_set_epi32(0, 0, 0, 0, 0, 0, -1, -1),
Expand Down Expand Up @@ -69,7 +70,7 @@ namespace Eval
}

#ifdef USE_FILE_SQUARE_EVAL
// 縦型Square用の評価関数バイナリを使うときは横型に変換して読み込む。
// BonaPieceの横→縦変換テーブル
int y2b[fe_end];

for (BonaPiece p = BONA_PIECE_ZERO; p < fe_end; p++)
Expand All @@ -88,9 +89,80 @@ namespace Eval
}
}


#ifndef IS_64BIT

// 縦→横
int f2r[fe_end];

for (BonaPiece p = BONA_PIECE_ZERO; p < fe_end; p++)
{
if (p < fe_hand_end)
{
f2r[p] = p;
}
else
{
auto wp = p - fe_hand_end;
Square sq = Square(wp % 81);
Square rsq = fileSq(sq);
auto np = p - sq + rsq;
f2r[p] = np;
}
}

// x86環境ではKPPT二つ分のメモリを確保しようとするとbad_allocを起こすことがある。
// 一時バッファ無しで縦型→横型変換するコードが理想だが今のところ思いつかない。
const size_t size_kk = SQ_MAX * SQ_MAX;
const size_t size_kkp = SQ_MAX * (int)SQ_MAX * (int)fe_end;
const size_t size_kpp = SQ_MAX * (int)fe_end * (int)fe_end;
ValueKk* kk2 = new ValueKk[size_kk];
ValueKkp* kkp2 = new ValueKkp[size_kkp];
const int sm = SQ_MAX, fe = fe_end;
ifsKK.read(reinterpret_cast<char*>(kk2), size_kk * sizeof(ValueKk));
ifsKKP.read(reinterpret_cast<char*>(kkp2), size_kkp * sizeof(ValueKkp));

// 元の重みをコピー
for (auto k1 : Squares)
for (auto k2 : Squares)
kk[k1][k2] = kk2[toEvalSq(k1) * sm + toEvalSq(k2)];

for (auto k1 : Squares)
for (auto k2 : Squares)
for (auto p = BONA_PIECE_ZERO; p < fe_end; ++p)
kkp[k1][k2][p] = kkp2[toEvalSq(k1) * sm * fe + toEvalSq(k2) * fe + y2b[p]];

// せめてkk, kkpだけでも先に解放してやる。
delete[] kk2;
delete[] kkp2;

// 3回に分けて読み込んでやるか...
const size_t r = size_kpp / 3;
ValueKpp* kpp2 = new ValueKpp[r];
ifsKPP.read(reinterpret_cast<char*>(kpp2), r * sizeof(ValueKpp));

for (Square k = SQ_ZERO; k <= SQ_13; k++)
for (auto p1 = BONA_PIECE_ZERO; p1 < fe_end; ++p1)
for (auto p2 = BONA_PIECE_ZERO; p2 < fe_end; ++p2)
kpp[fileSq(k)][f2r[p1]][f2r[p2]] = kpp2[(int)k * fe * fe + p1 * fe + p2];

ifsKPP.read(reinterpret_cast<char*>(kpp2), r * sizeof(ValueKpp));

for (Square k = SQ_94; k <= SQ_16; k++)
for (auto p1 = BONA_PIECE_ZERO; p1 < fe_end; ++p1)
for (auto p2 = BONA_PIECE_ZERO; p2 < fe_end; ++p2)
kpp[fileSq(k)][f2r[p1]][f2r[p2]] = kpp2[(int)(k - SQ_94) * fe * fe + p1 * fe + p2];

ifsKPP.read(reinterpret_cast<char*>(kpp2), r * sizeof(ValueKpp));

for (Square k = SQ_97; k <= SQ_19; k++)
for (auto p1 = BONA_PIECE_ZERO; p1 < fe_end; ++p1)
for (auto p2 = BONA_PIECE_ZERO; p2 < fe_end; ++p2)
kpp[fileSq(k)][f2r[p1]][f2r[p2]] = kpp2[(int)(k - SQ_97) * fe * fe + p1 * fe + p2];


delete[] kpp2;
#else
EvalTable et2;
auto tempeval = new SharedEval();
et2.set(tempeval);
Expand All @@ -115,6 +187,7 @@ namespace Eval
kkp[k1][k2][p] = (*et2.kkp_)[toEvalSq(k1)][toEvalSq(k2)][y2b[p]];

delete tempeval;
#endif
#else
ifsKK.read(reinterpret_cast<char*>(kk), sizeof(kk));
ifsKKP.read(reinterpret_cast<char*>(kkp), sizeof(kkp));
Expand Down

0 comments on commit ae3cac6

Please sign in to comment.