]> git.sesse.net Git - wloh/blobdiff - mcwordfeud.cpp
Take standard deviation of estimated mu into account when doing MC simulation.
[wloh] / mcwordfeud.cpp
index 2bd4a5243cc1847b8251b5d4ed1ed48787dd2531..b48936d4a36c43a606fe57a95061a6e486bd9f89 100644 (file)
@@ -14,7 +14,7 @@ using namespace std;
 
 #define MAX_PLAYERS 16
 
-float match_stddev = 70.0f;
+float match_variance = 70.0f * 70.0f;
 
 struct player {
        int player_index;
@@ -67,12 +67,15 @@ float draw_gaussian(float mu, float stddev)
 int main(int argc, char **argv)
 {
        int trials = atoi(argv[1]);
+       float match_stddev;
 
        if (scanf("%f", &match_stddev) != 1) {
                fprintf(stderr, "Could't read match stddev\n");
                exit(1);
        }
 
+       match_variance = match_stddev * match_stddev;
+
        int num_players;
        if (scanf("%d", &num_players) != 1) {
                fprintf(stderr, "Could't read number of players\n");
@@ -87,6 +90,7 @@ int main(int argc, char **argv)
        vector<string> players;
        map<string, int> player_map;
        float ratings[MAX_PLAYERS];
+       float ratings_variance[MAX_PLAYERS];
        bool has_scores[MAX_PLAYERS][MAX_PLAYERS];
        for (int pl1 = 0; pl1 < num_players; ++pl1) {
                for (int pl2 = 0; pl2 < num_players; ++pl2) {
@@ -97,19 +101,23 @@ int main(int argc, char **argv)
        int scores[MAX_PLAYERS][MAX_PLAYERS];
        for (int i = 0; i < num_players; ++i) {
                char buf[256];
-               float rating;
-               int ret = scanf("%s %f", buf, &rating);
+               float rating, rating_stddev;
+               int ret = scanf("%s %f %f", buf, &rating, &rating_stddev);
                if (ret < 1) {
                        fprintf(stderr, "Couldn't read player %d\n", i);
                        exit(1);
                }
-               if (ret != 2) {
+               if (ret < 2) {
                        rating = 1500.0f;
                }
+               if (ret < 3) {
+                       rating_stddev = 0.0f;
+               }
 
                players.push_back(buf);
                player_map[buf] = i;
                ratings[i] = rating;
+               ratings_variance[i] = rating_stddev * rating_stddev;
        }
 
        for ( ;; ) {
@@ -151,8 +159,9 @@ int main(int argc, char **argv)
                                }
 
                                float mu = ratings[pl1] - ratings[pl2];
+                               float stddev = sqrt(match_variance + ratings_variance[pl1] + ratings_variance[pl2]);
                                
-                               int score = lrintf(draw_gaussian(mu, match_stddev));
+                               int score = lrintf(draw_gaussian(mu, stddev));
                                scores[pl1][pl2] = score;
                                scores[pl2][pl1] = -score;
                        }