From 36b74c04154cdecba1f999f5b358874502755cd0 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 20 Apr 2022 06:00:00 -0700 Subject: add function to test three-dart averages --- dartbot.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'dartbot.c') diff --git a/dartbot.c b/dartbot.c index 314548f..03b4ec5 100644 --- a/dartbot.c +++ b/dartbot.c @@ -13,11 +13,11 @@ void test_match(int start_points) { struct leg *l = leg_init(start_points, NULL); - while(l->rem > 0) + while (l->rem > 0) comp_visit(l); printf("(%2d) %3d\n", 0, l->start); - for(int i = 0; i < l->n_visits; ++i) { + for (int i = 0; i < l->n_visits; ++i) { struct visit *v = l->visits + i; printf("(%2d) %3d %3d", i+1, v->points, v->rem); @@ -129,6 +129,27 @@ void pvp_curses_match(int start_points) curses_match(start_points, "David", user_visit, "Davidn't", user_visit); } +void test_averages() +{ + int rounds = 100000; + + for (int stdev = 4; stdev < 25; ++stdev) { + horizontal_stdev = vertical_stdev = stdev; + + int darts = 0; + for (int i = 0; i < rounds; ++i) { + struct leg *l = leg_init(501, NULL); + while (l->rem > 0) + comp_visit(l); + leg_free(l); + + darts += (l->n_visits-1)*3 + l->visits[l->n_visits-1].n_darts; + } + + printf("%d %f\n", stdev, (double)(501*rounds)/darts*3); + } +} + int main() { srand(time(NULL)); @@ -138,6 +159,7 @@ int main() pvc_curses_match(501); //pvp_curses_match(501); test_match(501); + //test_averages(); return 0; } -- cgit v1.2.3-70-g09d2