-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuleEngine.cs
More file actions
31 lines (29 loc) · 773 Bytes
/
RuleEngine.cs
File metadata and controls
31 lines (29 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using ChunkPriorityCalculator.Rules;
namespace ChunkPriorityCalculator
{
public class RuleEngine
{
/// <summary>
/// Predefined rules to be evaluated. The order is not relevant.
/// </summary>
public IEnumerable<IPriorityRule>? Rules;
/// <summary>
/// Evaluates the rules and calculates the priority of the chunk.
/// </summary>
/// <param name="chunk">A chunk</param>
/// <returns>A value representing priority. A higher value indicate higher priority.</returns>
public decimal CalculatePriority(Model.OreChunk? chunk)
{
if (Rules is null || chunk is null)
{
return 0;
}
var priority = 0M;
foreach (var rule in Rules)
{
priority += rule.Evaluate(chunk) * rule.RuleWeightMultiplier;
}
return priority;
}
}
}