Ejemplo n.º 1
0
        public void TestGenerateSqareB()
        {
            Square squareA = SquareHelper.GenerateInitSqare();

            Square[] squares = new Square[] { squareA };
            Square   squareB = SquareHelper.GenerateMatchfieldRow1(squares);

            Assert.IsTrue(squareB.IsCorrectly());

            List <int> row1 = new List <int>();

            row1.AddRange(squareA.GetRowNumbers(SquareRow.Row1));
            row1.AddRange(squareB.GetRowNumbers(SquareRow.Row1));
            int count = row1.GroupBy(v => v).Count();

            Assert.AreEqual(6, count);

            List <int> row2 = new List <int>();

            row2.AddRange(squareA.GetRowNumbers(SquareRow.Row2));
            row2.AddRange(squareB.GetRowNumbers(SquareRow.Row2));
            count = row2.GroupBy(v => v).Count();

            Assert.AreEqual(6, count);

            List <int> row3 = new List <int>();

            row3.AddRange(squareA.GetRowNumbers(SquareRow.Row3));
            row3.AddRange(squareB.GetRowNumbers(SquareRow.Row3));
            count = row3.GroupBy(v => v).Count();

            Assert.AreEqual(6, count);
        }
Ejemplo n.º 2
0
 public TransactionResult ProcessTransaction(TransactionRequest request)
 {
     if (request.RequestType == TransactionRequestType.Payment)
     {
         return(SquareHelper.ProcessPayment(request, _squareSettings, _logger));
     }
     if (request.RequestType == TransactionRequestType.Refund)
     {
         return(SquareHelper.ProcessRefund(request, _squareSettings, _logger));
     }
     if (request.RequestType == TransactionRequestType.Void)
     {
         return(SquareHelper.ProcessVoid(request, _squareSettings, _logger));
     }
     if (request.RequestType == TransactionRequestType.Capture)
     {
         return(SquareHelper.ProcessCapture(request, _squareSettings, _logger));
     }
     if (request.RequestType == TransactionRequestType.SubscriptionCreate)
     {
         return(SquareHelper.CreateSubscription(request, _squareSettings, _logger));
     }
     if (request.RequestType == TransactionRequestType.SubscriptionCancel)
     {
         return(SquareHelper.StopSubscription(request, _squareSettings, _logger));
     }
     return(null);
 }
Ejemplo n.º 3
0
        public void TestGetPosibleNumbers()
        {
            int[]      a       = new int[] { 1, 2, 3 };
            List <int> possibe = SquareHelper.GetPosibleNumbers(a);

            Assert.AreEqual(6, possibe.Count);
        }
        public async Task <long> GetAmount(PaymentModel model)
        {
            var square       = new SquareHelper(GetSquareLocation(model.LocationId));
            var orderRequest = await GetOrderRequest(model, false);

            var squareOrder = await square.Client.OrdersApi.CreateOrderAsync(square.LocationId, orderRequest);

            return(squareOrder.Order.TotalMoney.Amount ?? 0);
        }
Ejemplo n.º 5
0
        public static Square[] GetSquares()
        {
            Square squareI = new Square();

            Square[] output = new Square[9];

            while (!squareI.IsCorrectly())
            {
                try
                {
                    Square squareA = SquareHelper.GenerateInitSqare();
                    output[0] = squareA;

                    Square[] squares = new Square[] { squareA };
                    Square   squareB = SquareHelper.GenerateMatchfieldRow1(squares);
                    output[1] = squareB;
                    Square squareD = SquareHelper.GenerateMatchfieldColumn1(squares);
                    output[3] = squareD;

                    squares = new Square[] { squareA, squareB };
                    Square squareC = SquareHelper.GenerateMatchfieldRow1(squares);
                    output[2] = squareC;

                    squares = new Square[] { squareA, squareD };
                    Square squareG = SquareHelper.GenerateMatchfieldColumn1(squares);
                    output[6] = squareG;

                    Square[] rows    = new Square[] { squareD };
                    Square[] columns = new Square[] { squareB };
                    Square   squareE = SquareHelper.GenerateSqare(rows, columns);
                    output[4] = squareE;

                    rows    = new Square[] { squareD, squareE };
                    columns = new Square[] { squareC };
                    Square squareF = SquareHelper.GenerateSqare(rows, columns);
                    output[5] = squareF;

                    rows    = new Square[] { squareG };
                    columns = new Square[] { squareB, squareE };
                    Square squareH = SquareHelper.GenerateSqare(rows, columns);
                    output[7] = squareH;

                    rows      = new Square[] { squareG, squareH };
                    columns   = new Square[] { squareC, squareF };
                    squareI   = SquareHelper.GenerateSqare(rows, columns);
                    output[8] = squareI;
                }
                catch (NoMoreSolution)
                {
                    squareI.Set(new int[9]);
                    output = new Square[9];
                }
            }

            return(output);
        }
        private async Task <CreateOrderRequest> GetOrderRequest(PaymentModel model, bool saveOrder)
        {
            var square = new SquareHelper(GetSquareLocation(model.LocationId));
            var taxes  = await square.GetTaxes();

            taxes = taxes ?? new List <CatalogObject>();
            var tax = await square.GetAdditiveTaxPercentage(taxes);

            _order = _handler.Submit(model.OrderType, model, tax, square.UseProduction, deferSave: !saveOrder);
            return(square.GetCreateOrderRequest(model, _order, Guid.NewGuid(), taxes));
        }
Ejemplo n.º 7
0
        public void TestGenerateSqareG()
        {
            Square squareA = SquareHelper.GenerateInitSqare();

            squareA.Set(new int[] { 5, 3, 4,
                                    6, 7, 2,
                                    1, 9, 8 });

            Square squareD = new Square();

            squareD.Set(new int[] { 8, 5, 9,
                                    4, 2, 6,
                                    7, 1, 3 });

            Square[] squares = new Square[] { squareA, squareD };

            Square squareG = SquareHelper.GenerateMatchfieldColumn1(squares);

            Assert.IsTrue(squareG.IsCorrectly());

            List <int> column1 = new List <int>();

            column1.AddRange(squareA.GetColumnNumbers(SquareColumn.Column1));
            column1.AddRange(squareD.GetColumnNumbers(SquareColumn.Column1));
            column1.AddRange(squareG.GetColumnNumbers(SquareColumn.Column1));
            int count = column1.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> column2 = new List <int>();

            column2.AddRange(squareA.GetColumnNumbers(SquareColumn.Column2));
            column2.AddRange(squareD.GetColumnNumbers(SquareColumn.Column2));
            column2.AddRange(squareG.GetColumnNumbers(SquareColumn.Column2));
            count = column2.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> column3 = new List <int>();

            column3.AddRange(squareA.GetColumnNumbers(SquareColumn.Column3));
            column3.AddRange(squareD.GetColumnNumbers(SquareColumn.Column3));
            column3.AddRange(squareG.GetColumnNumbers(SquareColumn.Column3));
            count = column3.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);
        }
Ejemplo n.º 8
0
        public void TestGenerateSqareC()
        {
            Square squareA = SquareHelper.GenerateInitSqare();

            squareA.Set(new int[] { 5, 3, 4,
                                    6, 7, 2,
                                    1, 9, 8 });

            Square squareB = SquareHelper.GenerateInitSqare();

            squareB.Set(new int[] { 6, 7, 8,
                                    1, 9, 5,
                                    3, 4, 2 });

            Square[] squares = new Square[] { squareA, squareB };

            Square squareC = SquareHelper.GenerateMatchfieldRow1(squares);

            Assert.IsTrue(squareC.IsCorrectly());

            List <int> row1 = new List <int>();

            row1.AddRange(squareA.GetRowNumbers(SquareRow.Row1));
            row1.AddRange(squareB.GetRowNumbers(SquareRow.Row1));
            row1.AddRange(squareC.GetRowNumbers(SquareRow.Row1));
            int count = row1.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> row2 = new List <int>();

            row2.AddRange(squareA.GetRowNumbers(SquareRow.Row2));
            row2.AddRange(squareB.GetRowNumbers(SquareRow.Row2));
            row2.AddRange(squareC.GetRowNumbers(SquareRow.Row2));
            count = row2.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> row3 = new List <int>();

            row3.AddRange(squareA.GetRowNumbers(SquareRow.Row3));
            row3.AddRange(squareB.GetRowNumbers(SquareRow.Row3));
            row3.AddRange(squareC.GetRowNumbers(SquareRow.Row3));
            count = row3.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);
        }
Ejemplo n.º 9
0
 public IActionResult SettingsSave(SettingsModel settingsModel)
 {
     _squareSettings.Description                   = settingsModel.Description;
     _squareSettings.SandboxApplicationId          = settingsModel.SandboxApplicationId;
     _squareSettings.SandboxAccessToken            = settingsModel.SandboxAccessToken;
     _squareSettings.AdditionalFee                 = settingsModel.AdditionalFee;
     _squareSettings.AuthorizeOnly                 = settingsModel.AuthorizeOnly;
     _squareSettings.EnableSandbox                 = settingsModel.EnableSandbox;
     _squareSettings.ApplicationId                 = settingsModel.ApplicationId;
     _squareSettings.AccessToken                   = settingsModel.AccessToken;
     _squareSettings.LocationId                    = settingsModel.LocationId;
     _squareSettings.UsePercentageForAdditionalFee = settingsModel.UsePercentageForAdditionalFee;
     _settingService.Save(_squareSettings, CurrentStore.Id);
     //reset settings
     SquareHelper.InitSquare(_squareSettings);
     return(R.Success.Result);
 }
Ejemplo n.º 10
0
 public IActionResult Webhook()
 {
     SquareHelper.ParseWebhookResponse(ApplicationEngine.CurrentHttpContext.Request);
     return(Ok());
 }
Ejemplo n.º 11
0
        public async Task <IActionResult> Pay(PaymentModel model)
        {
            var system   = new SystemModel(_settingHandler.GetAll());
            var settings = new SettingsModel(_azureSettings, _squareLocations, system, _context);

            try
            {
                if (!settings.IsOrderingOn)
                {
                    throw new Exception("Online ordering is temporarily disabled");
                }
                if (settings.IsBrickAndMortar && !settings.IsValidTimeForOnlineOrder)
                {
                    throw new Exception("Too late for online order");
                }

                if (!string.Equals(system.Settings[SettingName.IsOrderingOn], true.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("Online ordering is currently unavailable");
                }

                var square           = new SquareHelper(GetSquareLocation(model.LocationId));
                var isBrickAndMortar = string.Equals(system.Settings[SettingName.BrickAndMortarMode], true.ToString(), StringComparison.OrdinalIgnoreCase);
                var orderRequest     = await GetOrderRequest(model, true);

                var squareOrder = await square.Client.OrdersApi.CreateOrderAsync(square.LocationId, orderRequest);

                var note = $"ONLINE ORDER - ID: {_order.Id}";

                if (squareOrder.Order.TotalMoney.Amount == 0)
                {
                    _handler.TransactionApproved(_order.Id, string.Empty, "NO_PAYMENT");
                }
                else
                {
                    var paymentRequest = new CreatePaymentRequest(
                        amountMoney: squareOrder.Order.TotalMoney,
                        idempotencyKey: Guid.NewGuid().ToString(),
                        sourceId: model.Nonce,
                        verificationToken: model.BuyerVerificationToken,
                        buyerEmailAddress: model.Email,
                        orderId: squareOrder.Order.Id,
                        note: note);

                    var paymentResponse = await square.Client.PaymentsApi.CreatePaymentAsync(paymentRequest);

                    try
                    {
                        _order = _handler.TransactionApproved(_order.Id, paymentResponse.Payment.Id, paymentResponse.Payment.OrderId);
                        _order.SetFullText();
                    }
                    catch (Exception ex) // order and payment went through, there was a DB error
                    {
                        ex.Ship(this.HttpContext);
                        throw;
                    }
                }

                DoNotification(_order, system, settings.IsTextOn, model.Name);
                return(Ok());
            }
            catch (Exception ex)
            {
                Log(ex);
                return(new BadRequestObjectResult(ex.Message));
            }
        }
Ejemplo n.º 12
0
        public void UpdateForNewPosition()
        {
            const int duration = 400;

            this.UpdatePieceSizes();

            Storyboard animation = new Storyboard();

            animation.Duration = TimeSpan.FromMilliseconds(duration + 25);
            this.Resources.Add("tmpTimline" + this.currentAnimation++, animation);

            for (int i = 0; i < this.position.PieceList.Length; i++)
            {
                byte oldPieceLocation = 0xFF;
                if (this.oldPieceList != null)
                {
                    oldPieceLocation = this.oldPieceList[i];
                }

                byte newPieceLocation = this.position.PieceList[i];

                Piece oldPiece = oldPieceLocation != 0xFF ? this.pieces[this.oldBoard[oldPieceLocation]] : null;
                Piece newPiece = newPieceLocation != 0xFF ? this.pieces[this.position.Board[newPieceLocation]] : null;

                if (oldPieceLocation != newPieceLocation)
                {
                    if (newPieceLocation == 0xFF)
                    {
                        // Piece was captured
                        DoubleAnimation opacityAnimation = new DoubleAnimation();
                        Storyboard.SetTarget(opacityAnimation, oldPiece);
                        Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
                        opacityAnimation.Duration = TimeSpan.FromMilliseconds(duration);
                        opacityAnimation.To       = 0;

                        animation.Children.Add(opacityAnimation);
                    }
                    else if (oldPieceLocation == 0xFF)
                    {
                        // Piece was created (game reset, undo)

                        DoubleAnimation opacityAnimation = new DoubleAnimation();
                        Storyboard.SetTarget(opacityAnimation, newPiece);
                        Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
                        opacityAnimation.Duration = TimeSpan.FromMilliseconds(duration);
                        opacityAnimation.To       = 1;

                        Grid.SetRow(newPiece, SquareHelper.GetRow(newPieceLocation));
                        Grid.SetColumn(newPiece, SquareHelper.GetColumn(newPieceLocation));

                        animation.Children.Add(opacityAnimation);
                    }
                    else
                    {
                        if (oldPiece == newPiece)
                        {
                            // Piece just moved
                            Grid.SetRow(newPiece, SquareHelper.GetRow(newPieceLocation));
                            Grid.SetColumn(newPiece, SquareHelper.GetColumn(newPieceLocation));

                            DoubleAnimation yAnimation = new DoubleAnimation();
                            Storyboard.SetTarget(yAnimation, ((TransformGroup)newPiece.RenderTransform).Children[0]);
                            Storyboard.SetTargetProperty(yAnimation, new PropertyPath("Y"));

                            yAnimation.Duration = TimeSpan.FromMilliseconds(duration);
                            yAnimation.From     = (SquareHelper.GetRow(oldPieceLocation) - SquareHelper.GetRow(newPieceLocation)) * 100;
                            yAnimation.To       = 0;

                            animation.Children.Add(yAnimation);

                            DoubleAnimation xAnimation = new DoubleAnimation();
                            Storyboard.SetTarget(xAnimation, ((TransformGroup)newPiece.RenderTransform).Children[0]);
                            Storyboard.SetTargetProperty(xAnimation, new PropertyPath("X"));

                            xAnimation.Duration = TimeSpan.FromMilliseconds(duration);
                            xAnimation.From     = (SquareHelper.GetColumn(oldPieceLocation) - SquareHelper.GetColumn(newPieceLocation)) * 100;
                            xAnimation.To       = 0;

                            animation.Children.Add(xAnimation);
                        }
                        else
                        {
                            // Promotion
                            DoubleAnimation opacityAnimation = new DoubleAnimation();
                            Storyboard.SetTarget(opacityAnimation, newPiece);
                            Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
                            opacityAnimation.Duration = TimeSpan.FromMilliseconds(duration);
                            opacityAnimation.To       = 1;

                            Grid.SetRow(newPiece, SquareHelper.GetRow(newPieceLocation));
                            Grid.SetColumn(newPiece, SquareHelper.GetColumn(newPieceLocation));

                            animation.Children.Add(opacityAnimation);

                            opacityAnimation = new DoubleAnimation();
                            Storyboard.SetTarget(opacityAnimation, oldPiece);
                            Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
                            opacityAnimation.Duration = TimeSpan.FromMilliseconds(duration);
                            opacityAnimation.To       = 0;

                            animation.Children.Add(opacityAnimation);
                        }
                    }
                }
                else
                {
                    // TODO: what should be done here?
                }
            }

            // Workaround layout bug.
            this.LayoutRoot.Width--;
            this.LayoutRoot.Height++;

            animation.Completed += this.OnAnimationCompleted;
            animation.Begin();

            this.oldBoard     = new List <byte>(this.position.Board);
            this.oldPieceList = new List <byte>(this.position.PieceList);
            this.oldPieces    = new List <Piece>(this.pieces);
        }
Ejemplo n.º 13
0
        public void TestGenerateInitSqare()
        {
            Square square = SquareHelper.GenerateInitSqare();

            Assert.IsTrue(square.IsCorrectly());
        }
Ejemplo n.º 14
0
        public void TestGenerateSqareF()
        {
            Square squareA = SquareHelper.GenerateInitSqare();

            Square[] squares = new Square[] { squareA };
            Square   squareB = SquareHelper.GenerateMatchfieldRow1(squares);
            Square   squareD = SquareHelper.GenerateMatchfieldColumn1(squares);

            squares = new Square[] { squareA, squareB };
            Square squareC = SquareHelper.GenerateMatchfieldRow1(squares);

            squares = new Square[] { squareA, squareD };
            Square squareG = SquareHelper.GenerateMatchfieldColumn1(squares);

            Square[] rows    = new Square[] { squareD };
            Square[] columns = new Square[] { squareB };
            Square   squareE = SquareHelper.GenerateSqare(rows, columns);


            Trace.WriteLine($"{squareA.Get(SquarePlace.A)} {squareA.Get(SquarePlace.B)} {squareA.Get(SquarePlace.C)} | {squareB.Get(SquarePlace.A)} {squareB.Get(SquarePlace.B)} {squareB.Get(SquarePlace.C)} | {squareC.Get(SquarePlace.A)} {squareC.Get(SquarePlace.B)} {squareC.Get(SquarePlace.C)}");
            Trace.WriteLine($"{squareA.Get(SquarePlace.D)} {squareA.Get(SquarePlace.E)} {squareA.Get(SquarePlace.F)} | {squareB.Get(SquarePlace.D)} {squareB.Get(SquarePlace.E)} {squareB.Get(SquarePlace.F)} | {squareC.Get(SquarePlace.D)} {squareC.Get(SquarePlace.E)} {squareC.Get(SquarePlace.F)}");
            Trace.WriteLine($"{squareA.Get(SquarePlace.G)} {squareA.Get(SquarePlace.H)} {squareA.Get(SquarePlace.I)} | {squareB.Get(SquarePlace.G)} {squareB.Get(SquarePlace.H)} {squareB.Get(SquarePlace.I)} | {squareC.Get(SquarePlace.G)} {squareC.Get(SquarePlace.H)} {squareC.Get(SquarePlace.I)}");

            Trace.WriteLine("---------------------");
            Trace.WriteLine($"{squareD.Get(SquarePlace.A)} {squareD.Get(SquarePlace.B)} {squareD.Get(SquarePlace.C)} | {squareE.Get(SquarePlace.A)} {squareE.Get(SquarePlace.B)} {squareE.Get(SquarePlace.C)}");
            Trace.WriteLine($"{squareD.Get(SquarePlace.D)} {squareD.Get(SquarePlace.E)} {squareD.Get(SquarePlace.F)} | {squareE.Get(SquarePlace.D)} {squareE.Get(SquarePlace.E)} {squareE.Get(SquarePlace.F)}");
            Trace.WriteLine($"{squareD.Get(SquarePlace.G)} {squareD.Get(SquarePlace.H)} {squareD.Get(SquarePlace.I)} | {squareE.Get(SquarePlace.G)} {squareE.Get(SquarePlace.H)} {squareE.Get(SquarePlace.I)} ");
            Trace.WriteLine("---------------------");
            Trace.WriteLine($"{squareG.Get(SquarePlace.A)} {squareG.Get(SquarePlace.B)} {squareG.Get(SquarePlace.C)} |");
            Trace.WriteLine($"{squareG.Get(SquarePlace.D)} {squareG.Get(SquarePlace.E)} {squareG.Get(SquarePlace.F)} |");
            Trace.WriteLine($"{squareG.Get(SquarePlace.G)} {squareG.Get(SquarePlace.H)} {squareG.Get(SquarePlace.I)} |");


            rows    = new Square[] { squareD, squareE };
            columns = new Square[] { squareC };
            Square squareF = SquareHelper.GenerateSqare(rows, columns);

            Assert.IsTrue(squareF.IsCorrectly());

            Trace.WriteLine($"{squareA.Get(SquarePlace.A)} {squareA.Get(SquarePlace.B)} {squareA.Get(SquarePlace.C)} | {squareB.Get(SquarePlace.A)} {squareB.Get(SquarePlace.B)} {squareB.Get(SquarePlace.C)} | {squareC.Get(SquarePlace.A)} {squareC.Get(SquarePlace.B)} {squareC.Get(SquarePlace.C)}");
            Trace.WriteLine($"{squareA.Get(SquarePlace.D)} {squareA.Get(SquarePlace.E)} {squareA.Get(SquarePlace.F)} | {squareB.Get(SquarePlace.D)} {squareB.Get(SquarePlace.E)} {squareB.Get(SquarePlace.F)} | {squareC.Get(SquarePlace.D)} {squareC.Get(SquarePlace.E)} {squareC.Get(SquarePlace.F)}");
            Trace.WriteLine($"{squareA.Get(SquarePlace.G)} {squareA.Get(SquarePlace.H)} {squareA.Get(SquarePlace.I)} | {squareB.Get(SquarePlace.G)} {squareB.Get(SquarePlace.H)} {squareB.Get(SquarePlace.I)} | {squareC.Get(SquarePlace.G)} {squareC.Get(SquarePlace.H)} {squareC.Get(SquarePlace.I)}");
            Trace.WriteLine("---------------------");
            Trace.WriteLine($"{squareD.Get(SquarePlace.A)} {squareD.Get(SquarePlace.B)} {squareD.Get(SquarePlace.C)} | {squareE.Get(SquarePlace.A)} {squareE.Get(SquarePlace.B)} {squareE.Get(SquarePlace.C)} | {squareF.Get(SquarePlace.A)} {squareF.Get(SquarePlace.B)} {squareF.Get(SquarePlace.C)}");
            Trace.WriteLine($"{squareD.Get(SquarePlace.D)} {squareD.Get(SquarePlace.E)} {squareD.Get(SquarePlace.F)} | {squareE.Get(SquarePlace.D)} {squareE.Get(SquarePlace.E)} {squareE.Get(SquarePlace.F)} | {squareF.Get(SquarePlace.D)} {squareF.Get(SquarePlace.E)} {squareF.Get(SquarePlace.F)}");
            Trace.WriteLine($"{squareD.Get(SquarePlace.G)} {squareD.Get(SquarePlace.H)} {squareD.Get(SquarePlace.I)} | {squareE.Get(SquarePlace.G)} {squareE.Get(SquarePlace.H)} {squareE.Get(SquarePlace.I)} | {squareF.Get(SquarePlace.G)} {squareF.Get(SquarePlace.H)} {squareF.Get(SquarePlace.I)}");
            Trace.WriteLine("---------------------");
            Trace.WriteLine($"{squareG.Get(SquarePlace.A)} {squareG.Get(SquarePlace.B)} {squareG.Get(SquarePlace.C)} |");
            Trace.WriteLine($"{squareG.Get(SquarePlace.D)} {squareG.Get(SquarePlace.E)} {squareG.Get(SquarePlace.F)} |");
            Trace.WriteLine($"{squareG.Get(SquarePlace.G)} {squareG.Get(SquarePlace.H)} {squareG.Get(SquarePlace.I)} |");



            List <int> row1 = new List <int>();

            row1.AddRange(squareD.GetRowNumbers(SquareRow.Row1));
            row1.AddRange(squareE.GetRowNumbers(SquareRow.Row1));
            row1.AddRange(squareF.GetRowNumbers(SquareRow.Row1));
            int count = row1.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> row2 = new List <int>();

            row2.AddRange(squareD.GetRowNumbers(SquareRow.Row2));
            row2.AddRange(squareE.GetRowNumbers(SquareRow.Row2));
            row2.AddRange(squareF.GetRowNumbers(SquareRow.Row2));
            count = row2.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> row3 = new List <int>();

            row3.AddRange(squareD.GetRowNumbers(SquareRow.Row3));
            row3.AddRange(squareE.GetRowNumbers(SquareRow.Row3));
            row3.AddRange(squareF.GetRowNumbers(SquareRow.Row3));
            count = row3.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> column1 = new List <int>();

            column1.AddRange(squareC.GetColumnNumbers(SquareColumn.Column1));
            column1.AddRange(squareF.GetColumnNumbers(SquareColumn.Column1));
            count = column1.GroupBy(v => v).Count();

            Assert.AreEqual(6, count);

            List <int> column2 = new List <int>();

            column2.AddRange(squareC.GetColumnNumbers(SquareColumn.Column2));
            column2.AddRange(squareF.GetColumnNumbers(SquareColumn.Column2));
            count = column2.GroupBy(v => v).Count();

            Assert.AreEqual(6, count);

            List <int> column3 = new List <int>();

            column3.AddRange(squareC.GetColumnNumbers(SquareColumn.Column3));
            column3.AddRange(squareF.GetColumnNumbers(SquareColumn.Column3));
            count = column3.GroupBy(v => v).Count();

            Assert.AreEqual(6, count);
        }
Ejemplo n.º 15
0
        public void TestGenerateSqareI()
        {
            Square squareA = new Square();

            squareA.Set(new[] { 5, 3, 4, 6, 7, 2, 1, 9, 8 });
            Square squareB = new Square();

            squareB.Set(new[] { 6, 7, 8, 1, 9, 5, 3, 4, 2 });
            Square squareC = new Square();

            squareC.Set(new[] { 9, 1, 2, 3, 4, 8, 5, 6, 7 });
            Square squareD = new Square();

            squareD.Set(new[] { 8, 5, 9, 4, 2, 6, 7, 1, 3 });
            Square squareE = new Square();

            squareE.Set(new[] { 7, 6, 1, 8, 5, 3, 9, 2, 4 });
            Square squareF = new Square();

            squareF.Set(new[] { 4, 2, 3, 7, 9, 1, 8, 5, 6 });
            Square squareG = new Square();

            squareG.Set(new[] { 9, 6, 1, 2, 8, 7, 3, 4, 5 });
            Square squareH = new Square();

            squareH.Set(new[] { 5, 3, 7, 4, 1, 9, 2, 8, 6 });

            Square[] rows    = new Square[] { squareG, squareH };
            Square[] columns = new Square[] { squareC, squareF };

            Square squareI = new Square();

            squareI = SquareHelper.GenerateSqare(rows, columns);
            Assert.IsTrue(squareI.IsCorrectly());

            List <int> row1 = new List <int>();

            row1.AddRange(squareG.GetRowNumbers(SquareRow.Row1));
            row1.AddRange(squareH.GetRowNumbers(SquareRow.Row1));
            row1.AddRange(squareI.GetRowNumbers(SquareRow.Row1));
            int count = row1.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> row2 = new List <int>();

            row2.AddRange(squareG.GetRowNumbers(SquareRow.Row2));
            row2.AddRange(squareH.GetRowNumbers(SquareRow.Row2));
            row2.AddRange(squareI.GetRowNumbers(SquareRow.Row2));
            count = row2.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> row3 = new List <int>();

            row3.AddRange(squareG.GetRowNumbers(SquareRow.Row3));
            row3.AddRange(squareH.GetRowNumbers(SquareRow.Row3));
            row3.AddRange(squareI.GetRowNumbers(SquareRow.Row3));
            count = row3.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> column1 = new List <int>();

            column1.AddRange(squareC.GetColumnNumbers(SquareColumn.Column1));
            column1.AddRange(squareF.GetColumnNumbers(SquareColumn.Column1));
            column1.AddRange(squareI.GetColumnNumbers(SquareColumn.Column1));
            count = column1.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> column2 = new List <int>();

            column2.AddRange(squareC.GetColumnNumbers(SquareColumn.Column2));
            column2.AddRange(squareF.GetColumnNumbers(SquareColumn.Column2));
            column2.AddRange(squareI.GetColumnNumbers(SquareColumn.Column2));
            count = column2.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> column3 = new List <int>();

            column3.AddRange(squareC.GetColumnNumbers(SquareColumn.Column3));
            column3.AddRange(squareF.GetColumnNumbers(SquareColumn.Column3));
            column3.AddRange(squareI.GetColumnNumbers(SquareColumn.Column3));
            count = column3.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);
        }
Ejemplo n.º 16
0
        public void OnSquareClicked(int row, int column)
        {
            int square = SquareHelper.MakeSquare(row, column);

            List <ushort> validMoves = this.position.GenerateValidMoves();

            if (validMoves.Count == 0)
            {
                return;
            }

            if (this.previousSquareSelected == -1)
            {
                // Select a square
                if (this.position.Board[square] != Pieces.Empty)
                {
                    if ((this.position.Board[square] & 0x8) == position.ToMove)
                    {
                        this.squares[row][column].Highlight = true;
                        this.previousSquareSelected         = square;
//						this.StatusText = "Select square to move to";
                    }
                    else
                    {
//						this.StatusText = String.Format("You must select a {0} piece", position.ToMove == Pieces.White ? "White" : "Red");
                    }
                }
            }
            else if (this.previousSquareSelected == square)
            {
                // Deselect the square
                this.squares[row][column].Highlight = false;
                this.previousSquareSelected         = -1;
//				this.StatusText = "Select piece to move";
            }
            else
            {
                // Find a move
                int from = this.previousSquareSelected;
                int to   = square;

                ushort validMove = 0;
                foreach (ushort move in validMoves)
                {
                    if (MoveHelper.From(move) == from &&
                        MoveHelper.To(move) == to)
                    {
                        validMove = move;
                    }
                }

                if (validMove == 0)
                {
//					this.StatusText = "Invalid move!";
                    return;
                }

                this.squares[SquareHelper.GetRow(from)][SquareHelper.GetColumn(from)].Highlight = false;
                this.previousSquareSelected = -1;

                if (this.UserMove != null)
                {
                    this.UserMove(validMove);
                }
            }
        }
Ejemplo n.º 17
0
        public void TestGenerateSqare_Full()
        {
            Square squareA = new Square();
            Square squareB = new Square();
            Square squareC = new Square();
            Square squareD = new Square();
            Square squareE = new Square();
            Square squareF = new Square();
            Square squareG = new Square();
            Square squareH = new Square();
            Square squareI = new Square();

            while (!squareI.IsCorrectly())
            {
                try
                {
                    squareA = SquareHelper.GenerateInitSqare();

                    Square[] squares = new Square[] { squareA };
                    squareB = SquareHelper.GenerateMatchfieldRow1(squares);
                    squareD = SquareHelper.GenerateMatchfieldColumn1(squares);

                    squares = new Square[] { squareA, squareB };
                    squareC = SquareHelper.GenerateMatchfieldRow1(squares);

                    squares = new Square[] { squareA, squareD };
                    squareG = SquareHelper.GenerateMatchfieldColumn1(squares);

                    Square[] rows    = new Square[] { squareD };
                    Square[] columns = new Square[] { squareB };
                    squareE = SquareHelper.GenerateSqare(rows, columns);

                    rows    = new Square[] { squareD, squareE };
                    columns = new Square[] { squareC };
                    squareF = SquareHelper.GenerateSqare(rows, columns);

                    rows    = new Square[] { squareG };
                    columns = new Square[] { squareB, squareE };
                    squareH = SquareHelper.GenerateSqare(rows, columns);


                    rows    = new Square[] { squareG, squareH };
                    columns = new Square[] { squareC, squareF };


                    squareI = SquareHelper.GenerateSqare(rows, columns);
                }
                catch (NoMoreSolution)
                {
                    squareI.Set(new int[9]);
                    Trace.WriteLine("Restart");
                }
            }

            List <int> row1 = new List <int>();

            row1.AddRange(squareG.GetRowNumbers(SquareRow.Row1));
            row1.AddRange(squareH.GetRowNumbers(SquareRow.Row1));
            row1.AddRange(squareI.GetRowNumbers(SquareRow.Row1));
            int count = row1.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> row2 = new List <int>();

            row2.AddRange(squareG.GetRowNumbers(SquareRow.Row2));
            row2.AddRange(squareH.GetRowNumbers(SquareRow.Row2));
            row2.AddRange(squareI.GetRowNumbers(SquareRow.Row2));
            count = row2.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> row3 = new List <int>();

            row3.AddRange(squareG.GetRowNumbers(SquareRow.Row3));
            row3.AddRange(squareH.GetRowNumbers(SquareRow.Row3));
            row3.AddRange(squareI.GetRowNumbers(SquareRow.Row3));
            count = row3.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> column1 = new List <int>();

            column1.AddRange(squareC.GetColumnNumbers(SquareColumn.Column1));
            column1.AddRange(squareF.GetColumnNumbers(SquareColumn.Column1));
            column1.AddRange(squareI.GetColumnNumbers(SquareColumn.Column1));
            count = column1.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> column2 = new List <int>();

            column2.AddRange(squareC.GetColumnNumbers(SquareColumn.Column2));
            column2.AddRange(squareF.GetColumnNumbers(SquareColumn.Column2));
            column2.AddRange(squareI.GetColumnNumbers(SquareColumn.Column2));
            count = column2.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);

            List <int> column3 = new List <int>();

            column3.AddRange(squareC.GetColumnNumbers(SquareColumn.Column3));
            column3.AddRange(squareF.GetColumnNumbers(SquareColumn.Column3));
            column3.AddRange(squareI.GetColumnNumbers(SquareColumn.Column3));
            count = column3.GroupBy(v => v).Count();

            Assert.AreEqual(9, count);
        }