From 5e9c9f503dc42a579288240fb2a61c6ac6256d8b Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 24 May 2020 22:22:09 +0200 Subject: [PATCH] asd --- Game1/Sources/Crops/Crops.cs | 9 +++++++-- Game1/Sources/Crops/Farm.cs | 26 ++++++++++++++++++++++++-- Game1/Sources/ML/MLModel.cs | 6 ++---- Game1/Sources/ML_Joel/Model.cs | 12 ++++++------ Game1/Sources/Objects/Tractor.cs | 3 +-- Game1/Sources/Smart/SmartTractor.cs | 4 ++-- 6 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Game1/Sources/Crops/Crops.cs b/Game1/Sources/Crops/Crops.cs index 019c6d9..b18b7b3 100644 --- a/Game1/Sources/Crops/Crops.cs +++ b/Game1/Sources/Crops/Crops.cs @@ -22,7 +22,7 @@ class Crops SoilProperties soilProperties = new SoilProperties(); private float ProductionRate; private float tempRain; - public DayNightCycle Time { get; set; } + private DayNightCycle Time = new DayNightCycle(); @@ -30,7 +30,6 @@ class Crops { Time = nTime; tempRain = Rain; - getProductionRate(DataSet); if (UpdateCrop == 60) { degradeSoil(Rain); @@ -50,6 +49,11 @@ class Crops } } + public void updateProductionRate() + { + getProductionRate(DataSet); + } + public float getSpeedFactor(float tractorSpeed) { if (getCostOnMovement() == 1) @@ -328,6 +332,7 @@ class Crops public float getProductionRate(CropTypes Sample) { + ProductionRate = 1; float min = 1.0f; if (DataSet != null) diff --git a/Game1/Sources/Crops/Farm.cs b/Game1/Sources/Crops/Farm.cs index ad7204e..05568d1 100644 --- a/Game1/Sources/Crops/Farm.cs +++ b/Game1/Sources/Crops/Farm.cs @@ -20,6 +20,10 @@ class Farm private float[][] whiteNoise; private float[][] perlinNoise; private DayNightCycle Time; + private float updatePerc = 0.25f; + private float updateProgress = 0; + private int nextUpdate = 0; + private int productionUpdate = 0; //initializes the crops @@ -133,7 +137,25 @@ class Farm Update = 0; } - updateRainMapPosition(Size); + if (productionUpdate == 20) + { + nextUpdate = (int)(nextUpdate + Size.X * updatePerc); + for (int i = (int)(updateProgress * Size.X); i < nextUpdate; i++) + { + for (int j = 0; j < Size.Y; j++) + { + crops[i, j].updateProductionRate(); + } + } + updateProgress = updateProgress + updatePerc; + if (updateProgress > 1) + { + updateProgress = 0; + } + updateRainMapPosition(Size); + productionUpdate = 0; + } + productionUpdate++; } public void updateRainFall(Vector2 Size, DayNightCycle nTime) @@ -239,7 +261,7 @@ class Farm { for (int j = 0; j < Size.X; j++) { - if (crops[i, j].getStatus() != 3) + if (crops[i, j].getStatus() == 2) { int x = getHighestProductionRate(i, j); crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x)); diff --git a/Game1/Sources/ML/MLModel.cs b/Game1/Sources/ML/MLModel.cs index 1dc20b5..c13e78a 100644 --- a/Game1/Sources/ML/MLModel.cs +++ b/Game1/Sources/ML/MLModel.cs @@ -11,7 +11,7 @@ using Microsoft.ML.Trainers.LightGbm; class MLModel { private static MLContext mlContext = new MLContext(seed: 1); - + /* private static string path = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/Fertilizer_Prediction.csv"; private static string modelpath = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/MLmodel"; private static string report = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/report"; @@ -19,8 +19,7 @@ class MLModel private static string pathBig = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/BigFertPredict.csv"; private static string modelpathBig = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/MLmodelBig"; private static string reportBig = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/report_BigModel"; - - /* + */ private static string pathBig = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/BigFertPredict.csv"; private static string modelpathBig = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/MLmodelBig"; private static string reportBig = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/report_BigModel"; @@ -28,7 +27,6 @@ class MLModel private static string path = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/Fertilizer_Prediction.csv"; private static string modelpath = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/MLmodel"; private static string report = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/report"; - */ // Loading data, creatin and saving ML model for smaller dataset (100) public static void CreateModel() diff --git a/Game1/Sources/ML_Joel/Model.cs b/Game1/Sources/ML_Joel/Model.cs index 0096921..d543240 100644 --- a/Game1/Sources/ML_Joel/Model.cs +++ b/Game1/Sources/ML_Joel/Model.cs @@ -18,13 +18,13 @@ namespace Game1.Sources.ML_Joel private static string modelpath = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/MLmodel_Joel"; private static string report = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/report_Joel"; */ - private static string path = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/Rainfall.csv"; - private static string modelpath = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/MLmodel_Joel"; - private static string report = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/report_Joel"; + private static string path = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/Rainfall.csv"; + private static string modelpath = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/MLmodel_Joel"; + private static string report = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/report_Joel"; - private static string path_area = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/Rainfall_area.csv"; - private static string modelpath_area = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/MLmodel_Joel_area"; - private static string report_area = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/report_Joel_area"; + private static string path_area = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/Rainfall_area.csv"; + private static string modelpath_area = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/MLmodel_Joel_area"; + private static string report_area = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/report_Joel_area"; // Loading data, creatin and saving ML model for smaller dataset (100) public static void CreateModel() diff --git a/Game1/Sources/Objects/Tractor.cs b/Game1/Sources/Objects/Tractor.cs index f49a3f6..fc9c0e5 100644 --- a/Game1/Sources/Objects/Tractor.cs +++ b/Game1/Sources/Objects/Tractor.cs @@ -6,11 +6,10 @@ class Tractor { private int Spacing, sizeTile, Speed = 1; private float tractorSpeed = 1; - private Vector2 Position, TargetPosition, Size, housePos, oldDeltaPosition, DeltaPosition; + private Vector2 Position, TargetPosition, Size, housePos, DeltaPosition; private Path path = new Path(); private SmartTractor smartTractor = new SmartTractor(); private HandleRotation handleRotation = new HandleRotation(); - private int WaitFrame = 30; private int j; diff --git a/Game1/Sources/Smart/SmartTractor.cs b/Game1/Sources/Smart/SmartTractor.cs index 810d106..20c3d21 100644 --- a/Game1/Sources/Smart/SmartTractor.cs +++ b/Game1/Sources/Smart/SmartTractor.cs @@ -74,13 +74,13 @@ class SmartTractor farm.setNewHousePos(pos, newState); } - public void UpdateCrops(int Speed, DayNightCycle Time) + public void UpdateCrops(int Speed, DayNightCycle nTime) { for (int i = 0; i < Speed; i++) { farm.updateFarm(Size); } - farm.updateRainFall(Size, Time); + farm.updateRainFall(Size, nTime); } public Inventory getInventory()