Skip to content

Commit

Permalink
Merge pull request #64 from kobanium/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yssaya authored Jun 26, 2022
2 parents dd6eb18 + fd2752f commit 31513e4
Show file tree
Hide file tree
Showing 9 changed files with 522 additions and 71 deletions.
3 changes: 2 additions & 1 deletion src/autousi/play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ class USIEngine : public Child {

char opt_kld[] = "-kldgain";
// char opt_kld_value[] = "0.0000013";
char opt_kld_value[] = "0.000006";
// char opt_kld_value[] = "0.000006";
char opt_kld_value[] = "0.000005";
argv[argc++] = opt_kld;
argv[argc++] = opt_kld_value;
#endif
Expand Down
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 = 3; //
constexpr unsigned char minor = 5; //
// 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 = 34; // 1...18 AobaZero, 16...26 komaochi, 27...Swish AobaZero
constexpr unsigned short usi_engine = 36; // 1...18 AobaZero, 16...26 komaochi, 27...Swish AobaZero
}

#define AOBA_UNIQUE ".oeWK7ZhnLN"
Expand Down
94 changes: 94 additions & 0 deletions src/usi-engine/bona/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,104 @@ eval_material( const tree_t * restrict ptree )
return material;
}

// piece value from AobaZero kifu. https://524.teacup.com/yss/bbs/3946
int aoba_piece_v[13] = {
// FU KY KE GI KI KA HI TO NK NG NG UM RY
100,198,367,562,674,775,871, 496,364,459,649,1133,1408
};
int aoba_hand_v[7] = {
106,351,403,663,889,924,1257
};

int CONV
eval_aoba_material( const tree_t * restrict ptree )
{
int material, itemp;

itemp = PopuCount( BB_BPAWN );
itemp -= PopuCount( BB_WPAWN );
material = itemp * aoba_piece_v[0];
itemp = (int)I2HandPawn( HAND_B );
itemp -= (int)I2HandPawn( HAND_W );
material += itemp * aoba_hand_v[0];

itemp = PopuCount( BB_BLANCE );
itemp -= PopuCount( BB_WLANCE );
material += itemp * aoba_piece_v[1];
itemp = (int)I2HandLance( HAND_B );
itemp -= (int)I2HandLance( HAND_W );
material += itemp * aoba_hand_v[1];

itemp = PopuCount( BB_BKNIGHT );
itemp -= PopuCount( BB_WKNIGHT );
material += itemp * aoba_piece_v[2];
itemp = (int)I2HandKnight( HAND_B );
itemp -= (int)I2HandKnight( HAND_W );
material += itemp * aoba_hand_v[2];

itemp = PopuCount( BB_BSILVER );
itemp -= PopuCount( BB_WSILVER );
material += itemp * aoba_piece_v[3];
itemp = (int)I2HandSilver( HAND_B );
itemp -= (int)I2HandSilver( HAND_W );
material += itemp * aoba_hand_v[3];

itemp = PopuCount( BB_BGOLD );
itemp -= PopuCount( BB_WGOLD );
material += itemp * aoba_piece_v[4];
itemp = (int)I2HandGold( HAND_B );
itemp -= (int)I2HandGold( HAND_W );
material += itemp * aoba_hand_v[4];

itemp = PopuCount( BB_BBISHOP );
itemp -= PopuCount( BB_WBISHOP );
material += itemp * aoba_piece_v[5];
itemp = (int)I2HandBishop( HAND_B );
itemp -= (int)I2HandBishop( HAND_W );
material += itemp * aoba_hand_v[5];

itemp = PopuCount( BB_BROOK );
itemp -= PopuCount( BB_WROOK );
material += itemp * aoba_piece_v[6];
itemp = (int)I2HandRook( HAND_B );
itemp -= (int)I2HandRook( HAND_W );
material += itemp * aoba_hand_v[6];

itemp = PopuCount( BB_BPRO_PAWN );
itemp -= PopuCount( BB_WPRO_PAWN );
material += itemp * aoba_piece_v[7];

itemp = PopuCount( BB_BPRO_LANCE );
itemp -= PopuCount( BB_WPRO_LANCE );
material += itemp * aoba_piece_v[8];

itemp = PopuCount( BB_BPRO_KNIGHT );
itemp -= PopuCount( BB_WPRO_KNIGHT );
material += itemp * aoba_piece_v[9];

itemp = PopuCount( BB_BPRO_SILVER );
itemp -= PopuCount( BB_WPRO_SILVER );
material += itemp * aoba_piece_v[10];

itemp = PopuCount( BB_BHORSE );
itemp -= PopuCount( BB_WHORSE );
material += itemp * aoba_piece_v[11];

itemp = PopuCount( BB_BDRAGON );
itemp -= PopuCount( BB_WDRAGON );
material += itemp * aoba_piece_v[12];

return material;
}

int CONV
evaluate( tree_t * restrict ptree, int ply, int turn )
{
if (1) {
int score = eval_aoba_material(ptree);
score = turn ? -score : score;
return score;
}
int list0[52], list1[52];
int nlist, score, sq_bk, sq_wk, k0, k1, l0, l1, i, j, sum;

Expand Down
3 changes: 1 addition & 2 deletions src/usi-engine/bona/ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int CONV load_fv( void )
# undef x0
# undef x1
#endif

PRT("load fv.bin...\n");
return 1;
}

Expand All @@ -89,7 +89,6 @@ ini( tree_t * restrict ptree )
{
int i;

//if ( ini_fv() < 0 ) { return -1; }
// if ( load_fv() < 0 ) { return -1; }

for ( i = 0; i < 31; i++ ) { p_value[i] = 0; }
Expand Down
1 change: 1 addition & 0 deletions src/usi-engine/bona/proce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ usi_go( tree_t * restrict ptree, char **lasts )
if ( get_elapsed( &time_turn_start ) < 0 ) { return -1; }
*/
// PRT("iterate()=%d\n",iterate(ptree));
// iret = com_turn_start( ptree, 0 );
iret = YssZero_com_turn_start( ptree );
if ( iret < 0 ) {
Expand Down
152 changes: 152 additions & 0 deletions src/usi-engine/bona/quiesrch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,155 @@ gen_next_quies( tree_t * restrict ptree, int alpha, int turn, int ply,

return 0;
}




















static int CONV gen_next_quies_aoba( tree_t * restrict ptree, int alpha, int turn, int ply, int qui_ply );

int CONV
search_quies_aoba( tree_t * restrict ptree, int alpha, int beta, int turn, int ply, int qui_ply )
{
int value, alpha_old, stand_pat;

#if defined(TLP)
if ( ! ptree->tlp_id )
#endif
{
node_last_check += 1;
}
ptree->node_searched += 1;
ptree->nquies_called += 1;
alpha_old = alpha;

stand_pat = evaluate( ptree, ply, turn );

if ( alpha < stand_pat ) {
if ( beta <= stand_pat ) {
// PRT( ", cut by stand-pat\n" );
MOVE_CURR = MOVE_PASS;
return stand_pat;
}
alpha = stand_pat;
}

if ( ply >= PLY_MAX-1 ) {
if ( alpha_old != alpha ) { pv_close( ptree, ply, no_rep ); }
MOVE_CURR = MOVE_NA;
return stand_pat;
}

ptree->anext_move[ply].next_phase = next_quies_gencap;
while ( gen_next_quies_aoba( ptree, alpha, turn, ply, qui_ply ) ) {
// PRT( "\nexpand %s (%" PRIu64 ")%2d", str_CSA_move(MOVE_CURR), ptree->node_searched,ply );
MakeMove( turn, MOVE_CURR, ply );
if ( InCheck(turn) ) {
UnMakeMove( turn, MOVE_CURR, ply );
continue;
}

value = -search_quies_aoba( ptree, -beta, -alpha, Flip(turn), ply+1, qui_ply+1 );
UnMakeMove( turn, MOVE_CURR, ply );

if ( alpha < value ) {
// check_futile_score_quies( ptree, MOVE_CURR, ptree->save_eval[ply], -ptree->save_eval[ply+1], turn );
if ( beta <= value ) {
// PRT( ", beta cut (%" PRIu64 ")\n", ptree->node_searched );
assert( ! IsMove(MOVE_CURR) || is_move_valid( ptree, MOVE_CURR, turn ) );
return value;
}
// PRT( ", renew alpha=%d (%" PRIu64 ")\n", value, ptree->node_searched );
alpha = value;
}
}

// PRT( "\nall searched (%" PRIu64 ")\n", ptree->node_searched );

if ( alpha_old != alpha ) {
if ( alpha == stand_pat ) { pv_close( ptree, ply, no_rep ); }
else { pv_copy( ptree, ply ); }
}

return alpha;
}

static int CONV
gen_next_quies_aoba( tree_t * restrict ptree, int /*alpha*/, int turn, int ply, int qui_ply )
{
switch ( ptree->anext_move[ply].next_phase ) {
case next_quies_gencap:
{
unsigned int * restrict pmove;
int * restrict psortv;
int i, j, n, nqmove, value;
unsigned int move;
ptree->move_last[ply] = GenCaptures( turn, ptree->move_last[ply-1] );

/* set sort values */
pmove = ptree->move_last[ply-1];
psortv = ptree->sort_value;
nqmove = 0;
n = (int)( ptree->move_last[ply] - pmove );

for ( i = 0; i < n; i++ ) {
move = pmove[i];
if ( qui_ply >= QUIES_PLY_LIMIT && ( ( UToCap(move) == pawn && ! I2IsPromote(move) ) || ( ! UToCap(move) && I2PieceMove(move) != pawn ) ) ) {
continue;
}
/*
int diff = estimate_score_diff( ptree, move, turn );
int min_score = eval_max_score( ptree, move, ptree->save_eval[ply], turn, diff );
if ( alpha < min_score ) {
value = swap( ptree, move, -1, MT_CAP_SILVER, turn );
if ( -1 < value ) {
psortv[nqmove] = value + diff;
pmove[nqmove++] = move;
}
}
*/
psortv[nqmove] = 0;
pmove[nqmove++] = move;

}

/* insertion sort */
psortv[nqmove] = INT_MIN;
for ( i = nqmove-2; i >= 0; i-- ) {
value = psortv[i]; move = pmove[i];
for ( j = i+1; psortv[j] > value; j++ ) {
psortv[j-1] = psortv[j]; pmove[j-1] = pmove[j];
}
psortv[j-1] = value; pmove[j-1] = move;
}

ptree->move_last[ply] = ptree->move_last[ply-1] + nqmove;
ptree->anext_move[ply].move_last = pmove;
ptree->anext_move[ply].next_phase = next_quies_captures;
}

case next_quies_captures:
if ( ptree->anext_move[ply].move_last != ptree->move_last[ply] ) {
MOVE_CURR = *ptree->anext_move[ply].move_last++;
return 1;
}
}

return 0;
}
6 changes: 5 additions & 1 deletion src/usi-engine/bona/shogi.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ extern unsigned char ailast_one[512];
//#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 "34" // 20220429 dfpn time limit stop.
//#define BNZ_VER "34" // 20220429 dfpn time limit stop.
//#define BNZ_VER "35" // 20220430 perpetual check bug fixed(again).
#define BNZ_VER "36" // 20220626 pawn ,rook, bishop are always promoted. discovered attack moves have 30% of best policy. safe LCB, kldgain 0.000005.
#define BNZ_NAME "AobaZero"

//#define BNZ_VER "16" // 20210528 komaochi, mate3
Expand Down Expand Up @@ -1149,6 +1151,8 @@ int CONV make_move_root( tree_t * restrict ptree, unsigned int move,
int flag );
int CONV search_quies( tree_t * restrict ptree, int alpha, int beta, int turn,
int ply, int qui_ply );
int CONV search_quies_aoba( tree_t * restrict ptree, int alpha, int beta, int turn,
int ply, int qui_ply );
int CONV search( tree_t * restrict ptree, int alpha, int beta, int turn,
int depth, int ply, unsigned int state_node );
int CONV searchr( tree_t * restrict ptree, int alpha, int beta, int turn,
Expand Down
1 change: 1 addition & 0 deletions src/usi-engine/bona/yss_dcnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct hash_shogi {
int deleted; //
int mate_bit;
float win_sum;
float squared_eval; // variance for Dynamic Variance-Scaled cPUCT
int games_sum; // sum of children selected
int col; // color 1 or 2
int age; //
Expand Down
Loading

0 comments on commit 31513e4

Please sign in to comment.