fixed the croptype change and runs the ML for those that change in the middle of the day with no lag

This commit is contained in:
Joel 2020-05-25 13:13:11 +02:00
parent 631ad7c12f
commit b6078e14ac
5 changed files with 53 additions and 39 deletions

BIN
Game1/Content/Example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 KiB

View File

@ -14,7 +14,7 @@ class Crops
private int cropType = 0;
private float Timer = 1;
private int UpdateCrop;
private float fullTimer;
private float fullTimer = 1;
private bool housePos = false;
private Vector2 Size;
private Random r = new Random();
@ -24,6 +24,7 @@ class Crops
private float tempRain;
private float prevpred;
private DayNightCycle Time = new DayNightCycle();
private int previousDay = 0;
@ -244,13 +245,17 @@ class Crops
public void setCropType(int Type, CropTypes nCropType)
{
DataSet = nCropType;
cropType = Type;
if (Status == 3)
if (Timer == fullTimer)
{
soilProperties.Area = r.Next(nCropType.AreaMin, nCropType.AreaMax);
CropTypes temp = DataSet;
DataSet = nCropType;
cropType = Type;
if (Status > 1)
{
soilProperties.Area = r.Next(nCropType.AreaMin, nCropType.AreaMax);
if (temp != nCropType)
updateMLModel(DataSet, 1.0f);
}
}
}
@ -275,6 +280,7 @@ class Crops
public void setStatus(int newStatus)
{
Status = newStatus;
Timer = getCropTimer();
}
public void setOriginalStatus()
@ -334,25 +340,9 @@ class Crops
public float getProductionRate(CropTypes Sample)
{
float predProd = 1.0f;
if (Status > 1 && Time.nDay())
if (Status > 1 && Time.getDays() != previousDay)
{
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;
predProd = updateMLModel(Sample, predProd);
}
prevpred = predProd;
ProductionRate = 1;
@ -396,6 +386,30 @@ class Crops
return ProductionRate * prevpred;
}
public float updateMLModel(CropTypes Sample, float predProd)
{
previousDay = Time.getDays();
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;
return predProd;
}
public float getProductionRate()
{
return ProductionRate;

View File

@ -20,7 +20,7 @@ class Farm
private float[][] whiteNoise;
private float[][] perlinNoise;
private DayNightCycle Time;
private float updatePerc = 0.10f;
private float updatePerc = 0.01f;
private float updateProgress = 0;
private float nextUpdate = 0;
private int productionUpdate = 0;
@ -141,7 +141,7 @@ class Farm
Update = 0;
}
updateRainMapPosition(Size);
if (productionUpdate == 60)
if (productionUpdate == 2)
{
nextUpdate = updateProgress + updatePerc;
for (int i = (int)(updateProgress * Size.X); i < nextUpdate * Size.X; i++)

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,15 +19,15 @@ 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";
*/
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";
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";
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()
{