From e2ac5f3572e94e01f5df5efd55ba78b536bc2e4b Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 11 May 2020 01:11:00 +0200 Subject: [PATCH 1/4] More UI --- Game1/Sources/Controlls/Controller.cs | 2 +- Game1/Sources/Crops/Crops.cs | 22 ++++++++++++++++ Game1/Sources/Crops/SoilProperties.cs | 2 +- .../Objects/InventorySystem/Inventory.cs | 25 ++++++++++++++++--- Game1/Sources/Smart/AI.cs | 2 +- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Game1/Sources/Controlls/Controller.cs b/Game1/Sources/Controlls/Controller.cs index 7f6cce5..dc69deb 100644 --- a/Game1/Sources/Controlls/Controller.cs +++ b/Game1/Sources/Controlls/Controller.cs @@ -17,7 +17,7 @@ class Controller public Vector2 updateWindow(int tileSize, int Spacing, Vector2 Size) { KeyboardState state = Keyboard.GetState(); - if (state.IsKeyDown(Keys.D) && Size.X < 100) + if (state.IsKeyDown(Keys.D) && Size.X < 90) { Size.X++; graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing; diff --git a/Game1/Sources/Crops/Crops.cs b/Game1/Sources/Crops/Crops.cs index c3f74d9..ff09de1 100644 --- a/Game1/Sources/Crops/Crops.cs +++ b/Game1/Sources/Crops/Crops.cs @@ -302,6 +302,28 @@ class Crops //ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Temperature, Sample.Temparature)); //ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Moisture, Sample.Moisture)); //ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Humidity, Sample.Humidity)); + if (DataSet.soilType[0] != null) + { + if (Sample.soilType[0] == soilProperties.soilType) + { + ProductionRate = ProductionRate + 0.1f; + } + if (DataSet.soilType[1] != null) + { + if (Sample.soilType[1] == soilProperties.soilType) + { + ProductionRate = ProductionRate + 0.08f; + } + if (DataSet.soilType[2] != null) + { + if (Sample.soilType[2] == soilProperties.soilType) + { + ProductionRate = ProductionRate + 0.5f; + } + + } + } + } min = Math.Min(compareToDatset(soilProperties.Phosphorous, Sample.Phosphorous), Math.Min(compareToDatset(soilProperties.Potassium, Sample.Potassium), compareToDatset(soilProperties.Nitrogen, Sample.Nitrogen))); ProductionRate = ProductionRate + (ProductionRate * min); if (ProductionRate < 0) diff --git a/Game1/Sources/Crops/SoilProperties.cs b/Game1/Sources/Crops/SoilProperties.cs index c1b7558..4491557 100644 --- a/Game1/Sources/Crops/SoilProperties.cs +++ b/Game1/Sources/Crops/SoilProperties.cs @@ -46,7 +46,7 @@ class SoilProperties soilType = "Clayey"; } Temperature = GetRandomNumber(22, 30); - Humidity = Temperature * GetRandomNumber(1.9, 2.1); + Humidity = Temperature * GetRandomNumber(1.9f, 2.1f); Moisture = GetRandomNumber(20, 70); Nitrogen = GetRandomNumber(4 , 42); //was 4, 60 Potassium = GetRandomNumber(0.01f, 19); // was 0, 28 diff --git a/Game1/Sources/Objects/InventorySystem/Inventory.cs b/Game1/Sources/Objects/InventorySystem/Inventory.cs index a6e418e..7441edc 100644 --- a/Game1/Sources/Objects/InventorySystem/Inventory.cs +++ b/Game1/Sources/Objects/InventorySystem/Inventory.cs @@ -12,6 +12,8 @@ class Inventory { private int Weight = 0; private int maxWeight = 350; + private int[] totalHarvested = new int[11]; + private int[] totalFertilizerUsed = new int[8]; private Cargo cargo = new Cargo(); private Cargo itemStorage = new Cargo(); @@ -59,6 +61,10 @@ class Inventory public bool addItem(int newItemIndex, int Type) { Items newItem; + if (Type == 1) + { + totalHarvested[newItemIndex]++; + } newItem = itemStorage.getItemByIndex(newItemIndex, Type); if (maxWeight >= Weight + newItem.getWeight()) { @@ -76,10 +82,14 @@ class Inventory // Uses an item from the tractor. // 0 = Fertilizer // 1 = Crops - public bool useItem(int Index, int Type) + public bool useItem(int Index, int Type, bool isClearing) { if (cargo.itemExists(Index, Type)) { + if (Type == 0 && !isClearing) + { + totalFertilizerUsed[Index]++; + } removeItem(Index, Type); return true; } @@ -101,6 +111,7 @@ class Inventory public void removeItem(int Index, int Type) { + Weight = Weight - itemStorage.getItemByIndex(Index, Type).getWeight(); cargo.removeItem(Index, Type); } @@ -113,10 +124,10 @@ class Inventory public void clearInventory() { for (int i = 0; i <= 6; i++) - while (useItem(i, 0)) ; + while (useItem(i, 0, true)) ; for (int i = 0; i <= 10; i++) - while (useItem(i, 1)) ; + while (useItem(i, 1, true)) ; } public void fillWithFertilizer() @@ -145,15 +156,21 @@ class Inventory { spriteBatch.DrawString(Bold, "Crops: ", new Vector2(470, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); + spriteBatch.DrawString(Bold, "Harvested:", new Vector2(600, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); for (int i = 0; i < 11; i++) //Print Crops { spriteBatch.DrawString(Bold, cargo.getCount(i, 1) + " " + itemStorage.getItemByIndex(i, 1).getItemType(), new Vector2(470, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); + spriteBatch.DrawString(Bold, totalHarvested[i].ToString(), new Vector2(620, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); } spriteBatch.DrawString(Bold, "Fertilizers: ", new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); + spriteBatch.DrawString(Bold, "Used ", new Vector2(830, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); for (int i = 0; i < 7; i++) //Print Fertilizers { - spriteBatch.DrawString(Bold, cargo.getCount(i, 0) + " " + itemStorage.getItemByIndex(i, 0).getItemType(), new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); + spriteBatch.DrawString(Bold, cargo.getCount(i, 0) + " " + itemStorage.getItemByIndex(i, 0).getItemType(), new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); + spriteBatch.DrawString(Bold, totalFertilizerUsed[i].ToString(), new Vector2(835, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); } + + } } diff --git a/Game1/Sources/Smart/AI.cs b/Game1/Sources/Smart/AI.cs index 50cc358..1092227 100644 --- a/Game1/Sources/Smart/AI.cs +++ b/Game1/Sources/Smart/AI.cs @@ -111,7 +111,7 @@ class AI if (farm.getCrop(x, y).getStatus() >= 2) { fertilizer = fertilizerHolder.GetFertilizer(Engine.PredictFertilizer(farm.getCrop(x, y), farm.getPresetCropTypes(farm.getCrop(x, y).getCropType()))); - while (!(farm.getCrop(x, y).isSaturated(-1)) && farm.getCrop(x, y).belowCapacity() && inventory.useItem(fertilizerHolder.GetFertilizerID(fertilizer.Name), 0)) + while (!(farm.getCrop(x, y).isSaturated(-1)) && farm.getCrop(x, y).belowCapacity() && inventory.useItem(fertilizerHolder.GetFertilizerID(fertilizer.Name), 0, false)) { farm.getCrop(x, y).Fertilize(fertilizer); fertilizer = fertilizerHolder.GetFertilizer(Engine.PredictFertilizer(farm.getCrop(x, y), farm.getPresetCropTypes(farm.getCrop(x, y).getCropType()))); From 7691828cae4d04800f91ff43cef4d202d6cb50fb Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 11 May 2020 01:30:18 +0200 Subject: [PATCH 2/4] UI --- Game1/Game1.cs | 6 ++++++ Game1/Sources/ML/MLModel.cs | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Game1/Game1.cs b/Game1/Game1.cs index 1a1b4d8..e1b8e9b 100644 --- a/Game1/Game1.cs +++ b/Game1/Game1.cs @@ -2,6 +2,7 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using System; +using System.IO; namespace Game1 { @@ -19,6 +20,9 @@ namespace Game1 private Texture2D house; private Texture2D markers; private Texture2D mouseCursor; + string directory = Directory.GetCurrentDirectory(); + + private Texture2D ProgressionBar; private Texture2D ProgressionBarStatus; @@ -69,6 +73,8 @@ namespace Game1 //Generates the map with some random values inventory.initInventorySystem(); + + string path = directory + "Game1/Content/ML/Fertilizer_Prediction.csv"; input.init(graphics, new Vector2(16,16), 56, 1); //Generates the starting size houseUnit.init(input.getTileSize(), input.getSpacing()); //Generates the house position tractorUnit.init(houseUnit.GetRectangle(), input); //Generates the Tractor diff --git a/Game1/Sources/ML/MLModel.cs b/Game1/Sources/ML/MLModel.cs index 2eec77c..32bc6fa 100644 --- a/Game1/Sources/ML/MLModel.cs +++ b/Game1/Sources/ML/MLModel.cs @@ -11,12 +11,13 @@ 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"; - 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 directory = Directory.GetCurrentDirectory(); + private static string path = directory; + private static string modelpath = directory; + private static string report = directory; + private static string pathBig = directory; + private static string modelpathBig = directory; + private static string reportBig = directory; // Loading data, creatin and saving ML model for smaller dataset (100) public static void CreateModel() From e4568f2c81fe441713dede2a49a4c6970b1a002f Mon Sep 17 00:00:00 2001 From: BOTLester <58360400+BOTLester@users.noreply.github.com> Date: Mon, 11 May 2020 01:41:38 +0200 Subject: [PATCH 3/4] correcting paths --- Game1/Sources/ML/MLModel.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Game1/Sources/ML/MLModel.cs b/Game1/Sources/ML/MLModel.cs index 32bc6fa..2eec77c 100644 --- a/Game1/Sources/ML/MLModel.cs +++ b/Game1/Sources/ML/MLModel.cs @@ -11,13 +11,12 @@ using Microsoft.ML.Trainers.LightGbm; class MLModel { private static MLContext mlContext = new MLContext(seed: 1); - private static string directory = Directory.GetCurrentDirectory(); - private static string path = directory; - private static string modelpath = directory; - private static string report = directory; - private static string pathBig = directory; - private static string modelpathBig = directory; - private static string reportBig = directory; + 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"; + 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"; // Loading data, creatin and saving ML model for smaller dataset (100) public static void CreateModel() From b21fc0776e7a3e362838c9709169c33498dc9807 Mon Sep 17 00:00:00 2001 From: BOTLester <58360400+BOTLester@users.noreply.github.com> Date: Mon, 11 May 2020 01:45:41 +0200 Subject: [PATCH 4/4] UI fix --- Game1/Sources/Objects/InventorySystem/Inventory.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Game1/Sources/Objects/InventorySystem/Inventory.cs b/Game1/Sources/Objects/InventorySystem/Inventory.cs index 7441edc..2566377 100644 --- a/Game1/Sources/Objects/InventorySystem/Inventory.cs +++ b/Game1/Sources/Objects/InventorySystem/Inventory.cs @@ -156,19 +156,19 @@ class Inventory { spriteBatch.DrawString(Bold, "Crops: ", new Vector2(470, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); - spriteBatch.DrawString(Bold, "Harvested:", new Vector2(600, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); + //spriteBatch.DrawString(Bold, "Harvested:", new Vector2(600, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); for (int i = 0; i < 11; i++) //Print Crops { spriteBatch.DrawString(Bold, cargo.getCount(i, 1) + " " + itemStorage.getItemByIndex(i, 1).getItemType(), new Vector2(470, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); - spriteBatch.DrawString(Bold, totalHarvested[i].ToString(), new Vector2(620, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); + //spriteBatch.DrawString(Bold, totalHarvested[i].ToString(), new Vector2(620, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); } spriteBatch.DrawString(Bold, "Fertilizers: ", new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); - spriteBatch.DrawString(Bold, "Used ", new Vector2(830, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); + //spriteBatch.DrawString(Bold, "Used ", new Vector2(830, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed); for (int i = 0; i < 7; i++) //Print Fertilizers { spriteBatch.DrawString(Bold, cargo.getCount(i, 0) + " " + itemStorage.getItemByIndex(i, 0).getItemType(), new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); - spriteBatch.DrawString(Bold, totalFertilizerUsed[i].ToString(), new Vector2(835, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); + //spriteBatch.DrawString(Bold, totalFertilizerUsed[i].ToString(), new Vector2(835, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue); }