Download

Building a very basic Mahjong for a very special person.

Hello Community,

Today, I have some very personal request and maybe I can find some help out here on getting some ideas on how to deal with this task.

TLDR:

  • I need to figure out how to place a fixed number of Mahjong stones on a fixed grid (made of single actors / null objects for example) randomly.
  • If two of the same stones gets clicked by the mouse, they need to be deleted and on top of each stone, I need to show a plane where I can load in a fitting video/flipbook animation
  • If it happens that the game can’t be finished, I would love to add a randomize button that randomizes the stone’s position, but keeps the layout intact.

The long cringe part: My mother turned 70 and due to medical things she has a hard time doing anything else than watching TV or sometimes playing a game. She just plays one particular game. I tried to show her a lot of games but this is the one she loves: A very specific Mahjong game from the 90’s. It gives me and Windows 10 headaches to make it run here and there and I thought it might be an interesting little project, building a very very simple Mahjong game in UE4.

Most time, it’s pretty basic gameplay. There is a fixed number of existing “common” layouts on how stones get placed. As a Senior Artist, it’s not a big deal for me to get all stuff done from the graphical side of things, but struggling to find certain Blueprint mechanics to place a fixed number of assets on a fixed number of actors or predefined positions - and randomize it. Then, how to tell stones what type of stone they are. Example: You have Stones with Numbers - So you can click on a stone with the number 1 and on another stone with the same number to delete it. But there might be stones with the four seasons which you can pair like Winter + Summer or Summer and Autumn.

From my perspective, I have the feeling that such mechanics could be done inside Blueprints, but really looking for some opinion here what would be a good approach.
I found some pointers like “Memory games” that would have similar mechanics but still looking for any viable tutorials which would solve my “place fixed number of meshes randomly on fixed positions” issue.

Best,
Tobias

Little addition: I thought this here could be a start for me to figure out some basic elements for finding pairs and setting up the layout but can’t find the project anywhere. https://docs.unrealengine.com/en-US/…ame/index.html

I noticed this:

which would be a big leap forward. But it’s not going to play video on the pieces I assume.

Mhm, I’ve seen this before. The problem here is that I don’t actually need any premade assets since I’m doing these on my own but also further down the road this is not the Mahjong I am talking about and probably comes with Blueprints that does apply to what I really need - which is far less than this MP asset provides or probably does not have. Except for the placement, if I am in luck.

For reference (Warning: Might contain nostalgic moments from childhood):

https://youtu.be/Ry3flKIPNVM?t=73

Maybe I’ve got the terminology wrong and need Mahjong Solitaire and not the 2-4 player Classic Mahjong.

Ok, I get it.

Yes, blueprints. You could either do it with static meshes in blueprints, or widgets. For sure the little videos that play would be widgets.

You would need to make all of the possible textures obviously.

Whether you do the bricks with BPs or widgets doesn’t really matter, I get the idea what you’re most focused on is how to program the logic. You can do that in both.

Laying them out randomly is literally a few blueprint nodes, the most tricky part is how to know when they’re pairing up.

I think the best approach is to have a few variables in each brick. You have the ‘id’ which will just be a number. In the case of number bricks it’s the actual number, in the case of seasons ( for instance ), it’s just a number so you have a reference point ( a bit like a jack in playing cards could be considered 11 ).

Then also have a name variable in each brick, so you can represent seasons, for instance ( I don’t play the game so I’m fumbling a bit here ).

In addition to these brick BPs and movies widgets, you need a central controller blueprint. This would ( probably ) be the level blueprint. You need a controller, because it’s a lot easier to recognize patterns from a central piece of code. You can’t recognize patterns from inside individual blueprints.

Am I zoning in here?

PS: Quote me or hit the like button, otherwise I don’t get a notification when you have answered.

Wow, thank you for the input ClockworkOcean! Indeed your post helps a lot. See, I have a certain work background on using Material BP’s and know how to read Blueprints or simple C# / C++. But coming from a very artistic driven life, I almost go with trial and error approaches on building up BP’s with pretty basic: “if > then > else > or” logic. That works…sometimes :smiley: but not every day and then I get lost in the node-woods and running against walls if I build up a blueprint which of course will not work in the way I think it should be…and then one of my coding friends is telling me: Nah, thats ultra easy…and then makes a node network that looks like the Matrix itself. (aka BP’s from hell)

Little hints like “widget” or “ID’s” giving me a good base where to search for. I will, of course, keep this thread updated with my progress and hope it will also help other artists to understand this wonderland. Thank you!!

My logic from the art side at the moment would be that I have a texture with all stone prints, the stone’s appearance (wood, marble, stone, etc) on a different one. Within, I just need one mesh and would probably not use 144 copies or material instances just for each stone. Yeah the more I think about, the more complex the system becomes, but for the better and more ways to customize later on. So the bricks are more or less non-existent in a physical way but each of them being a blueprint data-entry with pieces of information about texture, style, number, tag/type. Maybe I could look at Poker-Game BP’s and how they deal with cards.

Note: No one needs to answer on things above - I may use this thread as a little post-it with open thoughts as well to document the whole process. <3

Hey no worries.

If you get some artwork together, come back and I can knock up a basic blueprint structure for you.

I’ll need a few basic rules to work with also.

Bit busy at the mo, but about a week from now things will hopefully ease off a bit and we can swap a few basic projects if you like…

Oh hey, no worries as well!!

I actually would love to figure it out on my own as much as possible because, in all the years of game development, I really let that part slip. Of course, why not if you have an army of coders on your back and don’t need to worry about a single line of code or BP node. What I am doing at the moment is to set up a spreadsheet with all pieces of information about the tiles and creating a struct file inside UE4, loading in the database with all information needed.

I have one particular question on this: I thought it might be pretty convenient to use one texture for a complete tileset and creating a flipbook to have access to each tile.
Is there a way to tell the structure to use Row and Line of a Flipbook or the Flipbooks Number when going from first to the last frame of a flipbook picture?

UPDATE: My bad… I probably just set up the frame number as an integer and deal with it later on in the blueprint.

How my current database may look like.

I made this data table based on the number of stones. Normally, there a 4 Stones of each like the dotted ones. So you have a stone with 1 dot four times. Of course, I could save some space and say I want to just copy the Stone with Dot1 four times, but I also would love to have the option to add some more realism to it with different variants on carving and details per stone. So I thought its better to give each individual stone an individual ID and may change FB textures later on.

Update: I probably start with one tileset texture first that contains all stones at once (without copies). All stones (42) would fit in a single 6x7 flipbook and would have enough details with a 2k texture.

Ok, sounds like you’ve thought it out pretty thoroughly. The easiest way to do the flip book is using the flip book node in the material, you can parameterize it and call it on a material instance.

Update: I think, it does not look bad at all.

Thoughts:

a) Is it allowed or “ok” to have an Uppercase letter in TileName like Dot1a or should it better be dot1a?

b) I am not sure which type of texture might be better, texture or texture2D

c) I think I have this ID’s too many times. Do I really need the first two columns?

a) names are often case sensitive, good to stick with it

b) that I’m not sure of, you’ll have to experiment

c) Yes, too many IDs :slight_smile: Still not exactly sure how that’s going to work yet.

You -might- get problems trying to put everything in one data structure, not sure about that yet. Because what’s really elegant about object orientated programming ( which unreal is ), is that objects know about themselves and know what they can / can’t do. You’re taking a sort of old school FORTRAN type approach here, which will mean you just have one massive chunk of code which is constantly hammering this central data structure and will probably get pretty fiddly.

For instance, a season block knows that it fits with another season block, of the right type. It just knows that.

With this approach, you have to do all this looking up ‘what kind of block is it’, ‘what kind of block does it fit with’… see what I mean?

I kinda understand what you’re telling me. What would be the better alternative approach? For now, I just finished a very basic 2k texture with all 42 stone textures. These will be transparent and goes on top of each stone. I am at the point where I need to define somewhere that each stone (except seasons and flowers!) exist 4 times. Overall, we have 42 stones virtually and 144 stones physically (if we would build up solitaire mahjong in real life with real stones)

For now, this is just a prototype texture. I may squeeze more stones into it with 8 columns instead of 7 but even, for now, there are still 7 open slots for any kind of extra stones/variation.

Credit goes to Wikipedia on the textures but will be replaced once the system works.

Another look at the tex:

Actually, I wanted to use the spreadsheet for easy maintenance, having all 144 stones altogether. I don’t know what would be a better approach to tell the system that there is four times the Dot1 stone but having in mind that these are not instances but four individual ones. And in the next step, what I had in mind was placing these on another database driven layout.

I found one video a couple of weeks ago where somebody is programming a simple mahjong game - exactly in the direction I was looking for:

There, a simple txt is being used as a layout file to define where the stones are being placed and how many go on top of each other. Just the last stone needs to be added manually on top of the four stones in the middle and two stones left and right.

with that in mind, I think it’s pretty easy to build up own layouts outside of UE4 by using a simple text file. But I was not able to find a way to tell UE4 to eat something like this and interpret this into actors inside a scene environment plus placing the 144 stones from the database into this layout.

[Let's make 16 games in C++: Mahjong Solitaire - YouTube

](Let's make 16 games in C++: Mahjong Solitaire - YouTube)

Another thought I had was to have 144 actors inside a blueprint with single material instances and dropping these on a predefined layout. But that’s pretty inconvenient on both setup and custom changes. I also thought about setting up a simple point cloud data to define the spots where the meshes need to spawn - but I probably miss certain English terminology during my research to solve this puzzle.

Remember to like a post or quote me, I only saw this by chance!..

Getting stuff like text files into UE is not smooth, and I don’t know much about it.

Load the texture, no problemo.

What you have is one BP which is one stone. This one BP has it’s ID number, which tells it which row and column to use from the texture. The ID will be set at runtime by the ‘controller’ BP.

( It can also set the ‘height’ )

That’s it so far, you can make the board like that…

That would be interesting. I need to know a couple of things here:

a) I made a Texture that contains all bricks. Now, I am unsure if Flipbook has the option to say: “I am the Flipbook and I have 42 frames because I have 7 rows and 7 columns” - Is there an actual integer/value option to have access to that provides the ability to say: (example) Brick with ID number 36 needs “frame” 27 from the 42 frames long flipbook texture? So far I was not able to find a way to access this.

b) Instead of Flipbook, should I better go with UV spaces to set up the rows and lines and then just tell Brick with ID 36 (example) to use the UV space which contains the texture for that particular brick?

c) Does anyone know any sources on how to set up a texture with a layout (probably little white dots to define positions) and to interpret these points to actual actor spawn positions?

d) My first thought was that its best to not spawn or add any mesh and drive the system by spawning the stones on runtime directly. So that on gameplay starts, the system reads a location data table and knows there are 144 predefined points in space that needs to be filled with 144 ID’s from another data table, which will use the brick mesh and their fitting UV texture. All of the 144 stones have to be added randomly though.

Yeah, I really need to dig deeper into spawn actors first - But I really wonder why there is so little documentation or information about using data to define points in space and then let meshes spawn on these positions.