diff options
Diffstat (limited to 'server/player.cpp')
-rw-r--r-- | server/player.cpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/server/player.cpp b/server/player.cpp index 8397c48..7e890fb 100644 --- a/server/player.cpp +++ b/server/player.cpp @@ -7,6 +7,7 @@ void Game::Player::round_start(int w) { hand.clear(); open.clear(); pond.clear(); + tenpai_indexes.clear(); riichi = false; score = 25000; wind = w; @@ -54,8 +55,15 @@ Actions Game::Player::get_actions_draw() { } } else { - // Only tile that can be discarded is the last drawn one. - possible_actions.push_back(Action(Action::Discard, Action::Hand, hand.size() - 1)); + if(tenpai_indexes) { + for(List<int>::iterator it = tenpai_indexes.begin(); it != tenpai_indexes.end(); it++) { + possible_actions.push_back(Action(Action::Discard, Action::Hand, *it)); + } + tenpai_indexes.clear(); + } else { + // Only tile that can be discarded is the last drawn one. + possible_actions.push_back(Action(Action::Discard, Action::Hand, hand.size() - 1)); + } } return possible_actions; @@ -105,26 +113,18 @@ bool Game::Player::can_riichi() { return false; } - Tiles tiles = hand; - - tiles.sort(); - - // Take first tile out of the set. - Tile out = tiles.front(); - tiles.erase(tiles.begin()); - - // Iterate over the rest of the set, exchanging the tile until a tenpai is found or all is tested. - for(Tiles::iterator it = tiles.begin(); it != tiles.end(); it++) { + // Iterate over the hand, testing to remove each tile and see if it gives tenpai. + for(Tiles::iterator it = hand.begin(); it != hand.end(); it++) { + Tiles tiles = hand; + tiles.del(it - hand.begin()); + tiles.sort(); + if(Hand::tenpai(tiles)) { - return true; + tenpai_indexes.push_back(it - hand.begin()); } - - // TODO: Skip unnecessary tests if player got several equal tiles on hand. - - std::swap(*it, out); } - return false; + return bool(tenpai_indexes); } Game::Player::Targets Game::Player::can_chi(Tile tile) { @@ -225,6 +225,10 @@ Tile Game::Player::claim() { return t; } +void Game::Player::declare_riichi() { + riichi = true; +} + void Game::Player::make_chi(Tile tile, int target) { Tiles chi; |