A framework for Unity that implements a rules engine to ease up the development of card and board games with setup from minimal C# code, or via the editor with the help of a custom scripting language.
How it Works
It implements a rules engine pattern, so a game is simplified down to a set of rules to be executed when a certain event happens in the game. Each rule has a trigger, a condition, and two effects to be executed, one for when the condition is true, and one for when the condition is false.
For example, let's consider a rule for shuffling cards at the start of the game:
Rule: Shuffle Trigger: The game has started Condition: None (always true) True Effects: Shuffle all cards. False Effects: None
In this case, when the game starts, the rule is triggered. Since the condition is always true (denoted by "None"), the true effect is executed, resulting in shuffling all the cards. The false effect is empty, indicating that no action needs to be taken when the condition is false. By utilizing this breakdown into rules, developers can easily define the behavior and logic of their card or board game. Check the breakdown for Solitaire below.
Reveal Klondike Solitaire Breakdown into rules.
How to Use
1. Implement the Rules
Once a game is broken down into rules, it's possible to implement them via the editor using a custom scripting language.
Create a new game by right-clicking in the Asset Menu > Cardgame > Game
Write each rule script conditions and commands
2. Create Cards
Create 'Card' scriptable objects with the info for the cards and/or other components.
3. Create a Scene
Create scene objects with the 'Zone' script positioned and configured according to the game needs
Create a scene object with the 'Match' script and reference the game created.
Instantiate cards in scene providing a configured prefab
Run the scene in Unity.
A description on how to use the custom scripting language can be found here.