From 83f8b8ab849b855fa87323ee1155dfd84d5596f6 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 5 Dec 2010 06:59:23 +0100 Subject: Test for concealed and extended kans. --- server/game.h | 5 ++++- server/player.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) (limited to 'server') 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 { //! 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) { -- cgit v1.2.3