summaryrefslogtreecommitdiff
path: root/server/wall.cpp
blob: b19d81aa82889012c27f9c5f7bc0e3084140c6e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "wall.h"

#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
#include <ctime>

#include <iostream>

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;
	}
}

Tile Wall::take_one() {
	
	boost::uniform_int<> range( 0, num_tiles - 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--;
	
	return to_return;
}