From: Steinar H. Gunderson Date: Mon, 19 Mar 2012 13:44:58 +0000 (+0100) Subject: When doing Monte Carlo, player strength should be constant within a simulated round. X-Git-Url: https://git.sesse.net/?p=wloh;a=commitdiff_plain;h=d76a4688b44cd0b1fcef71ea52d5a70bc9df3d00 When doing Monte Carlo, player strength should be constant within a simulated round. --- diff --git a/mcwordfeud.cpp b/mcwordfeud.cpp index b48936d..ce9dc5f 100644 --- a/mcwordfeud.cpp +++ b/mcwordfeud.cpp @@ -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 players; map 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; }