Add files via upload

This is this starting of the layout of Conway's Life game.  I'm trying to make it so that having different states is as easy as just adding them to State.cs and that any number of dimensions should be handled quickly.  Visualizing higher dimensional life games might be tricky, but this should be able to determine it.
This commit is contained in:
neogeek23 2017-09-29 02:22:00 -05:00 committed by GitHub
parent 344f7145a5
commit 92fa0de002
8 changed files with 440 additions and 0 deletions

46
Dimension.cs Normal file
View File

@ -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<Dimension> _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<Dimension>();
}
_child.Add(child);
_child.Sort((x, y) => x._index.CompareTo(y._index));
}
public int GetIndex() {
return _index;
}
public Dimension GetParent() {
return _parent;
}
public List<Dimension> GetChildList() {
return _child;
}
public Location GetLocation() {
return _location;
}
}
}

71
Dimension_Test.cs Normal file
View File

@ -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.");
}
}
}
}

88
Location.cs Normal file
View File

@ -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<int[]> _neighbors;
public Location(State? present, State? future, int[] coordinate, int maxSize) {
_present = present;
_future = future;
_coordinate = coordinate;
_neighbors = SetNeighborCoordinates(maxSize);
}
public List<int[]> GetNeighborCoodrinates() {
return _neighbors;
}
private List<int[]> SetNeighborCoordinates(int maxSize) {
List<int[]> seed = new List<int[]>();
seed.Add(_coordinate);
seed = IndexEvaluationTrain(seed, 0);
return RemoveUndesirableNeighbors(seed, maxSize);
}
private List<int[]> RemoveUndesirableNeighbors(List<int[]> 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<int[]> IndexEvaluationTrain(List<int[]> seed, int index) {
if (index < _coordinate.Length) {
return IndexEvaluationTrain(CoordinateMutator(seed, index), index + 1);
}
return seed;
}
private List<int[]> CoordinateMutator(List<int[]> currentList, int index) {
List<int[]> result = new List<int[]>();
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;
}
}
}

173
Location_Test.cs Normal file
View File

@ -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<int[]> testResultA = new List<int[]>();
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<int[]> testResultB = new List<int[]>();
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<int[]> testResultC = new List<int[]>();
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<int[]> testResultD = new List<int[]>();
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.");
}
}
}
}

14
Program.cs Normal file
View File

@ -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();
}
}
}

24
Region.cs Normal file
View File

@ -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()
}
}

18
Region_Test.cs Normal file
View File

@ -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");
}
}
}
}

6
State.cs Normal file
View File

@ -0,0 +1,6 @@
namespace N_Space {
public enum State: byte {
Dark = 0,
Light = 1
};
}