summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comp.c7
-rw-r--r--comp.h2
-rw-r--r--dartbot.c26
3 files changed, 29 insertions, 6 deletions
diff --git a/comp.c b/comp.c
index 13b21a6..4932e37 100644
--- a/comp.c
+++ b/comp.c
@@ -7,8 +7,7 @@
#include <stdbool.h>
#include <stdlib.h>
-#define HORIZONTAL_STDEV 24
-#define VERTICAL_STDEV 24
+int horizontal_stdev = 24, vertical_stdev = 24;
double drand()
{
@@ -38,8 +37,8 @@ double gauss(double mean, double stdev)
struct ccoords get_offset()
{
- return (struct ccoords){ .x = gauss(0, HORIZONTAL_STDEV),
- .y = gauss(0, VERTICAL_STDEV) };
+ return (struct ccoords){ .x = gauss(0, horizontal_stdev),
+ .y = gauss(0, vertical_stdev) };
}
struct ccoords pol_to_cart(struct pcoords c)
diff --git a/comp.h b/comp.h
index c7bc830..460291e 100644
--- a/comp.h
+++ b/comp.h
@@ -3,6 +3,8 @@
#include "match.h"
+extern int horizontal_stdev, vertical_stdev;
+
void comp_visit(struct leg *l);
#endif
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;
}