Example #1
0
 /// <summary> <!-- {{{1 --> Get cells from house index
 /// </summary>
 /// <param name="idx"></param>
 /// <returns></returns>
 public IEnumerable <Cell> CellsFromHouse(SudokuHouseIndex idx)
 {
     idx.AssertWhenInvalid();
     return(CellsFromRow(idx)
            .Concat(CellsFromCol(idx))
            .Concat(CellsFromBox(idx)));
 }
Example #2
0
 /// <summary> <!-- {{{1 --> Throw exception when specified index is invalid.
 /// </summary>
 /// <param name="self"></param>
 public static void AssertWhenInvalid(this SudokuHouseIndex self)
 {
     if (self.IsInvalid())
     {
         var msg = string.Format("Invalid house index: {0}", self.ToInt());
         throw new ArgumentOutOfRangeException(msg);
     }
 }
Example #3
0
        /// <summary> <!-- {{{1 --> Convert house index to cell indexes in box.
        /// </summary>
        /// <param name="self"></param>
        /// <returns></returns>
        public static IEnumerable <SudokuCellIndex> ToCellsIndexInBox(this SudokuHouseIndex self)
        {
            // calculate Top Left index in target Box
            var idx     = self.ToInt();
            int topleft = (27 * (idx / 3)) + (3 * (idx % 3));

            return(Enumerable.Range(0, 3)
                   .SelectMany(y => Enumerable.Range(0, 3)
                               .Select(x => (SudokuCellIndex)(topleft + x + 9 * y))));
        }
Example #4
0
 /// <summary> <!-- {{{1 --> Convert house index to cell indexes in column.
 /// </summary>
 /// <param name="self"></param>
 /// <returns></returns>
 public static IEnumerable <SudokuCellIndex> ToCellsIndexInCol(this SudokuHouseIndex self)
 {
     return(Enumerable.Range(0, 9)
            .Select(x => (SudokuCellIndex)(9 * x + self.ToInt())));
 }
Example #5
0
 /// <summary> <!-- {{{1 --> Convert house index to cell indexes in row.
 /// </summary>
 /// <param name="self"></param>
 /// <returns></returns>
 public static IEnumerable <SudokuCellIndex> ToCellsIndexInRow(this SudokuHouseIndex self)
 {
     return(SudokuCellIndexExtension.IndexList()
            .Skip(self.ToInt() * 9).Take(9));
 }
Example #6
0
 /// <summary> <!-- {{{1 --> Convert the house index to String
 /// </summary>
 /// <param name="self"></param>
 /// <returns></returns>
 public static string ToStr(this SudokuHouseIndex self)
 {
     return(self.ToInt().ToString());
 }
Example #7
0
 /// <summary> <!-- {{{1 --> Convert the house index to Integer
 /// </summary>
 /// <param name="self"></param>
 /// <returns></returns>
 public static int ToInt(this SudokuHouseIndex self)
 {
     return((int)self);
 }
Example #8
0
 /// <summary> <!-- {{{1 --> Return true if the index is invalid.
 /// </summary>
 /// <param name="self"></param>
 /// <returns></returns>
 public static bool IsInvalid(this SudokuHouseIndex self)
 {
     return((SudokuHouseIndex._1 > self) || (SudokuHouseIndex._9 < self));
 }
Example #9
0
 /// <summary> <!-- {{{1 --> Get cells from box index
 /// </summary>
 /// <param name="idx"></param>
 /// <returns></returns>
 public IEnumerable <Cell> CellsFromBox(SudokuHouseIndex idx)
 {
     idx.AssertWhenInvalid();
     return(idx.ToCellsIndexInBox().Select(x => this.board.ElementAt(x.ToInt())));
 }