/** * 清理某记录的总玩和总赢 */ void clear_record(Kvs_t* kvs, long id) { Kv_t* kv = find_kv(kvs, (Key_t)id); if(kv == NULL) return; ((Record_t *)kv -> value) -> play_total = 0; ((Record_t *)kv -> value) -> win_total = 0; }
/** * 递增修改某记录的总赢 */ void incr_record_win(Kvs_t* kvs, long id, int incr) { if(incr <= 0) return; Kv_t* kv = find_kv(kvs, (Key_t)id); if(kv == NULL) return; ((Record_t *)kv -> value) -> win_total += incr; }
bool update_kv(Kvs_t* kvs, Kv_t* kv) { Kv_t* kv_raw = find_kv(kvs, kv -> key); if(kv_raw == NULL) return false; kv_raw = kv; kv_raw -> key = kv -> key; return true; }
/** * 修改新参数列表里某id的几率 */ bool update_probability(Kvs_t* kvs, long id, double probability) { if(probability < 0 || probability > 1) return false; Kv_t* kv = find_kv(kvs, (Key_t)id); if(kv == NULL) return false; ((Param_t *)kv -> value) -> probability = probability; return true; }
void charizer_go(float * db_out) { // Perform a binary search for the deadband cutoff float del_db = .05; float db = .1; while(del_db > .0001) { test(db); if(find_vfinal() > .01) db -= del_db; else db += del_db; del_db /= 2; } *db_out = db; // Accelerate with power 0.2, and assess the results test(db + 0.2*(1-db)); float kv = find_kv(0.2); float ka = find_ka(0.2, kv, T); }
Kvs_t* add_kv(Kvs_t* kvs, Kv_t* kv) { if(kvs == NULL) { kvs = init_kvs(); } if(kvs -> usable_key <= kv -> key) { kvs -> usable_key = kv -> key + 1; } Kv_t* kv_raw = find_kv(kvs, kv -> key); if(kv_raw != NULL) { update_kv(kvs, kv); return kvs; } else { if(kvs -> count < kvs ->capacity) { kvs -> kv[kvs -> count] = kv; kvs -> count = kvs -> count + 1; return kvs; } else { Kvs_t* kvs_new = init_with_capacity(kvs -> capacity + EMPTY_COUNT); int i = 0; for(i = 0; i < kvs -> count; i++) { kvs_new -> kv[i] = kvs -> kv[i]; } kvs_new -> count = kvs -> count; kvs_new -> usable_key = kvs -> usable_key; free(kvs); kvs = NULL; kvs_new -> kv[kvs_new -> count] = kv; kvs_new -> count = kvs_new -> count + 1; return kvs_new; } } return kvs; }