Play Chinese MahJong , Win the Game, Get the Money!
Description:
BackGround
If you've ever been to China, you may have noticed that local people, especially the elderly, like to play a special game called MahJong, and sometimes people bet on it.
When the game starts, people are supposed to take turns rearranging their "cards" (in fact, they look like tiles rather than cards), and if one's tiles fit the winning pattern, then one wins, or "hoos" (胡了, hú le ).
Tiles
There are 34 kinds of tiles in total:.
English:
1 million, 2 million, 3 million, ... 9 million
sparrow, 2 worms, 3 worms, ... 9 worms (also bamboo)
(1 worm is replaced by sparrow)1 pancake, 2 pancakes, 3 pancakes, ... 9 pancakes (also circle)
Cardinal tiles : east, south, west, north
Honor tiles:middle, rich, blank.
you can also called "middle, rich and blank" as "Red Dragon, Green Dragon and White Dragon"Chinese:
1万,2万,3万,... 9万
鸟,2条,3条, ... 9条 (也叫索)
(没有1条,换成了鸟)1饼,2饼,3饼,... 9饼 (也叫筒)
东 西 南 北 中 发 白
Groups:
Straight, 顺子: Three of the continous tiles.
example: 4 pancakes, 5 pancakes, 6 pancakes. Obviously, honor tiles and cardinal tiles can't make up a Straight.Triplet, 刻子: three of the same tiles
example: rich, rich, rich.Pair, 眼: two of the same tiles
example: middle, middleTask:
write a function, check if certain pattern fits winning pattern.
A winning pattern should have 14 tiles.
normal winning pattern :
the number of triplets and the number of straight should add up to FOUR, and remaining two tiles should be a pair.
examples:
(sparrow, 2 worms, 3 worms), (east, east, east), (south, south, south), (1 pancake, 2 pancakes, 3 pancakes), (rich, rich)
2 straights, 2 triplets, 1 pair.
(鸟,2条,3条),(7条,8条,9条),(4条,5条,6条),(1饼,2饼,3饼),(东,东)
(sparrow, 2 worms, 3 worms), (7 worms, 8 worms, 9 worms), (4 worms, 5 worms, 6 worms), (1 pancake, 2 pancakes, 3 pancakes), (east, east)
there's no need to have trplets and straight at same time.
鸟,东,东,2条,3条,南,1饼,2饼,东,南,南,3饼,发,发
sparrow, east, east, 2 worms, 3 worms, east, 2 pancakes, south, south, south, 3 pancakes, rich, rich, 1 pancake
If you rearange the set above, you can find that it's the same as first one. Your function should pass this pattern.
unusual winning pattern - seven pairs, 七对子
example:
east,east,south,south,north,north,1 million,1 million,7 pancakes,7 pancakes,sparrow,sparrow,east,east
unusual winning pattern - independence, 全不靠
Each tile is belong to {east,south,west,north,middle,rich, blank} and (1,4,7)(million), (2,5,8)(pancakes), (3,6,9)(worm)
THE MILLION,PANCAKES,AND WORM IN PARENTHESES ABOVE ARE INTERCHANGABLE!
example:
sparrow and 4 worms,2,5,8 pancakes,3,6,9 million,east,south,north,middle,rich,blank
unusual winning pattern - thirteen orphans, 十三幺
east,south,north,west,middle,rich,blank,1 million,9 million,1 pancakes,9 pancakes,sparrow,9 worms,random tiles above.
example:
east,south,west,north,middle,rich,blank,1 million,9 million,1 pancake,9 pancakes,sparrow,9 worms,(blank, random above)
The function receives a string and returns a boolean, to check if the tiles fit the winning pattern.
All test points will be in Chinese. If you think Chinese chracters are difficult to type, I preload some characters for you.
Preloaded
million = ['1万', ...... '9万']
pancake = ['1饼', ...... '9饼']
worm = ['鸟', '2条', ...... '9条']
east, west, south, north = '东', '南', '西', '北'
middle, rich, blank = '中', '发', '白'
alll = [all tiles, a list]
alll: three 'l's , to avoid overwriting the built-in function 'all'
coordinate = ['东','南','西','北']
unit = ['万','饼','条']
honor = ['中','发','白']
thirteen = ['东','南','西','北','中','发','白','1万','9万','1饼','9饼','1条','9条']
Notice
PLEASE RATE AND RANK THE KATA IF YOU SOLVED IT, TO HELP IT GET OUT OF BETA. THANKS!
Translations are welcome!
Similar Kata:
Stats:
Created | Aug 23, 2022 |
Published | Aug 24, 2022 |
Warriors Trained | 122 |
Total Skips | 76 |
Total Code Submissions | 67 |
Total Times Completed | 8 |
Python Completions | 8 |
Total Stars | 4 |
% of votes with a positive feedback rating | 100% of 3 |
Total "Very Satisfied" Votes | 3 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 3 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |