Solving non-determinism with blackboard architecture.

Mohaned Mashaly
CodeX
Published in
4 min readAug 5, 2021

Sequential model and why it is not the solution for all your problems

The standard way to solve many problems that are followed by different architectures is the sequential model.

The sequential model or program is a program that executes a series that consists of steps that follow an order and output the same result, it is used in solving a deterministic problem that has a specific solution. For example, computing the sum of two numbers given by the user, the flowchart of the program is sequential as shown below.

The sequential model can not solve problems with non-deterministic solutions, which are solutions that do not have a pre-defined solution or formulas to calculate at use when solving the problem

.

Model for computing sum of two numbers.

Regardless of the two numerical values, the user provides, it will follow the same sequence to compute the sum by using the addition sign.

What if we want to solve more complex problems with non-deterministic nature, where we do not know the right sequence of steps to solve the problem. In the next paragraph, we will give an example of a non-deterministic problem and proposing a way to solve it.

Designing a battle royal game

Let’s say we want to design a battle royal game like Fortnite or Pubg. The game assets and logic are developed, only one thing is left to develop, the bots that attack the players, we are trying to make this game harder so, the bots are going to be AI agents that get potential threats(real players or other bots) and track all their information in a real-time manner.

The AI agent should identify all potential threats(players, other bots) in their surroundings and retrieve their location coordinates, and attempt to predict the player’s movements in the future and based on this prediction, the bot should move in the same direction to attack the player and cause the largest damage they can.

If we divided each related functionalities into different modules, we will have five components/modules as shown in the below figure.

Components of the game

If we attempt to design a sequential model for the game, it is going to be similar to the model below.

Sequential model for the game.

The sequential model might look like a good solution to the problem, but we will look at why the sequential model is not a robust solution.

Let's assume that the bot retrieved the coordinates of a player and the player coordinates passed the target check, but it did change its position during the damage estimation phase, so the new coordinates of the player are different than the coordinates, the damage function is calculating, and if the damage is high enough, the attack component will fire and the attack will go to different coordinates, this problem happens because of the continuous update of the game, as the player keeps changing his position all the time and following steps in order won not help.

One of the Architectural patterns that can solve this problem is the Blackboard pattern.

Blackboard pattern.

BlackBoard pattern is a pattern used to solve problems with non-deterministic solutions. For example, problems in AI, Game theory problems.

BlackBoard is divided into three main parts as shown in the below figure.

BlackBoard consists of:-

. Knowledge source

Knowledge source represents the modules used in solving the problem, there is no single knowledge source or component that can solve the problem, their efforts are combined to solve the problem.

. Repository

The repository is used to store the output of each component, which is used by another component as its input. For example, the output of the target identification component is used by the target prediction component.

. Controller

The controller is used to manage the flow of data between components to share data from the blackboard.

BlackBoard Components
BlackBoard Interaction Diagram

As the diagram above illustrates the interaction between the different components of the Blackboard parts, the components modify the data in the repository and the controller, and the repository notifies the controller about changes in the data, and each component can look at the Repository and controller allow the components to decide the next component.

How blackboard pattern will solve the problem.

The Blackboard uses the three parts in the system to get updated information about the player, where each component posts its data in the Repository, and based on data in the Repo, controllers take actions through a forward-backward approach, where each component computes its function based on the latest updated data in the repository which is accessible by every component, so the component gets it latest data, unlike sequential model which base their decision base on stale data.

--

--

Mohaned Mashaly
CodeX
Writer for

Loves Computer Science with focused interest in (Back-end Development, Data Structures and Algorithms ,Machine Learning)