summaryrefslogtreecommitdiffstats
path: root/mbbsd/chc.c
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-02-24 03:51:17 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-02-24 03:51:17 +0800
commit3f3e1fffbfc6139dd8f734b84302548574e693bc (patch)
tree25a947ae898c8e7e92b15c5cb54a3caaa48ce2cb /mbbsd/chc.c
parentdcce445703588499ffcd2a3de2e1df2410deb6d9 (diff)
downloadpttbbs-3f3e1fffbfc6139dd8f734b84302548574e693bc.tar
pttbbs-3f3e1fffbfc6139dd8f734b84302548574e693bc.tar.gz
pttbbs-3f3e1fffbfc6139dd8f734b84302548574e693bc.tar.bz2
pttbbs-3f3e1fffbfc6139dd8f734b84302548574e693bc.tar.lz
pttbbs-3f3e1fffbfc6139dd8f734b84302548574e693bc.tar.xz
pttbbs-3f3e1fffbfc6139dd8f734b84302548574e693bc.tar.zst
pttbbs-3f3e1fffbfc6139dd8f734b84302548574e693bc.zip
avoid use math library (-lm).
sanity check for result of elo rating git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2528 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/chc.c')
-rw-r--r--mbbsd/chc.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/mbbsd/chc.c b/mbbsd/chc.c
index 8b74709d..8ce25f3f 100644
--- a/mbbsd/chc.c
+++ b/mbbsd/chc.c
@@ -1,7 +1,8 @@
/* $Id$ */
-#include <math.h>
#include "bbs.h"
+extern const double elo_exp_tab[1000];
+
enum Turn {
BLK,
RED
@@ -805,6 +806,14 @@ myplay(int s, chcusr_t *user1, chcusr_t *user2, board_t board, board_t tmpbrd)
return endgame;
}
+int round_to_int(double x)
+{
+ /* assume that double cast to int will drop fraction parts */
+ if(x>=0)
+ return (int)(x+0.5);
+ return (int)(x-0.5);
+}
+
/*
* ELO rating system
* see http://www.wordiq.com/definition/ELO_rating_system
@@ -814,6 +823,8 @@ count_chess_elo_rating(chcusr_t *user1, chcusr_t *user2, double myres)
{
double k;
double exp_res;
+ int diff;
+ int newrating;
if(user1->rating < 1800)
k = 30;
@@ -826,8 +837,19 @@ count_chess_elo_rating(chcusr_t *user1, chcusr_t *user2, double myres)
else
k = 10;
- exp_res = 1.0/(1.0 + pow(10.0, (user2->rating-user1->rating)/400.0));
- user1->rating += (int)floor(k*(myres-exp_res)+0.5);
+ //exp_res = 1.0/(1.0 + pow(10.0, (user2->rating-user1->rating)/400.0));
+ //user1->rating += (int)floor(k*(myres-exp_res)+0.5);
+ diff=(int)user2->rating-(int)user1->rating;
+ if(diff<=-1000 || diff>=1000)
+ exp_res=diff>0?0.0:1.0;
+ else if(diff>=0)
+ exp_res=elo_exp_tab[diff];
+ else
+ exp_res=1.0-elo_exp_tab[-diff];
+ newrating = (int)user1->rating + round_to_int(k*(myres-exp_res));
+ if(newrating > 3000) newrating = 3000;
+ if(newrating < 1) newrating = 1;
+ user1->rating = newrating;
}
static void