1
0
forked from s425077/PotatoPlan

Merge branch 'Oskar-ML' into dev

This commit is contained in:
BOTLester 2020-05-11 01:47:24 +02:00
commit 5293312938
6 changed files with 52 additions and 7 deletions

View File

@ -2,6 +2,7 @@
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System; using System;
using System.IO;
namespace Game1 namespace Game1
{ {
@ -19,6 +20,9 @@ namespace Game1
private Texture2D house; private Texture2D house;
private Texture2D markers; private Texture2D markers;
private Texture2D mouseCursor; private Texture2D mouseCursor;
string directory = Directory.GetCurrentDirectory();
private Texture2D ProgressionBar; private Texture2D ProgressionBar;
private Texture2D ProgressionBarStatus; private Texture2D ProgressionBarStatus;
@ -69,6 +73,8 @@ namespace Game1
//Generates the map with some random values //Generates the map with some random values
inventory.initInventorySystem(); inventory.initInventorySystem();
string path = directory + "Game1/Content/ML/Fertilizer_Prediction.csv";
input.init(graphics, new Vector2(16,16), 56, 1); //Generates the starting size input.init(graphics, new Vector2(16,16), 56, 1); //Generates the starting size
houseUnit.init(input.getTileSize(), input.getSpacing()); //Generates the house position houseUnit.init(input.getTileSize(), input.getSpacing()); //Generates the house position
tractorUnit.init(houseUnit.GetRectangle(), input); //Generates the Tractor tractorUnit.init(houseUnit.GetRectangle(), input); //Generates the Tractor

View File

@ -17,7 +17,7 @@ class Controller
public Vector2 updateWindow(int tileSize, int Spacing, Vector2 Size) public Vector2 updateWindow(int tileSize, int Spacing, Vector2 Size)
{ {
KeyboardState state = Keyboard.GetState(); KeyboardState state = Keyboard.GetState();
if (state.IsKeyDown(Keys.D) && Size.X < 100) if (state.IsKeyDown(Keys.D) && Size.X < 90)
{ {
Size.X++; Size.X++;
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing; graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;

View File

@ -302,6 +302,28 @@ class Crops
//ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Temperature, Sample.Temparature)); //ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Temperature, Sample.Temparature));
//ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Moisture, Sample.Moisture)); //ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Moisture, Sample.Moisture));
//ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Humidity, Sample.Humidity)); //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))); min = Math.Min(compareToDatset(soilProperties.Phosphorous, Sample.Phosphorous), Math.Min(compareToDatset(soilProperties.Potassium, Sample.Potassium), compareToDatset(soilProperties.Nitrogen, Sample.Nitrogen)));
ProductionRate = ProductionRate + (ProductionRate * min); ProductionRate = ProductionRate + (ProductionRate * min);
if (ProductionRate < 0) if (ProductionRate < 0)

View File

@ -46,7 +46,7 @@ class SoilProperties
soilType = "Clayey"; soilType = "Clayey";
} }
Temperature = GetRandomNumber(22, 30); Temperature = GetRandomNumber(22, 30);
Humidity = Temperature * GetRandomNumber(1.9, 2.1); Humidity = Temperature * GetRandomNumber(1.9f, 2.1f);
Moisture = GetRandomNumber(20, 70); Moisture = GetRandomNumber(20, 70);
Nitrogen = GetRandomNumber(4 , 42); //was 4, 60 Nitrogen = GetRandomNumber(4 , 42); //was 4, 60
Potassium = GetRandomNumber(0.01f, 19); // was 0, 28 Potassium = GetRandomNumber(0.01f, 19); // was 0, 28

View File

@ -12,6 +12,8 @@ class Inventory
{ {
private int Weight = 0; private int Weight = 0;
private int maxWeight = 350; private int maxWeight = 350;
private int[] totalHarvested = new int[11];
private int[] totalFertilizerUsed = new int[8];
private Cargo cargo = new Cargo(); private Cargo cargo = new Cargo();
private Cargo itemStorage = new Cargo(); private Cargo itemStorage = new Cargo();
@ -59,6 +61,10 @@ class Inventory
public bool addItem(int newItemIndex, int Type) public bool addItem(int newItemIndex, int Type)
{ {
Items newItem; Items newItem;
if (Type == 1)
{
totalHarvested[newItemIndex]++;
}
newItem = itemStorage.getItemByIndex(newItemIndex, Type); newItem = itemStorage.getItemByIndex(newItemIndex, Type);
if (maxWeight >= Weight + newItem.getWeight()) if (maxWeight >= Weight + newItem.getWeight())
{ {
@ -76,10 +82,14 @@ class Inventory
// Uses an item from the tractor. // Uses an item from the tractor.
// 0 = Fertilizer // 0 = Fertilizer
// 1 = Crops // 1 = Crops
public bool useItem(int Index, int Type) public bool useItem(int Index, int Type, bool isClearing)
{ {
if (cargo.itemExists(Index, Type)) if (cargo.itemExists(Index, Type))
{ {
if (Type == 0 && !isClearing)
{
totalFertilizerUsed[Index]++;
}
removeItem(Index, Type); removeItem(Index, Type);
return true; return true;
} }
@ -101,6 +111,7 @@ class Inventory
public void removeItem(int Index, int Type) public void removeItem(int Index, int Type)
{ {
Weight = Weight - itemStorage.getItemByIndex(Index, Type).getWeight(); Weight = Weight - itemStorage.getItemByIndex(Index, Type).getWeight();
cargo.removeItem(Index, Type); cargo.removeItem(Index, Type);
} }
@ -113,10 +124,10 @@ class Inventory
public void clearInventory() public void clearInventory()
{ {
for (int i = 0; i <= 6; i++) for (int i = 0; i <= 6; i++)
while (useItem(i, 0)) ; while (useItem(i, 0, true)) ;
for (int i = 0; i <= 10; i++) for (int i = 0; i <= 10; i++)
while (useItem(i, 1)) ; while (useItem(i, 1, true)) ;
} }
public void fillWithFertilizer() 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, "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 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, 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, "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 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);
} }
} }
} }

View File

@ -111,7 +111,7 @@ class AI
if (farm.getCrop(x, y).getStatus() >= 2) if (farm.getCrop(x, y).getStatus() >= 2)
{ {
fertilizer = fertilizerHolder.GetFertilizer(Engine.PredictFertilizer(farm.getCrop(x, y), farm.getPresetCropTypes(farm.getCrop(x, y).getCropType()))); 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); farm.getCrop(x, y).Fertilize(fertilizer);
fertilizer = fertilizerHolder.GetFertilizer(Engine.PredictFertilizer(farm.getCrop(x, y), farm.getPresetCropTypes(farm.getCrop(x, y).getCropType()))); fertilizer = fertilizerHolder.GetFertilizer(Engine.PredictFertilizer(farm.getCrop(x, y), farm.getPresetCropTypes(farm.getCrop(x, y).getCropType())));