summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/game.cpp13
-rw-r--r--server/game.h6
-rw-r--r--server/player.cpp42
3 files changed, 60 insertions, 1 deletions
diff --git a/server/game.cpp b/server/game.cpp
index c8950ce..565468b 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -200,7 +200,18 @@ void Game::handle_action_draw(Action action) {
round_update_draw();
} break;
- case Action::Kan:
+ case Action::Kan: {
+ if(action.target_type == Action::Index) {
+ players[current_player].make_kan(action.target_offset - 2);
+ dora.push_back(wall.take_one());
+ } else {
+ players[current_player].make_kan_extend(action.target_offset);
+ kan_dora_pending = true;
+ }
+ players[current_player].draw(wall.take_one());
+ round_update_draw();
+ } break;
+
case Action::Draw:
// Not implemented yet.
diff --git a/server/game.h b/server/game.h
index fca71fa..c8c5d6a 100644
--- a/server/game.h
+++ b/server/game.h
@@ -102,6 +102,12 @@ class Game : public boost::enable_shared_from_this<Game> {
//! Make open kan from tile.
void make_kan(Tile tile, int target, PlayerNum discarder);
+
+ //! Make concealed kan.
+ void make_kan(int target);
+
+ //! Make extended kan.
+ void make_kan_extend(int target);
};
Player players[4];
diff --git a/server/player.cpp b/server/player.cpp
index 2454a98..0c30608 100644
--- a/server/player.cpp
+++ b/server/player.cpp
@@ -379,3 +379,45 @@ void Game::Player::make_kan(Tile tile, int target, PlayerNum discarder) {
open.push_back(Set(Set::Kan, kan, true));
}
+
+void Game::Player::make_kan(int target) {
+ Tiles kan;
+
+ Tiles::iterator it = hand.begin() + target;
+ Tile t = *it;
+ kan.push_back(Tile::Back);
+ it = hand.erase(it);
+
+ it = std::find(it, hand.end(), t);
+ kan.push_back(*it);
+ it = hand.erase(it);
+
+ it = std::find(it, hand.end(), t);
+ kan.push_back(*it);
+ it = hand.erase(it);
+
+ it = std::find(it, hand.end(), t);
+ kan.push_back(Tile::Back);
+ hand.erase(it);
+
+ open.push_back(Set(Set::Kan, kan, false));
+}
+
+void Game::Player::make_kan_extend(int target) {
+ Set& set = open[target - 1];
+
+ Tiles::iterator it = std::find(hand.begin(), hand.end(), set.tiles.front());
+ Tile t = *it;
+ hand.erase(it);
+
+ t.rotated = true;
+
+ for(it = set.tiles.begin(); it != set.tiles.end(); it++) {
+ if(it->rotated) {
+ set.tiles.insert(it + 1, t);
+ break;
+ }
+ }
+
+ set.type = Set::Kan;
+}