diff --git a/Dimension.cs b/Dimension.cs new file mode 100644 index 0000000..9450b96 --- /dev/null +++ b/Dimension.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; + +namespace N_Space { + class Dimension { + private readonly int _index; + private Dimension _parent; //These are the dimensional parents so in (1,2) the dimension that has the index=1 would be the parent of the dimention that has the index=2 + private List _child; + private readonly Location _location; + + public Dimension(int n, Location location) { + _index = n; + _parent = null; + _child = null; + _location = location; + } + + public void SetParent(Dimension parent) { + _parent = parent; + } + + public void AddChild(Dimension child) { + if (_child == null) { + _child = new List(); + } + + _child.Add(child); + _child.Sort((x, y) => x._index.CompareTo(y._index)); + } + + public int GetIndex() { + return _index; + } + + public Dimension GetParent() { + return _parent; + } + + public List GetChildList() { + return _child; + } + + public Location GetLocation() { + return _location; + } + } +} \ No newline at end of file diff --git a/Dimension_Test.cs b/Dimension_Test.cs new file mode 100644 index 0000000..4603f5a --- /dev/null +++ b/Dimension_Test.cs @@ -0,0 +1,71 @@ +namespace N_Space { + public class Dimension_Test { + public void CreateDimensionTest() { + Location LocationA = new Location(State.Light, State.Dark, new int[]{0,1}, 2); + Dimension DimensionTestA = new Dimension(0, LocationA); + + if (DimensionTestA == null) { + throw new System.ArgumentException("Test Failed: Dimension created cannot be null."); + } + } + + public void DimensionParentTest() { + Dimension DimensionTestA = new Dimension(0, null); + + if (DimensionTestA.GetParent() != null) { + throw new System.ArgumentException("Test Failed: Dimension Parent Test expected null on get."); + } + + Location LocationB = new Location(State.Light, State.Dark, new int[] { 0, 0 }, 1); + Dimension DimensionTestB = new Dimension(0, LocationB); + DimensionTestA.SetParent(DimensionTestB); + + if (DimensionTestA.GetParent() != DimensionTestB) { + throw new System.ArgumentException("Test Failed: Dimension Parent Test expected DimensionTestB on get following set."); + } + } + + public void DimensionChildTest() { + Dimension DimensionTestA = new Dimension(0, null); + Dimension DimensionTestB = new Dimension(1, null); + Dimension DimensionTestC = new Dimension(0, null); + + DimensionTestB.SetParent(DimensionTestA); + DimensionTestA.AddChild(DimensionTestB); + + if (DimensionTestA.GetChildList()[0] != DimensionTestB) { + throw new System.ArgumentException("Test Failed: Dimension Child Test expected DimensionTestB on get."); + } + + DimensionTestC.SetParent(DimensionTestA); + DimensionTestA.AddChild(DimensionTestC); + + if (DimensionTestA.GetChildList()[0] != DimensionTestC) { + throw new System.ArgumentException("Test Failed: Dimension Child Test expected DimensionTestC on get following sort."); + } + } + + public void DimensionIndexTest() { + Dimension DimensionTestA = new Dimension(0, null); + + if (DimensionTestA.GetIndex() != 0) { + throw new System.ArgumentException("Test Failed: Dimension Index Test expected 0 on get."); + } + } + + public void DimensionStateTest() { + Dimension DimensionTestA = new Dimension(0, null); + + if (DimensionTestA.GetLocation() != null) { + throw new System.ArgumentException("Test Failed: Dimension State Test expected null on get."); + } + + Location LocationB = new Location(State.Light, State.Dark, new int[] { 2, 2 }, 5); + Dimension DimensionTestB = new Dimension(0, LocationB); + + if (DimensionTestB.GetLocation() != LocationB) { + throw new System.ArgumentException("Test Failed: Dimension State Test expected LocationB on get."); + } + } + } +} \ No newline at end of file diff --git a/Location.cs b/Location.cs new file mode 100644 index 0000000..105bd34 --- /dev/null +++ b/Location.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlTypes; + +namespace N_Space { + public class Location { + private State? _present; + private State? _future; + private readonly int[] _coordinate; + private readonly List _neighbors; + + public Location(State? present, State? future, int[] coordinate, int maxSize) { + _present = present; + _future = future; + _coordinate = coordinate; + _neighbors = SetNeighborCoordinates(maxSize); + } + + public List GetNeighborCoodrinates() { + return _neighbors; + } + + private List SetNeighborCoordinates(int maxSize) { + List seed = new List(); + + seed.Add(_coordinate); + seed = IndexEvaluationTrain(seed, 0); + return RemoveUndesirableNeighbors(seed, maxSize); + } + + private List RemoveUndesirableNeighbors(List seed, int maxSize) { + bool shouldRemove; + foreach (int[] s in seed) { + shouldRemove = s.Equals(_coordinate); + if (!shouldRemove) { + foreach (int i in s) { + shouldRemove = i < 0 || i > maxSize; + } + } + if (shouldRemove) { + seed.Remove(s); + } + } + return seed; + } + + private List IndexEvaluationTrain(List seed, int index) { + if (index < _coordinate.Length) { + return IndexEvaluationTrain(CoordinateMutator(seed, index), index + 1); + } + return seed; + } + + private List CoordinateMutator(List currentList, int index) { + List result = new List(); + int[] mutations = new int[3]; + + mutations[0] = -1; + mutations[1] = 0; + mutations[2] = 1; + + for (int i = 1; i < currentList.Count; i++) { + for (int j = 0; j < mutations.Length; j++) { + int[] tempCopy = (int[])currentList[i].Clone(); + tempCopy[index] = tempCopy[index] + mutations[j]; + result.Add(tempCopy); + } + } + return result; + } + + public State? GetPresentState() { + return _present; + } + + public State? GetFutureState() { + return _future; + } + + public void SetPresentState(State? n) { + _present = n; + } + + public void SetFutureState(State? n) { + _future = n; + } + } +} \ No newline at end of file diff --git a/Location_Test.cs b/Location_Test.cs new file mode 100644 index 0000000..b3ca7e1 --- /dev/null +++ b/Location_Test.cs @@ -0,0 +1,173 @@ +using System.Collections.Generic; + +namespace N_Space { + public class Location_Test { + public void CreateLocationTest() { + Location locationA = new Location(State.Dark, State.Light, new int[]{2,2,2}, 5); + + if (locationA == null) { + throw new System.ArgumentException("Test Failed: Location created cannot be null."); + } + } + + public void GetNeighborhoodCoordinateTest() { + Location locationA = new Location(State.Dark, State.Light, new int[] { 2, 2 }, 5); + List testResultA = new List(); + int[] testResultArrayA; + + testResultArrayA = new int[] { 1, 1 }; + testResultA.Add(testResultArrayA); + testResultArrayA = new int[] { 1, 2 }; + testResultA.Add(testResultArrayA); + testResultArrayA = new int[] { 1, 3 }; + testResultA.Add(testResultArrayA); + testResultArrayA = new int[] { 2, 1 }; + testResultA.Add(testResultArrayA); + testResultArrayA = new int[] { 2, 3 }; + testResultA.Add(testResultArrayA); + testResultArrayA = new int[] { 3, 1 }; + testResultA.Add(testResultArrayA); + testResultArrayA = new int[] { 3, 2 }; + testResultA.Add(testResultArrayA); + testResultArrayA = new int[] { 3, 3 }; + testResultA.Add(testResultArrayA); + + if (!locationA.GetNeighborCoodrinates().Equals(testResultA)) { + throw new System.ArgumentException("Test Failed: 2D Location neighbors do not match known neighbors away from edges."); + } + + Location locationB = new Location(State.Dark, State.Light, new int[] { 0, 1 }, 5); + List testResultB = new List(); + int[] testResultArrayB; + + testResultArrayB = new int[] { 0, 0 }; + testResultB.Add(testResultArrayB); + testResultArrayB = new int[] { 0, 2 }; + testResultB.Add(testResultArrayB); + testResultArrayB = new int[] { 1, 0 }; + testResultB.Add(testResultArrayB); + testResultArrayB = new int[] { 1, 1 }; + testResultB.Add(testResultArrayB); + testResultArrayB = new int[] { 1, 2 }; + testResultB.Add(testResultArrayB); + + if (!locationB.GetNeighborCoodrinates().Equals(testResultB)) { + throw new System.ArgumentException("Test Failed: 2D Location neighbors do not match known neighbors near small edges."); + } + + Location locationC = new Location(State.Dark, State.Light, new int[] { 4, 5 }, 5); + List testResultC = new List(); + int[] testResultArrayC; + + testResultArrayC = new int[] { 3, 4 }; + testResultC.Add(testResultArrayC); + testResultArrayC = new int[] { 3, 5 }; + testResultC.Add(testResultArrayC); + testResultArrayC = new int[] { 4, 4 }; + testResultC.Add(testResultArrayC); + testResultArrayC = new int[] { 5, 4 }; + testResultC.Add(testResultArrayC); + testResultArrayC = new int[] { 5, 5 }; + testResultC.Add(testResultArrayC); + + if (!locationC.GetNeighborCoodrinates().Equals(testResultC)) { + throw new System.ArgumentException("Test Failed: 2D Location neighbors do not match known neighbors near large edges."); + } + + Location locationD = new Location(State.Dark, State.Light, new int[] { 1, 1, 1 }, 5); + List testResultD = new List(); + int[] testResultArrayD; + + testResultArrayD = new int[] { 0, 0, 0 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 0, 0, 1 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 0, 0, 2 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 0, 1, 0 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 0, 1, 1 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 0, 1, 2 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 0, 2, 0 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 0, 2, 1 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 0, 2, 2 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 1, 0, 0 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 1, 0, 1 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 1, 0, 2 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 1, 1, 0 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 1, 1, 2 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 1, 2, 0 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 1, 2, 1 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 1, 2, 2 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 2, 0, 0 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 2, 0, 1 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 2, 0, 2 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 2, 1, 0 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 2, 1, 1 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 2, 1, 2 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 2, 2, 0 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 2, 2, 1 }; + testResultD.Add(testResultArrayD); + testResultArrayD = new int[] { 2, 2, 2 }; + testResultD.Add(testResultArrayD); + + if (!locationD.GetNeighborCoodrinates().Equals(testResultD)) { + throw new System.ArgumentException("Test Failed: 3D Location neighbors do not match known neighbors away from edges."); + } + } + + public void GetFutureStateTest() { + Location locationA = new Location(State.Dark, State.Light, new int[] { 2, 2, 2 }, 5); + + if (locationA.GetFutureState() != State.Light) { + throw new System.ArgumentException("Test Failed: Location get future state expected Light."); + } + } + + public void GetPresentStateTest() { + Location locationA = new Location(State.Dark, State.Light, new int[] { 2, 2, 2 }, 5); + + if (locationA.GetPresentState() != State.Light) { + throw new System.ArgumentException("Test Failed: Location get present state expected Light."); + } + } + + public void SetFutureStateTest() { + Location locationA = new Location(State.Dark, State.Light, new int[] { 2, 2, 2 }, 5); + + locationA.SetFutureState(State.Dark); + if (locationA.GetFutureState() != State.Dark) { + throw new System.ArgumentException("Test Failed: Location set future state expected Dark."); + } + } + + public void SetPresentStateTest() { + Location locationA = new Location(State.Dark, State.Light, new int[] { 2, 2, 2 }, 5); + + locationA.SetPresentState(State.Dark); + if (locationA.GetPresentState() != State.Dark) { + throw new System.ArgumentException("Test Failed: Location get present state expected Dark."); + } + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..48fcc6f --- /dev/null +++ b/Program.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Game_Of_Life___Console{ + class Program{ + static void Main(string[] args){ + Console.WriteLine("Hello World!"); + Console.ReadKey(); + } + } +} \ No newline at end of file diff --git a/Region.cs b/Region.cs new file mode 100644 index 0000000..d0a6d1f --- /dev/null +++ b/Region.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace N_Space { + class Region { + private readonly State _default; + private readonly int _size; + private Dimension _progenerator; + + public Region(int dimensionSize) { + _default = State.Dark; + _size = dimensionSize; + } + + public void ChangeCoordinateState(int[] coordinates, State state) { + + } + + //private void AddDimension() + } +} diff --git a/Region_Test.cs b/Region_Test.cs new file mode 100644 index 0000000..7d9bcba --- /dev/null +++ b/Region_Test.cs @@ -0,0 +1,18 @@ +using System; +using System.CodeDom; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace N_Space{ + public class Region_Test{ + public void CreateRegionTestObject() { + Region regionCheck = new Region(0); + + if (regionCheck == null) { + throw new System.ArgumentException("Region created cannot be null"); + } + } + } +} diff --git a/State.cs b/State.cs new file mode 100644 index 0000000..b9d5e23 --- /dev/null +++ b/State.cs @@ -0,0 +1,6 @@ +namespace N_Space { + public enum State: byte { + Dark = 0, + Light = 1 + }; +} \ No newline at end of file