/// <summary > /// read seed into the array /// The seed specifies the location of each alive cell /// updateCells interprets the .seed file and formats it into an array that can be manipulated /// </ summary > /// /// <param name =" cells " > this is dynamic as parameters have diffrent data types</ param > public override int[,] updateCells(int[,] cells) { outBounds = false; try { for (int i = 1; i < textArray.Length - 1; i++) { cells[Int32.Parse(textArray[i].Split(" ")[0]), Int32.Parse(textArray[i].Split(" ")[1])] = 1; } } catch (Exception) { outBounds = true;// out of bound cells. } if (outBounds) { validate.invalid("WARNING: Some seed cells may be out of bounds"); } return(cells); }
/// <summary > /// updatecells() interprets the version2 .seed files. /// The seed file specifies 3 shapes: cell, rectangle and ellipse. /// The seed file can paint alive or dead cells. /// </ summary > /// <returns > the version2 seed as an integer matrix of 1s and 0s</ returns > public override int[,] updateCells(int[,] cells) { outBounds = false; try { for (int i = 1; i < readLine.Length; i++) { if (readLine[i].Contains("(o)")) { brush = 1; } else if (readLine[i].Contains("(x)")) { brush = 0; } if (readLine[i].Contains("cell")) { cell(ref cells, readLine[i].Split(" "), brush); } else if (readLine[i].Contains("rectangle")) { rectangle(ref cells, readLine[i].Split(" "), brush); } else if (readLine[i].Contains("ellipse")) { ellipse(ref cells, readLine[i].Split(" "), brush); } } } catch (Exception) { outBounds = true; //out of bound cells. } if (outBounds) { validate.invalid("WARNING: Some seed cells may be out of bounds"); } return(cells); }
/// <summary > /// Updates the game settings with user defined parameters. /// Iterates through the settings array and sets each one in order, /// by comparing it to the arguments array. /// Uses an exception to catch badly formatted parameters and /// The validation class to validate parameters. /// </ summary > /// <param name =" args " >String arguments that initialise the Game of Life settings</ param > public void set(string[] args) { int pos = -1; int parameterInt; double parameterDouble; foreach (string op in Options) //Sets each setting in the pre-defined order. { pos = Array.IndexOf(args, op); if (pos > -1) { try { switch (op) { case "--dimensions": //sets the dimensions of the universe... parameterInt = int.Parse(args[pos + 2]); if (validate.dimensions(parameterInt)) { columns = parameterInt; } parameterInt = int.Parse(args[pos + 1]); if (validate.dimensions(parameterInt)) { rows = parameterInt; } break; case "--periodic": //turn on periodic mode periodicBehavior = true; break; case "--random": //sets the likelyhood that a cell is born initially... parameterDouble = double.Parse(args[pos + 1]); if (validate.randomFactor(parameterDouble)) { randomFactor = parameterDouble; } break; case "--seed": //sets the path to .seed file if (validate.seed(args[pos + 1])) { seed = args[pos + 1]; } break; case "--generations": //sets the maximum number of generations... parameterInt = int.Parse(args[pos + 1]); if (validate.generations(parameterInt)) { generations = parameterInt; } break; case "--max-update": //sets the maximum rate of generations per second... parameterDouble = double.Parse(args[pos + 1]); if (validate.updateRate(parameterDouble)) { updateRate = parameterDouble; } break; case "--step": //turn on step mode stepMode = true; break; case "--neighbour": //sets neighbourhood type, order and centre cell switch readNeighbour(pos, args); break; case "--survival": //sets number of cells for survival readSB(pos, args, survival); break; case "--birth": //sets the number of cells for birth readSB(pos, args, birth); break; case "--memory": //Sets memory size parameterInt = int.Parse(args[pos + 1]); if (validate.memory(parameterInt)) { memory = parameterInt; } break; case "--output": //sets the path to output .seed file if (validate.seed(args[pos + 1])) { output = args[pos + 1]; } break; case "--ghost": //sets the path to output .seed file ghostMode = true; break; } } catch (Exception) //catches badly formatted parameters { validate.invalid(args[pos] + " has an invalid parameter"); } } } if (validate.success) //when all arguments are read correctly { Console.ForegroundColor = ConsoleColor.Green; centerText("Successfully read arguments"); } }