private void SaveHexagonalGrid(Grid grid, FileStream fs, StringBuilder bits) { fs.WriteByte(1); #if LOG logger.AppendLine("Grid type : hexagonal = 1"); #endif HexagonalGrid hexa = (HexagonalGrid)grid; WriteGridProperties(hexa, fs); bits.Append(hexa.Cells[0].Alive ? '1' : '0'); for (int i = 1; i < hexa.Cells.Length; i++) { bits.Append(hexa.Cells[i].Alive ? '1' : '0'); if (i % sizeof(long) == 0) { string binary = bits.ToString().Reverse(); byte octopus = Convert.ToByte(binary, 2); fs.WriteByte(octopus); #if LOG logger.AppendLine("Bits { " + binary + " } = " + octopus); #endif bits.Clear(); } } }
private HexagonalGrid LoadHexagonalGrid(FileStream fs) { int width = fs.ReadByte(); int height = fs.ReadByte(); int gridArea = width * height; int iteration = ReadGridIteration(fs); int sequenceLength = width * height / sizeof(long); #if LOG logger.AppendLine("width : " + width); logger.AppendLine("height : " + height); logger.AppendLine("seq. length = " + sequenceLength); logger.AppendLine("area : " + gridArea); logger.AppendLine("iteration : " + iteration); #endif List <int> cellsLifeStates = GetCellsLifeState(fs, sequenceLength); #if LOG File.WriteAllText("log.txt", logger.ToString()); #endif List <HexagonalCell> cells = CreateHexagonalCells(width, gridArea, cellsLifeStates); HexagonalGrid hexa = new HexagonalGrid(new Vector2D(width, height), cells.ToArray(), iteration); SetCellsParent(hexa); return(hexa); }
private HexagonalGrid LoadHexagonalGrid(FileStream fs) { int width = fs.ReadByte(); int height = fs.ReadByte(); int gridArea = width * height; int iteration = ReadGridIteration(fs); int sequenceLength = width * height / sizeof(long); #if LOG logger.AppendLine("width : " + width); logger.AppendLine("height : " + height); logger.AppendLine("seq. length = " + sequenceLength); logger.AppendLine("area : " + gridArea); logger.AppendLine("iteration : " + iteration); #endif List<int> cellsLifeStates = GetCellsLifeState(fs, sequenceLength); #if LOG File.WriteAllText("log.txt", logger.ToString()); #endif List<HexagonalCell> cells = CreateHexagonalCells(width, gridArea, cellsLifeStates); HexagonalGrid hexa = new HexagonalGrid(new Vector2D(width, height), cells.ToArray(), iteration); SetCellsParent(hexa); return hexa; }