datamllab / rlcard

Reinforcement Learning / AI Bots in Card (Poker) Games - Blackjack, Leduc, Texas, DouDizhu, Mahjong, UNO.
http://www.rlcard.org
MIT License
2.85k stars 614 forks source link

Recommendations to Make Mahjong faster #211

Open jkterry1 opened 3 years ago

jkterry1 commented 3 years ago

Hey, the performance of Mahjong is becoming an issue for us, so we're starting to work on it ourselves. Do you have any recommendations on what we should be doing?

jkterry1 commented 3 years ago

In issue #91 you said you found some redundant logic

lhenry15 commented 3 years ago

Hi, The current bottleneck is actually on the "judger" class. Because in Mahjong, intensive judgement is needed to define the action space for the players in each round. Based on our evaluation, judging "chow" is now the most inefficient part. This redundant logic is actually due to the representation of the hand cards. Currently, we are using a string to represent each card, which make it super inefficient when calculating the possible sets in each player's hand. For example, the function "judge_chow" in judger.py, we need to first generate all possible "chow" cases based on one player's card, then we check if each case is consecutive to judge whether the player is able to "chow" in the next round. However, if the card representation can be changed to bag of cards (i.e., n dimensional vector where each dimension representing one kind of card and the value in each dimension representing the number of cards that a player is holding), then judging the "chow" will be simply checking if the card on the table is able to form consecutive non-zero indexes. This way, generating all possible "chow" will be no longer needed, also judging the "pong" and "hu" can also be simplified as well.