mega-yadoran / tempai

tempai.vercel.app
1 stars 0 forks source link

Query Regarding Tempai Hand Generation and Identification of Winning Hands #2

Open ZhouLixuanwu opened 1 year ago

ZhouLixuanwu commented 1 year ago

Hello Yado,

Firstly, I'd like to express my appreciation for the amazing work you've done with the Tempai practice tool. It has been an invaluable resource for me and many others in the Mahjong community.

I'm particularly curious about the algorithm or methodology you've used behind the scenes:

  1. Tempai Hand Generation: How have you managed to generate a Tempai hand consistently? Is there a specific logic or pattern that ensures that the hand generated is always in a Tempai state?

  2. Winning Hand Identification: Once a Tempai hand is generated, how does the tool determine which tile completes the hand, making it a winning hand? Is there an efficient algorithm in place that identifies the winning tile(s)?

Understanding the logic behind these features would not only satiate my curiosity but also potentially help in advancing the tool further and contributing to it. I would like to craft an iOS app for a similar purpose. However, I don't have too much experience in Vue2, Nuxt2, and TypeScript, I found it hard to understand the code, so I hope you could share some ideas or materials that you found helpful during your development of this web App.

Thank you for taking the time to read this, and I'm eagerly looking forward to your response. And once again, great job on the tool!

Best regards, Xavier

mega-yadoran commented 11 months ago

@ZhouLixuanwu Hi, Lixuanwu. Thank you for getting in touch! And I apologize for the late response.

First of all, as a premise, this application actually does not generate hands in Tempai or determine winning tiles. The list of Tempai hands and the corresponding winning tiles are compiled in the following files: https://github.com/mega-yadoran/tempai/blob/master/plugins/question.ts (The file size is large, and it might crash your browser, so it might be better to download it and check locally.) Tempai hands: questions Winning tiles: answers

For example, if the arrangement of the Tempai hand is as follows:

question[0] = [1,2,2,2,2,3,3,3,3,4,4,4,4]

Then the corresponding answer, which means what tiles are needed to win, would be:

answer[0] = [1,5]

This means, if the hand arrangement is 1,2,2,2,2,3,3,3,3,4,4,4,4 , winning can be achieved with either a 1 or a 5 .

As for how I created such data, I used a Python library related to Mahjong. https://pypi.org/project/mahjong/

This library allows for the calculation of points and Shanten numbers. Using these features and Python, I created the data in question.ts by enumerating all possible combinations.

I hope this information is helpful!