Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
    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();
            }
        }
    }
Ejemplo n.º 3
0
 public void OnValidate()
 {
     if (cells != null)
     {
         cellsList = cells.Cast <Cell>().ToList();
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <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());
        }
Ejemplo n.º 6
0
 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);
     //}
 }
Ejemplo n.º 7
0
 // 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());
 }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
        /// <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));
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
 private void OpenLast()
 {
     if (Cells.Cast <Cell>().Any(t => !t.IsOpen && !t.HasMine))
     {
         return;
     }
     if (Win != null)
     {
         Win(this, new EventArgs());
     }
 }
Ejemplo n.º 13
0
        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();
            }
        }
Ejemplo n.º 14
0
    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);
    }
Ejemplo n.º 15
0
 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();
 }
Ejemplo n.º 16
0
 bool CheckForTie()
 {
     return(grid.Cast <Cell>().Count(cell => cell.sign != 0) == _oldSize * _oldSize);
 }
Ejemplo n.º 17
0
 private bool IsDraw()
 {
     return(_grid.Cast <Cell>().All(c => c != Cell.Unowned));
 }
Ejemplo n.º 18
0
 public IEnumerable <Cell> GetCells()
 => grid.Cast <Cell>();
Ejemplo n.º 19
0
        private Cell[] GetRow(int row)
        {
            var offset = row * _size;

            return(_cells.Cast <Cell>().Skip(offset).Take(_size).ToArray());
        }
Ejemplo n.º 20
0
 public IEnumerable <Cell> GetInvalidCells()
 {
     return(matrix.Cast <Cell>().Select(x => x).Where(x => !x.IsValid));
 }
Ejemplo n.º 21
0
 public IEnumerator <Cell> GetEnumerator() => _content.Cast <Cell>().GetEnumerator();
Ejemplo n.º 22
0
 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());
 }
Ejemplo n.º 24
0
 public Cell GetStart()
 {
     return(_grid.Cast <Cell>().FirstOrDefault(cell => cell.Tipo == CellType.A));
 }