Initial commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user