This commit is contained in:
Joseph Redmon 2016-03-13 23:47:23 -07:00
parent 0a252433b8
commit 02bb33c645

View File

@ -161,11 +161,12 @@ void test_go(char *filename, char *weightfile)
set_batch_network(&net, 1); set_batch_network(&net, 1);
float *board = calloc(19*19, sizeof(float)); float *board = calloc(19*19, sizeof(float));
float *move = calloc(19*19, sizeof(float)); float *move = calloc(19*19, sizeof(float));
image bim = float_to_image(19, 19, 1, board);
while(1){ while(1){
float *output = network_predict(net, board); float *output = network_predict(net, board);
copy_cpu(19*19, output, 1, move, 1); copy_cpu(19*19, output, 1, move, 1);
int i; int i;
#ifdef GPU
image bim = float_to_image(19, 19, 1, board);
for(i = 1; i < 8; ++i){ for(i = 1; i < 8; ++i){
rotate_image_cw(bim, i); rotate_image_cw(bim, i);
if(i >= 4) flip_image(bim); if(i >= 4) flip_image(bim);
@ -182,6 +183,7 @@ void test_go(char *filename, char *weightfile)
rotate_image_cw(bim, -i); rotate_image_cw(bim, -i);
} }
scal_cpu(19*19, 1./8., move, 1); scal_cpu(19*19, 1./8., move, 1);
#endif
for(i = 0; i < 19*19; ++i){ for(i = 0; i < 19*19; ++i){
if(board[i]) move[i] = 0; if(board[i]) move[i] = 0;
} }
@ -197,29 +199,36 @@ void test_go(char *filename, char *weightfile)
printf("Suggested: %c %d, %.2f%%\n", col + 'A' + 1*(col > 7), 19 - row, move[index]*100); printf("Suggested: %c %d, %.2f%%\n", col + 'A' + 1*(col > 7), 19 - row, move[index]*100);
} }
int index = indexes[0]; int index = indexes[0];
row = index / 19; int rec_row = index / 19;
col = index % 19; int rec_col = index % 19;
printf("\u25C9 Enter move: "); printf("\u25C9 Enter move: ");
char c; char c;
char *line = fgetl(stdin); char *line = fgetl(stdin);
int num = sscanf(line, "%c %d", &c, &row); int num = sscanf(line, "%c %d", &c, &row);
if (c < 'A' || c > 'T'){ if (strlen(line) == 0){
if (c == 'p'){ row = rec_row;
col = rec_col;
board[row*19 + col] = 1; board[row*19 + col] = 1;
}else if (c < 'A' || c > 'T'){
if (c == 'p'){
flip_board(board);
continue;
}else{ }else{
char g; char g;
num = sscanf(line, "%c %c %d", &g, &c, &row); num = sscanf(line, "%c %c %d", &g, &c, &row);
row = 19 - row; row = 19 - row;
col = c - 'A'; col = c - 'A';
if (col > 7) col -= 1; if (col > 7) col -= 1;
board[row*19 + col] = 0; if (num == 2) board[row*19 + col] = 0;
} }
} else { } else if(num == 2){
row = 19 - row; row = 19 - row;
col = c - 'A'; col = c - 'A';
if (col > 7) col -= 1; if (col > 7) col -= 1;
if(num == 2) board[row*19 + col] = 1; board[row*19 + col] = 1;
}else{
continue;
} }
update_board(board); update_board(board);
flip_board(board); flip_board(board);