diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-12-05 06:59:23 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-12-05 06:59:48 +0100 |
commit | 83f8b8ab849b855fa87323ee1155dfd84d5596f6 (patch) | |
tree | e30a867e49b80311b198a3546956124b8c1fa1c7 /server | |
parent | 9cc4a3ca144332166c8b63f95c85ac6395698237 (diff) |
Test for concealed and extended kans.
Diffstat (limited to 'server')
-rw-r--r-- | server/game.h | 5 | ||||
-rw-r--r-- | server/player.cpp | 42 |
2 files changed, 42 insertions, 5 deletions
diff --git a/server/game.h b/server/game.h index f8d9ff4..bf7d37f 100644 --- a/server/game.h +++ b/server/game.h @@ -63,9 +63,12 @@ class Game : public boost::enable_shared_from_this<Game> { //! Check if tile can be called for a pon. int can_pon(Tile tile); - //! Check if it's possible to make a concealed kan or extend an open kan. + //! Check if it's possible to make a concealed kan. Targets can_kan(); + //! Check if it's possible to extend a pon to a kan. + Targets can_kan_extend(); + //! Check if tile can be called to kan target. bool can_kan(Tile tile, int target); diff --git a/server/player.cpp b/server/player.cpp index b6776df..ae07360 100644 --- a/server/player.cpp +++ b/server/player.cpp @@ -36,12 +36,24 @@ Actions Game::Player::get_actions_draw() { Actions possible_actions; // Check if player can force a draw. + // TODO: Implementation. (Low priority) + // Check if player can tsumo. if(can_tsumo()) { possible_actions.push_back(Action(Action::Tsumo)); } - // Check if player can declare a concealed kan or extend an open pon. List all possibilities. + // Check if player can declare a concealed kan. + Targets targets = can_kan(); + for(Targets::iterator it = targets.begin(); it != targets.end(); it++) { + possible_actions.push_back(Action(Action::Kan, Action::Index, *it + 2)); + } + + // Check if player can extend an open pon. + targets = can_kan_extend(); + for(Targets::iterator it = targets.begin(); it != targets.end(); it++) { + possible_actions.push_back(Action(Action::Kan, Action::Group, *it)); + } if(!riichi) { // Check if player can riichi. @@ -51,6 +63,11 @@ Actions Game::Player::get_actions_draw() { // List all tiles that can be discarded. for(std::size_t i = 0; i < hand.size(); i++) { + // Skip tiles already used to call kan. + if(possible_actions.contains(Action(Action::Kan, Action::Index, i))) { + continue; + } + possible_actions.push_back(Action(Action::Discard, Action::Index, i)); } @@ -180,9 +197,26 @@ int Game::Player::can_pon(Tile tile) { return -1; } -//Game::Player::Targets Game::Player::can_kan() { -// return Targets(); // TODO -//} +Game::Player::Targets Game::Player::can_kan() { + Targets targets; + + for(Tiles::iterator it = hand.begin(); it != hand.end(); it++) { + Tiles::iterator it_s = it; + int i = 1; + do { + it_s = std::find(it_s + 1, hand.end(), *it); + } while(it_s != hand.end() && i++); + if(i >= 4) { + targets.push_back(it - hand.begin()); + } + } + + return targets; +} + +Game::Player::Targets Game::Player::can_kan_extend() { + return Targets(); // TODO: Waiting for sets. +} bool Game::Player::can_kan(Tile tile, int target) { if(std::size_t(target + 2) < hand.size() && hand[target + 2] == tile) { |