From 629a4b06fbdb98b5016504e362f23f945ebf00ed Mon Sep 17 00:00:00 2001 From: neogeek23 Date: Sun, 8 Oct 2017 20:09:04 -0500 Subject: [PATCH] Update Location.cs --- N Space/Location.cs | 61 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/N Space/Location.cs b/N Space/Location.cs index 79497c8..447adff 100644 --- a/N Space/Location.cs +++ b/N Space/Location.cs @@ -1,6 +1,7 @@ -using System; +using System; using System.Collections.Generic; using System.Data.SqlTypes; +using System.Linq; namespace N_Space { public class Location { @@ -30,20 +31,42 @@ namespace N_Space { private List RemoveUndesirableNeighbors(List seed, int maxSize) { bool shouldRemove; - foreach (int[] s in seed) { - shouldRemove = s.Equals(_coordinate); + List indexToRemove = new List(); + + for (int i=0; i < seed.Count; i++) { + shouldRemove = IntArrayConentCompare(seed[i], _coordinate); if (!shouldRemove) { - foreach (int i in s) { - shouldRemove = i < 0 || i > maxSize; + foreach (int j in seed[i]) { + shouldRemove |= j < 0 || j > maxSize; } } if (shouldRemove) { - seed.Remove(s); + indexToRemove.Add(i); } } + + for (int i = indexToRemove.Count - 1; i >= 0; i--) { + seed.RemoveAt(indexToRemove[i]); + } + return seed; } + private bool IntArrayConentCompare(int[] array1, int[] array2) { + bool result = true; + + if (array1.Length == array2.Length) { + for (int i = 0; i < array1.Length; i++) { + result &= array1[i] == array2[i]; + if (!result) { + i = array1.Length; + } + } + } + + return result; + } + private List IndexEvaluationTrain(List seed, int index) { if (index < _coordinate.Length) { return IndexEvaluationTrain(CoordinateMutator(seed, index), index + 1); @@ -59,7 +82,7 @@ namespace N_Space { mutations[1] = 0; mutations[2] = 1; - for (int i = 1; i < currentList.Count; i++) { + for (int i = 0; i < currentList.Count; i++) { for (int j = 0; j < mutations.Length; j++) { int[] tempCopy = (int[])currentList[i].Clone(); tempCopy[index] = tempCopy[index] + mutations[j]; @@ -69,6 +92,30 @@ namespace N_Space { return result; } + public string NameNeighbors() { + string result = "{"; + for (int i = 0; i < _neighbors.Count; i++) { + string indexes = "["; + for (int j = 0; j < _neighbors[i].Length; j++) { + indexes += _neighbors[i][j].ToString(); + if (j == _neighbors[i].Length - 1) { + indexes += "]"; + } + else { + indexes += ","; + } + } + result += indexes; + if (i == _neighbors.Count - 1) { + result += "}"; + } + else { + result += ","; + } + } + return result; + } + public State? GetPresentState() { return _present; }