summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/score.cpp57
-rw-r--r--server/score.h28
2 files changed, 85 insertions, 0 deletions
diff --git a/server/score.cpp b/server/score.cpp
new file mode 100644
index 0000000..1af1d63
--- /dev/null
+++ b/server/score.cpp
@@ -0,0 +1,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);
+}
diff --git a/server/score.h b/server/score.h
new file mode 100644
index 0000000..7c5ca17
--- /dev/null
+++ b/server/score.h
@@ -0,0 +1,28 @@
+#ifndef SCORE_H
+#define SCORE_H
+
+class Score {
+ public:
+ int han;
+ int fu;
+
+ //! Constructor.
+ Score(int han_ = 0, int fu_ = 0);
+
+ //! Calculate base points.
+ int base_points();
+
+ //! Score paid upon ron. (4 BP)
+ int ron();
+
+ //! Score paid upon ron by east. (6 BP)
+ int ron_east();
+
+ //! Score paid by others upon tsumo by others. (BP)
+ int tsumo();
+
+ //! Score paid by east upon tsumo by others or others upon tsumo by east. (2 BP)
+ int tsumo_east();
+};
+
+#endif