Fix crash on rated Gothic games
authorH.G. Muller <h.g.muller@hccnet.nl>
Fri, 12 Mar 2010 08:07:46 +0000 (09:07 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Fri, 12 Mar 2010 08:07:46 +0000 (09:07 +0100)
The new game types were not everywere mapped on rating types, leading to
a crash. Types KNIGHTMATE, CAPABLANCA and GOTHIC are for the time being
now all treated as WILD, in rating calculations. Eventually these should
all have their own rating type, but this requires an extension of the
rating database format.

lasker-2.2.3/src/gamedb.c
lasker-2.2.3/src/ratings.c

index 666b5ed..0d1223f 100644 (file)
@@ -1216,6 +1216,7 @@ static void write_g_out(int g, char *file, int maxlines, int isDraw,
     type[1] = 'b';
   } else if (game_globals.garray[g].type == TYPE_WILD ||
             game_globals.garray[g].type == TYPE_KNIGHTMATE ||
+            game_globals.garray[g].type == TYPE_CAPABLANCA ||
             game_globals.garray[g].type == TYPE_GOTHIC) {
     wr = player_globals.parray[wp].w_stats.rating;
     br = player_globals.parray[bp].w_stats.rating;
index 55eaa74..6a6f629 100644 (file)
@@ -102,7 +102,7 @@ static void rating_add(int rating, int type)
     }
     Ratings_B_StdDev = sqrt(Rb_S / Rb_count);
     Ratings_B_Average = Rb_total / (double) Rb_count;
-  } else if (type == TYPE_WILD) {      /* TYPE_WILD */
+  } else if (type == TYPE_WILD || type == TYPE_KNIGHTMATE || type == TYPE_GOTHIC || type == TYPE_CAPABLANCA) { /* TYPE_WILD */
     wHist[which] += 1;
     Rw_count++;
     Rw_total += rating;
@@ -186,7 +186,7 @@ static void rating_remove(int rating, int type)
       Ratings_B_StdDev = 0;
       Ratings_B_Average = 0;
     }
-  } else if (type == TYPE_WILD) {      /* TYPE_WILD */
+  } else if (type == TYPE_WILD || type == TYPE_KNIGHTMATE || type == TYPE_GOTHIC || type == TYPE_CAPABLANCA) { /* TYPE_WILD */
     wHist[which] = wHist[which] - 1;
     if (wHist[which] < 0)
       wHist[which] = 0;
@@ -466,6 +466,9 @@ static void GetCurrentStats (int p, int *r, double *s, int *new,
       p_stats = &pp->s_stats;
       break;
     case TYPE_WILD:
+    case TYPE_KNIGHTMATE:
+    case TYPE_CAPABLANCA:
+    case TYPE_GOTHIC:
       p_stats = &pp->w_stats;
       break;
     case TYPE_LIGHT:
@@ -549,7 +552,10 @@ int rating_update(int g, int link_game)
   } else if (game_globals.garray[g].type == TYPE_STAND) {
     w_stats = &player_globals.parray[game_globals.garray[g].white].s_stats;
     b_stats = &player_globals.parray[game_globals.garray[g].black].s_stats;
-  } else if (game_globals.garray[g].type == TYPE_WILD) {
+  } else if (game_globals.garray[g].type == TYPE_WILD
+          || game_globals.garray[g].type == TYPE_KNIGHTMATE
+          || game_globals.garray[g].type == TYPE_GOTHIC
+          || game_globals.garray[g].type == TYPE_CAPABLANCA) {
     w_stats = &player_globals.parray[game_globals.garray[g].white].w_stats;
     b_stats = &player_globals.parray[game_globals.garray[g].black].w_stats;
   } else if (game_globals.garray[g].type == TYPE_LIGHT) {
@@ -692,7 +698,10 @@ int rating_update(int g, int link_game)
   } else if (game_globals.garray[g].type == TYPE_BUGHOUSE) {
     Rbug_count++;
     Rbug_total += (w_stats->rating + b_stats->rating) / 2.0;
-  } else if (game_globals.garray[g].type == TYPE_WILD) {
+  } else if (game_globals.garray[g].type == TYPE_WILD
+          || game_globals.garray[g].type == TYPE_KNIGHTMATE
+          || game_globals.garray[g].type == TYPE_CAPABLANCA
+          || game_globals.garray[g].type == TYPE_GOTHIC) {
     Rw_count++;
     Rw_total += (w_stats->rating + b_stats->rating) / 2.0;
   }