static void InitiateFloodFill(Cell cell, ref VoxelizationBounds bounds, BufferPool pool, ref CellSet occupiedCells, ref CellSet newlyFilledCells, ref CellList cellsToVisit) { //Check to make sure that this cell isn't already occupied before starting a new fill. if (occupiedCells.Contains(cell)) { return; } cellsToVisit.Add(cell, pool); while (cellsToVisit.Count > 0) { if (cellsToVisit.TryPop(out cell)) { if (!TryFloodFill(cell, ref bounds, pool, ref occupiedCells, ref newlyFilledCells, ref cellsToVisit)) { //The flood fill escaped the voxel bounds. Must be an open area; don't fill. cellsToVisit.Clear(); newlyFilledCells.Clear(); return; } } } //Flood fill completed without reaching the voxel bounds. Dump newly filled cells. for (int i = 0; i < newlyFilledCells.Count; ++i) { occupiedCells.Add(newlyFilledCells[i], pool); } newlyFilledCells.Clear(); }
public void Load(string sFileName) { if (!File.Exists(sFileName)) { return; } CellList.Clear(); // считать из файла string[] arLine = File.ReadAllLines(sFileName, Encoding.UTF8); // --- int iLineNum = 0; if (arLine[iLineNum++] != FileSignature) { return; } Width = Int32.Parse(arLine[iLineNum++]); Height = Int32.Parse(arLine[iLineNum++]); for (int ii = iLineNum; ii < arLine.Length; ii++) { ChessCell chessCell = new ChessCell(arLine[ii]); CellList.Add(chessCell); } }
/// <summary> /// 將指定的 BrailleWord 內容完整複製給自己。 /// </summary> /// <param name="brWord"></param> public void Copy(BrailleWord brWord) { if (brWord == null) { throw new ArgumentNullException("參數 brWord 不可為 null!"); } Text = brWord.Text; Language = brWord.Language; CellList.Clear(); foreach (BrailleCell brCell in brWord.CellList.Items) { CellList.Add(brCell); } PhoneticCode = brWord.PhoneticCode; IsPolyphonic = brWord.IsPolyphonic; IsContextTag = brWord.IsContextTag; IsConvertedFromTag = brWord.IsConvertedFromTag; ContextTag = brWord.ContextTag; ContextNames = brWord.ContextNames; /* * // 複製所有注音字根與點字串列, for 向下相容. * if (brWord.PhoneticCodes != null) * { * m_PhoneticCodes.Clear(); * m_PhoneticCodes.AddRange(brWord.PhoneticCodes); * m_ActivePhoneticIndex = brWord.ActivePhoneticIndex; * } */ }
private void AddCell(CellClass cell) { if (cell != null) // Is input a valid object? { // Yes. CellList.Add(cell); // Add the cell to the main list. _regionList[cell.Region].Add(cell); // Add the cell the corresponding region list. } else { throw new Exception("Cell cannot be null."); // TODO: Maybe add this to the event log instead? } }
public void AddCellsFromPositionNumbers(string positionNumberString) { if (String.IsNullOrEmpty(positionNumberString)) { return; } var numbers = positionNumberString.Split(' '); foreach (string num in numbers) { var cell = BrailleCell.GetInstanceFromPositionNumberString(num); CellList.Add(cell); } }
public GameViewModel(ArtificialIntelligence ai, Tetris game) { AI = ai; Game = game; Game.GameSpeed = 10; for (int x = 0; x < 10; x++) { CellList.Add(new ObservableCollection <Cell>()); for (int y = 21; y >= 0; y--) { CellList[x].Add(Game.Matrix[x, y]); } } }
/// <summary> /// 把指定的點字字串(16進位)轉成 BrailleCell 物件,並加入點字串列中。 /// </summary> /// <param name="brCodes">欲加入串列的點字碼 16 進位字串。</param> public void AddCells(string brCodes) { if (String.IsNullOrEmpty(brCodes)) { return; } for (int i = 0; i < brCodes.Length; i += 2) { string s = brCodes.Substring(i, 2); byte aByte = StrHelper.HexStrToByte(s); BrailleCell cell = BrailleCell.GetInstance(aByte); CellList.Add(cell); } }
public void AddCell(EvaluationOutdoorCell cell) { IOutdoorCell existedCell = _service.QueryCell(cell); if (existedCell == null) { existedCell = _service.QueryCell(cell); CellList.Add(cell); if (existedCell == null) { Region = new EvaluationRegion(CellList, EvaluationSettings.DistanceInMeter, EvaluationSettings.DegreeSpan); } Region.InitializeParameters(CellList, EvaluationSettings.DegreeSpan); } }
public void newfield() { CellList.Clear(); for (int i = 0; i <= Height; i++) { for (int j = 0; j <= Width; j++) { CCell Cell = new CCell() { xcoord = i, ycoord = j, bborder = false, lborder = false, rborder = false, tborder = false, type = EType.Ordinary }; //создание внешних границ if ((i == 0) || (i == Height)) { Cell.tborder = true; } if ((j == 0) || (j == Width)) { Cell.lborder = true; } if (i == (Height - 1)) { Cell.bborder = true; } if (j == (Width - 1)) { Cell.rborder = true; } CellList.Add(Cell); } } CellList[0].type = EType.Entry; CellList[CellList.Count - Width - 3].type = EType.Exit; borders(); //создание случайных границ bholes(); //создание "черных дыр" DrawingField(); //рисование поля DrawingBlackHoles(); //рисование черных дыр }
private void AdjustCells(NumberOfCells newCellValue) { //int currentCellsNumber = CellList.Count; int newValue = NumberOfCellsToInt(newCellValue); if (newValue == CellList.Count) { return; } if (newValue > CellList.Count) { // Thêm cells for (int i = CellList.Count; i < newValue; i++) { var cell = Factory.CreatePolyline(Drawing, GetCellDependencies(i)); cell.Name = "Cell" + (i + 1); cell.Style = DefaultStyles.StructureLineStyle; CellList.Add(cell); this.Children.Add(cell); this.Dependencies.Add(cell); cell.OnAddingToCanvas(Drawing.Canvas); cell.Selected = this.Selected; } } else { // Remove cell for (int i = CellList.Count; i > newValue; i--) { RemoveCell(); } } if (CellList == null) { return; } for (int i = 0; i < CellList.Count; i++) { CellList[i].Dependencies = GetCellDependencies(i); CellList[i].RecalculateAndUpdateVisual(); } }
private void h_FillCell3() { CellList.Clear(); for (int xx = 0; xx < Width; xx++) { for (int yy = 0; yy < Height; yy++) { Cell pCell = new Cell() { PositionX = xx, PositionY = yy, Value = EValue.Empty }; //if (xx == 1 && yy == 1) { // pCell.Value = EValue.X; //} CellList.Add(pCell); } } }
public static string Load(List <CellMap> CellList, string ReadPath) { try { using (StreamReader SR = new StreamReader(ReadPath, System.Text.Encoding.Default)) { if (CellList != null) { CellList.Clear(); } else { CellList = new List <CellMap>(); } string Line; int Index = 0; ReadPath = SR.ReadLine(); while ((Line = SR.ReadLine()) != null) { string[] Words = Line.Split(new char[] { ';' }); string[] Prop = new string[] { Words[2], Words[3], Words[4] }; CellList.Add(new CellMap(new AxialCoord(int.Parse(Words[0]), int.Parse(Words[1])), Prop)); Index++; } SR.Close(); } } catch (Exception er) { Console.WriteLine(er.Message); } return(ReadPath); }
/// <summary> /// Заполнение поля (создание клеток) заданного размера /// </summary> /// <param name="iW"></param> /// <param name="iH"></param> private void h_Fill(int iW, int iH) { EColor color = EColor.Black; for (int iX = 0; iX < iW; iX++) { for (int iY = 0; iY < iH; iY++) { if (color == EColor.Black) { color = EColor.White; } else { color = EColor.Black; } ChessCell pC = new ChessCell(iX, iY, color); CellList.Add(pC); } } }
private static bool TryFloodFill(Cell cell, ref VoxelizationBounds bounds, BufferPool pool, ref CellSet occupiedCells, ref CellSet newlyFilledCells, ref CellList cellsToVisit) { if (cell.X > bounds.X || cell.Y > bounds.Y || cell.Z > bounds.Z || cell.X < -1 || cell.Y < -1 || cell.Z < -1) { //We've escaped the world; the start location was not inside a closed section. Abandon the flood fill. return(false); } if (newlyFilledCells.Contains(cell) || occupiedCells.Contains(cell)) { //We already traversed this cell before or during the current flood fill. return(true); } var cellPool = pool.SpecializeFor <Cell>(); newlyFilledCells.Add(cell, cellPool, pool.SpecializeFor <int>()); cellsToVisit.Add(new Cell { X = cell.X, Y = cell.Y, Z = cell.Z - 1 }, cellPool); cellsToVisit.Add(new Cell { X = cell.X, Y = cell.Y, Z = cell.Z + 1 }, cellPool); cellsToVisit.Add(new Cell { X = cell.X, Y = cell.Y - 1, Z = cell.Z }, cellPool); cellsToVisit.Add(new Cell { X = cell.X, Y = cell.Y + 1, Z = cell.Z }, cellPool); cellsToVisit.Add(new Cell { X = cell.X - 1, Y = cell.Y, Z = cell.Z }, cellPool); cellsToVisit.Add(new Cell { X = cell.X + 1, Y = cell.Y, Z = cell.Z }, cellPool); return(true); }
private void FindAvalableCell(Cell cell) { Cell avalableCell; #region Haut-Droite if (cell.Position[0] == 0 && cell.Position[6] == 0) { avalableCell = cell.Pair ? matrix[cell.Id - 14] : matrix[cell.Id - 13]; if (avalableCell.End) { avalableCell.Parent = cell; find = true; return; } if (avalableCell.Walkable) { if (!avalableCell.InOpenList && !avalableCell.InClosedList) { avalableCell.Parent = cell; avalableCell.InOpenList = true; openList.Add(avalableCell); FixeCell(avalableCell, cell); } } } #endregion #region Bas-Droite if (cell.Position[2] == 0 && cell.Position[6] == 0) { avalableCell = cell.Pair ? matrix[cell.Id + 14] : matrix[cell.Id + 15]; if (avalableCell.End) { avalableCell.Parent = cell; find = true; return; } if (avalableCell.Walkable) { if (!avalableCell.InOpenList && !avalableCell.InClosedList) { avalableCell.Parent = cell; avalableCell.InOpenList = true; openList.Add(avalableCell); FixeCell(avalableCell, cell); } } } #endregion #region Haut-Gauche if (cell.Position[0] == 0 && cell.Position[4] == 0) { avalableCell = cell.Pair ? matrix[cell.Id - 15] : matrix[cell.Id - 14]; if (avalableCell.End) { avalableCell.Parent = cell; find = true; return; } if (avalableCell.Walkable) { if (!avalableCell.InOpenList && !avalableCell.InClosedList) { avalableCell.Parent = cell; avalableCell.InOpenList = true; openList.Add(avalableCell); FixeCell(avalableCell, cell); } } } #endregion #region Bas-Gauche if (cell.Position[2] == 0 && cell.Position[4] == 0) { avalableCell = cell.Pair ? matrix[cell.Id + 13] : matrix[cell.Id + 14]; if (avalableCell.End) { avalableCell.Parent = cell; find = true; return; } if (avalableCell.Walkable) { if (!avalableCell.InOpenList && !avalableCell.InClosedList) { avalableCell.Parent = cell; avalableCell.InOpenList = true; openList.Add(avalableCell); FixeCell(avalableCell, cell); } } } #endregion #region Droite if (cell.Position[6] == 0 && cell.Position[7] == 0 && useDiagonals) { avalableCell = matrix[cell.Id + 1]; if (avalableCell.End) { avalableCell.Parent = cell; find = true; return; } if (avalableCell.Walkable) { if (!avalableCell.InOpenList && !avalableCell.InClosedList) { avalableCell.Parent = cell; avalableCell.InOpenList = true; openList.Add(avalableCell); FixeCell(avalableCell, cell); } } } #endregion #region Gauche if (cell.Position[4] == 0 && cell.Position[5] == 0 && useDiagonals) { avalableCell = matrix[cell.Id - 1]; if (avalableCell.End) { avalableCell.Parent = cell; find = true; return; } if (avalableCell.Walkable) { if (!avalableCell.InOpenList && !avalableCell.InClosedList) { avalableCell.Parent = cell; avalableCell.InOpenList = true; openList.Add(avalableCell); FixeCell(avalableCell, cell); } } } #endregion #region Haut if (cell.Position[0] == 0 && cell.Position[1] == 0 && useDiagonals) { avalableCell = matrix[cell.Id - 28]; if (avalableCell.End) { avalableCell.Parent = cell; find = true; return; } if (avalableCell.Walkable) { if (!avalableCell.InOpenList && !avalableCell.InClosedList) { avalableCell.Parent = cell; avalableCell.InOpenList = true; openList.Add(avalableCell); FixeCell(avalableCell, cell); } } } #endregion #region Bas if (cell.Position[2] == 0 && cell.Position[3] == 0 && useDiagonals) { avalableCell = matrix[cell.Id + 28]; if (avalableCell.End) { avalableCell.Parent = cell; find = true; return; } if (avalableCell.Walkable) { if (!avalableCell.InOpenList && !avalableCell.InClosedList) { avalableCell.Parent = cell; avalableCell.InOpenList = true; openList.Add(avalableCell); FixeCell(avalableCell, cell); } } } #endregion SortOpenList(); }
public BrailleWord(string text, byte brCode) : this(text) { CellList.Add(BrailleCell.GetInstance(brCode)); }