Skip to content

Commit

Permalink
Merge pull request #63 from kobanium/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yssaya authored Apr 30, 2022
2 parents a66c76b + ce7ff86 commit dd6eb18
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/common/param.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions src/usi-engine/bona/dfpn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand Down
6 changes: 4 additions & 2 deletions src/usi-engine/bona/dfpnhash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/usi-engine/bona/ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
7 changes: 6 additions & 1 deletion src/usi-engine/bona/shogi.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ 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_VER "34" // 20220429 dfpn time limit stop.
#define BNZ_NAME "AobaZero"

//#define BNZ_VER "16" // 20210528 komaochi, mate3
Expand Down Expand Up @@ -1496,6 +1498,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 */
21 changes: 13 additions & 8 deletions src/usi-engine/bona/ysszero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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手だけを探索した、と扱われる
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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] にはこの手を指す前に王手がかかっていたか、が入る
Expand All @@ -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;

Expand All @@ -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 ) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dd6eb18

Please sign in to comment.