elo

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 4608f67a7c24ce9df226f10464043a21021bcd54
Author: Joakim <joakim@jnisse.xyz>
Date:   Sat, 13 Apr 2024 01:27:20 +0200

Initial Commit, supports rating change for given k-factor for one game.

Diffstat:
Aelo.c | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+), 0 deletions(-)

diff --git a/elo.c b/elo.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +int roof(int *x){ +if (*x<-400) return -400; +else if (*x>400) return 400; +return *x; +} +int main(int argc, char **argv) + +{ + int c; + int myelo,opprating; + int kfactor = 20; + int diff; + float res; + char *mopt=0, *eopt=0,*ropt=0, *kopt=0; + while ((c= getopt(argc,argv,"m:e:r:k:")) != -1) { + + switch (c) { + case 'm': + mopt=optarg; + break; + case 'r': + ropt=optarg; + break; + case 'e': + eopt=optarg; + break; + case 'k': + kopt=optarg; + kfactor= strtol(kopt,NULL,10); + break; + default: + printf("%s\n", "Ajabaja" ); + } + } + myelo= strtol(eopt,NULL,10); + opprating= strtol(mopt,NULL,10); + res = strtof(ropt,NULL); + diff = myelo - opprating; + diff = roof(&diff); + const int caps[41] = {7,14,21,29,36,43,50,57,65,72,80,87,95,102,110,117,125,133,141,149,158,166,175,184,193,202,211,220,230,240,251,262,273,284,296,309,322,336,351,366,383}; + int offset=0; + int p=50; + if (diff < 0) { + offset =100; + diff = -diff; + } + for (int i=0;i<41;++i) { + if (diff >= caps[i]) + {p++;} + + } + p++; + if (offset){ p = offset -p;} + printf("%3.2f\n", (float)kfactor*(100*res-p)/100); + exit(0); +}