From fe04a5cd073aed0448f2ec4d5e0ebce95d047891 Mon Sep 17 00:00:00 2001 From: BOTLester <58360400+BOTLester@users.noreply.github.com> Date: Sun, 24 May 2020 21:22:47 +0200 Subject: [PATCH 1/2] enigne --- Game1/Sources/Crops/Farm.cs | 4 ++-- Game1/Sources/ML_Joel/Engine.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Game1/Sources/Crops/Farm.cs b/Game1/Sources/Crops/Farm.cs index 36cd5de..e14492d 100644 --- a/Game1/Sources/Crops/Farm.cs +++ b/Game1/Sources/Crops/Farm.cs @@ -72,8 +72,8 @@ class Farm init(Size, housepos); RainPosition.X = r.Next(0, 1900); RainPosition.Y = r.Next(0, 1950); - 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"); + //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"); } public Rectangle getRainPosition(int TileSize, int x, int y, Vector2 Size) diff --git a/Game1/Sources/ML_Joel/Engine.cs b/Game1/Sources/ML_Joel/Engine.cs index e4b31af..8b512b1 100644 --- a/Game1/Sources/ML_Joel/Engine.cs +++ b/Game1/Sources/ML_Joel/Engine.cs @@ -39,7 +39,7 @@ namespace Game1.Sources.ML_Joel { InputArea modelInput = new InputArea { - //Season = , + //Season = crop. //Area = crop.getSoilProperties().Area, Rainfall = crop.getSoilProperties().Humidity, }; From e406823e47ba112a2d2e9ef7051addf0d79abcd3 Mon Sep 17 00:00:00 2001 From: BOTLester <58360400+BOTLester@users.noreply.github.com> Date: Sun, 24 May 2020 22:21:49 +0200 Subject: [PATCH 2/2] ml implement --- Game1/Sources/Crops/Crops.cs | 28 +++++++++++++++++++++++++--- Game1/Sources/ML_Joel/Engine.cs | 8 ++++---- Game1/Sources/Smart/SmartTractor.cs | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Game1/Sources/Crops/Crops.cs b/Game1/Sources/Crops/Crops.cs index 019c6d9..5b49553 100644 --- a/Game1/Sources/Crops/Crops.cs +++ b/Game1/Sources/Crops/Crops.cs @@ -22,8 +22,8 @@ class Crops SoilProperties soilProperties = new SoilProperties(); private float ProductionRate; private float tempRain; - public DayNightCycle Time { get; set; } - + private DayNightCycle Time = new DayNightCycle(); + public void updateCrop(Vector2 newSize, float Rain, DayNightCycle nTime) @@ -328,6 +328,28 @@ class Crops public float getProductionRate(CropTypes Sample) { + float predProd = 1.0f; + if (Status > 1) + { + bool correctSeason = false; + foreach (string i in Sample.Season) + { + if (i == Time.getTimeOfYear() || i == "Whole Year") + { + correctSeason = true; + break; + } + } + + if (correctSeason) + { + predProd = Game1.Sources.ML_Joel.Engine.PredictProductionwithRainfall(soilProperties, Time); + predProd = (predProd / soilProperties.Area) / 2; + } + else + predProd = 0.20f; + } + ProductionRate = 1; float min = 1.0f; if (DataSet != null) @@ -366,7 +388,7 @@ class Crops ProductionRate = ProductionRate / 1.5f; } ProductionRate = (float)Math.Pow(ProductionRate, 2.5f); - return ProductionRate; + return ProductionRate * predProd; } public float getProductionRate() diff --git a/Game1/Sources/ML_Joel/Engine.cs b/Game1/Sources/ML_Joel/Engine.cs index 8b512b1..aac86d7 100644 --- a/Game1/Sources/ML_Joel/Engine.cs +++ b/Game1/Sources/ML_Joel/Engine.cs @@ -35,13 +35,13 @@ namespace Game1.Sources.ML_Joel PredictionEngineArea = Model.CreateEngineArea(); } - public static float PredictProductionwithRainfall(Crops crop, CropTypes cropTypes) + public static float PredictProductionwithRainfall(SoilProperties soilProperties, DayNightCycle Time) { InputArea modelInput = new InputArea { - //Season = crop. - //Area = crop.getSoilProperties().Area, - Rainfall = crop.getSoilProperties().Humidity, + Season = Time.getTimeOfYear(), + Area = soilProperties.Area, + Rainfall = soilProperties.Humidity, }; return PredictionEngineArea.Predict(modelInput).Score; diff --git a/Game1/Sources/Smart/SmartTractor.cs b/Game1/Sources/Smart/SmartTractor.cs index 810d106..403c79d 100644 --- a/Game1/Sources/Smart/SmartTractor.cs +++ b/Game1/Sources/Smart/SmartTractor.cs @@ -16,7 +16,7 @@ class SmartTractor //What to do next public Path returnChoice() { - //System.Threading.St + //System.Threading.ThreadStart tractorThread = new System.Threading.ThreadStart(farm.UpdatePreferedCrops); ai.update(farm, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation); farm.UpdatePreferedCrops(Size); farm = ai.changeCropStatus();