-
Notifications
You must be signed in to change notification settings - Fork 19
/
HonitsuResolver.java
54 lines (42 loc) · 1.28 KB
/
HonitsuResolver.java
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
package org.mahjong4j.yaku.normals;
import org.mahjong4j.hands.Mentsu;
import org.mahjong4j.hands.MentsuComp;
import org.mahjong4j.tile.TileType;
import java.util.List;
import static org.mahjong4j.yaku.normals.NormalYaku.HONITSU;
/**
* 混一色判定クラス
* 萬子、索子、筒子のどれか一種と、字牌のみで構成される場合成立
*
* @author yu1ro
*/
public class HonitsuResolver implements NormalYakuResolver {
private final NormalYaku yakuEnum = HONITSU;
private List<Mentsu> allMentsu;
private boolean hasJihai = false;
private TileType type = null;
public HonitsuResolver(MentsuComp comp) {
allMentsu = comp.getAllMentsu();
}
public NormalYaku getNormalYaku() {
return yakuEnum;
}
public boolean isMatch() {
for (Mentsu mentsu : allMentsu) {
if (!hasOnlyOneType(mentsu)) {
return false;
}
}
return hasJihai;
}
private boolean hasOnlyOneType(Mentsu mentsu) {
if (mentsu.getTile().getNumber() == 0) {
hasJihai = true;
} else if (type == null) {
type = mentsu.getTile().getType();
} else if (type != mentsu.getTile().getType()) {
return false;
}
return true;
}
}