public static CellularAutomataWorld Create(int width, int height) { CellularAutomataWorld ToReturn = new CellularAutomataWorld(); if (height <= 0 || width <= 0) { throw new Exception("Height and/or Width was 0 or less than 0."); } ToReturn.WorldHeight = height; ToReturn.WorldWidth = width; int TotalCellCount = height * width; List <bool> NCells = new List <bool>(); int t = 1; for (t = 1; t <= TotalCellCount; t++) { bool NC = false; NCells.Add(NC); } ToReturn.Cells = NCells.ToArray(); ToReturn.RandomizeCells(); return(ToReturn); }
public static CellularAutomataWorld Load(bool[] cells, int width, int height) { if ((width * height) != cells.Length) { throw new Exception("Unable to load a Ceullular Automata world from those specifications. The number of cells in the world based on the width and height does not equal the cells provided."); } CellularAutomataWorld caw = new CellularAutomataWorld(); caw.Cells = cells; caw.WorldWidth = width; caw.WorldHeight = height; return(caw); }
/// <summary> /// Uses the Cellular Automata Game of Life Azure Function. /// </summary> /// <param name="world"></param> /// <returns></returns> public static async Task NextGenerationUsingCloudAsync(this CellularAutomataWorld world) { string json = JsonConvert.SerializeObject(world); StringContent sc = new StringContent(json); HttpClient hc = new HttpClient(); string url = "https://cellularautomatagol.azurewebsites.net/api/SimulateNextGeneration"; HttpResponseMessage hrm = await hc.PostAsync(url, sc); Stream s = await hrm.Content.ReadAsStreamAsync(); StreamReader sr = new StreamReader(s); JsonSerializer js = new JsonSerializer(); CellularAutomataWorld caw = (CellularAutomataWorld)js.Deserialize(sr, typeof(CellularAutomataWorld)); world.Cells = caw.Cells; }