From 5d667051b1b604ce829d25ce7d4e7944a871438b Mon Sep 17 00:00:00 2001 From: yssaya Date: Fri, 29 Apr 2022 10:11:46 +0900 Subject: [PATCH 1/3] perpetual check is illegal with 3 times(bug fixed). --- src/usi-engine/bona/shogi.h | 6 +++++- src/usi-engine/bona/ysszero.cpp | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/usi-engine/bona/shogi.h b/src/usi-engine/bona/shogi.h index 6f3a645..ad9bcec 100644 --- a/src/usi-engine/bona/shogi.h +++ b/src/usi-engine/bona/shogi.h @@ -129,7 +129,8 @@ extern unsigned char ailast_one[512]; //#define BNZ_VER "29" // 20220406 policy softmax temperature 1.0 -> 1.8 //#define BNZ_VER "30" // 20220406 kldgain 0.000006, balanced_opening within +150 ELO //#define BNZ_VER "31" // 20220407 cancel balanced_opening. resign ok under 30 moves in autousi. -#define BNZ_VER "32" // 20220418 initial winrate is adjusted(aka, first play urgency, fpu), +20 ELO. dfpn for all node visits >= 10, +40 ELO. +//#define BNZ_VER "32" // 20220418 initial winrate is adjusted(aka, first play urgency, fpu), +20 ELO. dfpn for all node visits >= 10, +40 ELO. +#define BNZ_VER "33" // 20220429 perpetual check is illegal with 3 times(bug fixed). #define BNZ_NAME "AobaZero" //#define BNZ_VER "16" // 20210528 komaochi, mate3 @@ -1496,6 +1497,9 @@ void init_state( const tree_t * restrict parent, tree_t * restrict child ); extern int sfen_current_move_number; extern int nHandicap; extern float average_winrate; +int is_stop_search(); +int is_limit_sec_or_stop_input(); + #endif #endif /* SHOGI_H */ diff --git a/src/usi-engine/bona/ysszero.cpp b/src/usi-engine/bona/ysszero.cpp index 1ef5fb1..ac34e98 100644 --- a/src/usi-engine/bona/ysszero.cpp +++ b/src/usi-engine/bona/ysszero.cpp @@ -844,6 +844,11 @@ int is_limit_sec() if ( get_spend_time(search_start_ct) >= dLimitSec ) return 1; return 0; } +int is_limit_sec_or_stop_input() { + if ( is_limit_sec() ) set_stop_search(); + if ( check_stop_input() ) set_stop_search(); + return is_stop_search(); +} bool is_do_mate3() { return true; } bool is_use_exact() { return true; } // 有効だと駒落ちで最後の1手詰を見つけたら高確率でその1手だけを探索した、と扱われる @@ -862,9 +867,8 @@ void uct_tree_loop(tree_t * restrict ptree, int sideToMove, int ply) int count = inc_uct_count(); if ( is_main_thread(ptree) ) { if ( is_send_usi_info(0) ) send_usi_info(ptree, sideToMove, ply, count, (int)(count/get_spend_time(search_start_ct))); - if ( check_stop_input() == 1 ) set_stop_search(); if ( IsHashFull() ) set_stop_search(); - if ( is_limit_sec() ) set_stop_search(); + is_limit_sec_or_stop_input(); if ( isKLDGainSmall(ptree, sideToMove) ) set_stop_search(); } if ( is_use_exact() && (exact_value == EX_WIN || exact_value == EX_LOSS) ) set_stop_search(); @@ -1604,8 +1608,6 @@ double uct_tree(tree_t * restrict ptree, int sideToMove, int ply, int *pExactVal // PRT("%2d:tid=%d:%s(%3d/%5d):select=%3d,v=%6.3f\n",ply,get_thread_id(ptree),string_CSA_move(pc->move).c_str(),pc->games,phg->games_sum,select,max_value); - int flag_illegal_move = 0; - if ( InCheck(sideToMove) ) { DEBUG_PRT("escape check err. %2d:%8s(%2d/%3d):selt=%3d,v=%.3f\n",ply,str_CSA_move(pc->move),pc->games,phg->games_sum,select,max_value); } @@ -1614,6 +1616,7 @@ double uct_tree(tree_t * restrict ptree, int sideToMove, int ply, int *pExactVal enum { SENNITITE_NONE, SENNITITE_DRAW, SENNITITE_WIN }; int flag_sennitite = SENNITITE_NONE; + int flag_illegal_move = 0; const int np = ptree->nrep + ply - 1; // ptree->history_in_check[np] にはこの手を指す前に王手がかかっていたか、が入る @@ -1631,7 +1634,7 @@ double uct_tree(tree_t * restrict ptree, int sideToMove, int ply, int *pExactVal if ( sum == SUM_MAX ) break; } } - if ( sum > 0 ) { + if ( sum >= SUM_MAX-1 ) { // PRT("sennnitite=%d,i=%d(%d),nrep=%d,ply=%d,%s\n",sum,i,np-i,ptree->nrep,ply,str_CSA_move(pc->move)); flag_sennitite = SENNITITE_DRAW; @@ -1652,8 +1655,10 @@ double uct_tree(tree_t * restrict ptree, int sideToMove, int ply, int *pExactVal flag_sennitite = SENNITITE_WIN; } } - if ( now_in_check ) flag_illegal_move = 1; // 王手の同一局面は指さない。王が逃げる手で4回目、だと3回目の王手を選ぶ - if ( sum != SUM_MAX ) flag_sennitite = SENNITITE_NONE; + // 王手の同一局面は3回目で指さない。王が逃げる手で4回目で負ける場合あり + if ( sum != SUM_MAX && flag_illegal_move == 0 ) { + flag_sennitite = SENNITITE_NONE; + } } if ( flag_illegal_move ) { @@ -1689,7 +1694,7 @@ double uct_tree(tree_t * restrict ptree, int sideToMove, int ply, int *pExactVal if ( skip_search == 0 && !now_in_check && is_do_mate3() && (pc->mate_bit & MATE_3)==0 ) { pc->mate_bit |= MATE_3; if ( is_mate_in3ply(ptree, Flip(sideToMove), ply+1) ) { - PRT("mated3ply: ply=%2d,col=%d,move=%08x(%s)\n",ply,sideToMove, MOVE_CURR,string_CSA_move(MOVE_CURR).c_str()); // str_CSA_move() は内部でstaticを持つので複数threadでは未定義 +// PRT("mated3ply: ply=%2d,col=%d,move=%08x(%s)\n",ply,sideToMove, MOVE_CURR,string_CSA_move(MOVE_CURR).c_str()); // str_CSA_move() は内部でstaticを持つので複数threadでは未定義 win = -1.0; // 3手で詰まされる pc->exact_value = EX_LOSS; skip_search = 1; From f796eee85883ad468a6952d4cb3ff508cde91105 Mon Sep 17 00:00:00 2001 From: yssaya Date: Fri, 29 Apr 2022 11:54:36 +0900 Subject: [PATCH 2/3] add dfpn time limit stop. --- src/usi-engine/bona/dfpn.cpp | 12 +++++++----- src/usi-engine/bona/dfpnhash.cpp | 6 ++++-- src/usi-engine/bona/ini.cpp | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/usi-engine/bona/dfpn.cpp b/src/usi-engine/bona/dfpn.cpp index 2d14021..2483cff 100644 --- a/src/usi-engine/bona/dfpn.cpp +++ b/src/usi-engine/bona/dfpn.cpp @@ -210,11 +210,13 @@ mid( tree_t * restrict ptree, dfpn_tree_t * restrict pdfpn_tree, int ply ) #if defined(TLP) if ( ! ptree->tlp_id ) #endif - if ( node_next_signal < ++node_last_check && detect_signals( ptree ) ) - { - return DFPN_ERRNO_SIGNAL; - } - +// if ( node_next_signal < ++node_last_check && detect_signals( ptree ) ) { return DFPN_ERRNO_SIGNAL; } + if ( node_next_signal < ++node_last_check ) { + node_last_check = 0; + if ( is_limit_sec_or_stop_input() ) return DFPN_ERRNO_SIGNAL; + } + if ( (ptree->node_searched & 0x0f)==0 && is_stop_search() ) return DFPN_ERRNO_SIGNAL; + if ( PLY_MAX-4 < ply ) { return DFPN_ERRNO_MAXPLY; } if ( init_children( ptree, pdfpn_tree, ply ) ) diff --git a/src/usi-engine/bona/dfpnhash.cpp b/src/usi-engine/bona/dfpnhash.cpp index f6fd408..4ca98a0 100644 --- a/src/usi-engine/bona/dfpnhash.cpp +++ b/src/usi-engine/bona/dfpnhash.cpp @@ -6,7 +6,8 @@ #include "shogi.h" #include "dfpn.h" -#if defined(DEBUG) +#if !defined(NDEBUG) +//#if defined(DEBUG) static int CONV dbg_is_hand_valid( unsigned int hand ); #endif @@ -608,7 +609,8 @@ hand_and( unsigned int a, unsigned int b ) return c; } -#if defined(DEBUG) +#if !defined(NDEBUG) +//#if defined(DEBUG) static int CONV dbg_is_hand_valid( unsigned int hand ) { diff --git a/src/usi-engine/bona/ini.cpp b/src/usi-engine/bona/ini.cpp index bfc9cf9..c1d016a 100644 --- a/src/usi-engine/bona/ini.cpp +++ b/src/usi-engine/bona/ini.cpp @@ -89,7 +89,7 @@ ini( tree_t * restrict ptree ) { int i; - /*if ( ini_fv() < 0 ) { return -1; }*/ +//if ( ini_fv() < 0 ) { return -1; } // if ( load_fv() < 0 ) { return -1; } for ( i = 0; i < 31; i++ ) { p_value[i] = 0; } From ce7ff86081d44b2208ebe257e632d311ebbdf56b Mon Sep 17 00:00:00 2001 From: yssaya Date: Fri, 29 Apr 2022 12:28:43 +0900 Subject: [PATCH 3/3] version number++ --- src/common/param.hpp | 4 ++-- src/usi-engine/bona/shogi.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/param.hpp b/src/common/param.hpp index 658bf2c..2686d75 100644 --- a/src/common/param.hpp +++ b/src/common/param.hpp @@ -3,9 +3,9 @@ #pragma once namespace Ver { constexpr unsigned char major = 3; // 2...komaochi, 3...Swish - constexpr unsigned char minor = 2; // + constexpr unsigned char minor = 3; // // usi_engine is no use. MUST increase "minor" for kicking old engine by server. Only major and minor are sent to client. - constexpr unsigned short usi_engine = 32; // 1...18 AobaZero, 16...26 komaochi, 27...Swish AobaZero + constexpr unsigned short usi_engine = 34; // 1...18 AobaZero, 16...26 komaochi, 27...Swish AobaZero } #define AOBA_UNIQUE ".oeWK7ZhnLN" diff --git a/src/usi-engine/bona/shogi.h b/src/usi-engine/bona/shogi.h index ad9bcec..0ebd06f 100644 --- a/src/usi-engine/bona/shogi.h +++ b/src/usi-engine/bona/shogi.h @@ -130,7 +130,8 @@ extern unsigned char ailast_one[512]; //#define BNZ_VER "30" // 20220406 kldgain 0.000006, balanced_opening within +150 ELO //#define BNZ_VER "31" // 20220407 cancel balanced_opening. resign ok under 30 moves in autousi. //#define BNZ_VER "32" // 20220418 initial winrate is adjusted(aka, first play urgency, fpu), +20 ELO. dfpn for all node visits >= 10, +40 ELO. -#define BNZ_VER "33" // 20220429 perpetual check is illegal with 3 times(bug fixed). +//#define BNZ_VER "33" // 20220429 perpetual check is illegal with 3 times(bug fixed). +#define BNZ_VER "34" // 20220429 dfpn time limit stop. #define BNZ_NAME "AobaZero" //#define BNZ_VER "16" // 20210528 komaochi, mate3