#include "shogi.h"
-int
+int CONV
ini_game( tree_t * restrict ptree, const min_posi_t *pmin_posi, int flag,
const char *str_name1, const char *str_name2 )
{
int piece;
int sq, iret;
+#if defined(INANIWA_SHIFT)
+ if ( inaniwa_flag )
+ {
+ inaniwa_flag = 0;
+ ehash_clear();
+ iret = ini_trans_table();
+ if ( iret < 0 ) { return iret; }
+ }
+#endif
+
if ( flag & flag_history )
{
iret = open_history( str_name1, str_name2 );
ptree->move_last[0] = ptree->amove;
ptree->nsuc_check[0] = 0;
ptree->nsuc_check[1] = 0;
- root_nrep = 0;
+ ptree->nrep = 0;
root_turn = pmin_posi->turn_to_move;
HAND_B = pmin_posi->hand_black;
HAND_W = pmin_posi->hand_white;
memset( ptree->hist_good, 0, sizeof(ptree->hist_good) );
memset( ptree->hist_tried, 0, sizeof(ptree->hist_tried) );
- memset( hash_rejections_parent, 0, sizeof(hash_rejections_parent) );
- memset( hash_rejections, 0, sizeof(hash_rejections) );
- game_status &= ( flag_quiet | flag_reverse | flag_narrow_book
+ game_status &= ( flag_reverse | flag_narrow_book
| flag_time_extendable | flag_learning
| flag_nobeep | flag_nostress | flag_nopeek
- | flag_noponder | flag_noprompt );
+ | flag_noponder | flag_noprompt | flag_sendpv
+ | flag_nostdout | flag_nonewlog );
sec_b_total = 0;
sec_w_total = 0;
sec_elapsed = 0;
last_root_value = 0;
- n_nobook_move = 0;
last_pv.depth = 0;
last_pv.length = 0;
last_pv.a[0] = 0;
return iret;
}
+ /* connect to Tsumeshogi server */
+#if defined(DFPN_CLIENT)
+ lock( &dfpn_client_lock );
+ dfpn_client_start( ptree );
+ snprintf( (char *)dfpn_client_signature, DFPN_CLIENT_SIZE_SIGNATURE,
+ "%" PRIx64 "_%x_%x_%x", HASH_KEY, HAND_B, HAND_W, root_turn );
+ dfpn_client_signature[DFPN_CLIENT_SIZE_SIGNATURE-1] = '\0';
+ dfpn_client_rresult = dfpn_client_na;
+ dfpn_client_num_cresult = 0;
+ dfpn_client_flag_read = 0;
+ dfpn_client_out( "new %s\n", dfpn_client_signature );
+ unlock( &dfpn_client_lock );
+#endif
+
return 1;
}
-int
-gen_legal_moves( tree_t * restrict ptree, unsigned int *p0 )
+int CONV gen_legal_moves( tree_t * restrict ptree, unsigned int *p0, int flag )
{
unsigned int *p1;
int i, j, n;
p1 = GenCaptures( root_turn, p0 );
p1 = GenNoCaptures( root_turn, p1 );
- p1 = GenCapNoProEx2( root_turn, p1 );
- p1 = GenNoCapNoProEx2( root_turn, p1 );
+ if ( flag )
+ {
+ p1 = GenCapNoProEx2( root_turn, p1 );
+ p1 = GenNoCapNoProEx2( root_turn, p1 );
+ }
p1 = GenDrop( root_turn, p1 );
n = (int)( p1 - p0 );
}
else { i++; }
}
-
+
return n;
}
- detection of perpetual check is omitted.
- weak moves are omitted.
*/
-int
+int CONV
is_mate( tree_t * restrict ptree, int ply )
{
int iret = 0;
}
-int
+int CONV
is_hand_eq_supe( unsigned int u, unsigned int uref )
{
#if 1
/* weak moves are omitted. */
-int
+int CONV
detect_repetition( tree_t * restrict ptree, int ply, int turn, int nth )
{
const unsigned int *p;
int n, i, imin, counter, irep, ncheck;
ncheck = (int)ptree->nsuc_check[ply];
- n = root_nrep + ply - 1;
+ n = ptree->nrep + ply - 1;
/*if ( ncheck >= 6 )*/
if ( ncheck >= nth * 2 )
}
-int
+int CONV
com_turn_start( tree_t * restrict ptree, int flag )
{
const char *str_move;
unsigned int move, sec_total;
- int iret, is_resign, value, ply;
+ int iret, is_resign, value;
if ( ! ( flag & flag_from_ponder ) )
{
time_start = time_turn_start;
game_status |= flag_thinking;
- iret = iterate( ptree, flag );
+ iret = iterate( ptree );
game_status &= ~flag_thinking;
if ( iret < 0 ) { return iret; }
}
move = last_pv.a[1];
value = root_turn ? -last_root_value : last_root_value;
- str_move = str_CSA_move( move );
if ( value < -resign_threshold && last_pv.type != pv_fail_high )
{
-#if defined(DEKUNOBOU)
- if ( dek_ngame )
- {
- dek_lost += 1;
- Out( "Bonanza lost against Dekunobou\n" );
- }
-#endif
is_resign = 1;
}
- else {
- is_resign = 0;
-
-#if defined(DEKUNOBOU)
- if ( dek_ngame && ! is_resign
- && value > ( MT_CAP_DRAGON * 3 ) / 2
- && value > resign_threshold
- && value != score_inferior )
- {
- is_resign = 1;
- dek_win += 1;
- Out( "Bonanza won against Dekunobou.\n" );
- }
- if ( dek_ngame && ! is_resign && value == -score_draw )
- {
- iret = make_move_root( ptree, move, ( flag_rep | flag_nomake_move ) );
- if ( iret < 0 )
- {
- Out( "%s\n\n", str_move );
- return iret;
- }
- else if ( iret == 2 )
- {
- is_resign = 1;
- Out( "The game with Dekunobou is drawn.\n" );
- }
- }
- if ( dek_ngame && ! is_resign && record_game.moves > 255 )
- {
- is_resign = 1;
- Out( "The game with Dekunobou is interrupted...\n" );
- }
-#endif
- }
+ else { is_resign = 0; }
#if defined(DBG_EASY)
if ( easy_move && easy_move != move )
}
#endif
OutCsaShogi( "resign\n" );
- OutDek( "%%TORYO\n" );
}
else {
-#if defined(CSA_LAN)
- if ( sckt_csa != SCKT_NULL )
+#if defined(USI)
+ if ( usi_mode != usi_off )
{
- iret = sckt_out( sckt_csa, "%c%s\n", ach_turn[root_turn], str_move );
- if ( iret < 0 ) { return iret; }
+ char buf[6];
+ csa2usi( ptree, str_CSA_move(move), buf );
+ USIOut( "bestmove %s\n", buf );
}
#endif
- OutCsaShogi( "move%s\n", str_move );
- OutDek( "%c%s\n", ach_turn[root_turn], str_move );
- }
- OutBeep();
+ OutCsaShogi( "move%s\n", str_CSA_move( move ) );
- /* learning and stuff */;
- ply = record_game.moves;
- if ( ply < HASH_REG_HIST_LEN )
- {
- history_book_learn[ply].data &= ~( (1U<<31) | 0xffffU );
- history_book_learn[ply].data |= (unsigned int)(value+32768);
- history_book_learn[ply].move_responsible = move;
- history_book_learn[ply].key_responsible = (unsigned int)HASH_KEY;
- history_book_learn[ply].hand_responsible = (unsigned int)HAND_B;
+#if defined(CSA_LAN)
+ if ( sckt_csa != SCKT_NULL ) {
+
+ if ( game_status & flag_sendpv ) {
+ int i, turn, byte;
+ char buf[256];
+
+ byte = snprintf( buf, 256, "%c%s,\'* %d",
+ ach_turn[root_turn], str_CSA_move( move ),
+ last_root_value );
+
+ turn = root_turn;
+ for( i = 2; i <= last_pv.length && i < 5; i++ )
+ {
+ turn = Flip(turn);
+ byte += snprintf( buf+byte, 256-byte, " %c%s",
+ ach_turn[turn], str_CSA_move(last_pv.a[i]) );
+ }
+
+ iret = sckt_out( sckt_csa, "%s\n", buf );
+ if ( iret < 0 ) { return iret; }
+
+ } else {
+
+ iret = sckt_out( sckt_csa, "%c%s\n", ach_turn[root_turn],
+ str_CSA_move( move ) );
+ if ( iret < 0 ) { return iret; }
+ }
}
-
- iret = hash_learn( ptree, move, value, iteration_depth - 1 );
- if ( iret < 0 ) { return iret; }
-
+#endif
+ }
+ OutBeep();
+
/* show search result and make a move */
if ( is_resign )
{
show_prompt();
game_status |= flag_resigned;
- renovate_time( root_turn );
+ update_time( root_turn );
out_CSA( ptree, &record_game, MOVE_RESIGN );
sec_total = root_turn ? sec_w_total : sec_b_total;
str_move = "resign";
else {
show_prompt();
iret = make_move_root( ptree, move,
- ( flag_rep | flag_time | flag_history
- | flag_rejections ) );
- if ( iret < 0 )
- {
- Out( "%s\n\n", str_move );
- return iret;
- }
+ ( flag_rep | flag_time | flag_history ) );
+ if ( iret < 0 ) { return iret; }
sec_total = root_turn ? sec_b_total : sec_w_total;
+ str_move = str_CSA_move( move );
}
OutCsaShogi( "info tt %03u:%02u\n", sec_total / 60U, sec_total % 60U );
if ( iret < 0 ) { return iret; }
#endif
}
-
+
return 1;
}
-
#if defined(MNJ_LAN)
-int mnj_reset_tbl( int sd, unsigned int seed )
+int CONV mnj_reset_tbl( int sd, unsigned int seed )
{
double average, deviation, d;
unsigned int u;
int i, j;
+ if ( sd <= 0 ) { return load_fv(); }
+
+ if ( load_fv() < 0 ) { return -1; }
if ( clear_trans_table() < 0 ) { return -1; }
ehash_clear();
- if ( sd <= 0 )
- {
- for ( i = 0; i < MNJ_MASK + 1; i++ ) { mnj_tbl[i] = 0; }
- return 1;
- }
ini_rand( seed );
+ average = 0.0;
+ deviation = 0.0;
- for( i = 0; i < MNJ_MASK + 1; i++ )
+ for( i = 0; i < nsquare * pos_n; i++ )
{
d = -6.0;
for ( j = 0; j < 12; j++ ) { d += (double)rand32() / (double)UINT_MAX; }
- mnj_tbl[i] = (short)( (double)sd * d );
+ d *= (double)sd;
+ average += d;
+ deviation += d * d;
+ pc_on_sq[0][i] = (short)( (int)pc_on_sq[0][i] + (int)d );
}
- average = 0.0;
- for ( i = 0; i < MNJ_MASK + 1; i++ ) { average += (double)mnj_tbl[i]; }
- average /= (double)( MNJ_MASK + 1 );
-
- deviation = 0.0;
- for ( i = 0; i < MNJ_MASK + 1; i++ )
+ for( i = 0; i < nsquare * nsquare * kkp_end; i++ )
{
- d = (double)mnj_tbl[i] - average;
- deviation += d * d;
+ d = -6.0;
+
+ for ( j = 0; j < 12; j++ ) { d += (double)rand32() / (double)UINT_MAX; }
+ d *= (double)sd;
+ average += d;
+ deviation += d * d;
+ kkp[0][0][i] = (short)( (int)kkp[0][0][i] + (int)d );
}
- deviation = sqrt( deviation / (double)( MNJ_MASK + 1 ) );
+
+ average /= (double)( nsquare * pos_n + nsquare * nsquare * kkp_end );
+ deviation /= (double)( nsquare * pos_n + nsquare * nsquare * kkp_end );
+ deviation = sqrt( deviation );
if ( get_elapsed( &u ) < 0 ) { return -1; }
ini_rand( u );
Out( "\nThe normal distribution N(0,sd^2) is generated.\n" );
- Out( " actual average: % .3f\n", average );
- Out( " actual standard deviation: % .3f\n", deviation );
+ Out( " actual average: % .7f\n", average );
+ Out( " actual standard deviation: % .7f\n", deviation );
Out( "rand seed = %x\n", u );
return 1;
}
#endif
-
-void *
-memory_alloc( size_t nbytes )
+void * CONV memory_alloc( size_t nbytes )
{
#if defined(_WIN32)
void *p = VirtualAlloc( NULL, nbytes, MEM_COMMIT, PAGE_READWRITE );
}
-int
-memory_free( void *p )
+int CONV memory_free( void *p )
{
#if defined(_WIN32)
if ( VirtualFree( p, 0, MEM_RELEASE ) ) { return 1; }