aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/rating_conv.c
blob: 3f5a98ed762c7e7b0fe519a2148e918492e81694 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Ratings conversions by DAV */
/* GNU licensing applies */

#include "stdinclude.h"

#include "command.h"
#include "common.h"
#include "rating_conv.h"
#include "utils.h"

PRIVATE int
elo_to_uscf(int elo)
{
	return (elo + 100);
}

PRIVATE int
uscf_to_elo(int uscf)
{
	return (uscf - 100);
}

PRIVATE int
bcf_to_elo(int bcf)
{
	return (bcf * 8 + 600);
}

PRIVATE int
elo_to_bcf(int elo)
{
	return (elo - 600) / 8;
}

#if 0
PRIVATE int
uscf_to_bcf(int uscf)
{
	return (uscf - 700) / 8;
}
#endif

#if 0
PRIVATE int
bcf_to_uscf(int bcf)
{
	return (bcf * 8 + 700);
}
#endif

PRIVATE void
printgrades(int p, int elo, int uscf, int bcf)
{
	pprintf(p, "Grading conversion:\n");
	pprintf(p, "  ELO = %d, USCF = %d, BCF = %d\n", elo, uscf, bcf);
}

PUBLIC int
com_CONVERT_BCF(int p, param_list param)
{
	int	elo = bcf_to_elo(param[0].val.integer);
	int	uscf = elo_to_uscf(elo);

	printgrades(p, elo, uscf, param[0].val.integer);
	return COM_OK;
}

PUBLIC int
com_CONVERT_ELO(int p, param_list param)
{
	int	bcf = elo_to_bcf(param[0].val.integer);
	int	uscf = elo_to_uscf(param[0].val.integer);

	printgrades(p, param[0].val.integer, uscf, bcf);
	return COM_OK;
}

PUBLIC int
com_CONVERT_USCF(int p, param_list param)
{
	int	elo = uscf_to_elo(param[0].val.integer);
	int	bcf = elo_to_bcf(elo);

	printgrades(p, elo, param[0].val.integer, bcf);
	return COM_OK;
}