void valid_go(char *cfgfile, char *weightfile, int multi) { srand(time(0)); char *base = basecfg(cfgfile); printf("%s\n", base); network net = parse_network_cfg(cfgfile); if(weightfile){ load_weights(&net, weightfile); } set_batch_network(&net, 1); printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay); float *board = calloc(19*19, sizeof(float)); float *move = calloc(19*19, sizeof(float)); moves m = load_go_moves("/home/pjreddie/backup/go.test"); int N = m.n; int i; int correct = 0; for(i = 0; i <N; ++i){ char *b = m.data[i]; int row = b[0]; int col = b[1]; int truth = col + 19*row; string_to_board(b+2, board); predict_move(net, board, move, multi); int index = max_index(move, 19*19); if(index == truth) ++correct; printf("%d Accuracy %f\n", i, (float) correct/(i+1)); } }
int generate_move(network net, int player, float *board, int multi, float thresh, float temp, char *ko, int print) { int i, j; for(i = 0; i < net.n; ++i) net.layers[i].temperature = temp; float move[361]; if (player < 0) flip_board(board); predict_move(net, board, move, multi); if (player < 0) flip_board(board); for(i = 0; i < 19; ++i){ for(j = 0; j < 19; ++j){ if (!legal_go(board, ko, player, i, j)) move[i*19 + j] = 0; } } int indexes[nind]; top_k(move, 19*19, nind, indexes); if(thresh > move[indexes[0]]) thresh = move[indexes[nind-1]]; for(i = 0; i < 19; ++i){ for(j = 0; j < 19; ++j){ if (move[i*19 + j] < thresh) move[i*19 + j] = 0; } } int max = max_index(move, 19*19); int row = max / 19; int col = max % 19; int index = sample_array(move, 19*19); if(print){ top_k(move, 19*19, nind, indexes); for(i = 0; i < nind; ++i){ if (!move[indexes[i]]) indexes[i] = -1; } print_board(board, player, indexes); for(i = 0; i < nind; ++i){ fprintf(stderr, "%d: %f\n", i+1, move[indexes[i]]); } } if(suicide_go(board, player, row, col)){ return -1; } if(suicide_go(board, player, index/19, index%19)) index = max; return index; }
int SV_CanSee(int player, int other) { sharedEntity_t *pent, *oent; playerState_t *ps; vec3_t viewpoint, tmp; int i; // check if bounding box has been changed if (sv_wh_bbox_horz->integer != bbox_horz) { init_horz_delta(); } if (sv_wh_bbox_vert->integer != bbox_vert) { init_vert_delta(); } ps = SV_GameClientNum(player); pent = SV_GentityNum(player); oent = SV_GentityNum(other); // check if 'other' is in the maximum fov allowed if (sv_wh_check_fov->integer > 0) { if (!player_in_fov(pent->s.apos.trBase, pent->s.pos.trBase, oent->s.pos.trBase)) { return 0; } } // check if visible in this frame calc_viewpoint(ps, pent->s.pos.trBase, viewpoint); for (i = 0; i < 8; i++) { VectorCopy(oent->s.pos.trBase, tmp); tmp[0] += delta[i][0]; tmp[1] += delta[i][1]; tmp[2] += delta[i][2] + VOFS; if (is_visible(viewpoint, tmp)) { return 1; } } // predict player positions copy_trajectory(&pent->s.pos, &traject); predict_move(pent, PREDICT_TIME, &traject, pred_ppos); copy_trajectory(&oent->s.pos, &traject); predict_move(oent, PREDICT_TIME, &traject, pred_opos); // Check again if 'other' is in the maximum fov allowed. // FIXME: We use the original viewangle that may have // changed during the move. This could introduce some // errors. if (sv_wh_check_fov->integer > 0) { if (!player_in_fov(pent->s.apos.trBase, pred_ppos, pred_opos)) { return 0; } } // check if expected to be visible in the next frame calc_viewpoint(ps, pred_ppos, viewpoint); for (i = 0; i < 8; i++) { VectorCopy(pred_opos, tmp); tmp[0] += delta[i][0]; tmp[1] += delta[i][1]; tmp[2] += delta[i][2] + VOFS; if (is_visible(viewpoint, tmp)) { return 1; } } return 0; }