plugined-mahjong banner

plugined-mahjong

9 devlogs
53h 15m 16s

Try to create a high customizable mahjong system with micro-services, typescript, grpc.
current is tried to maintain riichi mahjong system as base and add capability to add more rules by plugins. (and plugin is built on js code in a sandbox)
Whi…

Try to create a high customizable mahjong system with micro-services, typescript, grpc.
current is tried to maintain riichi mahjong system as base and add capability to add more rules by plugins. (and plugin is built on js code in a sandbox)
Which allows you create a brand new game mode or customize yaku for your own game

Though current state only part of the system.
(I haven’t done all of them. only backend have progress)
Include game, plugin, part of api.
(Demo frontend is helped by AI)

This project uses AI

AI helps me to generate some note and dev guide.
Also ideas for this project and bug fixing, tests, readme.

Demo Repository

Loading README...

Pikacnu

Shipped this project!

At first, I thought microservices wouldn’t be that hard. I had already built some projects adapted to Kubernetes, so I wanted to explore this approach further.

However, it turned out to be much harder than I expected.

For example, I chose gRPC as the backend service protocol. That meant learning a lot of new things, and it doesn’t integrate smoothly with TypeScript types. The types are not fully compatible, so you often need to write converters. Also, I can’t directly reuse JSON, which is used across the whole project, because I’m still unsure whether gRPC should be the primary data format or not.

On top of that, the types generated by gRPC come with many limitations, and there aren’t many resources available for TypeScript developers. There are also challenges like connection management, version control, and more.

The hardest part is designing the plugin system. I’ve discussed it many times with friends and AI. This version isn’t the best, but I still can’t come up with a better solution. The current strategy is mostly provided by AI, since almost none of my real-life friends are into programming.

I’ll keep working on it until it’s complete. This might be the last project I do in high school—and probably the largest one as well.

I hope I can make it.

Pikacnu

Finish Demo Page (Almost build by AI)
And lot of bug fixing
(Due to there are lots of bug not tested out.
With build demo website it appears)

Attachment
0
Pikacnu

Implementing gRPC Channel for game server and lobby to transfer messages.
Also Connection Manage Modules.
(It is much harder than I think…)

Attachment
0
Pikacnu

Due to the limited time remaining for Flavortown,
I’m trying to make it a functional system (as part of the whole game) that can be shipped.
However, it still seems like a difficult problem to deal with.

Since the last devlog,
I’ve been working on a messaging system to communicate with the frontend display (this won’t be finished in Flavortown).
I’ve also started building a RESTful API to add and run plugins.
Finally, I’m working on the game logic loop and its related functions.

There might end up being only some API endpoints without any frontend… or just an AI-generated one.
Sorry about that.

Attachment
0
Pikacnu

Make the VM stateless (even though it still maintains internal state, it is passed via arguments).
Plugins can still store variables internally.
After this change, some features that need to be shared across multiple games are now able to work
(because the VM’s variables no longer belong to a specific game).
However, you can no longer determine which game is using a particular function.
Btw some plugin function still working…

Attachment
0
Pikacnu

Finish plugin binding for the game (and player).
There is a huge problem that I didn’t realize: how many things I need to handle in the plugin system.
It seems like it will be difficult to deal with.
Even just implementing basic systems like riichi and tsumo feels challenging.
Btw It seems like i still need more hook to complete more function.
For example: If a player have Riichi. It should draw tile automatically If player can’t win this round.
Also plugin’s handler didn’t done yet.
Which means plugin still can’t change anything from game.

Attachment
0
Pikacnu

Rewriting Function Runner (now supports two types)
And bug fixes (the previous version had lots of bugs caused by the worker not sharing the same memory with the main thread, which made some classes inaccessible)

(Since I’m still working on the backend system…, the attachment is just part of the project plan.
Just the current plan — it might change during development)

I want to make the game class only handle storage and some simple functions.
The main logic (for example: Yaku checks) can be customized by plugins (running actual code in the runner).

Also some tricks (not sure if they will happen or not):
With a live runner, you can add a mystery counter,
which may cause someone to win without any clear reason.
(Though in the current implementation, this won’t happen,
since it requires enough games running in the same process and enough games using this plugin to keep it alive until it happens)

If you have any advice, please let me know.

Attachment
0
Pikacnu

Implement basic class and game flow
(not complete yet)
Image is mermaid which generate by ai

Attachment
0
Pikacnu

Change Restful API to gRPC
before everything is built.
(Though two of them are WIP)
(And None of them are well designed)

Attachment
0
Pikacnu

Create A js sandbox function runner with “quickjs-emscripten”
also a simple api to access it
(image below is test script which post code to the server and get result)

In my plan.
directly code execution will be change on next devlog
after change, you will need to upload it into another storage server.
then call function in sandbox by name and arguments

Attachment
0