summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/player.cpp59
-rw-r--r--server/player.h5
2 files changed, 53 insertions, 11 deletions
diff --git a/server/player.cpp b/server/player.cpp
index 5b6fc83..d87f8e8 100644
--- a/server/player.cpp
+++ b/server/player.cpp
@@ -440,9 +440,12 @@ void Player::declare_ron(Tile tile) {
Sets hand = hands.front();
hand.insert(hand.end(), open.begin(), open.end());
- Score score = calculate_score(hand, false);
+ List<std::pair<std::string, int> > han;
+
+ Score score = calculate_score(hand, han, false);
won = true;
+ won_han = han;
won_value = score;
}
@@ -455,13 +458,16 @@ void Player::declare_tsumo() {
Sets hand = hands.front();
hand.insert(hand.end(), open.begin(), open.end());
- Score score = calculate_score(hand, true);
+ List<std::pair<std::string, int> > han;
+
+ Score score = calculate_score(hand, han, true);
won = true;
+ won_han = han;
won_value = score;
}
-Score Player::calculate_score(const Sets& hand, bool tsumo) {
+Score Player::calculate_score(const Sets& hand, List<std::pair<std::string, int> >& han, bool tsumo) {
Tiles yakuhai = list_of(Tile::Chun)(Tile::Hatsu)(Tile::Haku); // TODO: Add seat and prevalent wind.
Tiles dora; // TODO: Fill this.
Tiles uradora; // TODO: Fill this.
@@ -471,22 +477,27 @@ Score Player::calculate_score(const Sets& hand, bool tsumo) {
// Check riichi.
if(riichi) {
score.yaku += 1;
+ han.push_back(std::make_pair("Riichi", 1));
// TODO: Check ippatsu.
}
// Check menzen tsumo.
if(tsumo && !open) {
score.yaku += 1;
+ han.push_back(std::make_pair("Menzen tsumo", 1));
}
bool possible_tanyao = true;
bool possible_toitoi = true;
+ int dora_n = 0;
+ int uradora_n = 0;
+ int akadora_n = 0;
for(Sets::const_iterator set = hand.begin(); set != hand.end(); set++) {
switch(set->type) {
case Set::Pair:
// Check for pair-related fu.
- score.fu += yakuhai.count(set->tiles.front());
+ score.fu += 2 * yakuhai.count(set->tiles.front());
break;
@@ -501,7 +512,10 @@ Score Player::calculate_score(const Sets& hand, bool tsumo) {
score.fu += 2 << (!set->open + !set->tiles.front().is_simple() + 2 * (set->type == Set::Kan));
// Check yakuhai.
- score.yaku += yakuhai.count(set->tiles.front());
+ if(int yakuhai_n = yakuhai.count(set->tiles.front())) {
+ score.yaku += yakuhai_n;
+ han.push_back(std::make_pair("Yakuhai", yakuhai_n)); // TODO: Specify which tile.
+ }
break;
}
@@ -513,14 +527,14 @@ Score Player::calculate_score(const Sets& hand, bool tsumo) {
}
// Check dora.
- score.dora += dora.count(*tile);
+ dora_n += dora.count(*tile);
// Check uradora.
- score.dora += uradora.count(*tile);
+ uradora_n += uradora.count(*tile);
// Check akadora.
if(tile->red) {
- score.dora += 1;
+ akadora_n += 1;
}
}
}
@@ -536,8 +550,15 @@ Score Player::calculate_score(const Sets& hand, bool tsumo) {
}
// Check pinfu.
- if(score.fu == 20 && !open) {
- score.yaku += 1;
+ if(score.fu == 20) {
+ if(open) {
+ score.fu += 2;
+ } else {
+ score.yaku += 1;
+ han.push_back(std::make_pair("Pinfu", 1));
+ }
+ } else if(tsumo) {
+ score.fu += 2;
}
// Check fu for ron.
@@ -546,5 +567,23 @@ Score Player::calculate_score(const Sets& hand, bool tsumo) {
score.fu += 10;
}
+ // Check dora.
+ if(dora_n) {
+ score.dora += dora_n;
+ han.push_back(std::make_pair("Dora", dora_n));
+ }
+
+ // Check uradora.
+ if(uradora_n) {
+ score.dora += uradora_n;
+ han.push_back(std::make_pair("Uradora", uradora_n));
+ }
+
+ // Check akadora.
+ if(akadora_n) {
+ score.dora += akadora_n;
+ han.push_back(std::make_pair("Akadora", akadora_n));
+ }
+
return score;
}
diff --git a/server/player.h b/server/player.h
index d5ca4e6..a4b3416 100644
--- a/server/player.h
+++ b/server/player.h
@@ -28,6 +28,9 @@ class Player {
//! Player has won.
bool won;
+ //! List of han in winning hand.
+ List<std::pair<std::string, int> > won_han;
+
//! Value of winning hand.
Score won_value;
@@ -109,7 +112,7 @@ class Player {
void declare_tsumo();
//! Calculate score for winning hand combination.
- Score calculate_score(const Sets& hand, bool tsumo);
+ Score calculate_score(const Sets& hand, List<std::pair<std::string, int> >& han, bool tsumo);
};
#endif