merge with dev

This commit is contained in:
BOTLester 2020-05-09 15:59:12 +02:00
commit f475f5bab5
28 changed files with 880 additions and 227 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -13,6 +13,18 @@
#---------------------------------- Content ---------------------------------#
#begin BarleyIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:BarleyIcon.png
#begin BerriesIcon.png
/importer:TextureImporter
/processor:TextureProcessor
@ -37,6 +49,18 @@
/processorParam:TextureFormat=Color
/build:CarronIcon.png;CarrotIcon.png
#begin CottonIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:CottonIcon.png
#begin Crop.png
/importer:TextureImporter
/processor:TextureProcessor
@ -56,6 +80,18 @@
/processorParam:TextureFormat=Compressed
/build:Font.spritefont
#begin GroundNutsIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:GroundNutsIcon.png
#begin house.png
/importer:TextureImporter
/processor:TextureProcessor
@ -68,6 +104,18 @@
/processorParam:TextureFormat=Color
/build:house.png
#begin MaizeIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:MaizeIcon.png
#begin Markers.png
/importer:TextureImporter
/processor:TextureProcessor
@ -80,6 +128,18 @@
/processorParam:TextureFormat=Color
/build:Markers.png
#begin MilletsIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:MilletsIcon.png
#begin Mountain.png
/importer:TextureImporter
/processor:TextureProcessor
@ -104,6 +164,18 @@
/processorParam:TextureFormat=Color
/build:MouseCursor.png
#begin PaddyIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:PaddyIcon.png
#begin Plantable.png
/importer:TextureImporter
/processor:TextureProcessor
@ -152,6 +224,42 @@
/processorParam:TextureFormat=Color
/build:ProgressionBarStatus.png
#begin PulsesIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:PulsesIcon.png
#begin SeedOilIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:SeedOilIcon.png
#begin SugarcaneIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:SugarcaneIcon.png
#begin Tile.png
/importer:TextureImporter
/processor:TextureProcessor
@ -176,6 +284,18 @@
/processorParam:TextureFormat=Color
/build:tileunplantable.png
#begin TobaccoIcon.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:TobaccoIcon.png
#begin Tractor.png
/importer:TextureImporter
/processor:TextureProcessor

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
Game1/Content/MaizeIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
Game1/Content/PaddyIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

View File

@ -14,7 +14,7 @@ namespace Game1
SpriteBatch spriteBatch;
SpriteFont Bold;
private Texture2D[] tile = new Texture2D[5];
private Texture2D[] Crops = new Texture2D[5];
private Texture2D[] Crops = new Texture2D[12];
private Texture2D tractor;
private Texture2D house;
private Texture2D markers;
@ -50,17 +50,18 @@ namespace Game1
// TODO: Add your initialization logic here
base.Initialize();
cropTypesNames[0] = "Barley";
cropTypesNames[1] = "Cotton";
cropTypesNames[2] = "Ground Nuts";
cropTypesNames[3] = "Maize";
cropTypesNames[4] = "Millets";
cropTypesNames[5] = "Oil Seeds";
cropTypesNames[6] = "Paddy";
cropTypesNames[7] = "Pulses";
cropTypesNames[8] = "Sugarcane";
cropTypesNames[9] = "Tobacco";
cropTypesNames[10] = "Wheat";
cropTypesNames[0] = "None";
cropTypesNames[1] = "Barley";
cropTypesNames[2] = "Cotton";
cropTypesNames[3] = "Ground Nuts";
cropTypesNames[4] = "Maize";
cropTypesNames[5] = "Millets";
cropTypesNames[6] = "Oil Seeds";
cropTypesNames[7] = "Paddy";
cropTypesNames[8] = "Pulses";
cropTypesNames[9] = "Sugarcane";
cropTypesNames[10] = "Tobacco";
cropTypesNames[11] = "Wheat";
@ -95,13 +96,25 @@ namespace Game1
tile[0] = Content.Load<Texture2D>("Mountain");
tile[1] = Content.Load<Texture2D>("tileunplantable");
tile[2] = Content.Load<Texture2D>("Plantable");
tile[3] = Content.Load<Texture2D>("Planted");
tile[4] = Content.Load<Texture2D>("Crop");
tile[3] = Content.Load<Texture2D>("Crop");
Crops[0] = Content.Load<Texture2D>("Markers");
Crops[1] = Content.Load<Texture2D>("BarleyIcon");
Crops[2] = Content.Load<Texture2D>("CottonIcon");
Crops[3] = Content.Load<Texture2D>("GroundNutsIcon");
Crops[4] = Content.Load<Texture2D>("MaizeIcon");
Crops[5] = Content.Load<Texture2D>("MilletsIcon");
Crops[6] = Content.Load<Texture2D>("SeedOilIcon");
Crops[7] = Content.Load<Texture2D>("PaddyIcon");
Crops[8] = Content.Load<Texture2D>("PulsesIcon");
Crops[9] = Content.Load<Texture2D>("SugarcaneIcon");
Crops[10] = Content.Load<Texture2D>("TobaccoIcon");
Crops[11] = Content.Load<Texture2D>("WheatIcon");
Crops[0] = Content.Load<Texture2D>("CarrotIcon");
Crops[1] = Content.Load<Texture2D>("WheatIcon");
Crops[2] = Content.Load<Texture2D>("BerriesIcon"); //Replace 2 and 3 with the new crop Textures
Crops[3] = Content.Load<Texture2D>("TreePlantationIcon");
ProgressionBar = Content.Load<Texture2D>("ProgressionBar");
ProgressionBarStatus = Content.Load<Texture2D>("ProgressionBarStatus");
@ -168,7 +181,7 @@ namespace Game1
for (int i = 0; i < 5; i++)
{
spriteBatch.Draw(ProgressionBar, new Rectangle(i * 227, (int)(input.getSize().Y * (input.getTileSize() + input.getSpacing())), 5, 300), Color.White);
spriteBatch.Draw(ProgressionBar, new Rectangle(i * 227, (int)(input.getSize().Y * (input.getTileSize() + input.getSpacing())), 5, 295), Color.White);
}
for (int i = 0; i < 15; i++)
{
@ -217,6 +230,9 @@ namespace Game1
for (int j = 0; j < input.getSize().Y; j++)
{
Rectangle tilePos = new Rectangle(i * (input.getSpacingTile()), j * (input.getSpacingTile()), input.getTileSize(), input.getTileSize());
spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).getStatus()], tilePos, Time.GetTimeOfDay());
if (tilePos.Intersects(mousePosition))
{
@ -232,15 +248,22 @@ namespace Game1
x = i;
y = j;
}
if (tractorUnit.getFarm().getCrop(i, j).getStatus() != 0 && tractorUnit.getFarm().getCrop(i, j).getStatus() != 1)
{
spriteBatch.Draw(Crops[tractorUnit.getFarm().getCrop(i, j).getCropType()], new Rectangle(i * input.getSpacingTile(), j * input.getSpacingTile(), input.getTileSize(), input.getTileSize()), Color.White);
}
if ((tractorUnit.getFarm().getCrop(i, j).getStatus() == 4))
}
else
{
if (tractorUnit.getFarm().getCrop(i, j).getStatus() != 0 && tractorUnit.getFarm().getCrop(i, j).getStatus() != 1)
{
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(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);
}
if (tractorUnit.getFarm().getCrop(i, j).getStatus() != 0 && tractorUnit.getFarm().getCrop(i, j).getStatus() != 1)
{
spriteBatch.Draw(Crops[tractorUnit.getFarm().getCrop(i, j).getCropType()], new Rectangle(i * (input.getSpacingTile()) + input.getTileSize() - input.getTileSize() / 3, j * (input.getSpacingTile()), input.getTileSize() / 3, 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

@ -17,6 +17,21 @@
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x64</PlatformTarget>
@ -63,10 +78,15 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="Game1.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sources\Crops\CropType.cs" />
<Compile Include="Sources\Crops\CropTypesHolder.cs" />
<Compile Include="Sources\Crops\SoilProperties.cs" />
<Compile Include="Sources\Objects\DayNightCycle.cs" />
<Compile Include="Sources\Objects\HandleRotation.cs" />
@ -92,8 +112,9 @@
<Compile Include="Sources\Pathing\A-Star\PathSaver\MinHeap.cs" />
<Compile Include="Sources\Pathing\A-Star\PathSaver\Nodes.cs" />
<Compile Include="Sources\Pathing\A-Star\PathSaver\Path.cs" />
<Compile Include="Sources\Pathing\A-Star\PathSaver\PriorityQueue.cs" />
<Compile Include="Sources\Controlls\Controller.cs" />
<Compile Include="Sources\Pathing\PQEntry.cs" />
<Compile Include="Sources\Pathing\PriorityQueueC5.cs" />
<Compile Include="Sources\Smart\AI.cs" />
<Compile Include="Sources\Smart\ScoreSystem.cs" />
<Compile Include="Sources\Smart\SmartTractor.cs" />
@ -173,6 +194,9 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="C5">
<Version>2.5.3</Version>
</PackageReference>
<PackageReference Include="LightGBM">
<Version>2.3.1</Version>
</PackageReference>
@ -210,6 +234,18 @@
<Version>4.11.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -59,7 +59,7 @@ class Controller
public int controllSpeed(int Speed)
{
KeyboardState state = Keyboard.GetState();
if (state.IsKeyDown(Keys.Right))
if (state.IsKeyDown(Keys.Right) && Speed < 350)
{
Speed++;
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class CropTypes
{
public string[] soilType = new string[3];
public int[] Times = new int[3];
public float Temparature;
public float Humidity;
public float Moisture;
public float Nitrogen;
public float Potassium;
public float Phosphorous;
public CropTypes()
{
soilType = new string[3];
Times = new int[3];
}
}

View File

@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class CropTypesHolder
{
private CropTypes[] cropTypes = new CropTypes[12];
public void init()
{
// None
cropTypes[0] = new CropTypes();
cropTypes[0].soilType[0] = "None";
cropTypes[0].soilType[1] = null;
cropTypes[0].soilType[2] = null;
cropTypes[0].Temparature = 0f;
cropTypes[0].Humidity = 0f;
cropTypes[0].Moisture = 0f;
cropTypes[0].Nitrogen = 0f;
cropTypes[0].Potassium = 0f;
cropTypes[0].Phosphorous = 0f;
// Barley
cropTypes[1] = new CropTypes();
cropTypes[1].soilType[0] = "Sandy";
cropTypes[1].soilType[1] = null;
cropTypes[1].soilType[2] = null;
cropTypes[1].Temparature = 30.1f;
cropTypes[1].Humidity = 59.0f;
cropTypes[1].Moisture = 41.7f;
cropTypes[1].Nitrogen = 25 + 12.6f;
cropTypes[1].Potassium = 14 + 5.3f;
cropTypes[1].Phosphorous = 30 + 26.0f;
// Cotton
cropTypes[2] = new CropTypes();
cropTypes[2].soilType[0] = "Red";
cropTypes[2].Times[0] = 5;
cropTypes[2].soilType[1] = "Black";
cropTypes[2].Times[1] = 4;
cropTypes[2].soilType[2] = "Loamy";
cropTypes[2].Times[2] = 3;
cropTypes[2].Temparature = 30.4f;
cropTypes[2].Humidity = 59.6f;
cropTypes[2].Moisture = 63.2f;
cropTypes[2].Nitrogen = 25 + 16.4f;
cropTypes[2].Potassium = 14 + 3.3f;
cropTypes[2].Phosphorous = 30 + 23.8f;
// Ground Nuts
cropTypes[3] = new CropTypes();
cropTypes[3].soilType[0] = "Red";
cropTypes[3].soilType[1] = null;
cropTypes[3].soilType[2] = null;
cropTypes[3].Temparature = 30.1f;
cropTypes[3].Humidity = 59.1f;
cropTypes[3].Moisture = 33.1f;
cropTypes[3].Nitrogen = 25 + 23.3f;
cropTypes[3].Potassium = 14 + 2.0f;
cropTypes[3].Phosphorous = 30 + 21.6f;
// Maize
cropTypes[4] = new CropTypes();
cropTypes[4].soilType[0] = "Sandy";
cropTypes[4].soilType[1] = null;
cropTypes[4].soilType[2] = null;
cropTypes[4].Temparature = 29.0f;
cropTypes[4].Humidity = 57.3f;
cropTypes[4].Moisture = 42.2f;
cropTypes[4].Nitrogen = 25 + 18.3f;
cropTypes[4].Potassium = 14 + 5.7f;
cropTypes[4].Phosphorous = 30 + 18.7f;
// Millets
cropTypes[5] = new CropTypes();
cropTypes[5].soilType[0] = "Sandy";
cropTypes[5].Times[0] = 7;
cropTypes[5].soilType[1] = "Black";
cropTypes[5].Times[0] = 4;
cropTypes[5].soilType[2] = null;
cropTypes[5].Temparature = 29.5f;
cropTypes[5].Humidity = 57.3f;
cropTypes[5].Moisture = 38.5f;
cropTypes[5].Nitrogen = 25 + 23.2f;
cropTypes[5].Potassium = 14 + 0.1f;
cropTypes[5].Phosphorous = 30 + 14.4f;
//Oil Seeds
cropTypes[6] = new CropTypes();
cropTypes[6].soilType[0] = "Black";
cropTypes[6].soilType[1] = null;
cropTypes[6].soilType[2] = null;
cropTypes[6].Temparature = 30.3f;
cropTypes[6].Humidity = 59.1f;
cropTypes[6].Moisture = 32.1f;
cropTypes[6].Nitrogen = 25 + 19.0f;
cropTypes[6].Potassium = 14 + 2.3f;
cropTypes[6].Phosphorous = 30 + 17.3f;
//Paddys
cropTypes[7] = new CropTypes();
cropTypes[7].soilType[0] = "Clayey";
cropTypes[7].soilType[1] = null;
cropTypes[7].soilType[2] = null;
cropTypes[7].Temparature = 31.2f;
cropTypes[7].Humidity = 60.4f;
cropTypes[7].Moisture = 41.5f;
cropTypes[7].Nitrogen = 25 + 20.8f;
cropTypes[7].Potassium = 14 + 3.7f;
cropTypes[7].Phosphorous = 30 + 16.3f;
//Pulses
cropTypes[8] = new CropTypes();
cropTypes[8].soilType[0] = "Clayey";
cropTypes[8].soilType[1] = null;
cropTypes[8].soilType[2] = null;
cropTypes[8].Temparature = 27.8f;
cropTypes[8].Humidity = 54.9f;
cropTypes[8].Moisture = 34.1f;
cropTypes[8].Nitrogen = 25 + 18.4f;
cropTypes[8].Potassium = 14 + 4.2f;
cropTypes[8].Phosphorous = 30 + 17.5f;
//Sugarcane
cropTypes[9] = new CropTypes();
cropTypes[9].soilType[0] = "Loamy";
cropTypes[9].Times[0] = 9;
cropTypes[9].soilType[1] = "Black";
cropTypes[9].Times[0] = 4;
cropTypes[9].soilType[2] = null;
cropTypes[9].Temparature = 30.0f;
cropTypes[9].Humidity = 58.6f;
cropTypes[9].Moisture = 51.2f;
cropTypes[9].Nitrogen = 25 + 14.6f;
cropTypes[9].Potassium = 14 + 4.2f;
cropTypes[9].Phosphorous = 30 + 17.6f;
//Tobacco
cropTypes[10] = new CropTypes();
cropTypes[10].soilType[0] = "Red";
cropTypes[10].soilType[1] = null;
cropTypes[10].soilType[2] = null;
cropTypes[10].Temparature = 31.9f;
cropTypes[10].Humidity = 62.4f;
cropTypes[10].Moisture = 31.6f;
cropTypes[10].Nitrogen = 25 + 19.1f;
cropTypes[10].Potassium = 14 + 4.9f;
cropTypes[10].Phosphorous = 30 + 19.3f;
//Wheat
cropTypes[11] = new CropTypes();
cropTypes[11].soilType[0] = "Loamy";
cropTypes[11].soilType[1] = null;
cropTypes[11].soilType[2] = null;
cropTypes[11].Temparature = 33.1f;
cropTypes[11].Humidity = 63.8f;
cropTypes[11].Moisture = 50.0f;
cropTypes[11].Nitrogen = 25 + 23.3f;
cropTypes[11].Potassium = 14 + 2.9f;
cropTypes[11].Phosphorous = 30 + 14.4f;
}
public CropTypes getPresetCropTypes(int Index)
{
return cropTypes[Index];
}
}

View File

@ -12,25 +12,45 @@ class Crops
private int Status;
private int originalStatus;
private int cropType = 0;
private int Timer = 1;
private int fullTimer;
private float Timer = 1;
private int UpdateCrop;
private float fullTimer;
private bool housePos = false;
private Vector2 Size;
private CropTypes DataSet;
SoilProperties soilProperties = new SoilProperties();
private float ProductionRate;
public void updateCrop(Vector2 newSize)
{
if (Status == 4 && Timer != 1)
getProductionRate(DataSet);
if (UpdateCrop == 60)
{
Timer--;
degradeSoil();
UpdateCrop = 0;
}
if (Status == 3 && Timer != 1)
{
Timer = Timer - 1f * ProductionRate;
}
Size = newSize;
UpdateCrop++;
if (Timer < 1)
{
Timer = 1;
}
}
public int getCropTimer()
public SoilProperties getSoilProperties()
{
return soilProperties;
}
public float getCropTimer()
{
return Timer;
}
@ -47,8 +67,6 @@ class Crops
soilProperties.setSoilProperties();
}
// Changes the time required for the crops to be harvestable
public void setCropTimer()
{
@ -84,7 +102,7 @@ class Crops
{
return 8;
}
else if (Status == 3) //crops
else
{
if (cropType == 0)
{
@ -103,36 +121,36 @@ class Crops
return 50; //Fruit Trees
}
}
else //Harvestable Crops
{
if (cropType == 0)
{
return 30; //Carrots
}
else if (cropType == 1)
public void degradeSoil()
{
return 40; //Wheat
}
else if (cropType == 2)
if (soilProperties.Nitrogen > 4.0f)
{
return 50; //Berries
soilProperties.Nitrogen = soilProperties.Nitrogen - soilProperties.NitrogenDegradeRate;
}
else
if (soilProperties.Phosphorous > 0.1f)
{
return 100; //Fruit Trees
soilProperties.Phosphorous = soilProperties.Phosphorous - soilProperties.PhosphorousDegradeRate;
}
if (soilProperties.Potassium > 0.1f)
{
soilProperties.Potassium = soilProperties.Potassium - soilProperties.PotassiumDegradeRate;
}
}
public void setCropType(int Type)
public void setCropType(int Type, CropTypes nCropType)
{
DataSet = nCropType;
cropType = Type;
}
public int getStatus()
{
if (Status != 4)
if (Status != 3)
{
return Status;
}
@ -176,6 +194,44 @@ class Crops
return housePos;
}
public float getProductionRate(CropTypes Sample)
{
ProductionRate = 1;
float min = 1.0f;
if (DataSet != null)
{
ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Temperature, Sample.Temparature));
ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Moisture, Sample.Moisture));
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)));
ProductionRate = ProductionRate + (ProductionRate * min);
//ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Phosphorous, Sample.Phosphorous));
//ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Potassium, Sample.Potassium));
//ProductionRate = ProductionRate + (ProductionRate * compareToDatset(soilProperties.Nitrogen, Sample.Nitrogen));
if (ProductionRate < 0)
{
ProductionRate = 0;
}
ProductionRate = ProductionRate / 10;
}
return ProductionRate;
}
public float compareToDatset(float i, float j)
{
if (i < j)
{
return (i / j);
}
else
{
return (j / i);
}
}
public void Inspect(int tileSize, int Spacing, SpriteFont Bold, SpriteBatch spriteBatch, string[] cropTypesNames)
{
spriteBatch.Begin();
@ -196,17 +252,13 @@ class Crops
spriteBatch.DrawString(Bold, "Tiletype: Soil", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.DarkBlue);
}
else if (Status == 3)
{
spriteBatch.DrawString(Bold, "Tiletype: Planted", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.DarkBlue);
}
else if (Status == 4)
{
int x = (int)(((float)Timer / fullTimer) * 100);
x = 100 - x;
spriteBatch.DrawString(Bold, "Tiletype: Crop ", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Completion: " + x + "%", new Vector2(240, Size.Y * (tileSize + Spacing) + 82), Color.DarkBlue);
}
if (Status != 4)
if (Status != 3)
{
spriteBatch.DrawString(Bold, "-------------", new Vector2(240, Size.Y * (tileSize + Spacing) + 82), Color.DarkRed);
}
@ -219,13 +271,22 @@ class Crops
spriteBatch.DrawString(Bold, "None", new Vector2(240, Size.Y * (tileSize + Spacing) + 62), Color.DarkBlue);
}
spriteBatch.DrawString(Bold, "Soil Properties:", new Vector2(240, Size.Y * (tileSize + Spacing) + 122), Color.DarkRed);
spriteBatch.DrawString(Bold, "Soil Type: " + soilProperties.soilType, new Vector2(240, Size.Y * (tileSize + Spacing) + 142), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Temparature: " + soilProperties.Temparature, new Vector2(240, Size.Y * (tileSize + Spacing) + 162), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Moisture: " + soilProperties.Moisture, new Vector2(240, Size.Y * (tileSize + Spacing) + 182), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Humidity: " + soilProperties.Humidity, new Vector2(240, Size.Y * (tileSize + Spacing) + 202), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Phosphorous: " + soilProperties.Phosphorous, new Vector2(240, Size.Y * (tileSize + Spacing) + 222), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Potassium: " + soilProperties.Potassium, new Vector2(240, Size.Y * (tileSize + Spacing) + 242), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Nitrogen: " + soilProperties.Nitrogen, new Vector2(240, Size.Y * (tileSize + Spacing) + 262), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Soil Type: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 142), Color.DarkRed);
spriteBatch.DrawString(Bold, soilProperties.soilType, new Vector2(370, Size.Y * (tileSize + Spacing) + 142), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Temparature: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 162), Color.DarkRed);
spriteBatch.DrawString(Bold, soilProperties.Temperature.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 162), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Moisture: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 182), Color.DarkRed);
spriteBatch.DrawString(Bold, soilProperties.Moisture.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 182), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Humidity: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 202), Color.DarkRed);
spriteBatch.DrawString(Bold, soilProperties.Humidity.ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 202), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Phosphorous: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 222), Color.DarkRed);
spriteBatch.DrawString(Bold, Math.Round(soilProperties.Phosphorous,1).ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 222), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Potassium: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 242), Color.DarkRed);
spriteBatch.DrawString(Bold, Math.Round(soilProperties.Potassium, 1).ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 242), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Nitrogen: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 262), Color.DarkRed);
spriteBatch.DrawString(Bold, Math.Round(soilProperties.Nitrogen, 1).ToString(), new Vector2(370, Size.Y * (tileSize + Spacing) + 262), Color.DarkBlue);
spriteBatch.DrawString(Bold, "Production Rate: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 282), Color.DarkRed);
spriteBatch.DrawString(Bold, Math.Round((ProductionRate * 100), 1).ToString() + "%", new Vector2(370, Size.Y * (tileSize + Spacing) + 282), Color.DarkBlue);
spriteBatch.End();
}
}

View File

@ -10,16 +10,19 @@ class Farm
{
private Crops[,] crops;
private Random r;
private CropTypesHolder PresetCrops = new CropTypesHolder();
private int Update;
//initializes the crops
public void init(Vector2 Size, Vector2 housepos)
{
PresetCrops.init();
r = new Random();
crops = new Crops[100, 100];
for (int i = 0; i < Size.X; i++)
for (int i = 0; i < 99; i++)
{
for (int j = 0; j < Size.Y; j++)
for (int j = 0; j < 99; j++)
{
int x = r.Next(0, 3);
if (x == 0)
@ -33,13 +36,17 @@ class Farm
crops[i, j] = new Crops();
crops[i, j].setStatus(x);
crops[i, j].setOriginalStatus();
crops[i, j].setCropType(x = r.Next(0, 4));
x = r.Next(0, 12);
crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x));
crops[i, j].init();
}
}
}
public void updateFarm(Vector2 Size)
{
Update++;
if (Update == 30)
{
for (int i = 0; i < Size.X; i++)
{
@ -49,6 +56,9 @@ class Farm
crops[i, j].updateCrop(Size);
}
}
Update = 0;
}
}
//Changes the properties of the tile when the tractor reaches this tile.
@ -56,7 +66,7 @@ class Farm
{
int x = (int)xfloat;
int y = (int)yfloat;
if (crops[x, y].getStatus() >= 4)
if (crops[x, y].getStatus() >= 3)
{
crops[x, y].setStatus(2);
}
@ -67,10 +77,6 @@ class Farm
else if (crops[x, y].getStatus() == 2)
{
crops[x, y].setStatus(3);
}
else if (crops[x, y].getStatus() == 3)
{
crops[x, y].setStatus(4);
crops[x, y].setCropTimer();
}
}
@ -85,22 +91,52 @@ class Farm
return crops;
}
public void updateSize(Vector2 Size, int tileSize, int Spacing)
{
for (int i = 0; i < (int)Size.X; i++)
{
for (int j = 0; j < (int)Size.Y; j++)
{
//crops[i, j].x = (tileSize + Spacing) * i;
//crops[i, j].y = (tileSize + Spacing) * j;
}
}
}
public void setNewHousePos(Vector2 pos, bool newState)
{
crops[(int)pos.X, (int)pos.Y].setHousePos(newState);
}
public CropTypes getPresetCropTypes(int Index)
{
return PresetCrops.getPresetCropTypes(Index - 1);
}
public void setCropType(int x, int y, int Type)
{
crops[x, y].setCropType(Type, PresetCrops.getPresetCropTypes(Type));
}
public void UpdatePreferedCrops(Vector2 Size)
{
for (int i = 0; i < Size.X; i++)
{
for (int j = 0; j < Size.X; j++)
{
int x = getHighestProductionRate(i, j);
crops[i,j].setCropType(x, PresetCrops.getPresetCropTypes(x));
}
}
}
private int getHighestProductionRate(int x, int y)
{
int i = 1, holderIndex = 0;
float holder = 0, SampleHolder = 0;
do
{
holder = getProductionRate(x, y, i);
if (SampleHolder < holder)
{
holderIndex = i;
SampleHolder = holder;
}
i++;
} while (i < 12);
return holderIndex;
}
public float getProductionRate(int x, int y, int Type)
{
return crops[x, y].getProductionRate(PresetCrops.getPresetCropTypes(Type));
}
}

View File

@ -11,21 +11,45 @@ class SoilProperties
public string soilType = "potato";
public float Temparature;
public float Temperature;
public float Humidity;
public float Moisture;
public float Nitrogen;
public float Potassium;
public float Phosphorous;
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 void setSoilProperties()
{
Temparature = GetRandomNumber(22, 30);
Humidity = GetRandomNumber(1, 5);
Moisture = GetRandomNumber(1, 10);
Nitrogen = GetRandomNumber(0.5 , 1);
Potassium = GetRandomNumber(5, 20);
Phosphorous = GetRandomNumber(4, 50);
int soilTypeRandomizer = r.Next(0, 1000);
if (soilTypeRandomizer < 210)
{
soilType = "Loamy";
}
else if (soilTypeRandomizer < 400)
{
soilType = "Red";
}
else if (soilTypeRandomizer < 600)
{
soilType = "Black";
}
else if (soilTypeRandomizer < 800)
{
soilType = "Sandy";
}
else
{
soilType = "Clayey";
}
Temperature = GetRandomNumber(22, 30);
Humidity = Temperature * GetRandomNumber(1.9, 2.1);
Moisture = GetRandomNumber(20, 70);
Nitrogen = GetRandomNumber(4 , 55);
Potassium = GetRandomNumber(0.01f, 28);
Phosphorous = GetRandomNumber(0.01f, 60);
}
public float GetRandomNumber(double minimum, double maximum)

View File

@ -12,7 +12,7 @@ class DayNightCycle
private int dayTime = 0;
private int lengthOfDay = 20000;
private int lengthOfNight = 20000;
private int Days;
private int Days = 1;
public void updateTime(int Speed)
{

View File

@ -37,7 +37,7 @@ class House
housePos = new Rectangle((int)pos.X * (tileSize + Spacing), (int)pos.Y * (tileSize + Spacing), tileSize, tileSize);
}
//Returns house Rectangle
public Rectangle GetRectangle()
{
return housePos;

View File

@ -4,36 +4,40 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Game1.Sources.ML;
using C5;
using System.Diagnostics;
class Astar
{
private Vector2 tractorPos;
private Vector2 housePos;
private Crops[,] crops;
private static Crops[,] crops;
private Vector2 Size;
private PriorityQueue allPaths;
private Vector2 targetPos;
private int Rotation;
public void update(Crops[,] newCrops, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, Vector2 newtargetPos, int rotation)
public void update(Crops[,] newCrops, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, int rotation)
{
tractorPos = new Vector2((int)newTractorPos.X, (int)newTractorPos.Y);
housePos = new Vector2((int)newHousePos.X, (int)newHousePos.Y);
targetPos = newtargetPos;
crops = newCrops;
Size = newSize;
Rotation = rotation;
}
public Nodes getOptimalPath()
public void update(Crops[,] newCrops, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, Vector2 newTargetPos, int rotation)
{
return allPaths.Peek();
tractorPos = new Vector2((int)newTractorPos.X, (int)newTractorPos.Y);
housePos = new Vector2((int)newHousePos.X, (int)newHousePos.Y);
crops = newCrops;
Size = newSize;
Rotation = rotation;
targetPos = newTargetPos;
}
// Get all adjacent nodes
private List<Nodes> GetAdjacentNodes(Vector2 currentPos)
public List<Nodes> GetAdjacentNodes(Vector2 currentPos)
{
var adjacentNodes = new List<Nodes>()
@ -71,9 +75,9 @@ class Astar
if (currDir == newDir)
return 0;
else if (Math.Abs(currDir - newDir) == 1 || Math.Abs(currDir - newDir) == 3)
return 2;
return 20;
else if (Math.Abs(currDir - newDir) == 0 || Math.Abs(currDir - newDir) == 2)
return 9;
return 900;
return 0;
}
@ -81,19 +85,19 @@ class Astar
public int ConvertRotation()
{
int rotation = 0;
if (Rotation == 180)
if (Rotation > 135 && Rotation < 225)
rotation = 0;
else if (Rotation == 270)
else if (Rotation > 225 && Rotation < 315)
rotation = 1;
else if (Rotation == 0)
else if (Rotation > 315 && Rotation < 45)
rotation = 2;
else if (Rotation == 90)
else if (Rotation > 45 && Rotation < 135)
rotation = -1;
return rotation;
}
// Main function of A* algorithm
public Path FindPath()
public Path FindPath(bool flipArray)
{
int g = 0;
int direction = ConvertRotation();
@ -124,7 +128,6 @@ class Astar
g = current.getG() + crops[(int)adjacentNode.getCords().X, (int)adjacentNode.getCords().Y].getCostOnMovement() + CalculateRotationCost(direction, adjacentNode.getDirection()); // calculate g - cost from start point
if (!(openList.Exists(adjacentNode.getCords()))) // if adjacent node is not on open list, add it
{
adjacentNode.setG(g);
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), target.getCords()));
adjacentNode.calculateF();
@ -150,10 +153,13 @@ class Astar
path.AddNode(current);
current = current.getParent();
}
if (flipArray)
path = path.FlipArray();
openList.deleteHeap();
closedList.deleteHeap();
return path;
}

View File

@ -6,8 +6,9 @@ using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using C5;
class Nodes
class Nodes : IComparable<Nodes>, IEqualityComparer<Nodes>, IPriorityQueueHandle<Nodes>
{
private int F = 0;
private int G = 0;
@ -27,6 +28,12 @@ class Nodes
Direction = direction;
}
public Nodes(int f, Vector2 coordinates)
{
Coordinates = coordinates;
F = f;
}
public Nodes(Nodes node)
{
F = node.F;
@ -94,4 +101,24 @@ class Nodes
{
return Direction;
}
public int CompareTo(Nodes other)
{
if (this.F < other.F)
return -1;
else if (this.F > other.F)
return 1;
else
return 0;
}
public bool Equals(Nodes source, Nodes other)
{
return (source.Coordinates.X == other.Coordinates.X && source.Coordinates.Y == other.Coordinates.Y);
}
public int GetHashCode(Nodes nodes)
{
return (nodes.Coordinates.GetHashCode());
}
}

View File

@ -1,88 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
class PriorityQueue
{
public List<Nodes> list;
public int Count { get { return list.Count; } }
public PriorityQueue()
{
list = new List<Nodes>();
}
public PriorityQueue(int count)
{
list = new List<Nodes>(count);
}
public void Enqueue(Nodes x)
{
list.Add(x);
int i = Count - 1;
while (i > 0)
{
int p = (i - 1) / 2;
if (list[p].getF() <= x.getF()) break;
list[i] = list[p];
i = p;
}
if (Count > 0) list[i] = x;
}
public void Dequeue()
{
Nodes min = Peek();
Nodes root = list[Count - 1];
list.RemoveAt(Count - 1);
int i = 0;
while (i * 2 + 1 < Count)
{
int a = i * 2 + 1;
int b = i * 2 + 2;
int c = b < Count && list[b].getF() < list[a].getF() ? b : a;
if (list[c].getF() >= root.getF()) break;
list[i] = list[c];
i = c;
}
if (Count > 0) list[i] = root;
}
public Nodes Peek()
{
if (Count == 0) throw new InvalidOperationException("Queue is empty.");
return list[0];
}
public Boolean Exists(Vector2 coordinates)
{
if (Count == 0)
return false;
foreach(Nodes node in list)
{
if (node.getCords() == coordinates)
return true;
}
return false;
}
public void Clear()
{
list.Clear();
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
public class PQEntry : IComparable<PQEntry>
{
public int Key { get; set; }
public Vector2 Coordinates { get; set; }
public int CompareTo(PQEntry other)
{
if (this.Key < other.Key)
return -1;
else if (this.Key > other.Key)
return 1;
else
return 0;
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using C5;
class PriorityQueueC5
{
private readonly Astar astar = new Astar();
private IPriorityQueue<PQEntry> queue = new IntervalHeap<PQEntry>();
public void AddToQueue(List<PQEntry> nodes)
{
foreach (PQEntry item in nodes)
{
PQEntry temp = new PQEntry
{
Key = item.Key,
Coordinates = item.Coordinates
};
queue.Add(temp);
}
}
public void AddToQueue(int x, int y, int score)
{
PQEntry temp = new PQEntry
{
Key = score,
Coordinates = new Vector2(x, y)
};
queue.Add(temp);
}
public PQEntry DeleteMax()
{
return queue.DeleteMax();
}
public void AddAll(List<PQEntry> entryList)
{
queue.AddAll(entryList);
}
}

View File

@ -9,7 +9,6 @@ using Microsoft.Xna.Framework.Graphics;
class AI
{
private Vector2 tractorPos;
private Vector2 housePos;
private Farm farm;
@ -17,9 +16,7 @@ class AI
private Vector2 targetPos;
private Inventory inventory = new Inventory();
private int Rotation;
private Astar astar = new Astar();
private Random r = new Random();
@ -27,21 +24,9 @@ class AI
public void init()
{
inventory.initInventorySystem();
inventory.addItem(1, 1);
inventory.addItem(1, 1);
inventory.addItem(3, 1);
inventory.addItem(5, 1);
inventory.addItem(7, 1);
inventory.addItem(7, 1);
inventory.addItem(10, 1);
inventory.addItem(10, 1);
inventory.useItem(10, 1);
}
public void update(Farm newFarm, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, Vector2 newtargetPos, int rotation)
{
tractorPos = new Vector2((int)newTractorPos.X, (int)newTractorPos.Y);
@ -50,6 +35,7 @@ class AI
farm = newFarm;
Size = newSize;
Rotation = rotation;
astar.update(farm.getCrops(), Size, tractorPos, housePos, rotation);
}
@ -61,7 +47,40 @@ class AI
public Vector2 newTarget()
{
return new Vector2(r.Next(0, (int)Size.X), r.Next(0, (int)Size.Y));
PriorityQueueC5 queue = new PriorityQueueC5();
int score = 0;
int count = 0;
int testsize = 2;
Vector2 newTarget;
while (true)
{
for (int x = 0; x < Size.X; x++)
for (int y = 0; y < Size.Y; y++)
{
if (farm.getCrop(x, y).getStatus() >= 2 && tractorPos != new Vector2(x, y))
{
score = calculateSoilScore(x, y);
queue.AddToQueue(x, y, score);
if (farm.getCrop(x, y).getCropTimer() == 1 || farm.getCrop(x, y).getStatus() == 2)
count++;
}
}
if (count > 0)
break;
else if (tractorPos != housePos)
return newTarget = GetMaxFNode(testsize, queue);
/*
else if (tractorPos == housePos)
{
List<Nodes> temp = astar.GetAdjacentNodes(tractorPos);
return temp[0].getCords();
}
*/
}
newTarget = GetMinFNode(Math.Min(testsize, count), queue);
return newTarget;
}
public Farm changeCropStatus()
@ -69,6 +88,11 @@ class AI
if (farm.getCrop((int)tractorPos.X, (int)tractorPos.Y).getCropTimer() == 1)
{
farm.setCropStatus(tractorPos.X, tractorPos.Y);
if (farm.getCrop((int)tractorPos.X, (int)tractorPos.Y).getStatus() == 2)
{
inventory.addItem(farm.getCrop((int)tractorPos.X, (int)tractorPos.Y).getCropType() - 1, 1);
}
}
return farm;
}
@ -77,4 +101,105 @@ class AI
{
return inventory;
}
private int calculateSoilScore(int x, int y)
{
int score = 0;
int statusScore = 0;
int timerScore = 0;
int aproxDistance = (int)(Math.Abs(x - tractorPos.X) + Math.Abs(y - tractorPos.Y));
CropTypesHolder holder = new CropTypesHolder();
holder.init();
Crops crop = farm.getCrop(x, y);
SoilProperties soilP = crop.getSoilProperties();
int cropType = crop.getCropType();
CropTypes avgHold = holder.getPresetCropTypes(cropType);
if (crop.getStatus() == 2)
statusScore = 25;
else if (crop.getStatus() == 3)
statusScore = -100;
else
statusScore = 1;
if (crop.getCropTimer() == 1)
timerScore = 999;
else
statusScore = 0;
score = (int)(crop.getProductionRate(avgHold) * 10);
return score + (-aproxDistance * 5) + statusScore + timerScore;
}
private float norm(float min, float max, float val)
{
return ((val - min) / (max - min));
}
public Vector2 GetMinFNode(int testSize, PriorityQueueC5 queue)
{
int index = 0;
int min = 9999;
Path path = new Path();
List<PQEntry> entryList = new List<PQEntry>();
for (int i = 0; i < testSize; i++)
{
entryList.Add(queue.DeleteMax());
}
for (int i = 0; i < testSize; i++)
{
Nodes temp = new Nodes(entryList[i].Coordinates);
path = astar.FindPath(false);
Nodes tempF = new Nodes(path.getByIndex(0));
if (min > tempF.getF())
{
min = tempF.getF();
index = i;
}
}
PQEntry minEntry = entryList[index];
entryList.RemoveAt(index);
//add the non-minimum entries back to the queue.
queue.AddAll(entryList);
return minEntry.Coordinates;
}
public Vector2 GetMaxFNode(int testSize, PriorityQueueC5 queue)
{
int index = 0;
int max = -9999;
Path path = new Path();
List<PQEntry> entryList = new List<PQEntry>();
for (int i = 0; i < testSize; i++)
{
entryList.Add(queue.DeleteMax());
}
for (int i = 0; i < testSize; i++)
{
Nodes temp = new Nodes(entryList[i].Coordinates);
path = astar.FindPath(false);
Nodes tempF = new Nodes(path.getByIndex(0));
if (max < tempF.getF())
{
max = tempF.getF();
index = i;
}
}
PQEntry minEntry = entryList[index];
entryList.RemoveAt(index);
//add the non-minimum entries back to the queue.
queue.AddAll(entryList);
return minEntry.Coordinates;
}
}

View File

@ -17,11 +17,13 @@ class SmartTractor
public Path returnChoice()
{
ai.update(farm, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
farm.UpdatePreferedCrops(Size);
farm = ai.changeCropStatus();
astar.update(farm.getCrops(), Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Rotation);
getTargetPosition(ai.newTarget());
astar.update(farm.getCrops(), Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
return astar.FindPath();
return astar.FindPath(true);
}