diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-26 00:43:29 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-26 00:43:29 -0700 |
commit | 6d3583f9811d2c7b184d0197c78e6f20cfc93549 (patch) | |
tree | f44a42e043bba8159bb7634563d45097c537a5b0 /web/web_opts.c | |
parent | 656be88ba3b0db383101449d7d2f09348601d7d7 (diff) | |
download | dartboat-6d3583f9811d2c7b184d0197c78e6f20cfc93549.tar.gz dartboat-6d3583f9811d2c7b184d0197c78e6f20cfc93549.tar.xz |
move difficulty-to-stdev logic to lib
Diffstat (limited to 'web/web_opts.c')
-rw-r--r-- | web/web_opts.c | 37 |
1 files changed, 2 insertions, 35 deletions
diff --git a/web/web_opts.c b/web/web_opts.c index b593306..b880fd3 100644 --- a/web/web_opts.c +++ b/web/web_opts.c @@ -16,51 +16,18 @@ int delay_ms = 1000; static int difficulty = 32; -static struct { int diff; double stdev; } DIFF_PRESETS[] = { - { 0, 66.80}, // 10 - { 8, 40.24}, // 20 - {16, 28.14}, // 30 - {24, 21.35}, // 40 - {32, 17.20}, // 50 - {40, 14.34}, // 60 - {48, 12.15}, // 70 - {56, 10.36}, // 80 - {64, 8.83}, // 90 - {72, 7.48}, // 100 - {80, 6.32}, // 110 - {88, 5.34}, // 120 - {99, 0.00}, // 167 -}; -#define NUM_DIFF_PRESETS (sizeof(DIFF_PRESETS) / sizeof(*DIFF_PRESETS)) static void set_delay(char *val) { delay_ms = atoi(val); } -static void set_stdev(int diff) -{ - if (diff < DIFF_PRESETS[0].diff) - diff = DIFF_PRESETS[0].diff; - else if (diff > DIFF_PRESETS[NUM_DIFF_PRESETS - 1].diff) - diff = DIFF_PRESETS[NUM_DIFF_PRESETS - 1].diff; - - size_t ind = 1; - while (ind < NUM_DIFF_PRESETS - 1 && DIFF_PRESETS[ind].diff <= diff) - ind++; - - double step = (DIFF_PRESETS[ind - 1].stdev - DIFF_PRESETS[ind].stdev) / - (DIFF_PRESETS[ind].diff - DIFF_PRESETS[ind - 1].diff); - horizontal_stdev = vertical_stdev = DIFF_PRESETS[ind - 1].stdev - - ((diff - DIFF_PRESETS[ind - 1].diff) * step); -} - static void set_difficulty(char *val) { int diff = atoi(val); difficulty = diff < 0 ? 0 : diff > 99 ? 99 : diff; - set_stdev(difficulty); + comp_set_difficulty(difficulty); } static char *prefix_opt(char *opt) @@ -105,7 +72,7 @@ void opts_init() { read_delay(); if (!read_difficulty()) - set_stdev(difficulty); + comp_set_difficulty(difficulty); char buf[64]; sprintf(buf, "%d", delay_ms); |