Esempio n. 1
0
 public static int eval(this Game o, Draw d, GameType gt, PrizeCategory pc)
 {
     if(gt == GameType.Undefined || pc == PrizeCategory.Undefined)
         return 0;
     o.notNull(); d.notNull();
     return o.Playslips.Sum(playslip => eval((Playslip)playslip, d, gt, pc));
 }
Esempio n. 2
0
        /// <summary>
        /// Loads all of the prize files (.prz) in a folder.
        /// Files are assigned to an index in the list depending on their file name.
        /// Files that have names that are num numbers, ids that are too large, or ids that are too small will be skipped.
        /// </summary>
        /// <param name="folder">Path to the directory</param>
        /// <param name="category">Category for the folder</param>
        public static void LoadPrizeFolder(string folder, PrizeCategory category)
        {
            string[] files = Directory.GetFiles(folder, "*.prz");
            if (files.Length == 0)
            {
                return;
            }

            foreach (string file in files)
            {
                string fileName = Path.GetFileNameWithoutExtension(file);
                int    id;

                //Ensures that the filename is in the correct format
                if (!int.TryParse(fileName, out id))
                {
                    continue;
                }

                //Makes sure that the id is a valid value
                if (id >= Count || id < 0)
                {
                    continue;
                }

                Prize prize = Prize.FromFile(file, category, id);

                prizes[id] = prize;
            }
        }
Esempio n. 3
0
 public int hits(GameType g, PrizeCategory p, int intersect)
 {
     if(GameType.Super6 == g)
         return Super6Map.X[(byte)p, intersect];
     if(GameType.Spiel77 == g)
         return Spiel77Map.X[(byte)p, intersect];
     return 0;
 }
Esempio n. 4
0
 public int hits(int intersect, bool hasZusatzzahl, bool hasSuperzahl, PrizeCategory prizeCategory, byte  comboType)
 {
     var zz = hasZusatzzahl ? 1 : 0;
     var sz = hasSuperzahl ? 1 : 0;
     return 6 == intersect
                ? LottoMap.X[comboType, intersect, zz, sz, (int)prizeCategory]
                : LottoMap.X[comboType, intersect, zz, 0, (int) prizeCategory];
 }
Esempio n. 5
0
 public static int eval(this Board o, Draw d, PrizeCategory pc)
 {
     if(pc == PrizeCategory.Undefined)
         return 0;
     o.notNull();
     d.notNull();
     var intersect = o.AsArray.Intersect(d.Lotto).Count();
     return EvalUtil.hits(intersect, o.AsArray.Contains(d.Zz), o.Playslip.Sz == d.Sz, pc, o.Combo);
 }
Esempio n. 6
0
        /// <summary>Indica a maior medalha de um ruler em determinada categoria</summary>
        public static Medal getBest(Ruler ruler, PrizeCategory category)
        {
            Medal best = Medal.None;

            foreach (Winner winner in ruler.Prizes)
            {
                if (winner.Category != category)
                {
                    continue;
                }
                Medal medal = winner.Medal;
                if (medal < best)
                {
                    best = medal;
                }
            }

            return(best);
        }
Esempio n. 7
0
        /// <summary>
        /// Loads a Prize from a random file in a folder.
        /// Prize files must have the extension .prz.
        /// </summary>
        /// <param name="folder">Folder cotaining .prz files.</param>
        /// <param name="category">Category of the prize</param>
        /// <returns>Prize generated from the file if successful; default prize if unsuccessful</returns>
        public static Prize RandomFromFolder(string folder, PrizeCategory category)
        {
            try
            {
                string[] files = Directory.GetFiles(folder, "*.prz");
                if (files.Length == 0)
                {
                    return(new Prize());
                }

                string file = files[ran.Next(0, files.Length)];

                return(FromFile(file, category, int.Parse(Path.GetFileNameWithoutExtension(file))));
            }
            catch
            {
                return(new Prize());
            }
        }
Esempio n. 8
0
        public ActionResult AddPrizeCategory(PrizeCatValidation pcv)
        {
            if (ModelState.IsValid)
            {
                PrizeCategory pc = _uow.PrizeCategoryService.Get(o => o.Name == pcv.Name);
                if (pc == null)
                {
                    pc      = new PrizeCategory();
                    pc.Name = pcv.Name;
                    _uow.PrizeCategoryService.Add(pc);
                    _uow.Commit();

                    return(RedirectToAction("PrizeCategory"));
                }
                ModelState.AddModelError("", "类别已存在");
                return(View());
            }

            return(View());
        }
Esempio n. 9
0
 public static int eval(this Playslip o, Draw d, GameType gt, PrizeCategory pc)
 {
     if(gt == GameType.Undefined || pc == PrizeCategory.Undefined)
         return 0;
     o.notNull(); d.notNull();
     switch(gt) {
         case (GameType.Lotto649):
             if(pc <= PrizeCategory.VIII)
                 return o.Boards.Sum(board => board.eval(d, pc));
             break;
         case (GameType.Spiel77):
             if(o.IsS77 && pc <= PrizeCategory.VII)
                 return EvalUtil.hits(gt, pc, o.Nr.AsSpiel77.rightToLeft(d.Spiel77));
             break;
         case (GameType.Super6):
             if(o.IsS6 && pc <= PrizeCategory.VI)
                 return EvalUtil.hits(gt, pc, o.Nr.AsSuper6.rightToLeft(d.Super6));
             break;
     }
     return 0;
 }
Esempio n. 10
0
        /// <summary>
        /// Loads a Prize from a file.
        /// </summary>
        /// <param name="file">Path to the prize file</param>
        /// <param name="category">Category of the prize</param>
        /// <returns>Prize generated from the file if successful; default prize if unsuccessful</returns>
        public static Prize FromFile(string file, PrizeCategory category, int id)
        {
            try
            {
                Prize result = new Prize();
                using (StreamReader reader = new StreamReader(file))
                {
                    result.display = new string[DISPLAY_HEIGHT];
                    StringBuilder line = new StringBuilder();
                    for (int i = 0; i < DISPLAY_HEIGHT; i++)
                    {
                        line.Append(reader.ReadLine());

                        while (line.Length < DISPLAY_WIDTH)
                        {
                            line.Append(' ');
                        }

                        result.display[i] = line.ToString().Substring(0, DISPLAY_WIDTH);
                        line.Clear();
                    }

                    result.name        = reader.ReadLine();
                    result.description = reader.ReadLine();
                    result.price       = reader.ReadLine();
                    result.category    = category;
                    result.id          = id;
                }

                return(result);
            }
            catch
            {
                return(new Prize());
            }
        }
Esempio n. 11
0
        /// <summary>Indica a maior medalha de um ruler em determinada categoria</summary>
        public static Medal getBest( Ruler ruler, PrizeCategory category )
        {
            Medal best = Medal.None;

            foreach( Winner winner in ruler.Prizes ) {
                if( winner.Category != category ) {
                    continue;
                }
                Medal medal = winner.Medal;
                if( medal < best ) {
                    best = medal;
                }
            }

            return best;
        }
Esempio n. 12
0
 public static int hits(GameType g, PrizeCategory p, int intersect)
 {
     return impl.hits(g, p, intersect);
 }
Esempio n. 13
0
 public static int hits( int intersect, bool hasZz, bool hasSz, PrizeCategory prizeCategory, byte comboType)
 {
     verify();
     return impl.hits(intersect, hasZz, hasSz, prizeCategory, comboType);
 }