SimpleBlackboard.Net
2.1.0.1
dotnet add package SimpleBlackboard.Net --version 2.1.0.1
NuGet\Install-Package SimpleBlackboard.Net -Version 2.1.0.1
<PackageReference Include="SimpleBlackboard.Net" Version="2.1.0.1" />
<PackageVersion Include="SimpleBlackboard.Net" Version="2.1.0.1" />
<PackageReference Include="SimpleBlackboard.Net" />
paket add SimpleBlackboard.Net --version 2.1.0.1
#r "nuget: SimpleBlackboard.Net, 2.1.0.1"
#:package SimpleBlackboard.Net@2.1.0.1
#addin nuget:?package=SimpleBlackboard.Net&version=2.1.0.1
#tool nuget:?package=SimpleBlackboard.Net&version=2.1.0.1
SimpleBlackboard.Net
A simple package containing a basic Blackboard data structure.
Installation
Nuget
The recommended installation approach is to use the available nuget package: SimpleBlackboard.Net
Clone
Alternatively, you can clone this repo and reference the SimpleBlackboard.Net project in your project.
Features
- A Blackboard interface that can be extended to create custom blackboards (
IBlackboard
). - A standard Blackboard class that can be used out-of-the-box (
Blackboard
)
What is a Blackboard?
A Blackboard is a data structure designed to act as a structured global memory containing objects from the solution space. For more information, see:
- https://architectural-patterns.net/blackboard
- https://en.wikipedia.org/wiki/Blackboard_(design_pattern)
Usage
Built-in Blackboard
The built-in Blackboard
class provides a ready-to-use very simplified implementation that can be used out-of-the-box
. This version relies on an internal dictionary to store the data and is agnostic about implementation details that may
be important for your specific implementation.
Example Usage:
using SimpleBlackboard.Net;
public class Program
{
public static void Main()
{
// Create a new blackboard (optionally with thread-safe concurrent dictionary)
var blackboard = new Blackboard(useConcurrentDictionary: true);
// Store different types of data
blackboard.SetValue("PlayerName", "John");
blackboard.SetValue("PlayerHealth", 100);
blackboard.SetValue("IsAlive", true);
blackboard.SetValue("Position", new Vector3(10.5f, 0, 3.2f));
// Retrieve data in a type-safe manner
string name = blackboard.GetValue<string>("PlayerName");
int health = blackboard.GetValue<int>("PlayerHealth");
// Check if a value exists
if (blackboard.HasValue<bool>("IsAlive"))
{
Console.WriteLine($"Player {name} is alive: {blackboard.GetValue<bool>("IsAlive")}");
}
// Try to get a value safely
if (blackboard.TryGetValue("Position", out Vector3? position))
{
Console.WriteLine($"Player position: {position}");
}
// Remove a value and get it at the same time
int oldHealth = blackboard.RemoveValue<int>("PlayerHealth") ?? 0;
// Try to remove a value safely
if (blackboard.TryRemoveValue("IsAlive", out bool isAlive))
{
Console.WriteLine($"Removed 'IsAlive' flag: {isAlive}");
}
// Clear all data from the blackboard
blackboard.ClearBlackboard();
}
}
Custom Blackboard
Below is a simple blackboard implementation. However, besides implementing the standard fields, you have full control as to the structure of the Blackboard and it would be highly recommended to have and use structured fields/properties additionally to the built-in methods.
Example Usage:
using SimpleBlackboard.Net;
public class MyBlackboard : IBlackboard
{
private readonly Dictionary<string, object?> _data = new();
public bool SetValue<T>(string key, T value)
{
_data[key] = value;
return true;
}
public T? GetValue<T>(string key)
{
if (_data.TryGetValue(key, out var value) && value is T typedValue)
{
return typedValue;
}
return default;
}
public bool TryGetValue<T>(string key, out T? value)
{
if (_data.TryGetValue(key, out var typedValue) && typedValue is T typedValueT)
{
value = typedValueT;
return true;
}
value = default;
return false;
}
public bool HasValue<T>(string key)
{
return this._data.ContainsKey(key);
}
public void ClearBlackboard()
{
_data.Clear();
}
public T? RemoveValue<T>(string key)
{
if (TryGetValue(key, out T? value))
{
_data.Remove(key);
return value;
}
return default;
}
public bool TryRemoveValue<T>(string key, out T? value)
{
if (_data.TryGetValue(key, out var typedValue) && typedValue is T typedValueT)
{
value = typedValueT;
return _data.Remove(key);
}
value = default;
return false;
}
}
public class Program
{
public static void Main()
{
var blackboard = new MyBlackboard();
// Set a value
blackboard.SetValue("Score", 100);
// Get a value
int score = blackboard.GetValue<int>("Score");
Console.WriteLine($"Score: {score}");
// Check if a value exists
bool hasScore = blackboard.HasValue<int>("Score");
Console.WriteLine($"Has Score: {hasScore}");
// Clear the blackboard
blackboard.ClearBlackboard();
}
}
Development
- Clone or fork the repo
- Create a new branch
- Code!
- Push your changes and open a PR
- Once approved, they'll be merged in
- Profit!
Future Plans
See list of issues under the Milestones: https://github.com/vonderborch/SimpleBlackboard.Net/milestones
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.