public Cell RandomCellOrDefault(CellType type) { if (type == CellType.All) { return(_cells.Cast <Cell>().ToList()[Program.Rand(1, _cells.Length) - 1]); } List <Cell> randCells = _cells.Cast <Cell>().Where(cell => cell.Type == type).ToList(); return(randCells.Count > 0 ? randCells[Program.Rand(randCells.Count - 1)] : default(Cell)); }
private void CreateMaze() { // Make the initial cell the current cell and mark it as visited var currentCell = _cells[0, 0]; currentCell.Visited = true; // while any of the cells is unvisited while (_cells.Cast <Cell>().Any(x => !x.Visited)) { //If the current cell has any neighbours which have not been visited var neighbour = FindRandomNeighbours(currentCell); if (neighbour != null) { // Push the current cell to the stack _backTrackerStack.Push(currentCell); // Remove the wall between the current cell and the chosen cell RemoveWall(currentCell, neighbour); // Make the chosen cell the current cell and mark it as visited currentCell = neighbour; currentCell.Visited = true; } else if (_backTrackerStack.Count > 0) { currentCell = _backTrackerStack.Pop(); } } }
public void OnValidate() { if (cells != null) { cellsList = cells.Cast <Cell>().ToList(); } }
public object Solve() { var remaingCells = map.Cast <Cell>().ToList(); while (remaingCells.Count > 0) { remaingCells.Sort(); var currentCell = remaingCells[remaingCells.Count - 1]; remaingCells.RemoveAt(remaingCells.Count - 1); if (currentCell == map[N - 1, M - 1]) { break; } Debug.Assert(!double.IsInfinity(currentCell.TimeToGetThere)); foreach (var adjCell in currentCell.AdjacentCells) { var delay = GetTimeToMove(currentCell, adjCell); if (adjCell.TimeToGetThere > currentCell.TimeToGetThere + delay) { Debug.Assert(remaingCells.Contains(adjCell)); adjCell.TimeToGetThere = currentCell.TimeToGetThere + delay; } } } return(map[N - 1, M - 1].TimeToGetThere); }
/// <summary> /// Get moves count /// </summary> /// <returns>Moves count</returns> private int GetMovesCount() { var moves = from c in cells.Cast <Cell>() where c.ForeColor == firstColor || c.ForeColor == secondColor select c; return(moves.Count()); }
void showField() { fieldPanel.Controls.Clear(); cells.Cast <Cell>().AsParallel().ForAll(x => fieldPanel.Invoke(new Action(() => fieldPanel.Controls.Add(x)))); //foreach (var item in cells) //{ // fieldPanel.Controls.Add(item); //} }
// f**k this method public Cell NearestCell(Cell startCell, Predicate <Cell> predicate) { Cell[] matches = cells.Cast <Cell>().Where(c => predicate(c)).ToArray(); if (matches.Length == 0) { return(null); } return(matches.OrderBy(c => c.DistanceToCell(startCell)).FirstOrDefault()); }
public static int Part1(Cell[,] cells) { var changed = true; while (changed) { (cells, changed) = Model1.Step(cells); } return(cells.Cast <Cell>().Count(cell => cell == Cell.OccupiedSeat)); }
public void Step() { var next = new Cell[Width, Height]; for (var x = 0; x < Width; x++) { for (var y = 0; y < Height; y++) { next[x, y] = Next(x, y); } } if (SeatGrid.Cast <Cell>().SequenceEqual(next.Cast <Cell>())) { Stable = true; } SeatGrid = next; }
/// <summary> /// Runs the cellular automaton until it reaches equilibrium. /// </summary> /// <param name="mode">Decides which cells count as "seen" from any set of coordinates.</param> /// <param name="thresholdForOff">The amount of seen <see cref="Cell.On"/> cells for the <see cref="Cell.On"/> -> <see cref="Cell.Off"/> rule to kick in.</param> /// <returns>The number of <see cref="Cell.On"/> cells.</returns> public int RunUntilNoChange(CountingMode mode, int thresholdForOff) { var targetCache = BuildTargetCache(mode == CountingMode.Neighbour ? (Func <int, int, IEnumerable <(int x, int y)> >)AdjacentTargets : VisibleTargets); while (Step(targetCache, thresholdForOff)) { ; } return(map.Cast <Cell>().Count(c => c == Cell.On)); }
private static Cell[,] ToEnemyCells(this Cell[,] cells) { var enemyCells = new Cell[cells.GetLength(0), cells.GetLength(1)]; foreach (var cell in cells.Cast <Cell>()) { enemyCells[cell.X, cell.Y] = cell.ToEnemyCell(); } return(enemyCells); }
private void OpenLast() { if (Cells.Cast <Cell>().Any(t => !t.IsOpen && !t.HasMine)) { return; } if (Win != null) { Win(this, new EventArgs()); } }
private void newThread() { while (!stopGameThread) { List <Cell> cells = Playground.Cast <Cell>().ToList(); cells.ForEach(item => item.BackColor = (item.Lives) ? Color.Green : Color.Gray); Thread.Sleep((int)Stepsize.Value); calcnextturn(); } }
private IEnumerable <Vertex> GetOutline(IEnumerable <Vertex> outline1, IEnumerable <Vertex> outline2) { testCollider.points = outline1.Select(x => x.Coordinates).ToArray(); int count1 = Enemies.Count(x => testCollider.OverlapPoint(x.CurrentCell.Coordinates)); testCollider.points = outline2.Select(x => x.Coordinates).ToArray(); int count2 = Enemies.Count(x => testCollider.OverlapPoint(x.CurrentCell.Coordinates)); if (count1 > count2) { return(outline1); } if (count2 > count1) { return(outline2); } testCollider.points = outline1.Select(x => x.Coordinates).ToArray(); count1 = _cells.Cast <Cell>().Count(x => testCollider.OverlapPoint(x.Coordinates)); testCollider.points = outline2.Select(x => x.Coordinates).ToArray(); count2 = _cells.Cast <Cell>().Count(x => testCollider.OverlapPoint(x.Coordinates)); if (count1 > count2) { return(outline1); } if (count2 > count1) { return(outline2); } return(outline1); }
public Map(int fieldHeight, int fieldWidth) { _rowCount = fieldHeight; _colCount = fieldWidth; _gameField = new Cell[_rowCount, _colCount]; for (var row = 0; row < _rowCount; ++row) { for (var col = 0; col < _colCount; ++col) { _gameField[row, col] = new Cell(row, col, CellState.Unknown); } } _cells = _gameField.Cast <Cell>().ToList().AsReadOnly(); }
bool CheckForTie() { return(grid.Cast <Cell>().Count(cell => cell.sign != 0) == _oldSize * _oldSize); }
private bool IsDraw() { return(_grid.Cast <Cell>().All(c => c != Cell.Unowned)); }
public IEnumerable <Cell> GetCells() => grid.Cast <Cell>();
private Cell[] GetRow(int row) { var offset = row * _size; return(_cells.Cast <Cell>().Skip(offset).Take(_size).ToArray()); }
public IEnumerable <Cell> GetInvalidCells() { return(matrix.Cast <Cell>().Select(x => x).Where(x => !x.IsValid)); }
public IEnumerator <Cell> GetEnumerator() => _content.Cast <Cell>().GetEnumerator();
private static bool StillPlaying(Cell[,] board) { return(board.Cast <Cell>().ToList().Any(x => !x.Bomb && !x.Revealed)); }
/// <summary> /// Returns list of board cells /// </summary> public IEnumerable <Cell> GetListOfCells() { return(cells.Cast <Cell>().Where(cell => cell != null).ToList()); }
public Cell GetStart() { return(_grid.Cast <Cell>().FirstOrDefault(cell => cell.Tipo == CellType.A)); }