Beispiel #1
0
 private decimal?GetMaxAverageBenefit()
 {
     try
     {
         return(Cows.Where(c => c.State == CowState.Ready).Max(c => c.AverageBenefit));
     }
     catch
     {
         return((decimal?)null);
     }
 }
Beispiel #2
0
 private int?GetMaxLastBenefit()
 {
     try
     {
         return(Cows.Where(c => c.State == CowState.Ready).Max(c => c.LastBenefit));
     }
     catch
     {
         return((int?)null);
     }
 }
Beispiel #3
0
        private bool AreAllCowsInMills(Color ID)
        {
            IMill[] PlayerOwnedMills = Mills.Where(x => x.color == ID).ToArray();
            ICow[]  PlayerOwnedCows  = Cows.Where(x => x.Color == ID).ToArray();

            for (int i = 0; i < PlayerOwnedCows.Length; i++)
            {
                if (!CowInAMill(ID, PlayerOwnedCows[i].Position))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Gets the best cow.
        /// </summary>
        /// <returns></returns>
        public override Cow GetBestCow()
        {
            RefreshState();

            var maxLastBenefit = GetMaxLastBenefit();

            if (maxLastBenefit.HasValue && maxLastBenefit > AppCore.AttackSettings.MinBenefit)
            {
                var result = Cows.Where(c => c.State == CowState.Ready && c.LastBenefit == maxLastBenefit.Value).FirstOrDefault();
                if (result != null)
                {
                    return(result);
                }
            }


            var maxAverageBenefit = GetMaxAverageBenefit();

            if (maxAverageBenefit.HasValue && maxAverageBenefit > AppCore.AttackSettings.MinBenefit)
            {
                return(Cows.Where(c => c.State == CowState.Ready && c.AverageBenefit == maxAverageBenefit.Value).FirstOrDefault());
            }
            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Gets the best cow.
        /// </summary>
        /// <returns></returns>
        public override Cow GetBestCow()
        {
            RefreshState();
            Cow     bestCow    = null;
            decimal maxBenefit = -1;
            var     readyCows  = Cows.Where(c => c.State == CowState.Ready).ToArray();

            foreach (var cow in readyCows)
            {
                var cristalBenefit = (cow.MilkingCount > 0 && cow.Cristals > 0)
                                         ? (cow.Cristals / cow.MilkingCount) * 800
                                         : 0;
                var benefit = cow.RivalHealth + cow.RivalInjuryHealth +
                              cow.AverageBenefit + cristalBenefit;
                if (benefit <= maxBenefit)
                {
                    continue;
                }

                bestCow    = cow;
                maxBenefit = benefit;
            }
            return(bestCow);
        }
Beispiel #6
0
 public IEnumerable <ICow> getCowsByPlayer(Color c)
 {
     return(Cows.Where(x => x.Color == c));
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Setup variables...");
            Statistic = new Dictionary <dynamic, double>();
            Console.WriteLine("Wait for ready...");
            LoadCowData();
            //try
            //{
            Console.WriteLine("Clearing old data...");
            DataProvider.ExecuteNonQuery("delete chamsoc");
            DataProvider.ExecuteNonQuery("delete tinhtrangbo");
            DataProvider.ExecuteNonQuery("update counter set index_chamsoc = 0");
            Console.WriteLine("Seeding data...");

            var PCs = DataProvider.ExecuteReader <dynamic>((SqlDataReader row) =>
            {
                return(new
                {
                    id = row.GetValueDefault <string>(0),
                    userid = row.GetValueDefault <string>(1),
                    barnid = row.GetValueDefault <string>(2),
                    start = row.GetValueDefault <DateTime>(3),
                    end = row.GetValueDefault <DateTime>(4),
                    daysOfWeek = row.GetValueDefault <string>(5).Replace("CN", "1"),
                    areaId = row.GetValueDefault <string>(1).Split(new string[] { "NV" }, 2, StringSplitOptions.RemoveEmptyEntries)[0],
                });
            }, "select maphancong, manv, machuong, ngaybatdau, ngayketthuc, ngaytrongtuan from phancong");

            DateTime run = START_DATE;

            while (run.CompareTo(DateTime.Now) == -1)
            {
                foreach (var eachPC in PCs)
                {
                    if (run.CompareTo(eachPC.start) == 1 && run.CompareTo(eachPC.end) == -1 && eachPC.daysOfWeek.Contains(((int)run.DayOfWeek + 1).ToString()))
                    {
                        foreach (var cow in Cows.Where(x => x.machuong == eachPC.barnid && x.daxoa == "0"))
                        {
                            string newId     = createId(eachPC.areaId);
                            bool   milk      = false;
                            double milkValue = 0d;
                            if (new Random().NextDouble() > 0.6)
                            {
                                milk      = true;
                                milkValue = (double)(new Random().Next(500, 1000)) / 100d;
                                AddMilk(cow.machinhanh, milkValue);
                            }

                            DataProvider.ExecuteNonQuery(
                                string.Format("insert into chamsoc(machamsoc, ngayghinhan, tinhtrangcongviec, luongsua, dachoan, dadonvesinh, davatsua, maphancong, mabo, machinhanh)" +
                                              " values ('{0}', '{1}', N'{2}', {3}, '{4}', '{5}', '{6}', '{7}', '{8}', '{9}')",
                                              newId, run, "Đã hoàn thành.", milkValue, true, true, milk, eachPC.id, cow.mabo, cow.machinhanh));

                            //loop 2-4 times
                            DateTime a = new DateTime(run.Year, run.Month, run.Day, 7, 0, 0);
                            for (int i = 0; i < new Random().Next(2, 4); i++)
                            {
                                a = a.Add(new TimeSpan(new Random().Next(1, 2), new Random().Next(1, 59), new Random().Next(1, 59)));
                                if ((int)DataProvider.ExecuteScalar(string.Format("select count(mabo) from tinhtrangbo a, chamsoc b where a.machamsoc = b.machamsoc and b.mabo = '{0}'", cow.mabo)) > 0)
                                {
                                    double maxWeight = (double)DataProvider.ExecuteScalar(string.Format("select max(a.cannang) from tinhtrangbo a, chamsoc b where a.machamsoc = b.machamsoc and b.mabo = '{0}'", cow.mabo));
                                    double maxHeight = (double)DataProvider.ExecuteScalar(string.Format("select max(a.chieucao) from tinhtrangbo a, chamsoc b where a.machamsoc = b.machamsoc and b.mabo = '{0}'", cow.mabo));
                                    DataProvider.ExecuteNonQuery(
                                        string.Format("insert into tinhtrangbo(machamsoc, thoigianghinhan, cannang, chieucao)" +
                                                      " values ('{0}', '{1}', {2}, {3})",
                                                      newId, a,
                                                      maxWeight + (new Random().NextDouble() > 0.6 ? (double)(new Random().Next(3, 9)) / 100d : 0d),
                                                      maxHeight + (new Random().NextDouble() > 0.6 ? (double)(new Random().Next(0, 3)) / 10000d : 0d)));
                                }
                                else
                                {
                                    DataProvider.ExecuteNonQuery(
                                        string.Format("insert into tinhtrangbo(machamsoc, thoigianghinhan, cannang, chieucao)" +
                                                      " values ('{0}', '{1}', {2}, {3})",
                                                      newId, a,
                                                      (double)(new Random().Next(8000, 12000)) / 100d,
                                                      (double)(new Random().Next(100, 120)) / 100d));
                                }
                            }
                        }
                    }
                }
                run = run.AddDays(1);
            }
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            Console.WriteLine("Wait for write statistic to file...");
            WriteStatisticData();
            Console.WriteLine("Finish! Press any to exit...");
            Console.Read();
        }