Exemplo n.º 1
0
        public static void SaveCarToDb(Classes.Car car)
        {
            string connectionString = Constants.connectionString;

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand command = conn.CreateCommand())
                {
                    command.CommandText = "INSERT INTO Cars VALUES (" +
                                          "@ChassisLevel, @ChassisWear, @EngineLevel, @EngineWear, " +
                                          "@FWingLevel, @FWingWear, @RWingLevel, @RWingWear, " +
                                          "@UnderbodyLevel, @UnderbodyWear, @SidepodsLevel, @SidepodsWear, " +
                                          "@CoolingLevel, @CoolingWear, @GearboxLevel, @GearboxWear, " +
                                          "@BrakesLevel, @BrakesWear, @SuspensionLevel, @SuspensionWear " +
                                          "@ElectronicsLevel, @ElectronicsWear " +
                                          ")";

                    command.Parameters.Clear();

                    command.Parameters.AddWithValue("@ChassisLevel", car.ChassisLevel);
                    command.Parameters.AddWithValue("@ChassisWear", car.ChassisWear);
                    command.Parameters.AddWithValue("@EngineLevel", car.EngineLevel);
                    command.Parameters.AddWithValue("@EngineWear", car.EngineWear);
                    command.Parameters.AddWithValue("@FWingLevel", car.FWingLevel);
                    command.Parameters.AddWithValue("@FWingWear", car.FWingWear);
                    command.Parameters.AddWithValue("@RWingLevel", car.RWingLevel);
                    command.Parameters.AddWithValue("@RWingWear", car.RWingWear);
                    command.Parameters.AddWithValue("@UnderbodyLevel", car.UnderbodyLevel);
                    command.Parameters.AddWithValue("@UnderbodyWear", car.UnderbodyWear);
                    command.Parameters.AddWithValue("@SidepodsLevel", car.SidepodsLevel);
                    command.Parameters.AddWithValue("@SidepodsWear", car.SidepodsWear);
                    command.Parameters.AddWithValue("@CoolingLevel", car.CoolingLevel);
                    command.Parameters.AddWithValue("@CoolingWear", car.CoolingWear);
                    command.Parameters.AddWithValue("@GearboxLevel", car.GearboxLevel);
                    command.Parameters.AddWithValue("@GearboxWear", car.GearboxWear);
                    command.Parameters.AddWithValue("@BrakesLevel", car.BrakesLevel);
                    command.Parameters.AddWithValue("@BrakesWear", car.BrakesWear);
                    command.Parameters.AddWithValue("@SuspensionLevel", car.SuspensionLevel);
                    command.Parameters.AddWithValue("@SuspensionWear", car.SuspensionWear);
                    command.Parameters.AddWithValue("@ElectronicsLevel", car.ElectronicsLevel);
                    command.Parameters.AddWithValue("@ElectronicsWear", car.ElectronicsWear);


                    conn.Open();

                    command.ExecuteNonQuery();

                    conn.Close();
                }
            }
        }
Exemplo n.º 2
0
        static internal int GetQualPosition(Classes.Driver driver, Classes.Car car, Classes.Divisions division)
        {
            int   position = 1;
            float sd       = Constants.sd;

            float qPerformance   = 80 - 0.03f * driver.GetOA() - 0.18f * car.GetCarLevel();
            float qOpPerformance = 80 - 0.03f * SpHelper.GetAvgOA(division) - 0.18f * SpHelper.GetAvgCarLevel(division);

            position = (int)(40 - 39 * Classes.Maths.NormalDistribution.GetCumulativeDistribution(qPerformance, qOpPerformance, sd));

            position = AssurePositionWithinLimits(position);

            return(position);
        }
Exemplo n.º 3
0
        public static Classes.Car ReadCarFromDB()
        {
            string connectionString = Constants.connectionString;

            Classes.Car car = new Classes.Car();

            string query = "SELECT * FROM Cars WHERE Id=1";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand(query, conn))
                {
                    conn.Open();

                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        car.Id = int.Parse(reader[0].ToString());

                        car.ChassisLevel     = int.Parse(reader[1].ToString());
                        car.ChassisWear      = int.Parse(reader[2].ToString());
                        car.EngineLevel      = int.Parse(reader[3].ToString());
                        car.EngineWear       = int.Parse(reader[4].ToString());
                        car.FWingLevel       = int.Parse(reader[5].ToString());
                        car.FWingWear        = int.Parse(reader[6].ToString());
                        car.RWingLevel       = int.Parse(reader[7].ToString());
                        car.RWingWear        = int.Parse(reader[8].ToString());
                        car.UnderbodyLevel   = int.Parse(reader[9].ToString());
                        car.UnderbodyWear    = int.Parse(reader[10].ToString());
                        car.SidepodsLevel    = int.Parse(reader[11].ToString());
                        car.SidepodsWear     = int.Parse(reader[12].ToString());
                        car.CoolingLevel     = int.Parse(reader[13].ToString());
                        car.CoolingWear      = int.Parse(reader[14].ToString());
                        car.GearboxLevel     = int.Parse(reader[15].ToString());
                        car.GearboxWear      = int.Parse(reader[16].ToString());
                        car.BrakesLevel      = int.Parse(reader[17].ToString());
                        car.BrakesWear       = int.Parse(reader[18].ToString());
                        car.SuspensionLevel  = int.Parse(reader[19].ToString());
                        car.SuspensionWear   = int.Parse(reader[20].ToString());
                        car.ElectronicsLevel = int.Parse(reader[21].ToString());
                        car.ElectronicsWear  = int.Parse(reader[22].ToString());
                    }

                    conn.Close();
                }
            }

            return(car);
        }
Exemplo n.º 4
0
        static Classes.Car GetCarAfterPartsChangeAndWear(Classes.Car car, bool testing, Classes.Track track,
                                                         Classes.Driver driver, Classes.TechnicalDirector td, Classes.StaffFacilities sf, int ct, int[] carPartsBought)
        {
            Classes.Car carAfterWear = (Classes.Car)car.Clone(); //all properties are value type

            carAfterWear.UpdateCarWearAndLevelAfterCarUpdate(carPartsBought);

            carAfterWear.UpdateCarWearAfterRace(track, driver, ct);
            if (testing)
            {
                carAfterWear.DoTesting(td, track, sf);
            }

            return(carAfterWear);
        }
Exemplo n.º 5
0
        static internal SeasonPlannerFullLine ProcessSeasonPlanner(SeasonPlannerFullLine spFull)
        {
            #region  Initial Values
            Classes.RaceTab rt = spFull.spOptimizer.raceTab;
            Classes.SeasonPlannerForDataTable spForDataTable = spFull.spTable; //null. Filled later
            Classes.TechnicalDirector         td             = spFull.spOptimizer.technicalDirector;
            Classes.Car             car          = (Classes.Car)spFull.spOptimizer.car.Clone();
            Classes.Car             carAfterRace = (Classes.Car)car.Clone();
            Classes.Driver          driver       = spFull.spOptimizer.driver;
            int                     trackId      = DB.SeasonTrack.GetTrackId(spFull.spTable.SeasonRaceNumber);
            Classes.Track           track        = DB.Track.ReadTrackFromDB(trackId);
            Classes.StaffFacilities sf           = spFull.spOptimizer.staffFacilities;
            Classes.TyresSupplier   tyre         = DB.Tyres.ReadActiveTyreSupplierFromDB();

            int seasonRaceNumber = rt.SeasonTrackIndex;
            //float balanceM = spFull.spTab.StartingBalanceM;
            float balanceM       = spFull.spTable.BalanceAfterRaceM;
            int[] carPartsBought = new int[11];

            Divisions division = (Divisions)spFull.spTab.Division;

            int  trainning       = (int)spFull.spDecisions.Training;
            bool testing         = spFull.spDecisions.Testing;
            int  targetCarLevel  = spFull.spDecisions.TargetCarLevelEngBra;
            int  targetCarLevel2 = spFull.spDecisions.TargetCarLevelOthers;
            int  ct = spFull.spDecisions.CT;
            #endregion

            #region Process
            carAfterRace.UpdateCarWearAfterRace(track, driver, ct);

            if (testing)
            {
                carAfterRace.DoTesting(td, track, sf);
            }
            carPartsBought = GetWhichCarPartsChange(car, carAfterRace, targetCarLevel, targetCarLevel2);

            carAfterRace = (Classes.Car)car.Clone();
            carAfterRace = GetCarAfterPartsChangeAndWear(car, testing, track, driver, td, sf, ct, carPartsBought);

            int qualPosition = SpHelper.GetQualPosition(driver, car, division);
            int racePosition = SpHelper.GetRacePosition(driver, car, division, ct);
            int racePoints   = SpHelper.GetPoints(racePosition);

            //Expenses processing
            float balanceAfterRaceM = ((balanceM * 1000000) + GetAfterRaceBalance(driver, td, sf, testing, tyre, car, division, qualPosition, racePosition, trainning, carPartsBought)) / 1000000f;
            #endregion

            #region Output
            SeasonPlannerDecision spDecisionsNext = new SeasonPlannerDecision();
            spDecisionsNext = (Classes.SeasonPlannerDecision)spFull.spDecisions.Clone();

            SeasonPlannerForDataTable spTableNext = new SeasonPlannerForDataTable();
            spTableNext.SeasonRaceNumber  = spFull.spTable.SeasonRaceNumber + 1;
            spTableNext.BalanceAfterRaceM = balanceAfterRaceM;
            spTableNext.CarPartsChanged   = carPartsBought;
            spTableNext.CarWearAfterRace  = carAfterRace.GetWears();
            spTableNext.QualPosition      = qualPosition;
            spTableNext.RacePosition      = racePosition;

            SeasonPlannerForOptimizer spOptimizerNext = new SeasonPlannerForOptimizer();
            spOptimizerNext.car = (Classes.Car)carAfterRace.Clone();

            driver.DoTrainning((DriverTrainning)trainning);
            driver.DriverUpdateAfterRace(racePosition);
            spOptimizerNext.driver            = driver;
            spOptimizerNext.Id                = spFull.spOptimizer.Id + 1;
            spOptimizerNext.raceTab           = rt; //How to update trackId?
            spOptimizerNext.staffFacilities   = sf; //To Do: Update sf after races (convert levels to float type)
            spOptimizerNext.technicalDirector = td;

            SeasonPlannerTab spTabNext = new SeasonPlannerTab();
            spTabNext.CurrentPoints    = spFull.spTab.CurrentPoints + racePoints;
            spTabNext.Division         = spFull.spTab.Division;
            spTabNext.StartingBalanceM = balanceAfterRaceM;
            spTabNext.TargetPoints     = spFull.spTab.TargetPoints;

            SeasonPlannerFullLine spFullNext = new SeasonPlannerFullLine(spDecisionsNext, spTableNext, spOptimizerNext, spTabNext);

            return(spFullNext);

            #endregion
        }
Exemplo n.º 6
0
        public static void UpdateCarToDb(Classes.Car car)
        {
            string connectionString = Constants.connectionString;

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand command = conn.CreateCommand())
                {
                    //command.CommandText = "UPDATE Cars SET ChassisLevel=4, ChassisWear=44 WHERE Id=1";

                    command.CommandText = "UPDATE Cars SET " +
                                          "ChassisLevel = @ChassisLevel, ChassisWear = @ChassisWear, " +
                                          "EngineLevel = @EngineLevel, EngineWear = @EngineWear, " +
                                          "FWingLevel = @FWingLevel, FWingWear = @FWingWear, " +
                                          "RWingLevel = @RWingLevel, RWingWear = @RWingWear, " +
                                          "UnderbodyLevel = @UnderbodyLevel, UnderbodyWear = @UnderbodyWear, " +
                                          "SidepodsLevel = @SidepodsLevel, SidepodsWear = @SidepodsWear, " +
                                          "CoolingLevel = @CoolingLevel, CoolingWear = @CoolingWear, " +
                                          "GearboxLevel = @GearboxLevel, GearboxWear = @GearboxWear, " +
                                          "BrakesLevel = @BrakesLevel, BrakesWear = @BrakesWear, " +
                                          "SuspensionLevel = @SuspensionLevel, SuspensionWear = @SuspensionWear, " +
                                          "ElectronicsLevel = @ElectronicsLevel, ElectronicsWear = @ElectronicsWear " +

                                          "WHERE Id = @Id";


                    command.Parameters.Clear();

                    command.Parameters.AddWithValue("@ChassisLevel", car.ChassisLevel);
                    command.Parameters.AddWithValue("@ChassisWear", car.ChassisWear);
                    command.Parameters.AddWithValue("@EngineLevel", car.EngineLevel);
                    command.Parameters.AddWithValue("@EngineWear", car.EngineWear);
                    command.Parameters.AddWithValue("@FWingLevel", car.FWingLevel);
                    command.Parameters.AddWithValue("@FWingWear", car.FWingWear);
                    command.Parameters.AddWithValue("@RWingLevel", car.RWingLevel);
                    command.Parameters.AddWithValue("@RWingWear", car.RWingWear);
                    command.Parameters.AddWithValue("@UnderbodyLevel", car.UnderbodyLevel);
                    command.Parameters.AddWithValue("@UnderbodyWear", car.UnderbodyWear);
                    command.Parameters.AddWithValue("@SidepodsLevel", car.SidepodsLevel);
                    command.Parameters.AddWithValue("@SidepodsWear", car.SidepodsWear);
                    command.Parameters.AddWithValue("@CoolingLevel", car.CoolingLevel);
                    command.Parameters.AddWithValue("@CoolingWear", car.CoolingWear);
                    command.Parameters.AddWithValue("@GearboxLevel", car.GearboxLevel);
                    command.Parameters.AddWithValue("@GearboxWear", car.GearboxWear);
                    command.Parameters.AddWithValue("@BrakesLevel", car.BrakesLevel);
                    command.Parameters.AddWithValue("@BrakesWear", car.BrakesWear);
                    command.Parameters.AddWithValue("@SuspensionLevel", car.SuspensionLevel);
                    command.Parameters.AddWithValue("@SuspensionWear", car.SuspensionWear);
                    command.Parameters.AddWithValue("@ElectronicsLevel", car.ElectronicsLevel);
                    command.Parameters.AddWithValue("@ElectronicsWear", car.ElectronicsWear);

                    command.Parameters.AddWithValue("@Id", car.Id);

                    conn.Open();

                    command.ExecuteNonQuery();

                    conn.Close();
                }
            }
        }