pla-01/Life/Automaton/MooreField.cs
2019-10-26 16:47:08 +02:00

31 lines
874 B
C#

using System.Collections.Generic;
using System.Linq;
namespace Life.Automaton
{
public class MooreField : BasicField
{
public MooreField(int width, int height) : base(width, height)
{
}
public override IEnumerable<Cell> Neighbours(int x, int y)
{
var potential = new []
{
(x - 1, y + 1), (x, y + 1), (x + 1, y + 1),
(x - 1, y) /*, (x, y) */, (x + 1, y),
(x - 1, y - 1), (x, y - 1), (x + 1, y - 1),
};
return potential
.Where(c => c.Item1 >= 0 && c.Item1 < Size.Width && c.Item2 >= 0 && c.Item2 < Size.Height)
.Select(c => this[c.Item1, c.Item2]);
}
public override string ToString()
{
return $"MooreField {Size.Width} x {Size.Height}";
}
}
}