1
0
forked from s425077/PotatoPlan

Fixes and fixes

This commit is contained in:
BOTLester 2020-06-15 00:59:39 +02:00
parent ad92969137
commit 9e07e0f6bd
8 changed files with 85 additions and 25 deletions

8
Final_evaluation.md Normal file
View File

@ -0,0 +1,8 @@
# Final Evaluation
## Introduction
Final evaluation doc.
WIP

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 4.8 MiB

View File

@ -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));
}
}

View File

@ -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)

View File

@ -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;

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()