This commit is contained in:
Joel 2020-05-24 22:22:09 +02:00
parent 10e58f984f
commit 5e9c9f503d
6 changed files with 42 additions and 18 deletions

View File

@ -22,7 +22,7 @@ class Crops
SoilProperties soilProperties = new SoilProperties(); SoilProperties soilProperties = new SoilProperties();
private float ProductionRate; private float ProductionRate;
private float tempRain; private float tempRain;
public DayNightCycle Time { get; set; } private DayNightCycle Time = new DayNightCycle();
@ -30,7 +30,6 @@ class Crops
{ {
Time = nTime; Time = nTime;
tempRain = Rain; tempRain = Rain;
getProductionRate(DataSet);
if (UpdateCrop == 60) if (UpdateCrop == 60)
{ {
degradeSoil(Rain); degradeSoil(Rain);
@ -50,6 +49,11 @@ class Crops
} }
} }
public void updateProductionRate()
{
getProductionRate(DataSet);
}
public float getSpeedFactor(float tractorSpeed) public float getSpeedFactor(float tractorSpeed)
{ {
if (getCostOnMovement() == 1) if (getCostOnMovement() == 1)
@ -328,6 +332,7 @@ class Crops
public float getProductionRate(CropTypes Sample) public float getProductionRate(CropTypes Sample)
{ {
ProductionRate = 1; ProductionRate = 1;
float min = 1.0f; float min = 1.0f;
if (DataSet != null) if (DataSet != null)

View File

@ -20,6 +20,10 @@ class Farm
private float[][] whiteNoise; private float[][] whiteNoise;
private float[][] perlinNoise; private float[][] perlinNoise;
private DayNightCycle Time; private DayNightCycle Time;
private float updatePerc = 0.25f;
private float updateProgress = 0;
private int nextUpdate = 0;
private int productionUpdate = 0;
//initializes the crops //initializes the crops
@ -133,7 +137,25 @@ class Farm
Update = 0; Update = 0;
} }
updateRainMapPosition(Size); if (productionUpdate == 20)
{
nextUpdate = (int)(nextUpdate + Size.X * updatePerc);
for (int i = (int)(updateProgress * Size.X); i < nextUpdate; i++)
{
for (int j = 0; j < Size.Y; j++)
{
crops[i, j].updateProductionRate();
}
}
updateProgress = updateProgress + updatePerc;
if (updateProgress > 1)
{
updateProgress = 0;
}
updateRainMapPosition(Size);
productionUpdate = 0;
}
productionUpdate++;
} }
public void updateRainFall(Vector2 Size, DayNightCycle nTime) public void updateRainFall(Vector2 Size, DayNightCycle nTime)
@ -239,7 +261,7 @@ class Farm
{ {
for (int j = 0; j < Size.X; j++) for (int j = 0; j < Size.X; j++)
{ {
if (crops[i, j].getStatus() != 3) if (crops[i, j].getStatus() == 2)
{ {
int x = getHighestProductionRate(i, j); int x = getHighestProductionRate(i, j);
crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x)); crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x));

View File

@ -11,7 +11,7 @@ using Microsoft.ML.Trainers.LightGbm;
class MLModel class MLModel
{ {
private static MLContext mlContext = new MLContext(seed: 1); 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 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 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 report = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/report";
@ -19,8 +19,7 @@ class MLModel
private static string pathBig = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/BigFertPredict.csv"; 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 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 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 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 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 reportBig = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/report_BigModel";
@ -28,7 +27,6 @@ class MLModel
private static string path = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/Fertilizer_Prediction.csv"; 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 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 report = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/report";
*/
// Loading data, creatin and saving ML model for smaller dataset (100) // Loading data, creatin and saving ML model for smaller dataset (100)
public static void CreateModel() public static void CreateModel()

View File

@ -18,13 +18,13 @@ namespace Game1.Sources.ML_Joel
private static string modelpath = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/MLmodel_Joel"; 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"; private static string report = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/report_Joel";
*/ */
private static string path = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/Rainfall.csv"; private static string path = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/Rainfall.csv";
private static string modelpath = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/MLmodel_Joel"; private static string modelpath = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/MLmodel_Joel";
private static string report = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/report_Joel"; private static string report = "C:/Users/Joel/source/repos/Oskars Repo/Game1/Content/ML/report_Joel";
private static string path_area = "C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/Rainfall_area.csv"; 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/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/MLmodel_Joel_area"; 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/Oskar/source/repos/PotatoPlanFinal/Game1/Content/ML/report_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) // Loading data, creatin and saving ML model for smaller dataset (100)
public static void CreateModel() public static void CreateModel()

View File

@ -6,11 +6,10 @@ class Tractor
{ {
private int Spacing, sizeTile, Speed = 1; private int Spacing, sizeTile, Speed = 1;
private float tractorSpeed = 1; private float tractorSpeed = 1;
private Vector2 Position, TargetPosition, Size, housePos, oldDeltaPosition, DeltaPosition; private Vector2 Position, TargetPosition, Size, housePos, DeltaPosition;
private Path path = new Path(); private Path path = new Path();
private SmartTractor smartTractor = new SmartTractor(); private SmartTractor smartTractor = new SmartTractor();
private HandleRotation handleRotation = new HandleRotation(); private HandleRotation handleRotation = new HandleRotation();
private int WaitFrame = 30;
private int j; private int j;

View File

@ -74,13 +74,13 @@ class SmartTractor
farm.setNewHousePos(pos, newState); farm.setNewHousePos(pos, newState);
} }
public void UpdateCrops(int Speed, DayNightCycle Time) public void UpdateCrops(int Speed, DayNightCycle nTime)
{ {
for (int i = 0; i < Speed; i++) for (int i = 0; i < Speed; i++)
{ {
farm.updateFarm(Size); farm.updateFarm(Size);
} }
farm.updateRainFall(Size, Time); farm.updateRainFall(Size, nTime);
} }
public Inventory getInventory() public Inventory getInventory()