/// <summary> /// Gets the index of the ingredient. /// </summary> /// <param name="cellIdx">Index of the cell.</param> /// <param name="rowsCount">The rows count.</param> /// <param name="columnsCount">The columns count.</param> /// <param name="source">The source.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">source;null</exception> public static int GetCellIndex(int cellIdx, int rowsCount, int columnsCount, TravelSource source = TravelSource.TopLeft) { int rowIdx = cellIdx / columnsCount; int columnIdx = cellIdx % columnsCount; return(GetCellIndex(rowIdx, columnIdx, rowsCount, columnsCount, source)); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <param name="source">The source.</param> /// <param name="skip">The skip.</param> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the collection. /// </returns> public IEnumerable <PizzaCell> GetEnumerator(TravelSource source, int skip = 0) { for (int idx = skip; idx < Cells.Length; idx++) { yield return(Cells[GetCellIndex(idx, source)]); } /*for(int rowIdx = 0; rowIdx < Rows; rowIdx++) { * for(int columnIdx = 0; columnIdx < Columns; columnIdx++) { * yield return Cells[GetCellIndex(rowIdx, columnIdx, source)]; * } * }*/ }
/// <summary> /// Gets the cells. /// </summary> /// <param name="source">The source.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">source;null</exception> public PizzaCell[] GetCells(TravelSource source = TravelSource.TopLeft) { switch (source) { case TravelSource.TopLeft: return(Cells); case TravelSource.BottomRight: return(_bottomRight ?? (_bottomRight = GetEnumerator(source).ToArray())); case TravelSource.TopRight: return(_topRight ?? (_topRight = GetEnumerator(source).ToArray())); case TravelSource.BottomLeft: return(_bottomLeft ?? (_bottomLeft = GetEnumerator(source).ToArray())); default: throw new ArgumentOutOfRangeException("source", source, null); } }
/// <summary> /// Gets the cell. /// </summary> /// <param name="source">The source.</param> /// <returns></returns> public PizzaCell GetCell(TravelSource source) { switch (source) { case TravelSource.TopLeft: return(GetTopLeftCell()); case TravelSource.BottomRight: return(GetBottomRightCell()); case TravelSource.TopRight: return(GetTopRightCell()); case TravelSource.BottomLeft: return(GetBottomLeftCell()); default: throw new ArgumentOutOfRangeException("source", source, null); } }
/// <summary> /// Gets the cell. /// </summary> /// <param name="cellIdx">Index of the cell.</param> /// <param name="source">The source.</param> /// <returns></returns> public PizzaCell GetCell(int cellIdx, TravelSource source = TravelSource.TopLeft) { return(Cells.Get(cellIdx, RowsCount, ColumnsCount, source)); }
/// <summary> /// Gets the row. /// </summary> /// <param name="rowIdx">Index of the row.</param> /// <param name="source">The start.</param> /// <returns></returns> public IEnumerable <PizzaCell> GetRow(int rowIdx, TravelSource source = TravelSource.TopLeft) { return(Cells.GetRow(rowIdx, RowsCount, ColumnsCount, source)); }
/// <summary> /// Gets the cell. /// </summary> /// <param name="rowIdx">Index of the row.</param> /// <param name="columnIdx">Index of the column.</param> /// <param name="source">The source.</param> /// <returns></returns> public Ingredient GetIngredient(int rowIdx, int columnIdx, TravelSource source = TravelSource.TopLeft) { return(GetCell(rowIdx, columnIdx, source).Ingredient); }
/// <summary> /// Gets the index of the ingredient. /// </summary> /// <param name="cellIdx">Index of the cell.</param> /// <param name="source">The source.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">source;null</exception> public int GetCellIndex(int cellIdx, TravelSource source) { return(BoardExtensions.GetCellIndex(cellIdx, ColumnsCount, RowsCount, source)); }
/// <summary> /// Gets the index of the ingredient. /// </summary> /// <param name="rowIdx">Index of the row.</param> /// <param name="columnIdx">Index of the column.</param> /// <param name="rowsCount">The rows count.</param> /// <param name="columnsCount">The columns count.</param> /// <param name="source">The source.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException">source;null</exception> public static int GetCellIndex(int rowIdx, int columnIdx, int rowsCount, int columnsCount, TravelSource source = TravelSource.TopLeft) { switch (source) { case TravelSource.TopLeft: return((rowIdx * columnsCount) + columnIdx); case TravelSource.BottomRight: return(((rowsCount - 1 - rowIdx) * columnsCount) + (columnsCount - 1 - columnIdx)); case TravelSource.TopRight: return((rowIdx * columnsCount) + (columnsCount - 1 - columnIdx)); case TravelSource.BottomLeft: return(((rowsCount - 1 - rowIdx) * columnsCount) + columnIdx); default: throw new ArgumentOutOfRangeException("source", source, null); } }
/// <summary> /// Gets the specified column index. /// </summary> /// <typeparam name="TItem">The type of the item.</typeparam> /// <param name="items">The items.</param> /// <param name="idx">The index.</param> /// <param name="rowsCount">The rows count.</param> /// <param name="columnsCount">The columns count.</param> /// <param name="source">The source.</param> /// <returns></returns> public static TItem Get <TItem>(this IList <TItem> items, int idx, int rowsCount, int columnsCount, TravelSource source = TravelSource.TopLeft) { return(items[GetCellIndex(idx, rowsCount, columnsCount, source)]); }
/// <summary> /// Gets the row. /// </summary> /// <typeparam name="TItem">The type of the item.</typeparam> /// <param name="items">The items.</param> /// <param name="rowIdx">Index of the row.</param> /// <param name="rowsCount">The rows count.</param> /// <param name="columnsCount">The columns count.</param> /// <param name="source">The start.</param> /// <returns></returns> public static IEnumerable <TItem> GetRow <TItem>(this IList <TItem> items, int rowIdx, int rowsCount, int columnsCount, TravelSource source = TravelSource.TopLeft) { for (int columnIdx = 0; columnIdx < columnsCount; columnIdx++) { yield return(items[GetCellIndex(rowIdx, columnIdx, rowsCount, columnsCount, source)]); } }
/// <summary> /// Return cells orders from. /// </summary> /// <param name="cells">The cells.</param> /// <param name="source">The source.</param> /// <returns></returns> public static IEnumerable <PizzaCell> OrderFrom(this IEnumerable <PizzaCell> cells, TravelSource source) { switch (source) { case TravelSource.TopLeft: return(cells.OrderBy(c => c.Y).ThenBy(c => c.X)); case TravelSource.BottomRight: return(cells.OrderByDescending(c => c.Y).ThenByDescending(c => c.X)); case TravelSource.TopRight: return(cells.OrderBy(c => c.Y).ThenByDescending(c => c.X)); case TravelSource.BottomLeft: return(cells.OrderByDescending(c => c.Y).ThenBy(c => c.X)); default: throw new ArgumentOutOfRangeException("source", source, null); } }
/// <summary> /// Gets the top right point. /// </summary> /// <param name="cells">The cells.</param> /// <param name="source">The source.</param> /// <returns></returns> public static PizzaCell Get(this IEnumerable <PizzaCell> cells, TravelSource source) { return(cells.OrderFrom(source).First()); }