32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
|
|
namespace GameOfLife.Entities
|
|
{
|
|
public class Projections : ReadOnlyCollection<Pattern>
|
|
{
|
|
public Dictionary<Pattern, Pattern> BoundaryCells { get; }
|
|
|
|
public Projections(IEnumerable<Pattern> pattern)
|
|
: base(pattern.SelectMany(GeneratePatterns).Distinct().ToList())
|
|
{
|
|
BoundaryCells = this.ToDictionary(p => p, p => p.GetBoundary);
|
|
}
|
|
|
|
public Projections(Pattern pattern) : this(new[] { pattern }) { }
|
|
|
|
private static List<Pattern> GeneratePatterns(Pattern pattern) =>
|
|
new[]
|
|
{
|
|
pattern.Normalize(),
|
|
pattern.Rotate(1).Normalize(),
|
|
pattern.Rotate(2).Normalize(),
|
|
pattern.Rotate(3).Normalize(),
|
|
pattern.ReflectX().Normalize(),
|
|
pattern.ReflectY().Normalize(),
|
|
pattern.ReflectX().Rotate().Normalize(),
|
|
pattern.ReflectY().Rotate().Normalize()
|
|
}.Distinct().ToList();
|
|
}
|
|
} |