diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-11-25 02:24:00 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-11-25 02:33:15 +0100 |
commit | d5aae396856ee801eb2e2420b786fda2f13cf391 (patch) | |
tree | 4799975814dfce34cea815716df9ed3dd2b7d0ac /server/wall.cpp | |
parent | a56f67de16faaeb730375814faa22d406eaca19b (diff) |
Changed parts of the Wall API to make it reusable. Simplified the building.
Diffstat (limited to 'server/wall.cpp')
-rw-r--r-- | server/wall.cpp | 62 |
1 files changed, 17 insertions, 45 deletions
diff --git a/server/wall.cpp b/server/wall.cpp index b19d81a..1c9ec04 100644 --- a/server/wall.cpp +++ b/server/wall.cpp @@ -6,63 +6,35 @@ #include <iostream> -Wall::Wall() : rand_gen( std::time(0) ) { +Wall::Wall() : rand_gen(std::time(0)) { - // The wall consists of 136 tiles in Riichi mahjong - num_tiles = 136; - - - // Awesome algorithm that loops trough a enum and creates a wall with 4 tiles of each type (and 1 red for each 5-tile( - for( Tile::Type current = Tile::Man_1; current <= Tile::Hatsu; current = Tile::Type( current + 1 )) { - - if(current == Tile::Man_5 || current == Tile::Pin_5 || current == Tile::Sou_5) { - - Tile tile1(current, true, false); - m_wall.push_back(tile1); - - } else { - - Tile tile1(current, false, false); - m_wall.push_back(tile1); - - } - - - Tile tile2(current, false, false); - Tile tile3(current, false, false); - Tile tile4(current, false, false); - - m_wall.push_back(tile2); - m_wall.push_back(tile3); - m_wall.push_back(tile4); - - #ifdef DEBUG - std::cout << "Added 4: " << tile2.type << std::endl; - #endif - } - } -bool Wall::is_done() { - if (num_tiles <= 14) { - return true; - } else { - return false; +void Wall::build() { + // Clear any previous wall. + wall.clear(); + + for(Tile tile = Tile::Man_1; tile.type <= Tile::Hatsu; tile++) { + wall.push_back(Tile(tile.type, tile.get_num() == 5)); // Insert a copy of the current tile, and make it red if it is 5. + wall.push_back(tile); + wall.push_back(tile); + wall.push_back(tile); } } +int Wall::remaining() { + return wall.size(); +} + Tile Wall::take_one() { - - boost::uniform_int<> range( 0, num_tiles - 1 ); + boost::uniform_int<> range(0, wall.size() - 1); boost::variate_generator<boost::mt19937&, boost::uniform_int<> > die(rand_gen, range); int num = die(); - Tile to_return = m_wall[num]; - m_wall.erase( m_wall.begin() + num); - - num_tiles--; + Tile to_return = wall[num]; + wall.erase(wall.begin() + num); return to_return; } |