Implements move execution for battle

This commit is contained in:
2024-08-10 11:18:10 +02:00
parent a049dda240
commit 488c717c5a
17 changed files with 433 additions and 14 deletions

View File

@@ -27,7 +27,7 @@ public interface IReadOnlyTypeLibrary
/// Gets the effectiveness for a single attacking type against an amount of defending types.
/// This is equivalent to running get_single_effectiveness on each defending type, and multiplying the results with each other.
/// </summary>
float GetEffectiveness(TypeIdentifier attacking, TypeIdentifier[] defending);
float GetEffectiveness(TypeIdentifier attacking, IReadOnlyList<TypeIdentifier> defending);
}
/// <inheritdoc />
@@ -66,7 +66,7 @@ public class TypeLibrary : IReadOnlyTypeLibrary
}
/// <inheritdoc />
public float GetEffectiveness(TypeIdentifier attacking, TypeIdentifier[] defending) =>
public float GetEffectiveness(TypeIdentifier attacking, IReadOnlyList<TypeIdentifier> defending) =>
defending.Aggregate<TypeIdentifier, float>(1,
(current, type) => current * GetSingleEffectiveness(attacking, type));

View File

@@ -10,4 +10,27 @@ public static class EnumerableHelpers
/// </summary>
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> enumerable) where T : class =>
enumerable.Where(x => x is not null)!;
/// <summary>
/// Finds the index of a value in an enumerable. Returns -1 if the value is not found.
/// </summary>
public static int IndexOf<T>(this IEnumerable<T> enumerable, T value)
{
var index = 0;
foreach (var item in enumerable)
{
if (item is null)
{
if (value is null)
return index;
continue;
}
if (item.Equals(value))
return index;
index++;
}
return -1;
}
}