summaryrefslogtreecommitdiff
path: root/common/tile.cpp
blob: 4b1f8b524b4c2067330798f0229151f0e7d3dcaa (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
#include "tile.h"

#include <algorithm>

Tile::Tile(Tile::Type t, bool re) : type(t), red(re), rotated(false), invisible(false) {
	
}

Tile::Tile(Set s, int num, bool re) : red(re), rotated(false), invisible(false) {
	switch(s) {
		case Man:
			type = Type(Man_1 + num - 1);
			break;
		case Pin:
			type = Type(Pin_1 + num - 1);
			break;
		case Sou:
			type = Type(Sou_1 + num - 1);
			break;
		default:
			// Invalid.
			break;
	}
}

int Tile::get_num() const {
	if(type >= Man_1 && type <= Sou_9) {
		return (type - Man_1) % 9 + 1;
	} else {
		return 0;
	}
}

Tile::Set Tile::get_set() const {
	if(type >= Man_1 && type <= Man_9) {
		return Man;
	} else if(type >= Pin_1 && type <= Pin_9) {
		return Pin;
	} else if(type >= Sou_1 && type <= Sou_9) {
		return Sou;
	} else {
		return Honor;
	}
}

bool Tile::is_simple() const {
	int n = get_num();
	return n > 1 && n < 9;
}

bool Tile::operator==(const Tile& other) const {
	return type == other.type;
}

bool Tile::operator<(const Tile& other) const {
	return type == other.type ? red : type < other.type;
}

Tile Tile::operator++(int) {
	type = Type(type + 1);
	return *this;
}