1
0
forked from s425077/PotatoPlan

Merge branch 'Oskar-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Oskar-ML

This commit is contained in:
Joel 2020-05-10 19:22:33 +02:00
commit b083ae4293
5 changed files with 53 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -258,7 +258,7 @@ namespace Game1
if ((tractorUnit.getFarm().getCrop(i, j).getStatus() == 3)) if ((tractorUnit.getFarm().getCrop(i, j).getStatus() == 3))
{ {
spriteBatch.Draw(ProgressionBar, new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 3, j * (input.getSpacingTile()), input.getTileSize() / 3, input.getTileSize()), Color.White); spriteBatch.Draw(ProgressionBar, new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 3, j * (input.getSpacingTile()), input.getTileSize() / 3, input.getTileSize()), Color.White);
spriteBatch.Draw(ProgressionBarStatus, new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 4, j * (input.getSpacingTile()) + input.getTileSize() / 3, input.getTileSize() / 4, tractorUnit.getFarm().getCrop(i, j).getCropTimerBar((input.getTileSize())) + 1), Color.White); spriteBatch.Draw(ProgressionBarStatus, new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 4, j * (input.getSpacingTile()) + input.getTileSize() / 3, input.getTileSize() / 4, tractorUnit.getFarm().getCrop(i, j).getCropTimerBar((input.getTileSize())) + 1), new Color(tractorUnit.getFarm().getCrop(i, j).getColour()));
} }
spriteBatch.Draw(Crops[tractorUnit.getFarm().getCrop(i, j).getCropType()], new Rectangle((int)(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 2.5), j * (input.getSpacingTile()), (int)(input.getTileSize() / 2.5), input.getTileSize() / 3), Color.White); spriteBatch.Draw(Crops[tractorUnit.getFarm().getCrop(i, j).getCropType()], new Rectangle((int)(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 2.5), j * (input.getSpacingTile()), (int)(input.getTileSize() / 2.5), input.getTileSize() / 3), Color.White);
} }

View File

@ -194,15 +194,15 @@ class Crops
if (soilProperties.Nitrogen > 4.0f) if (soilProperties.Nitrogen > 4.0f)
{ {
soilProperties.Nitrogen = soilProperties.Nitrogen - soilProperties.NitrogenDegradeRate; soilProperties.Nitrogen = soilProperties.Nitrogen - (soilProperties.NitrogenDegradeRate * (float)Math.Pow(ProductionRate, 2));
} }
if (soilProperties.Phosphorous > 0.1f) if (soilProperties.Phosphorous > 0.1f)
{ {
soilProperties.Phosphorous = soilProperties.Phosphorous - soilProperties.PhosphorousDegradeRate; soilProperties.Phosphorous = soilProperties.Phosphorous - (soilProperties.PhosphorousDegradeRate * (float)Math.Pow(ProductionRate, 2));
} }
if (soilProperties.Potassium > 0.1f) if (soilProperties.Potassium > 0.1f)
{ {
soilProperties.Potassium = soilProperties.Potassium - soilProperties.PotassiumDegradeRate; soilProperties.Potassium = soilProperties.Potassium - (soilProperties.PotassiumDegradeRate * (float)Math.Pow(ProductionRate, 2));
} }
} }
@ -265,22 +265,46 @@ class Crops
return ((int)(soilProperties.Nitrogen + soilProperties.Potassium + soilProperties.Phosphorous)) < soilProperties.Capacity; return ((int)(soilProperties.Nitrogen + soilProperties.Potassium + soilProperties.Phosphorous)) < soilProperties.Capacity;
} }
public Vector4 getColour()
{
float r, g, b, a;
float productionRate, overhead;
if (ProductionRate > 1.0f)
{
productionRate = 1.0f;
overhead = ProductionRate - 1.0f;
}
else
{
productionRate = ProductionRate;
overhead = 0.0f;
}
r = (1.0f - productionRate) * 2;
g = 0.0f + productionRate;
b = 0.0f + (float)Math.Pow((double)overhead * 10, 2);
a = 255;
return new Vector4(r, g, b, a);
}
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)
{ {
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));
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)
{ {
ProductionRate = 0; ProductionRate = 0;
} }
ProductionRate = ProductionRate / 10; ProductionRate = ProductionRate / 1.5f;
} }
ProductionRate = (float)Math.Pow(ProductionRate, 2.5f); ProductionRate = (float)Math.Pow(ProductionRate, 2.5f);
return ProductionRate; return ProductionRate;

View File

@ -46,4 +46,9 @@ class PriorityQueueC5
queue.AddAll(entryList); queue.AddAll(entryList);
} }
public int getCount()
{
return queue.Count();
}
} }

View File

@ -53,6 +53,11 @@ class AI
int count = 0; int count = 0;
int testsize = 2; int testsize = 2;
Path newTarget; Path newTarget;
Nodes nodes;
if (astar.GetAdjacentNodes(tractorPos).Count == 0)
nodes = new Nodes(housePos);
else
nodes = astar.GetAdjacentNodes(tractorPos)[0];
if (tractorPos != housePos) if (tractorPos != housePos)
if (inventory.getWeight() == inventory.getMaxWeight() || inventory.isMissingFertilizer()) if (inventory.getWeight() == inventory.getMaxWeight() || inventory.isMissingFertilizer())
{ {
@ -81,8 +86,18 @@ class AI
} }
if (count > 0) if (count > 0)
break; break;
else if (queue.getCount() == 0)
{
astar.update(farm.getCrops(), Size, tractorPos, housePos, nodes.getCords(), Rotation);
return newTarget = astar.FindPath(true);
}
else //if (tractorPos != housePos) else //if (tractorPos != housePos)
return newTarget = GetMaxFNode(testsize, queue); return newTarget = GetMaxFNode(Math.Min(queue.getCount(), testsize), queue);
}
if (queue.getCount() == 0)
{
astar.update(farm.getCrops(), Size, tractorPos, housePos, nodes.getCords(), Rotation);
return newTarget = astar.FindPath(true);
} }
newTarget = GetMinFNode(Math.Min(testsize, count), queue); newTarget = GetMinFNode(Math.Min(testsize, count), queue);
queue = null; queue = null;