Class BrainUpdaterBase<TState, TBot, TAction>
Used to run bot brains.
Inheritance
Implements
Inherited Members
Namespace: Microsoft.XboxStudios.BotBrain.Composition
Assembly: BotBrain.Core.dll
Syntax
public abstract class BrainUpdaterBase<TState, TBot, TAction> : IBrainUpdater where TState : notnull where TBot : IAutomatedBot<TAction>Type Parameters
| Name | Description | 
|---|---|
| TState | The game state type. | 
| TBot | The bot type. | 
| TAction | The action type. | 
Constructors
View SourceBrainUpdaterBase(IBrainSerializer, BrainManager<TState, TBot, TAction>?, ILogger<BrainUpdaterBase<TState, TBot, TAction>>?)
Initializes a new instance of the BrainUpdaterBase<TState, TBot, TAction> class.
Declaration
protected BrainUpdaterBase(IBrainSerializer serializer, BrainManager<TState, TBot, TAction>? brainManager = null, ILogger<BrainUpdaterBase<TState, TBot, TAction>>? logger = null)Parameters
| Type | Name | Description | 
|---|---|---|
| IBrainSerializer | serializer | The brain serializer. | 
| BrainManager<TState, TBot, TAction> | brainManager | The brain manager. | 
| ILogger<BrainUpdaterBase<TState, TBot, TAction>> | logger | The logger to use. | 
Properties
View SourceBots
Gets the collection of bots to update.
Declaration
public IReadOnlyCollection<TBot> Bots { get; }Property Value
| Type | Description | 
|---|---|
| IReadOnlyCollection<TBot> | 
Brain
Gets the default brain to use.
Declaration
public IBotBrain<TState, TBot, TAction>? Brain { get; }Property Value
| Type | Description | 
|---|---|
| IBotBrain<TState, TBot, TAction> | 
BrainManager
Gets the object used to manage and update the brain.
Declaration
protected BrainManager<TState, TBot, TAction> BrainManager { get; }Property Value
| Type | Description | 
|---|---|
| BrainManager<TState, TBot, TAction> | 
Brains
Gets the collection of bot brains to update.
Declaration
public IReadOnlyCollection<IBotBrain<TState, TBot, TAction>> Brains { get; }Property Value
| Type | Description | 
|---|---|
| IReadOnlyCollection<IBotBrain<TState, TBot, TAction>> | 
Logger
Gets the logger to use.
Declaration
public ILogger<BrainUpdaterBase<TState, TBot, TAction>> Logger { get; }Property Value
| Type | Description | 
|---|---|
| ILogger<BrainUpdaterBase<TState, TBot, TAction>> | 
Serializer
Gets the brain serializer.
Declaration
protected IBrainSerializer Serializer { get; }Property Value
| Type | Description | 
|---|---|
| IBrainSerializer | 
States
Gets the game state objects associated with running bots.
Declaration
public abstract IReadOnlyCollection<TState> States { get; }Property Value
| Type | Description | 
|---|---|
| IReadOnlyCollection<TState> | 
TickFrequency
Gets or sets the update frequency.
Declaration
public TimeSpan TickFrequency { get; set; }Property Value
| Type | Description | 
|---|---|
| TimeSpan | 
Methods
View SourceAddBotAsync(string, IBotBrain?, string?, int, CancellationToken)
Adds a bot to the brain.
Declaration
public abstract Task<IAutomatedBot?> AddBotAsync(string deviceName, IBotBrain? brain = null, string? botName = null, int playerIndex = 0, CancellationToken token = default)Parameters
| Type | Name | Description | 
|---|---|---|
| string | deviceName | The device name. | 
| IBotBrain | brain | The brain to use. | 
| string | botName | The bot's name. | 
| int | playerIndex | The bot's player index. | 
| CancellationToken | token | The cancellation token. | 
Returns
| Type | Description | 
|---|---|
| Task<IAutomatedBot> | The bot. | 
AddBotAsync(string, object, IBotBrain?, string?, int, CancellationToken)
Adds a bot to the brain.
Declaration
public Task<IAutomatedBot> AddBotAsync(string deviceName, object state, IBotBrain? brain = null, string? botName = null, int playerIndex = 0, CancellationToken token = default)Parameters
| Type | Name | Description | 
|---|---|---|
| string | deviceName | The device name. | 
| object | state | The game state. | 
| IBotBrain | brain | The brain to use. | 
| string | botName | The bot's name. | 
| int | playerIndex | The bot's player index. | 
| CancellationToken | token | The cancellation token. | 
Returns
| Type | Description | 
|---|---|
| Task<IAutomatedBot> | The bot. | 
AddBotAsync(string, TState, IBotBrain?, string?, int, CancellationToken)
Adds a bot to the brain.
Declaration
public virtual Task<TBot> AddBotAsync(string deviceName, TState state, IBotBrain? brain = null, string? botName = null, int playerIndex = 0, CancellationToken token = default)Parameters
| Type | Name | Description | 
|---|---|---|
| string | deviceName | The device name. | 
| TState | state | The game state. | 
| IBotBrain | brain | The brain to use. | 
| string | botName | The bot's name. | 
| int | playerIndex | The bot's player index. | 
| CancellationToken | token | The cancellation token. | 
Returns
| Type | Description | 
|---|---|
| Task<TBot> | The bot. | 
AddBrain(IBotBrain?)
Adds a brain instance.
Declaration
public virtual bool AddBrain(IBotBrain? brain)Parameters
| Type | Name | Description | 
|---|---|---|
| IBotBrain | brain | The brain. | 
Returns
| Type | Description | 
|---|---|
| bool | True if the brain was added successfully. | 
AddBrain(string)
Loads a brain file and adds the instance.
Declaration
public virtual bool AddBrain(string name)Parameters
| Type | Name | Description | 
|---|---|---|
| string | name | The name of the brain. | 
Returns
| Type | Description | 
|---|---|
| bool | True if the brain was loaded and added. | 
ClearBrains()
Removes all brain instances.
Declaration
public void ClearBrains()CreateBotAsync(string, TState, string, int)
Creates a bot.
Declaration
protected abstract Task<TBot> CreateBotAsync(string deviceName, TState state, string botName, int playerIndex)Parameters
| Type | Name | Description | 
|---|---|---|
| string | deviceName | The device name. | 
| TState | state | The game state. | 
| string | botName | The bot's name. | 
| int | playerIndex | The bot's player index. | 
Returns
| Type | Description | 
|---|---|
| Task<TBot> | The bot. | 
RemoveBotAsync(IAutomatedBot, IBotBrain?)
Removes a bot from the brain.
Declaration
public virtual Task RemoveBotAsync(IAutomatedBot bot, IBotBrain? brain = null)Parameters
| Type | Name | Description | 
|---|---|---|
| IAutomatedBot | bot | The bot. | 
| IBotBrain | brain | The brain to use. | 
Returns
| Type | Description | 
|---|---|
| Task | A task. | 
RemoveBrain(IBotBrain)
Removes a brain.
Declaration
public void RemoveBrain(IBotBrain brain)Parameters
| Type | Name | Description | 
|---|---|---|
| IBotBrain | brain | The brain. | 
Run(CancellationToken)
Runs each brain.
Declaration
public Task Run(CancellationToken token)Parameters
| Type | Name | Description | 
|---|---|---|
| CancellationToken | token | The cancellation token. | 
Returns
| Type | Description | 
|---|---|
| Task | A task which completes when the brains are stopped. | 
RunOnce()
Runs each brain once, if it is not currently updating.
Declaration
public void RunOnce()Remarks
This completes as soon as the brains are started.
SetBrain(IBotBrain)
Removes all brain instances, and then adds the given brain instance.
Declaration
public virtual bool SetBrain(IBotBrain brain)Parameters
| Type | Name | Description | 
|---|---|---|
| IBotBrain | brain | The brain. | 
Returns
| Type | Description | 
|---|---|
| bool | True if the brain was added successfully. | 
SetBrain(string)
Removes all brain instances, and then loads a brain file and adds the instance.
Declaration
public virtual bool SetBrain(string name)Parameters
| Type | Name | Description | 
|---|---|---|
| string | name | The name of the brain. | 
Returns
| Type | Description | 
|---|---|
| bool | True if the brain was loaded and added. |