Introduction

I made a board game called Mancala to learn Unreal Engine 5 and it went really well. In the following video you can see the final product.

Learning Unreal Engine 5

Tutorials

To start learning Unreal Engine 5 and blueprints I followed some tutorials to get familiar with the environment and to get a grip on how visual scripting works. I followed both the beginner blueprint tutorial from a youtuber named SmartPoly and the intermediate tutorial.

And in the following video you can see what I created by following these tutorials:

As you can see in the video I made a bit of everything and it really helped to learn blueprints.

How does Mancala work

In Mancala you have a board and it consists of 12 small pits or cups which I call the houses, with an additional large pit or scoring area which is the goal. At the beginning of a game all the houses get 4 seeds added to them. The objective of the game is to have more seeds in your goal then your opponent. You do this by taking seeds from a house and then distributing the seeds one by one into successive house in a counterclockwise direction around the board, including your goal but not the opponent's goal. If the last seed lands in the player's goal, they get to take another turn. Or If the last seed lands in an empty house on the player's side, and the opposite house has seeds in it, the player captures all the seeds in the opponent's house along with the seed that landed in the empty house. These captured seeds are then placed in the player's goal. Else if your last seed just lands on a regular house your opponent can take their turn. until one player's side is empty. The remaining seeds on the opponent's side are placed in their goal.

Making Mancala in Unreal Engine 5

To make Mancala I started by making a 3D model in blender for the board. And I really liked how it turned out!

Image Description

After that I made sure all the seeds spawn onto the board at the start of the game. So I made an actor for all the houses with a event that makes sure the seeds on the board are always eqeal to the seedAmount variable that every house has.

Image Description

Of course, the goal doesn't have to start with any seeds, and it also can't be selected among some other things. So, for the goal, it inherits from the house actor but I removed some of the functionality that isn't needed anymore.

All of the rules and management in the game is done by the gamemode blueprint. So when you select a house it calls an event to the gamemode which will handle all of the movement logic.

If a house is selected and the MoveSeeds event is called the gamemode saves the amount of seeds that need to be moved in a variable called seedsOver. And then as long if seedsOver isn't 0 the gamemode loops over all the houses and finds the next house to add a seed to.

Image Description

So as you can see in the foreach loop it searches for the next house in the order and if the next house is found it adds a seed to the house and repeats until seedsOver is 0

Image Description

Then on the last seed we need to check for captures, goals and an empty board to handle those special actions.

It is pretty easy to check the last seed since we allready have a while loop setup that keeps running if seedsOver is bigger than 0 so once that while loop is completed we know the nextHouse variable will be the house where the last seed has dropped.

And if the nextHouse is the goal the player turn switches to the other player which might be odd because the opposite should happen but since we are always switching the players turn at the end of all the checks this will make sure the player does get to move again.

Image Description

Sadly checking for captures isn't as easy I really struggled to find a good way to get the house across the house the last seed was dropped. Untill I eventually found that if you take the lenght of all the houses and goals which is 14 and subtract it from the house number where the last seed is dropped you get the house across it.

Image Description

And after you find the corresponding capture house we can simply add all those seeds to the player's goal.

Then finally the last thing that needs to be checked is if one of the board is empty. Which is done by adding all the seeds in every house on a side. And if that amount is 0 the side is empty and all the seeds on the other side can be added to that sides goal.

Discover Mancala