diff --git a/Final_evaluation.md b/Final_evaluation.md new file mode 100644 index 0000000..01d61e1 --- /dev/null +++ b/Final_evaluation.md @@ -0,0 +1,8 @@ +# Final Evaluation + + + +## Introduction + +Final evaluation doc. +WIP \ No newline at end of file diff --git a/Game1/Content/Clouds.png b/Game1/Content/Clouds.png index 338e5da..c7a6fb4 100644 Binary files a/Game1/Content/Clouds.png and b/Game1/Content/Clouds.png differ diff --git a/Game1/Sources/Crops/Crops.cs b/Game1/Sources/Crops/Crops.cs index 9b33722..c4d1e95 100644 --- a/Game1/Sources/Crops/Crops.cs +++ b/Game1/Sources/Crops/Crops.cs @@ -207,18 +207,18 @@ class Crops public void degradeSoil() { - + Random r = new Random(); if (soilProperties.Nitrogen > 4.0f) { - soilProperties.Nitrogen = soilProperties.Nitrogen - (soilProperties.NitrogenDegradeRate * (float)Math.Pow(ProductionRate, 2)); + soilProperties.Nitrogen = soilProperties.Nitrogen - ((soilProperties.NitrogenDegradeRate * (float)Math.Pow(ProductionRate, 2)) * (float)Math.Pow((r.NextDouble() + 0.5f), 2)); } if (soilProperties.Phosphorous > 0.1f) { - soilProperties.Phosphorous = soilProperties.Phosphorous - (soilProperties.PhosphorousDegradeRate * (float)Math.Pow(ProductionRate, 2)); + soilProperties.Phosphorous = soilProperties.Phosphorous - ((soilProperties.PhosphorousDegradeRate * (float)Math.Pow(ProductionRate, 2)) * (float)Math.Pow((r.NextDouble() + 0.5f), 2)); } if (soilProperties.Potassium > 0.1f) { - soilProperties.Potassium = soilProperties.Potassium - (soilProperties.PotassiumDegradeRate * (float)Math.Pow(ProductionRate, 2)); + soilProperties.Potassium = soilProperties.Potassium - ((soilProperties.PotassiumDegradeRate * (float)Math.Pow(ProductionRate, 2)) * (float)Math.Pow((r.NextDouble() + 0.5f), 2)); } } diff --git a/Game1/Sources/Crops/Farm.cs b/Game1/Sources/Crops/Farm.cs index 437c405..f971b99 100644 --- a/Game1/Sources/Crops/Farm.cs +++ b/Game1/Sources/Crops/Farm.cs @@ -77,8 +77,13 @@ class Farm init(Size, housepos); RainPosition.X = r.Next(0, 1900); RainPosition.Y = r.Next(0, 1950); - WindSpeed.X = GetRandomNumber(-1f, 1f) / 500; - WindSpeed.Y = GetRandomNumber(-1f, 1f) / 500; + float coef = GetRandomNumber(-1f, 1f); + if (coef < 0) + coef = -1.0f; + else + coef = 1.0f; + WindSpeed.X = GetRandomNumber(0.9f, 1f) / 50 * coef; + WindSpeed.Y = GetRandomNumber(0.9f, 1f) / 50 * coef; //RainfallMap = PerlinNoise.LoadImage("C:\\Users\\Joel\\source\\repos\\Oskars Repo\\Game1\\Content\\Rainfall.png"); RainfallMap = PerlinNoise.LoadImage("C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/Rainfall.png"); } @@ -215,17 +220,17 @@ class Farm private void updateRainMapPosition(Vector2 Size) { - float x, y; + double x, y; x = WindSpeed.X + GetRandomNumber(-1f, 1f) / 20000; y = WindSpeed.Y + GetRandomNumber(-1f, 1f) / 20000; if (x <= 0.02f && x >= -0.02f) { - WindSpeed.X = x; + WindSpeed.X = (float)x; } if (y < 0.02f && y > -0.02f) { - WindSpeed.Y = y; + WindSpeed.Y = (float)y; } if (WindSpeed.X > 0 && RainPosition.X < 2000) diff --git a/Game1/Sources/Crops/SoilProperties.cs b/Game1/Sources/Crops/SoilProperties.cs index ea7342c..1b61eb8 100644 --- a/Game1/Sources/Crops/SoilProperties.cs +++ b/Game1/Sources/Crops/SoilProperties.cs @@ -19,9 +19,9 @@ class SoilProperties public float Phosphorous; public float Rainfall; public float prevRainfall; - public float NitrogenDegradeRate = 1.0f - (1.0f/55 * 40); - public float PotassiumDegradeRate = 1.0f - (1.0f/28 * 23); - public float PhosphorousDegradeRate = 1.0f - (1.0f/60 * 37); + public float NitrogenDegradeRate = 0.8f; + public float PotassiumDegradeRate = 0.3f; + public float PhosphorousDegradeRate = 0.6f; public int Capacity = 80; public int Area; diff --git a/Game1/Sources/ML/MLModel.cs b/Game1/Sources/ML/MLModel.cs index c329bcf..4dd8cd5 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/Model.cs b/Game1/Sources/ML_Joel/Model.cs index fae4e65..1724956 100644 --- a/Game1/Sources/ML_Joel/Model.cs +++ b/Game1/Sources/ML_Joel/Model.cs @@ -13,7 +13,7 @@ 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"; @@ -21,8 +21,8 @@ namespace Game1.Sources.ML_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"; @@ -30,7 +30,7 @@ namespace Game1.Sources.ML_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() { diff --git a/Game1/Sources/Objects/InventorySystem/Inventory.cs b/Game1/Sources/Objects/InventorySystem/Inventory.cs index 2ca7d48..5f361df 100644 --- a/Game1/Sources/Objects/InventorySystem/Inventory.cs +++ b/Game1/Sources/Objects/InventorySystem/Inventory.cs @@ -16,6 +16,7 @@ class Inventory private int[] totalFertilizerUsed = new int[8]; private Cargo cargo = new Cargo(); private Cargo itemStorage = new Cargo(); + private int Refills = 0; // Item list by index: // --------------------------------------- @@ -128,18 +129,64 @@ class Inventory for (int i = 0; i <= 10; i++) while (useItem(i, 1, true)) ; + } public void fillWithFertilizer() { - int i = 0; - while (getWeight() < getMaxWeight()) + Refills++; + int fert_amount = 7; + float weightPerFertilizer = maxWeight / fert_amount; + float min = weightPerFertilizer / 10; + float max = (2 * weightPerFertilizer) - min; + float expectedUse = Refills * weightPerFertilizer; + + double[] useFactor = new double[fert_amount]; + for (int i = 0; i < fert_amount; i++) { - if (i > 6) - i = 0; - addItem(i, 0); - i++; + if (Refills <= 1) + useFactor[i] = weightPerFertilizer; + else + if (totalFertilizerUsed[i] / expectedUse + 0.85f > 1.0f) + useFactor[i] = Math.Round(Math.Pow((totalFertilizerUsed[i] / expectedUse) + 0.50f, 0.6f + Math.Min(Refills / 6.0f, 1.0f)) * weightPerFertilizer); + else + useFactor[i] = Math.Round(Math.Pow((totalFertilizerUsed[i] / expectedUse) + 0.50f, 1.0f + Math.Min(Refills / 6.0f, 1.8f)) * weightPerFertilizer); + if (useFactor[i] < min) + useFactor[i] = min; + else if (useFactor[i] > max) + useFactor[i] = max; } + int j = 0; + bool change = false; + while (getWeight() < getMaxWeight() - fert_amount) + { + if (useFactor[j] > 0) + { + addItem(j, 0); + useFactor[j]--; + change = true; + } + j++; + if (j >= fert_amount) + { + if (!change) + break; + else + { + j = 0; + change = false; + } + } + } + + int m = 0; + while (getWeight() < getMaxWeight()- fert_amount) + { + if (m > 6) + m = 0; + addItem(m, 0); + m++; + } } public bool isMissingFertilizer()