-
-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Analyse mode #266
Analyse mode #266
Conversation
Fixes repetition handling for analyzing
Not entirely sure about the
For shogi it would be:
I took the But I'm not familiar enough with the codebase to be sure. It works for the cases described in #264, but there might be some edge cases... Also maybe worth considering making this the default behavior for |
I fixed this issue with this : d49b90b |
Would you accept wrapping the draw in this if statement? if (++cnt + (i < sup_rep_ply ? 2 : 0) >= 3) Therefore something like this: // is_repetition()の、千日手が見つかった時に、現局面から何手遡ったかを返すバージョン。
// found_plyにその値が返ってくる。
RepetitionState Position::is_repetition2(int repPly, int sup_rep_ply) const
{
// pliesFromNullが未初期化になっていないかのチェックのためのassert
ASSERT_LV3(st->pliesFromNull >= 0);
// 遡り可能な手数。
// 最大でもrepPly手までしか遡らないことにする。
int end = std::min(repPly, st->pliesFromNull);
// 少なくとも4手かけないと千日手にはならないから、4手前から調べていく。
if (end < 4)
return REPETITION_NONE;
int cnt = 0;
StateInfo* stp = st->previous->previous;
for (int i = 4; i <= end ; i += 2)
{
stp = stp->previous->previous;
// board_key : 盤上の駒のみのhash(手駒を除く)
// 盤上の駒が同じ状態であるかを判定する。
if (stp->board_key() == st->board_key())
{
// 手駒が一致するなら同一局面である。(2手ずつ遡っているので手番は同じである)
if (stp->hand == st->hand)
{
if (++cnt + (i < sup_rep_ply ? 2 : 0) >= 3)
{
// 自分が王手をしている連続王手の千日手なのか?
if (i <= st->continuousCheck[sideToMove])
return REPETITION_LOSE;
// 相手が王手をしている連続王手の千日手なのか?
if (i <= st->continuousCheck[~sideToMove])
return REPETITION_WIN;
return REPETITION_DRAW;
}
else {
end = std::min(end + repPly, st->pliesFromNull);
}
}
else if (i < sup_rep_ply) {
// ↑rootより遡らないための措置
// 優等局面か劣等局面であるか。(手番が相手番になっている場合はいま考えない)
if (hand_is_equal_or_superior(st->hand, stp->hand))
return REPETITION_SUPERIOR;
if (hand_is_equal_or_superior(stp->hand, st->hand))
return REPETITION_INFERIOR;
}
}
}
// 同じhash keyの局面が見つからなかったので…。
return REPETITION_NONE;
} It's fine if this is not something you want to do, I can use my fork for my needs. Thanks! |
When attempting to analyze a shogi game record played by a human, it's understandable that it's not preferable to consider it a draw by repetition draw at the second occurrence of the same position. However, due to this modification, there is a slight decrease Elo, so I will think of a better solution. |
This issue has been resolved in the following commit. I have modified the code to not return the repetition draw evaluation value (-1) until the fourth occurrence of the same position. Also, there is almost no decrease in Elo due to this fix. I apologize for the long wait. |
Great work! Really happy to see this. Thanks a lot! |
As discussed here: #264
This is trying to solve two problems:
Currently repetitions are marked after the first repeated position. This is fine for playing, but not for analyzing, because it leads to graphs like this:
![image](https://private-user-images.githubusercontent.com/43043181/252815986-7c932f2f-ba8a-4e7c-ae17-e75266905095.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4MjcxNjIsIm5iZiI6MTczOTgyNjg2MiwicGF0aCI6Ii80MzA0MzE4MS8yNTI4MTU5ODYtN2M5MzJmMmYtYmE4YS00ZTdjLWFlMTctZTc1MjY2OTA1MDk1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE3VDIxMTQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM4YTAyZjlhMDk3MmQ1MTU2ODg3YzJkZjU2Yjc5NmVlMmFlYTVjMDRiNjBiMmIwZjAxOTdhMDFlOGRhYTNiYmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.DNqvAppup-MCoVG3kPGaiR_dKhfDvlb22XutluaPEts)
![yanerr_REP_P](https://private-user-images.githubusercontent.com/43043181/252816452-cf23966a-95a4-4bab-ab39-6d9ab7844ee7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4MjcxNjIsIm5iZiI6MTczOTgyNjg2MiwicGF0aCI6Ii80MzA0MzE4MS8yNTI4MTY0NTItY2YyMzk2NmEtOTVhNC00YmFiLWFiMzktNmQ5YWI3ODQ0ZWU3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE3VDIxMTQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY1MzU4YWYwYWJkZmRlYzNjOWMyMDcyM2FlOTg0YzJiNWE5MTkwYWNlYjRlNDViNzBkNTIyNTM2NzBmMDA4NjcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.GDQWfsDv6Bb8wQs2CGMHFSp_GWKE-VuA747PFOUhkBk)
![yancor_REP](https://private-user-images.githubusercontent.com/43043181/252816596-7c54da37-64f7-4a43-a6c8-b70d870679c4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4MjcxNjIsIm5iZiI6MTczOTgyNjg2MiwicGF0aCI6Ii80MzA0MzE4MS8yNTI4MTY1OTYtN2M1NGRhMzctNjRmNy00YTQzLWE2YzgtYjcwZDg3MDY3OWM0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE3VDIxMTQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJlNWZkNGJiYjYyMTIzOTljMzg3Zjk1ZWYxOGU5NmQyMGI2ZjU3YTRiMjI1MWUwYTgwODhhZjJiYWViMzE0ZTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.0eaFXp7HSy8LmoG2rX9TJB5mS3bCmarGSXDc5R7tppw)
Here's another simple example, in this example, I first captured opponent's bishop and started repeating the positions.
With red I marked the repeated positions, and in orange I marked the incorrect evaluations.
After this patch with
USI_AnalyseMode
:Superior position returning 31111 cp is a problem for analyzing because of graphs like this:
![image](https://private-user-images.githubusercontent.com/43043181/252816767-5c6c2c0c-e313-4089-aac6-d76c1f4cff38.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4MjcxNjIsIm5iZiI6MTczOTgyNjg2MiwicGF0aCI6Ii80MzA0MzE4MS8yNTI4MTY3NjctNWM2YzJjMGMtZTMxMy00MDg5LWFhYzYtZDc2YzFmNGNmZjM4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE3VDIxMTQyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk2NjFlMzAwZGNjNjk0NGM0MTI0NjllMGQ2NmY3ZjJiMDJmZThiODc3OGI1YzI4NzE1OTk4NGVhZDk3NzRlNzgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.WZTaqChNTpdRsuyc7WulfjpfoU6SUXKzVcE6Gr4Hv7I)
I try to solve this by adding
is_repetition_full
function that checks for all 4 repetitions (still only to rep_ply depth) before or at the root and checks for superior positions only after root.is_repetition_full
is called in yaneuraou-search ifUSI_AnalyseMode
is true. No functional change ifUSI_AnalyseMode
is false.Related commit/PR from Stockfish: