summaryrefslogtreecommitdiff
path: root/server/score.cpp
blob: 7d0dc417b1d0089eb690289744a3f14da1cd1a7d (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
#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 yaku_, int fu_, int dora_) : yaku(yaku_), fu(fu_), dora(dora_) {
	
}

int Score::han() {
	return yaku + dora;
}

int Score::fu_rounded() {
	return roundup(fu, 10);
}

int Score::base_points() {
	if(han() < 5) {
		// Normal hand.
		return max(fu_rounded() << (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);
}