summaryrefslogtreecommitdiff
path: root/server/score.cpp
blob: 1af1d63eca0fd0e025d849d39086fb79baa8f0c1 (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
#include "score.h"

inline int roundup(int value, int roundto) {
	return value % roundto ? value + roundto - value % roundto : value;
}

inline int max(int x, int y) {
	return x > y ? x : y;
}

Score::Score(int han_, int fu_) : han(han_), fu(fu_) {
	
}

int Score::base_points() {
	if(han < 5) {
		// Normal hand.
		return max(roundup(fu, 10) << (2 + han), 2000);
	
	} else if(han <= 5) {
		// Mangan.
		return 2000;
	
	} else if(han <= 7) {
		// Haneman.
		return 3000;
	
	} else if(han <= 10) {
		// Baiman.
		return 4000;
	
	} else if(han <= 12) {
		// Sanbaiman.
		return 6000;
	
	} else {
		// Kazoe yakuman.
		return 8000;
	
	}
}

int Score::ron() {
	return roundup(base_points() * 4, 100);
}

int Score::ron_east() {
	return roundup(base_points() * 6, 100);
}

int Score::tsumo() {
	return roundup(base_points(), 100);
}

int Score::tsumo_east() {
	return roundup(base_points() * 2, 100);
}