summaryrefslogtreecommitdiff
path: root/server/wall.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'server/wall.cpp')
-rw-r--r--server/wall.cpp62
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;
}