Exemple #1
0
 /// <summary> <!-- {{{1 --> Constructor
 /// </summary>
 /// <param name="idx"></param>
 public Cell(SudokuCellIndex idx)
 {
     idx.AssertWhenInvalid();
     this.index     = idx;
     this.candidate = new Candidates();
     this.value     = SudokuValue.NA;
 }
Exemple #2
0
 /// <summary> <!-- {{{1 --> Throw exception when specified different cell index.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="tgt"></param>
 public static void AssertWhenIndexNotEquals(this SudokuCellIndex self, SudokuCellIndex tgt)
 {
     if (!self.IsEquals(tgt))
     {
         var msg = string.Format("Different cell index: {0} != {1}", self.ToStr(), tgt.ToStr());
         throw new InvalidEnumArgumentException(msg);
     }
 }
Exemple #3
0
 /// <summary> <!-- {{{1 --> Throw exception when specified index is invalid.
 /// </summary>
 /// <param name="self"></param>
 public static void AssertWhenInvalid(this SudokuCellIndex self)
 {
     if (self.IsInvalid())
     {
         var msg = string.Format("Invalid cell index: {0}", self.ToStr());
         throw new ArgumentOutOfRangeException(msg);
     }
 }
Exemple #4
0
        /// <summary> <!-- {{{1 --> Convert from cell index to house index
        /// </summary>
        /// <param name="self"></param>
        /// <returns></returns>
        public static SudokuHouseIndex ToHouseIndex(this SudokuCellIndex self)
        {
            var row      = (int)self / 9;
            var col      = (int)self % 9;
            var houserow = row / 3;
            var housecol = col / 3;

            return((SudokuHouseIndex)(houserow * 3 + housecol));
        }
Exemple #5
0
        public void TestToHouseIndex()
        {
            var exps = new int[] {
                0, 0, 0, 1, 1, 1, 2, 2, 2,
                0, 0, 0, 1, 1, 1, 2, 2, 2,
                0, 0, 0, 1, 1, 1, 2, 2, 2,
                3, 3, 3, 4, 4, 4, 5, 5, 5,
                3, 3, 3, 4, 4, 4, 5, 5, 5,
                3, 3, 3, 4, 4, 4, 5, 5, 5,
                6, 6, 6, 7, 7, 7, 8, 8, 8,
                6, 6, 6, 7, 7, 7, 8, 8, 8,
                6, 6, 6, 7, 7, 7, 8, 8, 8
            }.Select(x => (SudokuHouseIndex)x);

            for (var i = 0; i < 81; i++)
            {
                tgt = (SudokuCellIndex)i;
                var ans = tgt.ToHouseIndex();
                var exp = exps.ElementAt(i);
                Assert.Equal(exp, ans);
            }
        }
Exemple #6
0
 /// <summary> <!-- {{{1 --> Convert the index to String
 /// </summary>
 /// <param name="self"></param>
 /// <returns></returns>
 public static string ToStr(this SudokuCellIndex self)
 {
     return(self.ToInt().ToString());
 }
Exemple #7
0
 /// <summary> <!-- {{{1 --> Convert the index to Integer
 /// </summary>
 /// <param name="self"></param>
 /// <returns></returns>
 public static int ToInt(this SudokuCellIndex self)
 {
     return((int)self);
 }
Exemple #8
0
 /// <summary> <!-- {{{1 --> Return true if the cells have same index.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="tgt"></param>
 /// <returns></returns>
 public static bool IsEquals(this SudokuCellIndex self, SudokuCellIndex tgt)
 {
     return(self == tgt);
 }
Exemple #9
0
 /// <summary> <!-- {{{1 --> Return true if the index is invalid.
 /// </summary>
 /// <param name="self"></param>
 /// <returns></returns>
 public static bool IsInvalid(this SudokuCellIndex self)
 {
     return((SudokuCellIndex.MIN > self) || (SudokuCellIndex.MAX < self));
 }
Exemple #10
0
 /// <summary> <!-- {{{1 --> Get cell from cell index
 /// </summary>
 /// <param name="idx"></param>
 /// <returns></returns>
 public Cell CellFromIndex(SudokuCellIndex idx)
 {
     idx.AssertWhenInvalid();
     return(this.board.ElementAt(idx.ToInt()));
 }
Exemple #11
0
 /// <summary> <!-- {{{1 --> teardown
 /// </summary>
 public void Dispose()
 {
     tgt = SudokuCellIndex.MIN;
 }
Exemple #12
0
 /// <summary> <!-- {{{1 --> Setup
 /// </summary>
 public TestCellExtension()
 {
     tgt = SudokuCellIndex.MIN;
 }