public List<Cell> AdjacentsCells(Cell cell) { if (cell.AdjacentsCells == null) { // West cell.AdjacentsCells.Add(this.TranslatedCell(cell, -1, 0)); // East cell.AdjacentsCells.Add(this.TranslatedCell(cell, +1, 0)); // North cell.AdjacentsCells.Add(this.TranslatedCell(cell, 0, -1)); // South cell.AdjacentsCells.Add(this.TranslatedCell(cell, 0, +1)); cell.AdjacentsCells.RemoveAll(item => item == null); } return cell.AdjacentsCells; }
public List<Cell> CoveredCells(Cell centerCell, int radius) { List<Cell> result = new List<Cell>(); for (int dC = 0; dC <= radius; dC++) { for (int dR = 1; dR <= radius; dR++) { Cell coveredCell = this.TranslatedCell(centerCell, dC, dR); bool valid = coveredCell != null && this.CalcColumnDist(centerCell, coveredCell) <= radius; if (valid) { result.Add(coveredCell); result.Add(this.TranslatedCell(centerCell, -dR, dC)); result.Add(this.TranslatedCell(centerCell, dC, -dR)); result.Add(this.TranslatedCell(centerCell, dR, dC)); } } } return result; }
public void GetWinds() { for (int a = 0; a < Altitude; a += 1) { var rav = FileUtils.In[_line++].Split(' '); for (int r = 0; r < RowsCount; r += 1) { int caseV = 0; for (int c = 0; c < ColumnsCount; c += 1) { if (Cells[c, r] == null) { Cells[c, r] = new Cell { Column = c, Row = r }; } if (Cells[c, r].Winds == null) { Cells[c, r].Winds = new Dictionary<int, Wind>(); } Cells[c, r].Winds.Add(a, new Wind(int.Parse(rav[caseV++]), int.Parse(rav[caseV++]))); } } } }
public int CalcColumnDist(Cell source, Cell dest) { return Convert.ToInt32((Math.Pow(( Math.Pow((source.Row - dest.Row), 2) + Math.Min(Math.Abs(source.Column - dest.Column), ColumnsCount - Math.Abs(source.Column - dest.Column))), 2))); }
public Cell TranslatedCell(Cell startingCell, int tC, int tR) { int c = (startingCell.Column + tC) % this.ColumnsCount; int r = startingCell.Row + tR; return (r < 0 || r >= this.RowsCount) ? this.Cells[c, r] : null; }
public Balloon(Cell startCell) { this.CurrentAltitude = 0; this.StartCell = startCell; this.CurrentCell = startCell; }