Example #1
0
        /// <summary>
        /// Index method
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IActionResult Index(SlotMachineModel model = null)
        {
            var bet = _slotmachine.GetNewBettingCoefficients();

            bet = CalculateBalance(model, bet);

            return(View(bet));
        }
Example #2
0
        public void TestCalculateProfit_Example()
        {
            SlotMachineModel testSlotMachine = new SlotMachineModel();
            ImageEntity      row1            = new ImageEntity
            {
                LeftSource       = ConstantsClass.SymbolImageSources[1],
                LeftCoefficent   = ConstantsClass.SymbolCoefficients[1],
                MiddleSource     = ConstantsClass.SymbolImageSources[0],
                MiddleCoefficent = ConstantsClass.SymbolCoefficients[0],
                RightSource      = ConstantsClass.SymbolImageSources[0],
                RightCoefficent  = ConstantsClass.SymbolCoefficients[0]
            };

            testSlotMachine.Sources[0] = row1;

            ImageEntity row2 = new ImageEntity
            {
                LeftSource       = ConstantsClass.SymbolImageSources[0],
                LeftCoefficent   = ConstantsClass.SymbolCoefficients[0],
                MiddleSource     = ConstantsClass.SymbolImageSources[0],
                MiddleCoefficent = ConstantsClass.SymbolCoefficients[0],
                RightSource      = ConstantsClass.SymbolImageSources[0],
                RightCoefficent  = ConstantsClass.SymbolCoefficients[0]
            };

            testSlotMachine.Sources[1] = row2;

            ImageEntity row3 = new ImageEntity
            {
                LeftSource       = ConstantsClass.SymbolImageSources[0],
                LeftCoefficent   = ConstantsClass.SymbolCoefficients[0],
                MiddleSource     = ConstantsClass.SymbolImageSources[2],
                MiddleCoefficent = ConstantsClass.SymbolCoefficients[2],
                RightSource      = ConstantsClass.SymbolImageSources[1],
                RightCoefficent  = ConstantsClass.SymbolCoefficients[1]
            };

            testSlotMachine.Sources[2] = row3;

            ImageEntity row4 = new ImageEntity
            {
                LeftSource       = ConstantsClass.SymbolImageSources[2],
                LeftCoefficent   = ConstantsClass.SymbolCoefficients[2],
                MiddleSource     = ConstantsClass.SymbolImageSources[0],
                MiddleCoefficent = ConstantsClass.SymbolCoefficients[0],
                RightSource      = ConstantsClass.SymbolImageSources[0],
                RightCoefficent  = ConstantsClass.SymbolCoefficients[0]
            };

            testSlotMachine.Sources[3] = row4;

            testSlotMachine.Bet     = 10;
            testSlotMachine.Balance = 200;

            _slotmachine.CalculateProfit(ref testSlotMachine);

            Assert.Equal(20, testSlotMachine.Won);
        }
Example #3
0
        public void IndexAction_ReturnsIndexView()
        {
            SlotMachineModel model = new SlotMachineModel();

            var result = _homecontroller.Index(model) as ViewResult;

            // Check for the type of IActionResult that is normally
            // returned from ASP.NET Core MVC Controller classes.
            Assert.IsAssignableFrom <ViewResult>(result);
        }
Example #4
0
    void OnReceivedResult(SlotMachineModel mo)
    {
        if (mo == null)
        {
            return;
        }

        for (int i = 0; i < slotMachineArr.Length; i++)
        {
            slotMachineArr[i].OnReceived(mo.dataArr[i]);
        }
    }
        /// <summary>
        /// GetNewBettingCoefficients method
        /// </summary>
        /// <returns></returns>
        public SlotMachineModel GetNewBettingCoefficients()
        {
            var imageSources = new SlotMachineModel();

            for (int i = 0; i < ConstantsClass.rowsNumber; i++)
            {
                var source = GetSource();

                imageSources.Sources[i] = source;
            }

            return(imageSources);
        }
        /// <summary>
        /// CalculateProfit method
        /// </summary>
        /// <param name="bet"></param>
        public void CalculateProfit(ref SlotMachineModel bet)
        {
            double profit = 0;

            foreach (var item in bet.Sources)
            {
                double sum = Math.Round(this.SumCoefficients(item), 2);

                switch (sum)
                {
                case 0.4:
                case 0.6:
                case 0.8:
                case 2.4:
                    profit += sum * bet.Bet;
                    break;

                case 1.2:
                    if (new List <double> {
                        item.LeftCoefficent, item.MiddleCoefficent, item.RightCoefficent
                    }
                        .Find(x => x == 0.8) != 0.8)
                    {
                        profit += sum * bet.Bet;
                    }
                    break;

                case 1.8:
                    if ((this.AllEqual(item.LeftCoefficent, item.MiddleCoefficent, item.RightCoefficent)))
                    {
                        profit += sum * bet.Bet;
                    }
                    break;

                case 1.6:
                    if (new List <double> {
                        item.LeftCoefficent, item.MiddleCoefficent, item.RightCoefficent
                    }
                        .Find(x => x == 0.4) != 0.4)
                    {
                        profit += sum * bet.Bet;
                    }
                    break;

                default:
                    break;
                }
            }

            bet.Won = Math.Round(profit, 2);
        }
Example #7
0
        /// <summary>
        /// CalculateBalance method
        /// </summary>
        /// <param name="model"></param>
        /// <param name="bet"></param>
        /// <returns></returns>
        private SlotMachineModel CalculateBalance(SlotMachineModel model, SlotMachineModel bet)
        {
            if (model.Bet != 0)
            {
                bet.Bet = model.Bet;

                _slotmachine.CalculateProfit(ref bet);

                bet.Balance       = ((model.Balance - model.Bet + bet.Won) >= 0) ? Math.Round((model.Balance - model.Bet + bet.Won), 2, MidpointRounding.AwayFromZero) : 0;
                bet.Bet           = (bet.Balance != 0) ? model.Bet : 0;
                bet.IsGameRunning = (bet.Balance != 0) ? model.IsGameRunning : false;
                bet.IsGameOver    = (bet.Balance == 0) ? true : false;
            }

            return(bet);
        }