]> git.sesse.net Git - wloh/commitdiff
When doing Monte Carlo, player strength should be constant within a simulated round.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 19 Mar 2012 13:44:58 +0000 (14:44 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 19 Mar 2012 13:44:58 +0000 (14:44 +0100)
mcwordfeud.cpp

index b48936d4a36c43a606fe57a95061a6e486bd9f89..ce9dc5fd482058895b2577817d1282d51e955e6f 100644 (file)
@@ -14,7 +14,7 @@ using namespace std;
 
 #define MAX_PLAYERS 16
 
-float match_variance = 70.0f * 70.0f;
+float match_stddev = 70.0f;
 
 struct player {
        int player_index;
@@ -67,15 +67,12 @@ 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");
@@ -90,7 +87,7 @@ int main(int argc, char **argv)
        vector<string> players;
        map<string, int> player_map;
        float ratings[MAX_PLAYERS];
-       float ratings_variance[MAX_PLAYERS];
+       float ratings_stddev[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) {
@@ -117,7 +114,7 @@ int main(int argc, char **argv)
                players.push_back(buf);
                player_map[buf] = i;
                ratings[i] = rating;
-               ratings_variance[i] = rating_stddev * rating_stddev;
+               ratings_stddev[i] = rating_stddev;
        }
 
        for ( ;; ) {
@@ -151,6 +148,12 @@ int main(int argc, char **argv)
        }
 
        for (int i = 0; i < trials; ++i) {
+               // draw true strength for all players
+               float drawn_ratings[MAX_PLAYERS];
+               for (int p = 0; p < num_players; ++p) {
+                       drawn_ratings[p] = draw_gaussian(ratings[p], ratings_stddev[p]);
+               }
+
                // draw the missing matches
                for (int pl1 = 0; pl1 < num_players; ++pl1) {
                        for (int pl2 = pl1 + 1; pl2 < num_players; ++pl2) {
@@ -158,10 +161,9 @@ int main(int argc, char **argv)
                                        continue;
                                }
 
-                               float mu = ratings[pl1] - ratings[pl2];
-                               float stddev = sqrt(match_variance + ratings_variance[pl1] + ratings_variance[pl2]);
+                               float mu = drawn_ratings[pl1] - drawn_ratings[pl2];
                                
-                               int score = lrintf(draw_gaussian(mu, stddev));
+                               int score = lrintf(draw_gaussian(mu, match_stddev));
                                scores[pl1][pl2] = score;
                                scores[pl2][pl1] = -score;
                        }