blob: 5a05548d032c60471113c6ea400564f1c668c4a7 (
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
|
#include "tile.h"
#include <algorithm>
Tile::Tile() {
}
Tile::Tile(Tile::Type t, bool re, bool ro) : type(t), red(re), rotated(ro) {
}
Tile::Tile(Set s, int num, bool re, bool ro) : red(re), rotated(ro) {
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::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;
}
void Tiles::sort() {
std::sort(begin(), end());
}
|