Skip to content

Commit

Permalink
Merge pull request #61 from kobanium/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yssaya authored Apr 7, 2022
2 parents 61189b0 + c8daf6a commit 4d0da9b
Show file tree
Hide file tree
Showing 16 changed files with 4,359 additions and 292 deletions.
1,756 changes: 1,756 additions & 0 deletions learn/aoba_256x20b_swish_mb128.prototxt

Large diffs are not rendered by default.

1,601 changes: 1,601 additions & 0 deletions learn/aoba_256x20b_swish_predict.prototxt

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion learn/aoba_zero_solver.prototxt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#net: "aoba_zero.prototxt"
#net: "aoba_zero_256x40b.prototxt"
#net: "aoba_zero_256x20b.prototxt"
net: "aoba_zero_256x20b_mb128.prototxt"
#net: "aoba_zero_256x20b_mb128.prototxt"
#net: "aoba_zero_256x40b_mb64.prototxt"
net: "aoba_256x20b_swish_mb128.prototxt"

# test_iter specifies how many forward passes the test should carry out.
# In the case of MNIST, we have test batch size 100 and 100 test iterations,
Expand Down
2 changes: 2 additions & 0 deletions learn/handicap_rate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
52240000 52172800 52172800 52172800 52172800 52172800 52172800
914 0 0 0 0 0 0
28 changes: 17 additions & 11 deletions learn/learn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ xz
$ sudo apt install xz-utils liblzma-dev

archive/ ���
arch000000000000.csa.xz ����
arch000000200000.csa.xz
arch000051420000.csa.xz ����
arch000052500000.csa.xz
���餤�ޤǤ��֤��ޤ���
https://drive.google.com/drive/folders/1dbE5xWGQLsduR00oxEGPpZQJtQr_EQ75
https://drive.google.com/drive/folders/1fZJn288VhU6kE7crX7H1Ml4GcRZH0uHK

$ cd archive
$ xz -d -k *.xz
�ǥ��쥯�ȥ��̾�˹�碌�� yss_dcnn.cpp �� 2778���ܤ�����β���2�Ĥ��ѹ����ޤ���
char dir_arch[] = "/home/yss/tcp_backup/archive/";
char dir_pool[] = "/home/yss/tcp_backup/pool";

�Ǥ��٤�Ÿ�����ޤ���
yss_dcnn.cpp ��
fReplayLearning = 1; �ˤ��ޤ���
����ǽ�������줿�Ťߤ���Ϥ����ϲ��ιԤ򥳥��ȥ����Ȥ��ޤ���
net->CopyTrainedLayersFrom(sNet); // caffemodel���ɤ߹���dzؽ���Ƴ�������
5142�����褫��ؽ�����ˤϲ��Τ褦�ˤ��ޤ���
int zdb_count_start = 51420000;

$ make
$ learn

�Ǽ¹Ԥ��ޤ���
12��������ɤ߹�����塢2000�����ɲä��Ȥ�4000��ؽ����򷫤��֤��ޤ���
���10�����褫��������64���̤���Ф���64 minibatch�dzؽ����ޤ���
100��������ɤ߹�����塢2000�����ɲä��Ȥ�4000��ؽ����򷫤��֤��ޤ���
���100�����褫��������64���̤���Ф���64 minibatch�dzؽ����ޤ���




�ºݤζ����ؽ���Ԥ��ˤ�
yss_dcnn.cpp ��
fReplayLearning = 0;
ZERO_DB_SIZE = 500000;
�ˤ��ơ�pool/ �β��˺ǿ��δ��褬
no000000000000.csa.xz
no000000000001.csa.xz
Expand All @@ -46,5 +52,5 @@ no000000009999.csa.xz
archive/arch000000000000.csa.xz
�������褦�ˤ��ޤ����ܤ����ϥ�����¦��������������

���50������ޤǸ���ˤϥ��꤬����Ǥ�19GB�ʾ�ɬ�פǤ���
���100������ޤǸ���ˤϥ��꤬����Ǥ�12GB�ʾ�ɬ�פǤ���

62 changes: 44 additions & 18 deletions learn/yss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int GetSystemMemoryMB()

const char *get_kdbDirSL() { return ""; } // NULLではない。長さが0の文字列の先頭アドレスを返す

int get_learning_dir_number() { PRT("must be programmed!\n"); debug(); return 0; }
int get_learning_dir_number() { DEBUG_PRT("must be programmed!\n"); return 0; }

int change_dir(const char* /* sDir */) { return 0; }
void return_dir() {}
Expand Down Expand Up @@ -208,7 +208,6 @@ int open_one_file(char *filename)

PS->SetSennititeKif(); // 千日手も棋譜情報に登録する


PRT_ON();
return 1;
}
Expand Down Expand Up @@ -290,7 +289,7 @@ int get_next_file_from_dirs(char *filename, const char *ext, const char *dir_lis
return 0;
}
if ( change_dir(p_current_dir) == 0 ) {
PRT("fail change dir=%s\n",p_current_dir); debug();
DEBUG_PRT("fail change dir=%s\n",p_current_dir);
}
}

Expand Down Expand Up @@ -386,7 +385,7 @@ void PRT_ON() { fPrtCut = 0; }
#else
if ( len < 0 || len >= PRT_LEN_MAX ) {
PRT_sub("PRT len over!\n");
debug();
DEBUG_PRT("PRT len over!");
}
PRT_sub("%s",text); // PRT(text) だとtext="%CHUDAN"が"HUDAN"になってしまう。
#endif
Expand Down Expand Up @@ -458,7 +457,7 @@ int shogi::kifu_set_move(int bz,int az,int tk,int nf, int t)
// char retp[20];
// change(bz,az,tk,nf,retp);
// PRT("%s, bz,az,tk,nf = %x,%x,%x,%x\n",retp,bz,az,tk,nf);
if ( tesuu >= KIFU_MAX-1 ) { PRT("KIFU_MAX Err\n"); debug(); }
if ( tesuu >= KIFU_MAX-1 ) { DEBUG_PRT("KIFU_MAX Err\n"); }
move_hit(bz,az,tk,nf);
tesuu++; all_tesuu = tesuu;
kifu[tesuu][0] = bz;
Expand Down Expand Up @@ -880,7 +879,6 @@ int shogi::getMoveFromCsaStr(int *bz, int *az, int *tk, int *nf, char *str)
return 1;
}


// CSA形式の棋譜を読み込む
int shogi::LoadCSA()
{
Expand Down Expand Up @@ -935,6 +933,11 @@ int shogi::LoadCSA()
prt_flag = 0;
ban_saikousei(); // 盤面の再構成。
check_kn(); // 盤面の状態が正常化チェック

// 駒落ち判定
ZERO_DB *pz = &zdb_one;
pz->handicap = get_handicap_from_board();
if ( pz->handicap && fGotekara==0 ) DEBUG_PRT("pz->handiacp=%d\n",pz->handicap);
}

// csa形式のコメントを取り込む
Expand Down Expand Up @@ -972,7 +975,7 @@ int shogi::LoadCSA()
char str[10];
int n = 0;
for (;;) {
if ( n>=10 ) { PRT("Err csa move str >= %d,w=%d,%s\n",n,pz->weight_n,sIndex); debug(); }
if ( n>=10 ) { DEBUG_PRT("Err csa move str >= %d,w=%d,%s\n",n,pz->weight_n,sIndex); }
c = *p++;
str[n++] = c;
if ( c==',' || c=='\r' || c =='\n' || c==0 ) break;
Expand All @@ -993,7 +996,7 @@ int shogi::LoadCSA()
}
} else {
if ( (count&1)== 0 ) {
if ( b0==0 && b1==0 ) debug();
if ( b0==0 && b1==0 ) DEBUG_PRT("");
int v = atoi(str);
if ( v > 0xffff ) v = 0xffff;
sum_visit += v;
Expand All @@ -1002,9 +1005,10 @@ int shogi::LoadCSA()
pz->vv_move_visit[tesuu].push_back(move_visit);
b0 = b1 = 0;
} else {
if ( getMoveFromCsaStr(&bz, &az, &tk, &nf, str)==0 ) debug();
if ( is_pseudo_legalYSS((Move)pack_te(bz,az,tk,nf), (Color)((tesuu&1)==1)) == false ) {
PRT("move Err %3d:%s\n",tesuu,str); debug();
if ( getMoveFromCsaStr(&bz, &az, &tk, &nf, str)==0 ) DEBUG_PRT("");
int c = (tesuu+(pz->handicap!=0))&1;
if ( is_pseudo_legalYSS((Move)pack_te(bz,az,tk,nf), (Color)(c==1) ) == false ) {
DEBUG_PRT("move Err %3d:%s\n",tesuu,str);
}
pack_from4_to_2_KDB(&b0,&b1, bz, az, tk, nf);
}
Expand Down Expand Up @@ -1051,7 +1055,7 @@ P+00KE00KE00FU
' 後手持駒
P-00HI
P-00AL
*/
*/
/*
P-21KE22OU33KE23FU
P+32GI14FU26KE
Expand All @@ -1061,6 +1065,15 @@ P-00AL
+2634KE
-2232OU
+0042KI
*/
/*
PI 平手
PI11KY 香落ち
PI22KA 角落ち
PI82HI 飛車落ち
PI82HI22KA 2枚落ち
PI82HI22KA11KY91KY 4枚落ち
PI82HI22KA11KY91KY21KE81KE 6枚落ち
*/

y = lpLine[1];
Expand Down Expand Up @@ -1102,6 +1115,17 @@ P-00AL
else if ( y == '-' ) mo_c[i]++; // 後手の持駒
}
}
if ( y == 'I' ) { // 初期設定配置
for (lpCopy=lpLine+2; lpCopy-lpLine<nLen-4; lpCopy+=4) {
int xx = *(lpCopy+0) - '0';
int yy = *(lpCopy+1) - '0';
if ( yy<1 || yy>9 || xx<1 || xx>9 ) { DEBUG_PRT("PI Err\n"); }
int i = get_csa_koma(lpCopy+2);
if ( i==0 ) { DEBUG_PRT("持駒種別エラー='%c%c'\n",*(lpCopy+2),*(lpCopy+3)); }
init_ban[yy*16+(10-xx)] = 0;
}
}

y = lpLine[1] - '0';
if ( 1<=y && y<=9 ) { // 1行の駒
lpCopy = lpLine+2;
Expand Down Expand Up @@ -1143,16 +1167,18 @@ P-00AL
pz->moves = tesuu;
pz->result = ZD_DRAW;
pz->result_type = RT_NONE;
int is_gote_turn = (tesuu + (pz->handicap!=0))& 1;

if ( strstr(lpLine,"TORYO") ) {
if ( tesuu & 1 ) {
if ( is_gote_turn ) {
pz->result = ZD_S_WIN;
} else {
pz->result = ZD_G_WIN;
}
pz->result_type = RT_TORYO;
}
if ( strstr(lpLine,"KACHI") ) {
if ( tesuu & 1 ) {
if ( is_gote_turn ) {
pz->result = ZD_G_WIN;
} else {
pz->result = ZD_S_WIN;
Expand Down Expand Up @@ -1180,7 +1206,7 @@ P-00AL
for (i=0;i<(int)pz->vv_move_visit.size();i++) {
sum += pz->vv_move_visit[i].size();
}
PRT("moves=%d,result=%d, mv_sum=%d,%.1f\n",pz->moves,pz->result,sum, (double)sum/(tesuu+0.00001f));
PRT("handicap=%d,moves=%d,result=%d, mv_sum=%d,%.1f\n",pz->handicap,pz->moves,pz->result,sum, (double)sum/(tesuu+0.00001f));
if ( pz->result_type == RT_NONE ) DEBUG_PRT("");
#endif
break; // 読み込み終了
Expand Down Expand Up @@ -1264,7 +1290,7 @@ void shogi::LoadShotest(void)
char *pdest;

pdest = strchr( drop_shotest, c );
if ( pdest == NULL ) { PRT("持ち駒発見ミス shotest\n"); debug(); }
if ( pdest == NULL ) { DEBUG_PRT("持ち駒発見ミス shotest\n"); }
i = pdest - drop_shotest + 1;
}
tk = i + (0x80)*(tesuu&1);
Expand Down Expand Up @@ -1361,7 +1387,7 @@ void shogi::LoadTextBan()
for (i=1;i<8;i++) {
sprintf(find,"%s",koma_kanji[i+16]);
char *q = strstr(p+2*9,find);
if ( q==NULL) { PRT("not found 駒\n"); debug(); }
if ( q==NULL) { DEBUG_PRT("not found 駒\n"); }
mo_c[i] = *(q+3) - '0';
}
}
Expand Down Expand Up @@ -1391,7 +1417,7 @@ void shogi::LoadTextBan()

const char *sSengoSankaku[3] = {"","",""};

int shogi::IsSenteTurn() { return ( ((fGotekara+tesuu)&1) == 0 ); } // 駒落ちで正しくない
int shogi::IsSenteTurn() { DEBUG_PRT(""); return ( ((fGotekara+tesuu)&1) == 0 ); } // 駒落ちで正しくない
int shogi::GetSennititeMax() { return nSennititeMax; }

// 柿木形式の棋譜を読み込む
Expand Down
19 changes: 16 additions & 3 deletions learn/yss.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
// This source code is in the public domain.
/* yss.h classの定義 */



#define F2187



#define SMP // 並列探索する場合には定義する

#ifdef SMP
Expand Down Expand Up @@ -211,6 +217,8 @@ class shogi {

void allkaku(void); // 全部利きを書く
void allkesu(void);
void kiki_write(int z);
void kiki_delete(int z);

// yss_ki2.cpp
void init(void); // kn[]を初期化して再設定。hash_code と tume_hyouka を再設定
Expand Down Expand Up @@ -376,6 +384,7 @@ class shogi {
void clear_mo();
void clear_init_ban();
void hirate_ban_init(int n);/*** 盤面を初期状態に戻す(駒落ち付き) ***/
int get_handicap_from_board();
void ban_saikousei(void); // 現在の持ち駒、盤面の状態(ban_init)を元に盤面状態を再構成する。
int is_hirate_ban(); // 平手の盤面か判定する
void hanten_with_hash_kifu();
Expand All @@ -402,11 +411,11 @@ class shogi {
}

// yss_bwh1.cpp
void trans_4_to_2_KDB(int b0,int b1, int num, int *bz,int *az, int *tk, int *nf); // 棋泉形式の2バイトを4バイトに変換。
void trans_4_to_2_KDB(int b0,int b1, bool bGoteTurn, int *bz,int *az, int *tk, int *nf); // 棋泉形式の2バイトを4バイトに変換。

// yss_dcnn.cpp
void make_policy_leveldb();
void set_dcnn_channels(Color sideToMove, const int ply, float *p_data, int stock_num, int net_type);
void set_dcnn_channels(Color sideToMove, const int ply, float *p_data, int stock_num, int nHandicap);
void setYssChannels(Color sideToMove, int moves, float *p_data, int net_kind, int input_num);
int get_cnn_next_move();
HASH_SHOGI* HashShogiReadLock();
Expand All @@ -417,8 +426,12 @@ class shogi {
int uct_search_start(Color sideToMove);
int think_kifuset();
void update_zero_kif_db();
void copy_restore_dccn_init_board(int fCopy);
void copy_restore_dccn_init_board(int handicap, bool fCopy);
#ifdef F2187
void prepare_kif_db(int fPW, int mini_batch, float *data, float *label_policy, float *label_value, float label_policy_visit[][2187]);
#else
void prepare_kif_db(int fPW, int mini_batch, float *data, float *label_policy, float *label_value, float label_policy_visit[][MOVE_C_Y_X_ID_MAX]);
#endif
void init_prepare_kif_db();
float get_network_policy_value(Color sideToMove, int ply, HASH_SHOGI *phg);
char *prt_pv_from_hash(int ply);
Expand Down
Loading

0 comments on commit 4d0da9b

Please sign in to comment.