// Fill in the board with the right numbers.  This can probably be done more intelligently than this.
        // Currently we just make sure that all the numbers are there.  9 of every number.  From here, we will
        // switch numbers...
        public void Init(Board board)
        {
            // Get the frequencies of numbers... Every number should be 9 times when filled in.
            var frequencies = board.GetFrequencies();

            _empty_squares = board.GetCurrentlyEmpty();
            foreach (var square in _empty_squares)
            {
                var constraints = square.GetConstraints();
                constraints.Update();
                _constraints.Add(constraints);
            }
            foreach (var square in _empty_squares)
            {
                var index = GetNextIndex(frequencies);
                square.SetValue(index + 1);
                frequencies[index]++;
            }
        }
示例#2
0
        /// <summary>
        /// マスの位置からメッシュを作成します。
        /// </summary>
        public override object ProvideValue(IServiceProvider service)
        {
            if (Squares == null)
            {
                if (SquaresText == null)
                {
                    throw new InvalidOperationException(
                              "SquareText and Squares are null.");
                }

                var trimmedText = SquaresText.RemoveQuote();
                Squares = SquareCollection.Parse(trimmedText);
            }

            if (Squares == null)
            {
                throw new InvalidOperationException(
                          "Squaresが設定されていません。");
            }

            return(CreateCellMesh(Squares, Widen));
        }
示例#3
0
        public static void Main()
        {
            var gracePeriod = new TimeSpan(1, 0, 0);
            var date        = DateTime.Now;
            var date1       = date.AddDays(-1);
            var date2       = date1 + TimeSpan.Parse("17:00");
            var date3       = date2 - gracePeriod;

            var aList = new ArrayList();

            //Example of Boxing
            for (var i = 1; i <= 10; i++)
            {
                aList.Add(i);
            }

            for (var i = 0; i < aList.Count; i++)
            {
                // Unboxing....
                var iV = (int)aList[i];
                WriteLine($"This is a list {i}={iV}");
            }

            //Better loop but also unboxing in i2
            foreach (var i2 in aList)
            {
                WriteLine($"{i2}");
            }

            //Better Use of Generics
            var bList = new List <int>();

            for (var i = 1; i <= 10; i++)
            {
                bList.Add(i);
                WriteLine($"Added {bList[i-1],-2:D} to bList position {i-1}");
            }


            //Generic LinkedList <T>
            var llList2 = new LinkedList <int>();

            llList2.AddLast(1);
            llList2.AddFirst(100);
            llList2.AddLast(10);

            foreach (var llint in llList2)
            {
                WriteLine($"{llint, -4} Item.");
            }

            var p1 = new Person();
            var p2 = new Person();

            p1.Name = "Dave";
            p2.Name = p1.Name;

            if (p1.CompareTo(p2) == 0)
            {
                p2.Name = "Chrissie";
            }

            /*
             * Covariance with classes
             */

            var s1 = new Shape
            {
                Width  = 101.45,
                Height = 25.25
            };

            WriteLine(s1.ToString());
            var q1 = new Square(s1.Width);

            WriteLine(q1.ToString());

            Shape s2 = s1.CreateSquare(s1.Width);

            WriteLine(s2.ToString());

            var ans = GiveIt("Do It ");

            WriteLine(ans);

            /*
             * Covariance with Generic Interfaces
             */

            IIndex <Square> squares = SquareCollection.GetReSquares();
            IIndex <Shape>  shapes  = squares;

            for (int i = 0; i < shapes.Count; i++)
            {
                WriteLine(shapes[i]);
            }

            var nShapeDisplay = new ShowShape();

            nShapeDisplay.Show(s1);
            IDisplay <Shape> nSqIDisplay = new ShowShape();
            var nBox = new Square(1.111);

            nSqIDisplay.Show(nBox);

            IDisplay <Shape>  iDisplayShape = new ShowShape();
            IDisplay <Square> iDisplaySq    = iDisplayShape;

            iDisplaySq.Show(q1);

            // Generic Struct
            Nullable <int> n;

            n = 1;
            if (n.HasValue)
            {
                WriteLine($"This is good. {n}");
            }

            int?n1 = 0;

            n1 = null;
            var msg = "";

            msg = (n1 == null ? $"n1 is null" : $"n1 is not null!");


            ReadKey();
        }
示例#4
0
 public Board()
 {
     squareCollection = SquareCollection.InitalizeEmpty(DIMENSION * DIMENSION);
 }
示例#5
0
 public static SquareCollection GetReSquares()
 {
     return(_sColl ?? (_sColl = new SquareCollection()));
 }