Files
Craftimizer/Solver/Crafty/ArenaNode.cs
T
Asriel Camora 636501ab86 Remove all concurrency code
Muddled the code too much, and only gave a marginal performance improvement in the grand scheme of things. Other ways to parallelize MCTS will be nicer to implement and could yield better results.
2023-07-07 20:17:35 +02:00

35 lines
909 B
C#

using System.Runtime.CompilerServices;
namespace Craftimizer.Solver.Crafty;
public sealed class ArenaNode<T> where T : struct
{
public T State;
public ArenaBuffer<T> Children;
public NodeScoresBuffer ChildScores;
public (int arrayIdx, int subIdx) ChildIdx;
public readonly ArenaNode<T>? Parent;
public NodeScoresBuffer? ParentScores => Parent?.ChildScores;
public ArenaNode(T state, ArenaNode<T>? parent = null)
{
State = state;
Children = new();
ChildScores = new();
Parent = parent;
}
public ArenaNode<T>? ChildAt((int arrayIdx, int subIdx) at) =>
Children.Data?[at.arrayIdx]?[at.subIdx];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ArenaNode<T> Add(T state)
{
var node = new ArenaNode<T>(state, this);
ChildScores.Add();
Children.Add(node);
return node;
}
}