Пример #1
0
        public WinnerModel GetWinner(Dictionary <int, string> board)
        {
            var winner         = new WinnerModel();
            var squaresToCheck = new List <int[]>
            {
                // Horizontal
                new int[] { 1, 2, 3 },
                new int[] { 4, 5, 6 },
                new int[] { 7, 8, 9 },

                // Vertical
                new int[] { 1, 4, 7 },
                new int[] { 2, 5, 8 },
                new int[] { 3, 6, 9 },

                // Diagonal
                new int[] { 1, 5, 9 },
                new int[] { 7, 5, 3 }
            };

            foreach (var squares in squaresToCheck)
            {
                winner = CheckBoardForWinner(squares, board);
                if (winner.HasWon)
                {
                    return(winner);
                }
            }

            return(winner);
        }
Пример #2
0
 private WinnerDbo Winner(WinnerModel model)
 {
     return(new WinnerDbo()
     {
         FirstName = model.FirstName,
         LastName = model.LastName,
         Prize = model.Prize
     });
 }
Пример #3
0
        public WinnerModel CheckWinner()
        {
            var winner      = _boardService.CheckWinner();
            var winnerModel = new WinnerModel()
            {
                Winner = winner
            };

            return(winnerModel);
        }
Пример #4
0
        // GET: Vote/Edit/5
        public ActionResult Winner()
        {
            var voters  = _voteRep.GetAllVotes();
            var winners = _voteCalculator.CalculateWinner(voters).ToList();
            var emails  = voters.Select(v => v.Email).ToList();

            WinnerModel model = new WinnerModel();

            model.Locations          = winners;
            model.VotersWhoHaveVoted = emails;

            return(View(model));
        }
Пример #5
0
        private WinnerModel CheckBoardForWinner(int[] squares, Dictionary <int, string> board)
        {
            var winner = new WinnerModel();

            var a = board[squares[0]];
            var b = board[squares[1]];
            var c = board[squares[2]];

            if (a.Equals(string.Empty))
            {
                return(winner);
            }

            if (a == b && a == c)
            {
                winner.HasWon = true;

                Enum.TryParse(board[squares[0]], out Player player);
                winner.Player = player;
            }

            return(winner);
        }
Пример #6
0
        public List <WinnerModel> CheckWinners()
        {
            List <WinnerModel> winners = new List <WinnerModel>();
            var session      = _sessionRepository.GetAll().LastOrDefault();
            var luckyNumbers = Draw();

            var numbers = _ticketRepository.GetAll()
                          .Where(x => x.Session == session.Id)
                          .Select(x => new TicketModel()
            {
                UserId  = x.UserId,
                Session = x.Session,
                Numbers = x.Numbers.Split(',').Select(Int32.Parse).ToList()
            });

            foreach (var num in numbers)
            {
                var check = num.Numbers.Intersect(luckyNumbers).ToList();
                if (check.Count == 3)
                {
                    WinnerModel model = new WinnerModel()
                    {
                        FirstName = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).FirstName,
                        LastName  = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).LastName,
                        Prize     = Enum.GetName(typeof(Prizes), 5)
                    };
                    winners.Add(model);
                    _winnerRepository.Add(Winner(model));
                }
                else if (check.Count == 4)
                {
                    WinnerModel model = new WinnerModel()
                    {
                        FirstName = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).FirstName,
                        LastName  = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).LastName,
                        Prize     = Enum.GetName(typeof(Prizes), 4)
                    };
                    winners.Add(model);
                    _winnerRepository.Add(Winner(model));
                }
                else if (check.Count == 5)
                {
                    WinnerModel model = new WinnerModel()
                    {
                        FirstName = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).FirstName,
                        LastName  = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).LastName,
                        Prize     = Enum.GetName(typeof(Prizes), 3)
                    };
                    winners.Add(model);
                    _winnerRepository.Add(Winner(model));
                }
                else if (check.Count == 6)
                {
                    WinnerModel model = new WinnerModel()
                    {
                        FirstName = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).FirstName,
                        LastName  = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).LastName,
                        Prize     = Enum.GetName(typeof(Prizes), 2)
                    };
                    winners.Add(model);
                    _winnerRepository.Add(Winner(model));
                }
                else if (check.Count == 7)
                {
                    WinnerModel model = new WinnerModel()
                    {
                        FirstName = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).FirstName,
                        LastName  = _userRepository.GetAll().FirstOrDefault(x => x.Id == num.UserId).LastName,
                        Prize     = Enum.GetName(typeof(Prizes), 1)
                    };
                    winners.Add(model);
                    _winnerRepository.Add(Winner(model));
                }
            }
            return(winners);
        }