diff --git a/Game1/Game1.cs b/Game1/Game1.cs index a282e74..6af18be 100644 --- a/Game1/Game1.cs +++ b/Game1/Game1.cs @@ -170,9 +170,9 @@ namespace Game1 input.controlWindowSize(); //Controls the size of the screen depending on the number of tiles houseUnit.updateRectangle(input.getSize(), input.getTileSize(), input.getSpacing()); //Updates the position of the house if the house appears out of bound Time.updateTime(tractorUnit.getSpeed()); - + //System.Threading.Thread updatethread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Update)); base.Update(gameTime); } diff --git a/Game1/Sources/Crops/Farm.cs b/Game1/Sources/Crops/Farm.cs index c99cfa1..9586152 100644 --- a/Game1/Sources/Crops/Farm.cs +++ b/Game1/Sources/Crops/Farm.cs @@ -20,7 +20,7 @@ class Farm private float[][] whiteNoise; private float[][] perlinNoise; private DayNightCycle Time; - private float updatePerc = 0.25f; + private float updatePerc = 0.5f; private float updateProgress = 0; private int nextUpdate = 0; private int productionUpdate = 0; @@ -147,13 +147,14 @@ class Farm crops[i, j].updateProductionRate(); } } - updateProgress = updateProgress + updatePerc; + updateProgress = updateProgress + nextUpdate; if (updateProgress > 1) { updateProgress = 0; } updateRainMapPosition(Size); productionUpdate = 0; + nextUpdate = 0; } productionUpdate++; } @@ -310,7 +311,7 @@ class Farm public float getProductionRate(int x, int y, int Type) { - return crops[x, y].getProductionRate(PresetCrops.getPresetCropTypes(Type)); + return crops[x, y]. getProductionRate(PresetCrops.getPresetCropTypes(Type)); } public float GetRandomNumber(double minimum, double maximum) diff --git a/Game1/Sources/ML/MLModel.cs b/Game1/Sources/ML/MLModel.cs index c13e78a..30e3510 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,7 +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"; @@ -27,7 +27,7 @@ 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/DataModel/OutputArea.cs b/Game1/Sources/ML_Joel/DataModel/OutputArea.cs index 36254f2..79a5700 100644 --- a/Game1/Sources/ML_Joel/DataModel/OutputArea.cs +++ b/Game1/Sources/ML_Joel/DataModel/OutputArea.cs @@ -9,12 +9,7 @@ namespace Game1.Sources.ML_Joel { class OutputArea { - //[ColumnName("PredictedLabel")] public float Prediction { get; set; } public float Score { get; set; } - - //[ColumnName("Score")] - // public float[] Score { get; set; } - } } diff --git a/Game1/Sources/ML_Joel/Engine.cs b/Game1/Sources/ML_Joel/Engine.cs index aac86d7..ae5f78d 100644 --- a/Game1/Sources/ML_Joel/Engine.cs +++ b/Game1/Sources/ML_Joel/Engine.cs @@ -41,7 +41,7 @@ namespace Game1.Sources.ML_Joel { Season = Time.getTimeOfYear(), Area = soilProperties.Area, - Rainfall = soilProperties.Humidity, + Rainfall = soilProperties.prevRainfall, }; return PredictionEngineArea.Predict(modelInput).Score; diff --git a/Game1/Sources/ML_Joel/Model.cs b/Game1/Sources/ML_Joel/Model.cs index d543240..060f968 100644 --- a/Game1/Sources/ML_Joel/Model.cs +++ b/Game1/Sources/ML_Joel/Model.cs @@ -13,19 +13,24 @@ namespace Game1.Sources.ML_Joel class Model { private static MLContext mlContext = new MLContext(seed: 1); + + 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_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 = "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 = "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/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() { @@ -142,7 +147,7 @@ namespace Game1.Sources.ML_Joel var eval = mlContext.Regression.Evaluate(trainingDataView, labelColumnName: labelColumnName); var report = File.CreateText(reportPath); - report.Write("Mean Absolute Error: " + eval.MeanAbsoluteError + '\n' + "Mean Squared Error: " + eval.MeanSquaredError + '\n' + "R Squared: " + eval.RSquared, 0, 0); + report.Write("Mean Absolute Error: " + eval.MeanAbsoluteError + '\n' + "R Squared: " + eval.RSquared, 0, 0); report.Flush(); report.Close(); }