コード例 #1
0
        private Bua TaoBua()
        {
            Bua b = new Bua();

            for (int i = 0; i < 3; i++)
            {
                MON tmp = TaoMon();
                while (b.Mon.IndexOf(tmp) != -1)
                {
                    tmp = TaoMon();
                }
                b.Mon.Add(tmp);
            }
            return(b);
        }
コード例 #2
0
        private void TraNguyenLieu(MON x)
        {
            List <CONGTHUCMON> tmp = db.CONGTHUCMONs.Where(a => a.IDMon == x.ID).ToList();

            for (int i = 0; i < tmp.Count(); i++)
            {
                foreach (var t in nguyenlieu)
                {
                    if (tmp[i].IDNL == t.ID && tmp[i].IDNL != 70)
                    {
                        if (tmp[i].LieuLuong <= t.SoLuong)
                        {
                            t.SoLuong += tmp[i].LieuLuong;
                        }
                    }
                }
            }
        }
コード例 #3
0
 private ThucDon DotBien(ThucDon x)
 {
     for (int i = 0; i < soNgay; i++)
     {
         for (int j = 0; j < soBua; j++)
         {
             for (int k = 0; k < 3; k++)
             {
                 int tyLe = ran.Next(0, 100);
                 if (tyLe < tyLeDotBien)
                 {
                     TraNguyenLieu(x.Ngay[i].Bua[j].Mon[k]);
                     MON ano = TaoMon();
                     x.Ngay[i].Bua[j].Mon[k] = ano;
                 }
             }
         }
     }
     return(x);
 }
コード例 #4
0
        private bool KiemTraMon(MON x)
        {
            List <CONGTHUCMON> tmp = db.CONGTHUCMONs.Where(a => a.IDMon == x.ID).ToList();

            for (int i = 0; i < tmp.Count(); i++)
            {
                foreach (var t in nguyenlieu)
                {
                    if (tmp[i].IDNL == t.ID && tmp[i].IDNL != 70)
                    {
                        if (tmp[i].LieuLuong <= t.SoLuong)
                        {
                            t.SoLuong -= tmp[i].LieuLuong;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #5
0
        private void LaiTao()
        {
            int t;
            int k;

            for (int i = 0; i < QTbandau.Count() / 2; i++)
            {
                t = ran.Next(0, QTbandau.Count());
                k = ran.Next(0, QTbandau.Count());
                while (t == k && QTbandau.Count() > 1)
                {
                    t = ran.Next(0, QTbandau.Count());
                    k = ran.Next(0, QTbandau.Count());
                }
                ThucDon ct1  = QTbandau[t];
                ThucDon ct2  = QTbandau[k];
                ThucDon ctc1 = new ThucDon();
                ThucDon ctc2 = new ThucDon();
                for (int j = 0; j < soNgay; j++)
                {
                    Ngay ngay1 = new Ngay();
                    Ngay ngay2 = new Ngay();
                    for (int a = 0; a < soBua; a++)
                    {
                        Bua bua1 = ct1.Ngay[j].Bua[a];
                        Bua bua2 = ct2.Ngay[j].Bua[a];
                        for (int b = 0; b < 3; b++)
                        {
                            MON mon1 = bua1.Mon[b];
                            MON mon2 = bua2.Mon[b];
                            int tyLe = ran.Next(0, 100);
                            if (tyLe < tyLeLaiTao)
                            {
                                bua1.Mon[b] = mon2;
                                bua2.Mon[b] = mon1;
                            }
                        }
                        ngay1.Bua.Add(bua1);
                        ngay2.Bua.Add(bua2);
                    }
                    ctc1.Ngay.Add(ngay1);
                    ctc2.Ngay.Add(ngay2);
                }
                ctc1 = DotBien(ctc1);
                ctc2 = DotBien(ctc2);
                int tyLeSongSot = ran.Next(0, 100);
                if (tyLeSongSot < tyLeSongSot1)
                {
                    QTmoi.Add(ctc1);
                }
                else
                {
                    if (tyLeSongSot < tyLeSongSot2)
                    {
                        QTmoi.Add(ctc2);
                    }
                    else
                    {
                        int o = ran.Next(0, 2);
                        if (o == 0)
                        {
                            QTmoi.Add(ctc1);
                        }
                        else
                        {
                            QTmoi.Add(ctc2);
                        }
                    }
                }
                if (k > t)
                {
                    QTbandau.Remove(QTbandau[k]);
                    QTbandau.Remove(QTbandau[t]);
                }
                else
                {
                    QTbandau.Remove(QTbandau[t]);
                    QTbandau.Remove(QTbandau[k]);
                }
            }
        }