Class Engine
Blazor component wrapping an UCI compliant WebAssembly Chess Engine
The component uses the WebAssembly port of Nathan Rugg of ((https://github.com/nmrugg/stockfish.js) Stockfish 14.1
NOTE: Stockfish.js 14.1 reqiures some of the latest features and does not work in every browser.
As it uses the latest WebAssembly threading proposal it requires these HTTP headers on the top level response:
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
And the following header on the included files:
Cross-Origin-Embedder-Policy: require-corp
The UI of the engine component consists of 3 parts:
- Info Panel showing the engine's evaluation info (score, depth and principal variation)
- Evaluation Bar showing the current evaluation graphically
- Log Panel showing the uci communication
To have more flexibiliyt regarding the UI setup, the evaluation bar and the log panel are offered as independent components: EvaluationGauge and EngineLog
There is only one Engine Process available per window. So by using 2 Engine components, you will not get 2 engine workers, but only one. All UCI commands you to one of your engine commands will reach the same engine.
Inheritance
Inherited Members
Namespace: PonzianiComponents
Assembly: PonzianiComponents.dll
Syntax
public class Engine
Properties
| Improve this Doc View SourceName
Engine name (only available after engine has been initialized)
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
System.String |
NumberOfLines
Number of lines to be analyzed
Declaration
[Parameter]
public int NumberOfLines { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
OnEngineInfo
Engine reports new, updated analysis info
Declaration
[Parameter]
public EventCallback<UCIEngine.Info> OnEngineInfo { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.EventCallback<UCIEngine.Info> |
OtherAttributes
Other HTML Attributes, which are applied to the root element of the rendered scoresheet.
Declaration
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> OtherAttributes { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.Object> |
Score
Score from white's point of view in centipawns. Mate scores are converted to very high scores
Declaration
public int Score { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
ShowEvaluationbar
Shows engine evaluation Bar
Declaration
[Parameter]
public bool ShowEvaluationbar { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
ShowEvaluationInfo
Shows evaluation output (score, depth and principal variation)
Declaration
[Parameter]
public bool ShowEvaluationInfo { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
ShowLog
Shows engine evaluation Bar
Declaration
[Parameter]
public bool ShowLog { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceEngineMessageAsync(String)
Declaration
[JSInvokable]
public async Task EngineMessageAsync(string msg)
Parameters
Type | Name | Description |
---|---|---|
System.String | msg |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
GetScore(Int32)
Score from white's point of view
Declaration
public int GetScore(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | zero-based index of line |
Returns
Type | Description |
---|---|
System.Int32 | score in centipawns, mate scores are converted to very high scores |
OnAfterRenderAsync(Boolean)
Declaration
protected override async Task OnAfterRenderAsync(bool firstRender)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | firstRender |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
ScoreText(Int32)
Textual representation of Score (with representations for mate scores and upper-/lowerbound scores)
Declaration
public string ScoreText(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | zero-based index of line |
Returns
Type | Description |
---|---|
System.String | Score as text |
SendAsync(String)
Send UCI message to the engine process
Attention: Sending an incorrect or invalid UCI message might break the engine process, there is no input validation!
Declaration
public async Task SendAsync(string command)
Parameters
Type | Name | Description |
---|---|---|
System.String | command | UCI message |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
StartAnalysisAsync(String)
Start analysing a position
Declaration
public async Task<bool> StartAnalysisAsync(string fen)
Parameters
Type | Name | Description |
---|---|---|
System.String | fen | Position to be analyzed in FEN representation |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> |