summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/game.cpp127
-rw-r--r--server/game.h7
2 files changed, 130 insertions, 4 deletions
diff --git a/server/game.cpp b/server/game.cpp
index ab61a7d..76ee99d 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -135,7 +135,7 @@ void Game::round_update_discard() {
Actions a;
if(player != current_player) {
- if(a = players[player].get_actions_discard(discarded_tile, current_player + player)) {
+ if(a = players[player].get_actions_discard(discarded_tile, current_player - player)) {
possible_actions[player] = a;
}
}
@@ -230,9 +230,24 @@ void Game::handle_action_discard(Action action, int player) {
round_update_draw();
} break;
- case Action::Chi:
- case Action::Kan:
- case Action::Pon:
+ case Action::Chi: {
+ players[preceding_action_owner].make_chi(players[current_player].claim(), preceding_action.target_offset);
+ current_player = preceding_action_owner;
+ round_update_draw();
+ } break;
+
+ case Action::Pon: {
+ players[preceding_action_owner].make_pon(players[current_player].claim(), preceding_action.target_offset - 1, current_player - preceding_action_owner);
+ current_player = preceding_action_owner;
+ round_update_draw();
+ } break;
+
+ case Action::Kan: {
+ players[preceding_action_owner].make_kan(players[current_player].claim(), preceding_action.target_offset - 2, current_player - preceding_action_owner);
+ current_player = preceding_action_owner;
+ round_update_draw();
+ } break;
+
case Action::Ron:
// Not implemented yet.
std::cout << "Hei, morn, god dag!" << std::endl;
@@ -421,3 +436,107 @@ void Game::Player::discard(int target) {
Tile Game::Player::last_discard() {
return pond.back();
}
+
+Tile Game::Player::claim() {
+ Tile& t = pond.back();
+ t.invisible = true;
+ return t;
+}
+
+void Game::Player::make_chi(Tile tile, int target) {
+ Tiles chi;
+
+ tile.rotated = true;
+ chi.push_back(tile);
+
+ Tile::Set set = tile.get_set();
+ int num = tile.get_num();
+
+ Tiles::iterator it = hand.begin();
+
+ switch(hand[target].get_num() - num) {
+ case -2:
+ it = std::find(it, hand.end(), Tile(set, num - 2));
+ chi.push_back(*it);
+ it = hand.erase(it);
+
+ case -1:
+ it = std::find(it, hand.end(), Tile(set, num - 1));
+ chi.push_back(*it);
+ it = hand.erase(it);
+
+ case 1:
+ if(chi.size() == 3) {
+ break;
+ }
+
+ it = std::find(it, hand.end(), Tile(set, num + 1));
+ chi.push_back(*it);
+ it = hand.erase(it);
+
+ if(chi.size() == 3) {
+ break;
+ }
+
+ it = std::find(it, hand.end(), Tile(set, num + 2));
+ chi.push_back(*it);
+ hand.erase(it);
+ }
+
+ open.push_back(chi);
+}
+
+void Game::Player::make_pon(Tile tile, int target, PlayerNum discarder) {
+ Tiles pon;
+
+ tile.rotated = true;
+
+ if(discarder == 3) {
+ pon.push_back(tile);
+ }
+
+ pon.push_back(hand[target]);
+ hand.del(target);
+
+ if(discarder == 2) {
+ pon.push_back(tile);
+ }
+
+ pon.push_back(hand[target]);
+ hand.del(target);
+
+ if(discarder == 1) {
+ pon.push_back(tile);
+ }
+
+ open.push_back(pon);
+}
+
+void Game::Player::make_kan(Tile tile, int target, PlayerNum discarder) {
+ Tiles kan;
+
+ tile.rotated = true;
+
+ if(discarder == 3) {
+ kan.push_back(tile);
+ }
+
+ kan.push_back(hand[target]);
+ hand.del(target);
+
+ if(discarder == 2) {
+ kan.push_back(tile);
+ }
+
+ kan.push_back(hand[target]);
+ hand.del(target);
+
+ kan.push_back(hand[target]);
+ hand.del(target);
+
+ if(discarder == 1) {
+ kan.push_back(tile);
+ }
+
+ open.push_back(kan);
+} \ No newline at end of file
diff --git a/server/game.h b/server/game.h
index 77a9053..a39b44a 100644
--- a/server/game.h
+++ b/server/game.h
@@ -74,7 +74,14 @@ class Game : public boost::enable_shared_from_this<Game> {
//! Claim last discard from pond.
Tile claim();
+ //! Make chi from tile.
+ void make_chi(Tile tile, int target);
+ //! Make pon from tile.
+ void make_pon(Tile tile, int target, PlayerNum discarder);
+
+ //! Make open kan from tile.
+ void make_kan(Tile tile, int target, PlayerNum discarder);
};
Player players[4];