Concepts
Overview
Actors & Controllers
An Actor is an Entity able to take initiative on her own i.e., her course of action is not described in the game logic.
For each Actor, there is a single corresponding Controller, choosing her actions.
There is a variety of Controller implementations such as
Mouse/Keyboard,
Random
and Machine Learning Ai.
The behaviour of the Controller depends on its implementation; however, controllers can be configured with metadata.
Beings
A Being is an Entity that does not have will on its own, i.e. it cannot take initiative.
Beings can be created (and destroyed):
- During the game start phase
- At any given step as an impact of an action performed by an Actor.
The Scene
The Scene (singleton) is the Entity that contains the Actors and the Beings.
Entities
The Actors, the Beings and the Scene are the Entities.
Entities have:
- Attributes: Data that are part of the game logic
- Metadata: Data that are not part of the game logic
- They are instructions for the Renderer, the Controllers and other mechanisms outside the game logic
- Game logic is only able to write metadata but not read them back
Example attributes would be: the utility of an actor, the price of an object, the position of a creature in the world.
Example metadata would be: the picture or 3D model to render, the position in the screen, a heuristic function
to be used by an Ai Controller.
Furthermore, each entity has a Unique ID.
Actors | Beings | Scene | |
---|---|---|---|
Attributes | ✅ | ✅ | ✅ |
Metadata | ✅ | ✅ | ✅ |
Take Actions | ✅ | ||
Controller | ✅ | ||
Create in-game | ✅ | ||
Destroy | ✅ | ||
Singleton | ✅ |
Summary of the three entity types.
Actions & Impacts
Unlike real life where our actions are unrestricted and our choices are boundless, in games there are rules restricting Actors to a specific set of actions and choices.
To describe an action, answer the following questions.
- When is an action available and for which Actors?
- Which choices do you have to make?
- What will be the impact of this action?
Note: Satisfying the "when" constraint does not mean you have to perform the action; it merely means that you can.
Example Action
Here is an example code for a simple action.
This action has 2 impacts:
- Update the Actor
- Update the CoffeeShop
Metadata
Metadata are arbitrary data that can be attached to Entities, actions and other game elements.
Game logic is able to write metadata but is not able to read them back.
Other components such as the renderer and the controllers can read and also write metadata.
Metadata provide a mechanism for components to store information and communicate in a way that is guaranteed to not interfere with game logic.
Worlds
Worlds are different environments where the Scene may unfold, such as planets, mazes, networks, economic environments.
Check the worlds' documentation for more.
GameRunner & Game Execution
A prominent component of the engine is the GameRunner
. The GameRunner
is responsible
for:
- Starting the game
- Communicating with the Controllers
- Performing action impacts
- Determining when the game has ended
Game execution goes through 3 phases: Start
, Running
, End
.
Start
When the game starts, the GameRunner
performs the start impacts.
Start impacts are like action impacts only they are performed once when
the game starts.
Overall, during game start, the following steps take place:
- Create declared actors
- Perform start impacts
- Create controllers and connect them with their actors
Running
While the game is running -on every game step- the following steps take place:
- Check which actors have available actions
- If any actor has an available action: Prompt their controllers to act
- else: Game End
- Receive the selected action and choices from the controllers and validate them
- Perform the impacts of the selected action (if validation succeeded)
- Repeat from step 1
End
The game ends when no actor has an available action.
Note: If a world is loading, then
GameRunner
will wait for it to load before checking for game over.
An example game
Let's see the elements of the game Tic-Tac-Toe.
Actors
The game will have 2 actors:
- X Player
- O Player
Beings
The game will have 9 beings: the 9 squares.
Actions
The only action an Actor can take is "Mark Square".
Constraint: It's the Actor's turn and we don't yet have a winner.
Choice: A square that is empty
Impacts:
- Mark the chosen square with the Actor's mark
- Determine if there is a winner
- Set the turn to the next actor (if there is no winner)
Game End
The game ends when no actor has available actions.
- If an actor wins, the game will end because the action "Mark Square" will not be available (by definition).
- If all the squares are marked, the game will end because the action "Mark Square" will not have available choices and therefore will not be available.