You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1023 B
40 lines
1023 B
using System.Collections.Generic;
|
|
|
|
public class Condition<T>
|
|
{
|
|
T[] condition;
|
|
int shouldMatchCount;
|
|
|
|
public Condition(IReadOnlyList<T> condition, int shouldMatchCount = 0)
|
|
{
|
|
this.condition = new T[condition.Count];
|
|
for (int i = 0; i < condition.Count; i++)
|
|
{
|
|
this.condition[i] = condition[i];
|
|
}
|
|
|
|
if(shouldMatchCount == 0)
|
|
shouldMatchCount = condition.Count;
|
|
|
|
this.shouldMatchCount = shouldMatchCount;
|
|
}
|
|
|
|
public bool CheckCondition(IReadOnlyList<T> currentState)
|
|
{
|
|
var currentRemainConditions = new List<T>(condition);
|
|
|
|
int currentMatchCount = 0;
|
|
for (int i = 0; i < currentState.Count; i++)
|
|
{
|
|
if (!currentRemainConditions.Contains(currentState[i])) continue;
|
|
|
|
currentMatchCount++;
|
|
currentRemainConditions.Remove(currentState[i]);
|
|
|
|
if (currentMatchCount >= shouldMatchCount)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|