Skip to content

Commit 252ab0d

Browse files
committed
Replace bad move in po
1 parent 68b3ba2 commit 252ab0d

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

src/GoBoard.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ int board_y[BOARD_MAX]; // y方向の座標
4040

4141
unsigned char eye[PAT3_MAX]; // 目のパターン
4242
unsigned char false_eye[PAT3_MAX];
43+
unsigned char falsy_eye[PAT3_MAX];
4344
unsigned char territory[PAT3_MAX]; // 領地のパターン
4445
unsigned char nb4_empty[PAT3_MAX]; // 上下左右の空点の数
4546
unsigned char eye_condition[PAT3_MAX];
@@ -547,6 +548,16 @@ InitializeEye( void )
547548
// XOO XOX ### ###
548549
0x5965, 0x9955, 0xFD56, 0xFF76,
549550
};
551+
const int falsy_eye_pat3[] = {
552+
// XOO XO+ XO+
553+
// O*O O*O O*O
554+
// OOX OOX +OX
555+
0x9556, 0x9546, 0x9146,
556+
// XOX XOX XOX
557+
// O*O O*O O*O
558+
// OOO OO+ +O+
559+
0x5566, 0x5166, 0x1166,
560+
};
550561

551562
const unsigned int complete_half_eye[12] = {
552563
// XOX OOX XOX XOX XOX
@@ -664,6 +675,14 @@ InitializeEye( void )
664675
}
665676
}
666677

678+
for (int p : falsy_eye_pat3) {
679+
Pat3Transpose8(p, transp);
680+
for (int j = 0; j < 8; j++) {
681+
falsy_eye[transp[j]] = S_BLACK;
682+
falsy_eye[Pat3Reverse(transp[j])] = S_WHITE;
683+
}
684+
}
685+
667686
}
668687

669688

@@ -957,6 +976,59 @@ IsLegalNotEye( game_info_t *game, const int pos, const int color )
957976
}
958977

959978

979+
bool
980+
ReplaceMove( game_info_t *game, const int pos, const int color, int* replace, int* replace_num )
981+
{
982+
const int *string_id = game->string_id;
983+
const string_t *string = game->string;
984+
int other = FLIP_COLOR(color);
985+
986+
//
987+
if (eye[Pat3(game->pat, pos)] != color ||
988+
string[string_id[NORTH(pos)]].libs == 1 ||
989+
string[string_id[EAST(pos)]].libs == 1 ||
990+
string[string_id[SOUTH(pos)]].libs == 1 ||
991+
string[string_id[WEST(pos)]].libs == 1) {
992+
993+
// 欠け眼に見える眼
994+
if (falsy_eye[Pat3(game->pat, pos)] == color &&
995+
string[string_id[NORTH(pos)]].libs > 1 &&
996+
string[string_id[EAST(pos)]].libs > 1 &&
997+
string[string_id[SOUTH(pos)]].libs > 1 &&
998+
string[string_id[WEST(pos)]].libs > 1) {
999+
int check[] = {
1000+
NORTH_WEST(pos),
1001+
NORTH_EAST(pos),
1002+
SOUTH_WEST(pos),
1003+
SOUTH_EAST(pos),
1004+
};
1005+
for (int p : check) {
1006+
if (game->board[p] != other)
1007+
continue;
1008+
const string_t *s = &string[string_id[p]];
1009+
if (s->libs == 1) {
1010+
int lib = s->lib[0];
1011+
replace[(*replace_num)++] = lib;
1012+
} else if (s->libs <= 2) {
1013+
int lib = s->lib[0];
1014+
while (lib != LIBERTY_END) {
1015+
//int neighbor = string[id].neighbor[0];
1016+
if (IsCapturableAtariForSimulation(game, lib, color, string_id[p])) {
1017+
replace[(*replace_num)++] = lib;
1018+
}
1019+
lib = s->lib[lib];
1020+
}
1021+
}
1022+
}
1023+
return true;
1024+
}
1025+
}
1026+
1027+
1028+
return false;
1029+
}
1030+
1031+
9601032
////////////////////
9611033
// 自殺手の判定 //
9621034
////////////////////

src/GoBoard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ bool IsLegalNotEye( game_info_t *game, const int pos, const int color );
245245
// 自殺手ならばtrueを返す
246246
bool IsSuicide( const game_info_t *game, const string_t *string, const int color, const int pos );
247247

248+
// プレイアウト中に手を置き換える
249+
bool ReplaceMove(game_info_t *game, const int pos, const int color, int* replace, int* replace_num);
250+
248251
// 石を置く
249252
void PutStone( game_info_t *game, const int pos, const int color );
250253

src/Rating.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,17 @@ RatingMove(game_info_t *game, int color, std::mt19937_64 *mt, LGR& lgr)
353353
// 選ばれた手が合法手ならループを抜け出し
354354
// そうでなければその箇所のレートを0にし, 手を選びなおす
355355
if (IsLegalNotEye(game, pos, color)) {
356+
int replace_num = 0;
357+
int replace[8];
358+
if (ReplaceMove(game, pos, color, replace, &replace_num)) {
359+
if (replace_num > 0) {
360+
int rep = replace[(*mt)() % replace_num];
361+
if (IsLegalNotEye(game, rep, color)) {
362+
//PrintBoard(game); cerr << "REPLACE " << FormatMove(pos) << " -> " << FormatMove(rep) << endl;
363+
return rep;
364+
}
365+
}
366+
}
356367
break;
357368
} else {
358369
*sum_rate -= rate[pos];

0 commit comments

Comments
 (0)