-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcombination.py
32 lines (24 loc) · 1.04 KB
/
combination.py
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
"""Transform combinations."""
from typing import Tuple
import utils as ut
def combination_to_fcombination(combination: Tuple[str, ...]) -> Tuple[int, ...]:
"""Convert a combination to a fcombination."""
fcombination = []
# Add the non-5 tiles
for tile in combination:
if tile != '5g':
fcombination.append(ut.TILES.index(tile))
# Add the 5 tiles
if combination.count('5g') == 1:
fcombination.append(10)
elif combination.count('5g') == 2:
fcombination.extend([10, 11])
return tuple(sorted(fcombination))
def fcombination_to_numbers(fcombination: Tuple[int, ...]) -> Tuple[int, ...]:
"""Return the ranks of the ftiles of a fcombination."""
return tuple(ftile//2 for ftile in fcombination)
def fcombination_to_colors(fcombination: Tuple[int, ...]) -> Tuple[str, ...]:
"""Return the colors of the ftiles of a fcombination."""
return tuple('b' if ftile in ut.BLACK_FTILES else
'w' if ftile in ut.WHITE_FTILES else
'g' for ftile in fcombination)