From 6d3583f9811d2c7b184d0197c78e6f20cfc93549 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Thu, 26 May 2022 00:43:29 -0700 Subject: move difficulty-to-stdev logic to lib --- comp.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'comp.c') diff --git a/comp.c b/comp.c index 012eea1..6b4ec26 100644 --- a/comp.c +++ b/comp.c @@ -9,6 +9,42 @@ double horizontal_stdev = 16, vertical_stdev = 16; +#define NUM_DIFF_PRESETS (sizeof(DIFF_PRESETS) / sizeof(*DIFF_PRESETS)) +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 +}; + +// optional function to set stdevs using precomputed 0-99 difficulty values. +// fixed-step interpolation is done between presets. +void comp_set_difficulty(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 double drand() { return (double)rand() / RAND_MAX; @@ -63,7 +99,7 @@ static struct pcoords throw_dart(struct pcoords target, struct ccoords *cc) return cart_to_pol(*cc); } -struct segment next_dart(int rem, int darts_in_hand) +static struct segment next_dart(int rem, int darts_in_hand) { char *c = NULL; if (rem <= NUM_CHECKOUTS) -- cgit v1.2.3-70-g09d2