Compare commits
No commits in common. "master" and "master" have entirely different histories.
Before Width: | Height: | Size: 134 KiB |
Before Width: | Height: | Size: 210 KiB |
BIN
Example.jpg
Before Width: | Height: | Size: 872 KiB |
@ -1,38 +0,0 @@
|
|||||||
# Final Evaluation
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
PotatoPlan is an Inteligent Tractor AI Project and is written in C# using Monogame framework.
|
|
||||||
NuGet Packages used and requeired for the project to work ar as follows:
|
|
||||||
C5
|
|
||||||
Microsoft.ML
|
|
||||||
Microsoft.ML.LightGBM
|
|
||||||
System.Drawing.Common
|
|
||||||
|
|
||||||
In our project agent (tractor) moves on resizable grid, which starting size is dependant on primary screen resolution.
|
|
||||||
The task of the agent is to go through all soil tiles and plant different types of crops, use proper fertilizer and collect crops when fully grown.
|
|
||||||
|
|
||||||
Window can be resized usind WASD. Tractor speed can be changed using UP and DOWN arrow keys, while simulation speed can be changed using LEFT and RIGHT arrow keys.
|
|
||||||
Also house placement can be changed by left clicking on a tile, and get info about the tile by right clicking.
|
|
||||||
|
|
||||||
Apart from Machine Learning Algorithms used in project there are also many different features implemented like:
|
|
||||||
- Using A* algorithm to find an optimal path to previously selected target.
|
|
||||||
- Target is found by scoring system which assign score to a tile based on few factors like production rate or distance.
|
|
||||||
- Dynamically allocated cargo space for each fertilizer based on how often each fertilizer is used.
|
|
||||||
- Day and night cycle and season system.
|
|
||||||
- Using noise map generated for rainfall calculations to draw moving clouds.
|
|
||||||
- ... and few other.
|
|
||||||
|
|
||||||
## Machine Learning Algorithms
|
|
||||||
Project in its current state uses Machine Learning Algorithms to solve 2 problems. Light Gradient-Boosted Trees are used for both problems:
|
|
||||||
1. Choosing a proper fertilizer which should be applied to current tile, based on few variables like nutrients in soil.
|
|
||||||
Applying proper fertilizer boosts production rate of a crop (rate of growth of a crop). This part was done by Oskar Nastały.
|
|
||||||
2. Calculating production rate of a tile based on rainfall and few other variabels. Noise map is generated and used to simulate dynamically changing rainfall.
|
|
||||||
Then once a day AI is used to calculate base production rate multiplier. This part was done by Joel Städe.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
### Clouds
|
|
||||||
![Clouds](https://git.wmi.amu.edu.pl/s425077/PotatoPlan/raw/Joel-ML/Evaluation_examples/Example_clouds.PNG)
|
|
||||||
|
|
||||||
### UI
|
|
||||||
![UI](https://git.wmi.amu.edu.pl/s425077/PotatoPlan/raw/Joel-ML/Evaluation_examples/Example_UI.PNG)
|
|
@ -7,18 +7,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game1", "Game1\Game1.csproj
|
|||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x64 = Debug|x64
|
|
||||||
Debug|x86 = Debug|x86
|
Debug|x86 = Debug|x86
|
||||||
Release|x64 = Release|x64
|
|
||||||
Release|x86 = Release|x86
|
Release|x86 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x86.ActiveCfg = Debug|x86
|
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x86.Build.0 = Debug|x86
|
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x86.Build.0 = Debug|x86
|
||||||
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x64.Build.0 = Release|x64
|
|
||||||
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x86.ActiveCfg = Release|x86
|
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x86.ActiveCfg = Release|x86
|
||||||
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x86.Build.0 = Release|x86
|
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x86.Build.0 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 1.4 MiB |
Before Width: | Height: | Size: 4.8 MiB |
@ -13,90 +13,6 @@
|
|||||||
|
|
||||||
#---------------------------------- Content ---------------------------------#
|
#---------------------------------- 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
|
|
||||||
/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:BerriesIcon.png
|
|
||||||
|
|
||||||
#begin Bottom.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:Bottom.png
|
|
||||||
|
|
||||||
#begin CarronIcon.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:CarronIcon.png;CarrotIcon.png
|
|
||||||
|
|
||||||
#begin Cloud.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:Cloud.png
|
|
||||||
|
|
||||||
#begin Clouds.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:Clouds.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
|
#begin Crop.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
@ -116,18 +32,6 @@
|
|||||||
/processorParam:TextureFormat=Compressed
|
/processorParam:TextureFormat=Compressed
|
||||||
/build:Font.spritefont
|
/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
|
#begin house.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
@ -140,30 +44,6 @@
|
|||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:house.png
|
/build:house.png
|
||||||
|
|
||||||
#begin Left.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:Left.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
|
#begin Markers.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
@ -176,18 +56,6 @@
|
|||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:Markers.png
|
/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
|
#begin Mountain.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
@ -200,30 +68,6 @@
|
|||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:Mountain.png
|
/build:Mountain.png
|
||||||
|
|
||||||
#begin MouseCursor.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: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
|
#begin Plantable.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
@ -236,7 +80,7 @@
|
|||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:Plantable.png
|
/build:Plantable.png
|
||||||
|
|
||||||
#begin ProgressionBar.png
|
#begin Planted.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
@ -246,79 +90,7 @@
|
|||||||
/processorParam:ResizeToPowerOfTwo=False
|
/processorParam:ResizeToPowerOfTwo=False
|
||||||
/processorParam:MakeSquare=False
|
/processorParam:MakeSquare=False
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:ProgressionBar.png
|
/build:Planted.png
|
||||||
|
|
||||||
#begin ProgressionBarStatus.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: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 rain.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:rain.png
|
|
||||||
|
|
||||||
#begin Right.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:Right.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
|
#begin Tile.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
@ -344,30 +116,6 @@
|
|||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:tileunplantable.png
|
/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 Top.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:Top.png
|
|
||||||
|
|
||||||
#begin Tractor.png
|
#begin Tractor.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
@ -380,39 +128,3 @@
|
|||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:Tractor.png
|
/build:Tractor.png
|
||||||
|
|
||||||
#begin TreePlantationIcon.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:TreePlantationIcon.png
|
|
||||||
|
|
||||||
#begin WheatIcon.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:WheatIcon.png
|
|
||||||
|
|
||||||
#begin WoodBackground.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:WoodBackground.png
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 872 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 3.8 KiB |
@ -1,100 +0,0 @@
|
|||||||
Temparature,Humidity ,Moisture,Soil Type,Crop Type,Nitrogen,Potassium,Phosphorous,Fertilizer Name
|
|
||||||
26,52,38,Sandy,Maize,37,0,0,Urea
|
|
||||||
29,52,45,Loamy,Sugarcane,12,0,36,DAP
|
|
||||||
34,65,62,Black,Cotton,7,9,30,14-35-14
|
|
||||||
32,62,34,Red,Tobacco,22,0,20,28-28
|
|
||||||
28,54,46,Clayey,Paddy,35,0,0,Urea
|
|
||||||
26,52,35,Sandy,Barley,12,10,13,17-17-17
|
|
||||||
25,50,64,Red,Cotton,9,0,10,20-20
|
|
||||||
33,64,50,Loamy,Wheat,41,0,0,Urea
|
|
||||||
30,60,42,Sandy,Millets,21,0,18,28-28
|
|
||||||
29,58,33,Black,Oil seeds,9,7,30,14-35-14
|
|
||||||
27,54,28,Clayey,Pulses,13,0,40,DAP
|
|
||||||
31,62,48,Sandy,Maize,14,15,12,17-17-17
|
|
||||||
25,50,65,Loamy,Cotton,36,0,0,Urea
|
|
||||||
32,62,41,Clayey,Paddy,24,0,22,28-28
|
|
||||||
26,52,31,Red,Ground Nuts,14,0,41,DAP
|
|
||||||
31,62,49,Black,Sugarcane,10,13,14,17-17-17
|
|
||||||
33,64,34,Clayey,Pulses,38,0,0,Urea
|
|
||||||
25,50,39,Sandy,Barley,21,0,19,28-28
|
|
||||||
28,54,65,Black,Cotton,39,0,0,Urea
|
|
||||||
29,58,52,Loamy,Wheat,13,0,36,DAP
|
|
||||||
30,60,44,Sandy,Millets,10,0,9,20-20
|
|
||||||
34,65,53,Loamy,Sugarcane,12,14,12,17-17-17
|
|
||||||
35,68,33,Red,Tobacco,11,0,37,DAP
|
|
||||||
28,54,37,Black,Millets,36,0,0,Urea
|
|
||||||
33,64,39,Clayey,Paddy,13,0,10,20-20
|
|
||||||
26,52,44,Sandy,Maize,23,0,20,28-28
|
|
||||||
30,60,63,Red,Cotton,9,9,29,14-35-14
|
|
||||||
32,62,30,Loamy,Sugarcane,38,0,0,Urea
|
|
||||||
37,70,32,Black,Oil seeds,12,0,39,DAP
|
|
||||||
26,52,36,Clayey,Pulses,14,0,13,20-20
|
|
||||||
29,58,40,Red,Ground Nuts,24,0,23,28-28
|
|
||||||
30,60,27,Loamy,Sugarcane,12,0,40,DAP
|
|
||||||
34,65,38,Clayey,Paddy,39,0,0,Urea
|
|
||||||
36,68,38,Sandy,Barley,7,9,30,14-35-14
|
|
||||||
26,52,48,Loamy,Wheat,23,0,19,28-28
|
|
||||||
28,54,35,Black,Millets,41,0,0,Urea
|
|
||||||
30,60,61,Loamy,Cotton,8,10,31,14-35-14
|
|
||||||
37,70,37,Clayey,Paddy,12,0,41,DAP
|
|
||||||
25,50,26,Red,Ground Nuts,15,14,11,17-17-17
|
|
||||||
29,58,34,Sandy,Millets,15,0,37,DAP
|
|
||||||
27,54,30,Clayey,Pulses,13,0,13,20-20
|
|
||||||
30,60,58,Loamy,Sugarcane,10,7,32,14-35-14
|
|
||||||
32,62,34,Red,Tobacco,22,0,24,28-28
|
|
||||||
34,65,60,Black,Sugarcane,35,0,0,Urea
|
|
||||||
35,67,42,Sandy,Barley,10,0,35,DAP
|
|
||||||
38,70,48,Loamy,Wheat,8,8,28,14-35-14
|
|
||||||
26,52,32,Black,Oil seeds,12,0,8,20-20
|
|
||||||
29,58,43,Clayey,Paddy,24,0,18,28-28
|
|
||||||
30,60,29,Red,Ground Nuts,41,0,0,Urea
|
|
||||||
33,64,51,Sandy,Maize,5,9,29,14-35-14
|
|
||||||
34,65,31,Red,Tobacco,23,0,21,28-28
|
|
||||||
36,68,33,Black,Oil seeds,13,0,14,20-20
|
|
||||||
28,54,38,Clayey,Pulses,40,0,0,Urea
|
|
||||||
30,60,47,Sandy,Barley,12,0,42,DAP
|
|
||||||
31,62,63,Red,Cotton,11,12,15,17-17-17
|
|
||||||
27,53,43,Black,Millets,23,0,24,28-28
|
|
||||||
34,65,54,Loamy,Wheat,38,0,0,Urea
|
|
||||||
29,58,37,Sandy,Millets,8,0,15,20-20
|
|
||||||
25,50,56,Loamy,Sugarcane,11,13,15,17-17-17
|
|
||||||
32,62,34,Red,Ground Nuts,15,0,37,DAP
|
|
||||||
28,54,41,Clayey,Paddy,36,0,0,Urea
|
|
||||||
30,60,49,Loamy,Wheat,13,0,9,20-20
|
|
||||||
34,65,64,Black,Cotton,24,0,20,28-28
|
|
||||||
28,54,47,Sandy,Barley,5,18,15,10-26-26
|
|
||||||
27,53,35,Black,Oil seeds,37,0,0,Urea
|
|
||||||
36,68,62,Red,Cotton,15,0,40,DAP
|
|
||||||
34,65,57,Black,Sugarcane,9,0,13,20-20
|
|
||||||
29,58,55,Loamy,Sugarcane,8,8,33,14-35-14
|
|
||||||
25,50,40,Clayey,Pulses,6,19,16,10-26-26
|
|
||||||
30,60,38,Sandy,Millets,10,0,14,20-20
|
|
||||||
26,52,39,Clayey,Pulses,21,0,23,28-28
|
|
||||||
31,62,32,Red,Tobacco,39,0,0,Urea
|
|
||||||
34,65,48,Loamy,Wheat,23,0,19,28-28
|
|
||||||
27,53,34,Black,Oil seeds,42,0,0,Urea
|
|
||||||
33,64,31,Red,Ground Nuts,13,0,39,DAP
|
|
||||||
29,58,42,Clayey,Paddy,9,10,22,14-35-14
|
|
||||||
30,60,47,Sandy,Maize,22,0,21,28-28
|
|
||||||
27,53,59,Loamy,Sugarcane,10,0,15,20-20
|
|
||||||
26,52,36,Clayey,Pulses,7,16,20,10-26-26
|
|
||||||
34,65,63,Red,Cotton,14,0,38,DAP
|
|
||||||
28,54,43,Clayey,Paddy,10,8,29,14-35-14
|
|
||||||
30,60,40,Sandy,Millets,41,0,0,Urea
|
|
||||||
29,58,65,Black,Cotton,14,0,35,DAP
|
|
||||||
26,52,59,Loamy,Sugarcane,11,0,9,20-20
|
|
||||||
31,62,44,Sandy,Barley,21,0,28,28-28
|
|
||||||
35,67,28,Clayey,Pulses,8,7,31,14-35-14
|
|
||||||
29,58,30,Red,Tobacco,13,17,16,10-26-26
|
|
||||||
27,53,30,Black,Millets,35,0,0,Urea
|
|
||||||
36,68,50,Loamy,Wheat,12,18,19,10-26-26
|
|
||||||
29,58,61,Loamy,Cotton,11,0,38,DAP
|
|
||||||
30,60,26,Black,Oil seeds,8,9,30,14-35-14
|
|
||||||
34,65,45,Clayey,Paddy,6,19,21,10-26-26
|
|
||||||
36,68,41,Red,Ground Nuts,41,0,0,Urea
|
|
||||||
28,54,25,Sandy,Maize,9,10,30,14-35-14
|
|
||||||
25,50,32,Clayey,Pulses,24,0,19,28-28
|
|
||||||
30,60,27,Red,Tobacco,4,17,17,10-26-26
|
|
||||||
38,72,51,Loamy,Wheat,39,0,0,Urea
|
|
||||||
36,60,43,Sandy,Millets,15,0,41,DAP
|
|
||||||
29,58,57,Black,Sugarcane,12,0,10,20-20
|
|
|
1048576
Game1/Content/ML/Rainfall.csv
@ -1,3 +0,0 @@
|
|||||||
Micro Accuracy: 0.95829
|
|
||||||
LogLoss Average: 0.100171
|
|
||||||
LogLoss Reduction: 0.933795
|
|
@ -1,3 +0,0 @@
|
|||||||
Micro Accuracy: 1
|
|
||||||
LogLoss Average: 0.002345
|
|
||||||
LogLoss Reduction: 0.998302
|
|
@ -1,3 +0,0 @@
|
|||||||
Mean Absolute Error: 0.0108015636096701
|
|
||||||
Mean Squared Error: 0.0434908452113952
|
|
||||||
R Squared: 0.702723944791744
|
|
@ -1,2 +0,0 @@
|
|||||||
Mean Absolute Error: 187.060835104336
|
|
||||||
R Squared: 0.913526230109177
|
|
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 578 B |
Before Width: | Height: | Size: 578 B |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 8.9 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 776 B |
BIN
Game1/Content/Planted.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 4.7 MiB |
Before Width: | Height: | Size: 2.8 MiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 631 B |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 747 B |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 7.5 KiB |
283
Game1/Game1.cs
@ -2,8 +2,6 @@
|
|||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using WinForm = System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace Game1
|
namespace Game1
|
||||||
{
|
{
|
||||||
@ -16,39 +14,13 @@ namespace Game1
|
|||||||
SpriteBatch spriteBatch;
|
SpriteBatch spriteBatch;
|
||||||
SpriteFont Bold;
|
SpriteFont Bold;
|
||||||
private Texture2D[] tile = new Texture2D[5];
|
private Texture2D[] tile = new Texture2D[5];
|
||||||
private Texture2D[] tileConnected = new Texture2D[5];
|
|
||||||
private Texture2D[] Crops = new Texture2D[12];
|
|
||||||
private Texture2D tractor;
|
private Texture2D tractor;
|
||||||
private Texture2D Background;
|
|
||||||
private Texture2D house;
|
private Texture2D house;
|
||||||
private Texture2D markers;
|
private Texture2D markers;
|
||||||
private Texture2D mouseCursor;
|
|
||||||
private Texture2D Rain;
|
|
||||||
string directory = Directory.GetCurrentDirectory();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Texture2D ProgressionBar;
|
|
||||||
private Texture2D ProgressionBarStatus;
|
|
||||||
|
|
||||||
private Tractor tractorUnit = new Tractor();
|
private Tractor tractorUnit = new Tractor();
|
||||||
private Input input = new Input();
|
private Input input = new Input();
|
||||||
private House houseUnit = new House();
|
private House houseUnit = new House();
|
||||||
private Rectangle mousePosition;
|
private Vector2 mousePosition;
|
||||||
|
|
||||||
private Inventory inventory = new Inventory();
|
|
||||||
|
|
||||||
DayNightCycle Time = new DayNightCycle();
|
|
||||||
|
|
||||||
private string[] cropTypesNames = new string[12];
|
|
||||||
|
|
||||||
private int x, y;
|
|
||||||
|
|
||||||
MouseState state;
|
|
||||||
|
|
||||||
private int cloudAnimationSpeed = 3;
|
|
||||||
private int cloudFrame = 0;
|
|
||||||
private int cloudSprite;
|
|
||||||
|
|
||||||
|
|
||||||
public Game1()
|
public Game1()
|
||||||
@ -62,43 +34,18 @@ namespace Game1
|
|||||||
// TODO: Add your initialization logic here
|
// TODO: Add your initialization logic here
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
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";
|
|
||||||
|
|
||||||
Engine.init();
|
|
||||||
Sources.ML_Joel.Engine.initArea();
|
|
||||||
//Sources.ML_Joel.Engine.CreateModel();
|
|
||||||
//Sources.ML_Joel.Engine.CreateModelArea();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Generates the map with some random values
|
//Generates the map with some random values
|
||||||
inventory.initInventorySystem();
|
input.init(graphics, new Vector2(16,16), 56, 1); //Generates the starting size
|
||||||
|
|
||||||
|
|
||||||
string path = directory + "Game1/Content/ML/Fertilizer_Prediction.csv";
|
|
||||||
int res = WinForm.Screen.PrimaryScreen.Bounds.Height;
|
|
||||||
input.init(graphics, new Vector2((float)Math.Floor(WinForm.Screen.PrimaryScreen.Bounds.Width/56*0.6f), (float)Math.Floor((WinForm.Screen.PrimaryScreen.Bounds.Height / 56f) - 7)), 56, 0); //Generates the starting size
|
|
||||||
houseUnit.init(input.getTileSize(), input.getSpacing()); //Generates the house position
|
houseUnit.init(input.getTileSize(), input.getSpacing()); //Generates the house position
|
||||||
tractorUnit.init(houseUnit.GetRectangle(), input); //Generates the Tractor
|
tractorUnit.init(houseUnit.GetRectangle(), input); //Generates the Tractor
|
||||||
tractorUnit.updateSizing(input, 0, houseUnit.getVector(), Time); //Updates the first Size of the Tractor
|
tractorUnit.updateSizing(input, 0, houseUnit.getVector()); //Updates the first Size of the Tractor
|
||||||
tractorUnit.setPos(houseUnit.getVector()); //Changes the position of the tractor to the houses position at the start
|
tractorUnit.setPos(houseUnit.getVector()); //Changes the position of the tractor to the houses position at the start
|
||||||
tractorUnit.setNewHousePos(houseUnit.getVector() / input.getSpacingTile(), true);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
graphics.PreferredBackBufferWidth = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().X;
|
graphics.PreferredBackBufferWidth = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().X;
|
||||||
graphics.PreferredBackBufferHeight = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().Y + 380;
|
graphics.PreferredBackBufferHeight = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().Y + 125;
|
||||||
graphics.ApplyChanges();
|
graphics.ApplyChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,38 +60,9 @@ namespace Game1
|
|||||||
tile[0] = Content.Load<Texture2D>("Mountain");
|
tile[0] = Content.Load<Texture2D>("Mountain");
|
||||||
tile[1] = Content.Load<Texture2D>("tileunplantable");
|
tile[1] = Content.Load<Texture2D>("tileunplantable");
|
||||||
tile[2] = Content.Load<Texture2D>("Plantable");
|
tile[2] = Content.Load<Texture2D>("Plantable");
|
||||||
tile[3] = Content.Load<Texture2D>("Crop");
|
tile[3] = Content.Load<Texture2D>("Planted");
|
||||||
|
tile[4] = Content.Load<Texture2D>("Crop");
|
||||||
tileConnected[0] = Content.Load<Texture2D>("Left");
|
|
||||||
tileConnected[1] = Content.Load<Texture2D>("Top");
|
|
||||||
tileConnected[2] = Content.Load<Texture2D>("Right");
|
|
||||||
tileConnected[3] = Content.Load<Texture2D>("Bottom");
|
|
||||||
|
|
||||||
Rain = Content.Load<Texture2D>("Clouds");
|
|
||||||
|
|
||||||
|
|
||||||
Background = Content.Load<Texture2D>("WoodBackground");
|
|
||||||
|
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
|
|
||||||
ProgressionBar = Content.Load<Texture2D>("ProgressionBar");
|
|
||||||
ProgressionBarStatus = Content.Load<Texture2D>("ProgressionBarStatus");
|
|
||||||
|
|
||||||
tractor = Content.Load<Texture2D>("Tractor");
|
tractor = Content.Load<Texture2D>("Tractor");
|
||||||
mouseCursor = Content.Load<Texture2D>("MouseCursor");
|
|
||||||
Bold = Content.Load<SpriteFont>("Font");
|
Bold = Content.Load<SpriteFont>("Font");
|
||||||
house = Content.Load<Texture2D>("house");
|
house = Content.Load<Texture2D>("house");
|
||||||
markers = Content.Load<Texture2D>("Markers");
|
markers = Content.Load<Texture2D>("Markers");
|
||||||
@ -164,188 +82,63 @@ namespace Game1
|
|||||||
Exit();
|
Exit();
|
||||||
|
|
||||||
|
|
||||||
state = Mouse.GetState();
|
MouseState state = Mouse.GetState();
|
||||||
mousePosition = new Rectangle(state.X, state.Y, 1, 1);
|
mousePosition = new Vector2(state.X, state.Y);
|
||||||
|
|
||||||
tractorUnit.updateSizing(input, 0, houseUnit.getVector(), Time); //Updates the size
|
tractorUnit.updateSizing(input, 0, houseUnit.getVector()); //Updates the size
|
||||||
tractorUnit.setSpeed(input.changeSpeed(tractorUnit.getSpeed())); //Updates the Simulation Speed
|
tractorUnit.setSpeed(input.changeSpeed(tractorUnit.getSpeed())); //Updates the Simulation Speed
|
||||||
tractorUnit.setTractorSpeed(input.changeTractorSpeed(tractorUnit.getTractorSpeed(), tractorUnit.getPos())); //Updates the Tractor Speed
|
tractorUnit.setTractorSpeed(input.changeTractorSpeed(tractorUnit.getTractorSpeed(), tractorUnit.getPos())); //Updates the Tractor Speed
|
||||||
input.controlWindowSize(); //Controls the size of the screen depending on the number of tiles
|
input.controlWindowSize(); //Controls the size of the screen depending on the number of tiles
|
||||||
houseUnit.updateRectangle(input.getSize(), input.getTileSize(), input.getSpacing()); //Updates the position of the house if the house appears out of bound
|
houseUnit.updateRectangle(input.getSize(), input.getTileSize(), input.getSpacing()); //Updates the position of the house if the house appears out of bound
|
||||||
Time.updateTime(tractorUnit.getSpeed());
|
|
||||||
|
|
||||||
|
|
||||||
//System.Threading.Thread updatethread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Update));
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void Draw(GameTime gameTime) //Draw Function
|
protected override void Draw(GameTime gameTime) //Draw Function
|
||||||
{
|
{
|
||||||
GraphicsDevice.Clear(Color.FromNonPremultiplied(255,255,255,140));
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||||
|
|
||||||
spriteBatch.Begin();
|
spriteBatch.Begin();
|
||||||
DrawTiles();
|
|
||||||
|
|
||||||
spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getTargetPosition().X / input.getSpacingTile() * (input.getTileSize() + input.getSpacing()) + input.getTileSize() / 4, (int)tractorUnit.getTargetPosition().Y / input.getSpacingTile() * (input.getTileSize() + input.getSpacing()) + input.getTileSize() / 4, input.getTileSize()/2, input.getTileSize()/2), Color.White);
|
for(int i = 0; i < input.getSize().X; i++) //Draw the tiles
|
||||||
for (int i = 0; i < tractorUnit.getPath().getCount() + 1; i++)
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getPath().getByIndex(i).getCords().X * (input.getSpacingTile()) + input.getTileSize() / 4, (int)tractorUnit.getPath().getByIndex(i).getCords().Y * (input.getSpacingTile()) + input.getTileSize() / 4, input.getTileSize()/2, input.getTileSize()/2), Color.White);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getPath().getFinalDest().getCords().X * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), (int)tractorUnit.getPath().getFinalDest().getCords().Y * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), Convert.ToInt32(input.getTileSize() / 1.5), Convert.ToInt32(input.getTileSize() / 1.5)), Color.White); //Draws the current target of the tractor
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < 5; j++)
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(Background, new Rectangle(i * 512, (int)input.getSize().Y * (input.getTileSize() + input.getSpacing()) + j * 512, 512, 512), Color.FromNonPremultiplied(125, 125, 125, 255));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(tile[0], new Rectangle(i * 227, (int)(input.getSize().Y * (input.getTileSize() + input.getSpacing())), 5, 500), Color.White);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 20; i++)
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(tile[0], new Rectangle(0, (int)(input.getSize().Y * (input.getTileSize() + input.getSpacing())) + i * 20, (int)(input.getSize().X * (input.getTileSize() + input.getSpacing())), 1), Color.White);
|
|
||||||
}
|
|
||||||
|
|
||||||
tractorUnit.drawInventory(input, spriteBatch, Bold, inventory.getPredefinedItems());
|
|
||||||
spriteBatch.DrawString(Bold, "Time: ", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, "Days " + Time.getDays(), new Vector2(60, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, Time.getTimeOfYear(), new Vector2(120, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Day Progression: ", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 22), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, Time.GetTimeOfDayInt().ToString() + "%", new Vector2(140, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 22), Color.Teal);
|
|
||||||
|
|
||||||
spriteBatch.DrawString(Bold, "Tractor Properties:", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 62), Color.DarkRed);
|
|
||||||
|
|
||||||
spriteBatch.DrawString(Bold, "Speed:" + tractorUnit.getSpeed().ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 82), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Tractor Position:" + new Vector2((float)Math.Round(tractorUnit.getPos().X / input.getSpacingTile(), 1), (float)Math.Round(tractorUnit.getPos().Y / input.getSpacingTile(), 1)), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 102), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Tractor Rotation:" + Math.Round(tractorUnit.getRotation(), 2).ToString() + " Degrees", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 122), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Tractor Speed:" + tractorUnit.getTractorSpeed().ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 142), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Tractor Target:" + tractorUnit.getPath().getFinalDest().getCords().ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 162), Color.Teal);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
spriteBatch.DrawString(Bold, "Map Properties:", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 202), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 222), Color.Teal); //Draws the tile size
|
|
||||||
spriteBatch.DrawString(Bold, "Matrix Size: " + input.getSize().X.ToString() + " X " + input.getSize().Y.ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 242), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "House Position: " + houseUnit.getVector() / input.getSpacingTile(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 262), Color.Teal);
|
|
||||||
tractorUnit.getFarm().drawWeatherInformation(spriteBatch, Bold, input);
|
|
||||||
spriteBatch.DrawString(Bold, "Total Weight: ", new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 182), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, "(" + tractorUnit.getInventory().getWeight() + "/" + tractorUnit.getInventory().getMaxWeight() + ")", new Vector2(800, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 182), Color.Teal);
|
|
||||||
spriteBatch.Draw(mouseCursor, new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 14, 21), Color.White);
|
|
||||||
|
|
||||||
spriteBatch.End();
|
|
||||||
|
|
||||||
spriteBatch.Begin();
|
|
||||||
InspectTile();
|
|
||||||
spriteBatch.End();
|
|
||||||
base.Draw(gameTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void DrawTiles()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < input.getSize().X; i++) //Draw the tiles
|
|
||||||
{
|
{
|
||||||
for (int j = 0; j < input.getSize().Y; j++)
|
for (int j = 0; j < input.getSize().Y; j++)
|
||||||
{
|
{
|
||||||
|
spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).Status], new Rectangle(i * (input.getSpacingTile()), j * (input.getSpacingTile()), input.getTileSize(), input.getTileSize()), Color.White);
|
||||||
|
|
||||||
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 (i > 0)
|
|
||||||
{
|
|
||||||
if (tractorUnit.getFarm().getCrop(i - 1, j).getStatus() == 2 || tractorUnit.getFarm().getCrop(i - 1, j).getStatus() == 3)
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(tileConnected[0], tilePos, Time.GetTimeOfDay());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (j > 0)
|
|
||||||
{
|
|
||||||
if (tractorUnit.getFarm().getCrop(i, j - 1).getStatus() == 2 || tractorUnit.getFarm().getCrop(i, j - 1).getStatus() == 3)
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(tileConnected[1], tilePos, Time.GetTimeOfDay());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i < input.getSize().X)
|
|
||||||
{
|
|
||||||
if (tractorUnit.getFarm().getCrop(i + 1, j).getStatus() == 2 || tractorUnit.getFarm().getCrop(i + 1, j).getStatus() == 3)
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(tileConnected[2], tilePos, Time.GetTimeOfDay());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (j < input.getSize().Y)
|
|
||||||
{
|
|
||||||
if (tractorUnit.getFarm().getCrop(i, j + 1).getStatus() == 2 || tractorUnit.getFarm().getCrop(i, j + 1).getStatus() == 3)
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(tileConnected[3], tilePos, Time.GetTimeOfDay());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tilePos.Intersects(mousePosition))
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).getStatus()], tilePos, Color.FromNonPremultiplied(0, 0, 20, 40));
|
|
||||||
if (state.LeftButton == ButtonState.Pressed && !tractorUnit.getFarm().getCrop(i, j).getHousePos())
|
|
||||||
{
|
|
||||||
tractorUnit.setNewHousePos(new Vector2(i, j), true);
|
|
||||||
tractorUnit.setNewHousePos(houseUnit.getVector() / input.getSpacingTile(), false);
|
|
||||||
houseUnit.setRectangle(i, j, input.getTileSize(), input.getSpacing());
|
|
||||||
}
|
|
||||||
if (state.RightButton == ButtonState.Pressed)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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), 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(house, houseUnit.GetRectangle(), Time.GetTimeOfDay());
|
spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getTargetPosition().X / input.getSpacingTile() * (input.getTileSize() + input.getSpacing()) + input.getTileSize() / 4, (int)tractorUnit.getTargetPosition().Y / input.getSpacingTile() * (input.getTileSize() + input.getSpacing()) + input.getTileSize() / 4, input.getTileSize()/2, input.getTileSize()/2), Color.Green);
|
||||||
spriteBatch.Draw(tractor, new Vector2((int)tractorUnit.getPos().X + input.getTileSize() / 2, (int)tractorUnit.getPos().Y + input.getTileSize() / 2), new Rectangle(0, 0, input.getTileSize(), input.getTileSize()), Time.GetTimeOfDay(), tractorUnit.getRotation(), new Vector2(input.getTileSize() / 2, input.getTileSize() / 2), 1.0f, SpriteEffects.None, 1);
|
for (int i = 0; i < tractorUnit.getPath().getCount() + 1; i++)
|
||||||
|
|
||||||
for (int i = -1; i < input.getSize().X + 1; i++) //Draw the tiles
|
|
||||||
{
|
{
|
||||||
for (int j = -1; j < input.getSize().Y + 1; j++)
|
spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getPath().getByIndex(i).getCords().X * (input.getSpacingTile()) + input.getTileSize() / 4, (int)tractorUnit.getPath().getByIndex(i).getCords().Y * (input.getSpacingTile()) + input.getTileSize() / 4, input.getTileSize()/2, input.getTileSize()/2), Color.Green);
|
||||||
{
|
|
||||||
spriteBatch.Draw(Rain, tractorUnit.getFarm().getRainPosition(input.getTileSize(), i, j, input.getSize()), tractorUnit.getFarm().getDestinationRectangle(i, j, input.getSize()), tractorUnit.getFarm().getRainAmount(i, j, Time.GetTimeOfDay(), input.getSize()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InspectTile()
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, "Crop:", new Vector2(240, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
|
spriteBatch.Draw(house, houseUnit.GetRectangle(), Color.White);
|
||||||
spriteBatch.DrawString(Bold, "Selected tile: (" + x.ToString() + ", " + y.ToString() + ")", new Vector2(240, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 22), Color.Teal);
|
spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getPath().getFinalDest().getCords().X * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), (int)tractorUnit.getPath().getFinalDest().getCords().Y * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), Convert.ToInt32(input.getTileSize() / 1.5), Convert.ToInt32(input.getTileSize() / 1.5)), Color.Red); //Draws the current target of the tractor
|
||||||
tractorUnit.getFarm().getCrop(x, y).Inspect(input.getTileSize(), input.getSpacing(), Bold, new SpriteBatch(GraphicsDevice), cropTypesNames);
|
spriteBatch.Draw(tractor, new Vector2((int)tractorUnit.getPos().X + input.getTileSize() / 2, (int)tractorUnit.getPos().Y + input.getTileSize() / 2), new Rectangle(0, 0, input.getTileSize(), input.getTileSize()), Color.White, tractorUnit.getRotation(), new Vector2(input.getTileSize() / 2, input.getTileSize() / 2), 1.0f, SpriteEffects.None, 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
spriteBatch.DrawString(Bold, "Speed:" + tractorUnit.getSpeed().ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20) , Color.White); //Draws the speed value
|
||||||
|
|
||||||
|
spriteBatch.DrawString(Bold, "Tractor Speed:" + tractorUnit.getTractorSpeed().ToString(), new Vector2(100, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20), Color.White);
|
||||||
|
spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 40), Color.White); //Draws the tile size
|
||||||
|
spriteBatch.DrawString(Bold, "Matrix Size: " + input.getSize().X.ToString() + " X " + input.getSize().Y.ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 60), Color.White);spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 40), Color.White);
|
||||||
|
spriteBatch.DrawString(Bold, "Tractor Rotation:" + tractorUnit.getRotation().ToString() + " Degrees", new Vector2(250, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20), Color.White);
|
||||||
|
spriteBatch.DrawString(Bold, tractorUnit.getCurrentTask(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 80), Color.White); //Draws the tile size
|
||||||
|
spriteBatch.DrawString(Bold, tractorUnit.getScore().ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 100), Color.White);
|
||||||
|
|
||||||
|
spriteBatch.Draw(tractor, new Rectangle((int)mousePosition.X, (int)mousePosition.Y, input.getTileSize() / 4, input.getTileSize() / 4), Color.White);
|
||||||
|
|
||||||
|
spriteBatch.End();
|
||||||
|
|
||||||
|
base.Draw(gameTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@ -13,28 +13,10 @@
|
|||||||
<AssemblyName>Game1</AssemblyName>
|
<AssemblyName>Game1</AssemblyName>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<MonoGamePlatform>Windows</MonoGamePlatform>
|
<MonoGamePlatform>Windows</MonoGamePlatform>
|
||||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
<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>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
@ -58,74 +40,21 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
|
||||||
<OutputPath>bin\x64\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE;WINDOWS</DefineConstants>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup>
|
|
||||||
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Game1.cs" />
|
<Compile Include="Game1.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Sources\Crops\CropType.cs" />
|
|
||||||
<Compile Include="Sources\Crops\CropTypesHolder.cs" />
|
|
||||||
<Compile Include="Sources\Crops\PerlinNoise.cs" />
|
|
||||||
<Compile Include="Sources\Crops\SoilProperties.cs" />
|
|
||||||
<Compile Include="Sources\ML\Engine.cs" />
|
|
||||||
<Compile Include="Sources\ML_Joel\DataModel\InputArea.cs" />
|
|
||||||
<Compile Include="Sources\ML_Joel\DataModel\Input.cs" />
|
|
||||||
<Compile Include="Sources\ML_Joel\DataModel\OutputArea.cs" />
|
|
||||||
<Compile Include="Sources\ML_Joel\DataModel\Output.cs" />
|
|
||||||
<Compile Include="Sources\ML_Joel\Engine.cs" />
|
|
||||||
<Compile Include="Sources\ML_Joel\Model.cs" />
|
|
||||||
<Compile Include="Sources\Objects\DayNightCycle.cs" />
|
|
||||||
<Compile Include="Sources\Objects\Fertilizer.cs" />
|
|
||||||
<Compile Include="Sources\Objects\FertilizerHolder.cs" />
|
|
||||||
<Compile Include="Sources\Objects\HandleRotation.cs" />
|
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Sources\ML\InOut\BigModelInput.cs" />
|
|
||||||
<Compile Include="Sources\ML\InOut\BigModelOutput.cs" />
|
|
||||||
<Compile Include="Sources\ML\MLModel.cs" />
|
|
||||||
<Compile Include="Sources\ML\InOut\ModelOutput.cs" />
|
|
||||||
<Compile Include="Sources\ML\InOut\ModelInput.cs" />
|
|
||||||
<Compile Include="Sources\Objects\House.cs" />
|
<Compile Include="Sources\Objects\House.cs" />
|
||||||
<Compile Include="Sources\Crops\Crops.cs" />
|
<Compile Include="Sources\Crops\Crops.cs" />
|
||||||
<Compile Include="Sources\Crops\Farm.cs" />
|
<Compile Include="Sources\Crops\Farm.cs" />
|
||||||
<Compile Include="Sources\Controlls\Input.cs" />
|
<Compile Include="Sources\Controlls\Input.cs" />
|
||||||
<Compile Include="Sources\Objects\InventorySystem\Cargo.cs" />
|
|
||||||
<Compile Include="Sources\Objects\InventorySystem\Inventory.cs" />
|
|
||||||
<Compile Include="Sources\Objects\InventorySystem\Items.cs" />
|
|
||||||
<Compile Include="Sources\Objects\tractorPositionCorrector.cs" />
|
<Compile Include="Sources\Objects\tractorPositionCorrector.cs" />
|
||||||
<Compile Include="Sources\Pathing\A-Star\Astar.cs" />
|
<Compile Include="Sources\Pathing\A-Star\Astar.cs" />
|
||||||
<Compile Include="Sources\Pathing\A-Star\PathSaver\MinHeap.cs" />
|
<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\Nodes.cs" />
|
||||||
<Compile Include="Sources\Pathing\A-Star\PathSaver\Path.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\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\ScoreSystem.cs" />
|
||||||
<Compile Include="Sources\Smart\SmartTractor.cs" />
|
<Compile Include="Sources\Smart\SmartTractor.cs" />
|
||||||
<Compile Include="Sources\Objects\Tractor.cs" />
|
<Compile Include="Sources\Objects\Tractor.cs" />
|
||||||
@ -135,15 +64,11 @@
|
|||||||
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll</HintPath>
|
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Numerics" />
|
|
||||||
<Reference Include="System.Windows.Forms" />
|
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Content\Crop.png" />
|
<Content Include="Content\Crop.png" />
|
||||||
<Content Include="Content\house.png" />
|
<Content Include="Content\house.png" />
|
||||||
<Content Include="Content\ProgressionBarStatus.png" />
|
|
||||||
<Content Include="Content\ProgressionBar.png" />
|
|
||||||
<Content Include="Content\Markers.png" />
|
<Content Include="Content\Markers.png" />
|
||||||
<Content Include="Content\Mountain.png" />
|
<Content Include="Content\Mountain.png" />
|
||||||
<Content Include="Content\Planted.png" />
|
<Content Include="Content\Planted.png" />
|
||||||
@ -151,120 +76,10 @@
|
|||||||
<Content Include="Content\tileunplantable.png" />
|
<Content Include="Content\tileunplantable.png" />
|
||||||
<Content Include="Content\Tractor.png" />
|
<Content Include="Content\Tractor.png" />
|
||||||
<Content Include="Icon.ico" />
|
<Content Include="Icon.ico" />
|
||||||
<None Include="Resources\TextFile1.txt" />
|
|
||||||
<None Include="Sources\ML\Data\FertPredictDataset.csv" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<MonoGameContentReference Include="Content\Content.mgcb" />
|
<MonoGameContentReference Include="Content\Content.mgcb" />
|
||||||
<None Include="app.config" />
|
|
||||||
<None Include="app.manifest" />
|
<None Include="app.manifest" />
|
||||||
<None Include="Sources\ML\Data\Fertilizer Prediction.csv" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
|
||||||
</EmbeddedResource>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="LibNoise">
|
|
||||||
<Version>0.2.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="LightGBM">
|
|
||||||
<Version>2.3.1</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.Common">
|
|
||||||
<Version>3.6.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.ML">
|
|
||||||
<Version>1.4.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.ML.CpuMath">
|
|
||||||
<Version>1.4.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.ML.FastTree">
|
|
||||||
<Version>1.4.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.ML.LightGbm">
|
|
||||||
<Version>1.4.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Newtonsoft.Json">
|
|
||||||
<Version>12.0.3</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.CodeDom">
|
|
||||||
<Version>4.7.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Collections.Immutable">
|
|
||||||
<Version>1.7.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Drawing.Common">
|
|
||||||
<Version>4.7.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Memory">
|
|
||||||
<Version>4.5.4</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Reflection.Emit.Lightweight">
|
|
||||||
<Version>4.7.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe">
|
|
||||||
<Version>4.7.1</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Threading.Tasks.Dataflow">
|
|
||||||
<Version>4.11.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="C5">
|
|
||||||
<Version>2.5.3</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="LightGBM">
|
|
||||||
<Version>2.3.1</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.ML">
|
|
||||||
<Version>1.4.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.ML.CpuMath">
|
|
||||||
<Version>1.4.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.ML.FastTree">
|
|
||||||
<Version>1.4.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.ML.LightGbm">
|
|
||||||
<Version>1.4.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Newtonsoft.Json">
|
|
||||||
<Version>12.0.3</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.CodeDom">
|
|
||||||
<Version>4.7.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Collections.Immutable">
|
|
||||||
<Version>1.7.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Memory">
|
|
||||||
<Version>4.5.4</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Reflection.Emit.Lightweight">
|
|
||||||
<Version>4.7.0</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe">
|
|
||||||
<Version>4.7.1</Version>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="System.Threading.Tasks.Dataflow">
|
|
||||||
<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>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
|
||||||
|
84
Game1/Properties/Resources.Designer.cs
generated
@ -1,84 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// This code was generated by a tool.
|
|
||||||
// Runtime Version:4.0.30319.42000
|
|
||||||
//
|
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
|
||||||
// the code is regenerated.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace Game1.Properties {
|
|
||||||
using System;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
|
||||||
/// </summary>
|
|
||||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
|
||||||
// class via a tool like ResGen or Visual Studio.
|
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
|
||||||
// with the /str option, or rebuild your VS project.
|
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
|
||||||
internal class Resources {
|
|
||||||
|
|
||||||
private static global::System.Resources.ResourceManager resourceMan;
|
|
||||||
|
|
||||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
|
||||||
|
|
||||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
||||||
internal Resources() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the cached ResourceManager instance used by this class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
|
||||||
get {
|
|
||||||
if (object.ReferenceEquals(resourceMan, null)) {
|
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Game1.Properties.Resources", typeof(Resources).Assembly);
|
|
||||||
resourceMan = temp;
|
|
||||||
}
|
|
||||||
return resourceMan;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Overrides the current thread's CurrentUICulture property for all
|
|
||||||
/// resource lookups using this strongly typed resource class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
internal static global::System.Globalization.CultureInfo Culture {
|
|
||||||
get {
|
|
||||||
return resourceCulture;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
resourceCulture = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Temparature,Humidity ,Moisture,Soil Type,Crop Type,Nitrogen,Potassium,Phosphorous,Fertilizer Name
|
|
||||||
///26,52,38,Sandy,Maize,37,0,0,Urea
|
|
||||||
///29,52,45,Loamy,Sugarcane,12,0,36,DAP
|
|
||||||
///34,65,62,Black,Cotton,7,9,30,14-35-14
|
|
||||||
///32,62,34,Red,Tobacco,22,0,20,28-28
|
|
||||||
///28,54,46,Clayey,Paddy,35,0,0,Urea
|
|
||||||
///26,52,35,Sandy,Barley,12,10,13,17-17-17
|
|
||||||
///25,50,64,Red,Cotton,9,0,10,20-20
|
|
||||||
///33,64,50,Loamy,Wheat,41,0,0,Urea
|
|
||||||
///30,60,42,Sandy,Millets,21,0,18,28-28
|
|
||||||
///29,58,33,Black,Oil seeds,9,7,30,14-35-14
|
|
||||||
///27,54,28,Clayey,Pulses,13,0,40,DAP
|
|
||||||
///31,62, [rest of string was truncated]";.
|
|
||||||
/// </summary>
|
|
||||||
internal static string Fertilizer_Prediction {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("Fertilizer_Prediction", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,124 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
|
||||||
<data name="Fertilizer_Prediction" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
|
||||||
<value>..\sources\ml\data\fertilizer prediction.csv;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
|
||||||
</data>
|
|
||||||
</root>
|
|
@ -2,8 +2,6 @@
|
|||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
|
||||||
using WinForm = System.Windows.Forms;
|
|
||||||
|
|
||||||
class Controller
|
class Controller
|
||||||
{
|
{
|
||||||
@ -19,7 +17,7 @@ class Controller
|
|||||||
public Vector2 updateWindow(int tileSize, int Spacing, Vector2 Size)
|
public Vector2 updateWindow(int tileSize, int Spacing, Vector2 Size)
|
||||||
{
|
{
|
||||||
KeyboardState state = Keyboard.GetState();
|
KeyboardState state = Keyboard.GetState();
|
||||||
if (state.IsKeyDown(Keys.D) && Size.X < Math.Floor(WinForm.Screen.PrimaryScreen.Bounds.Width / (float)tileSize))
|
if (state.IsKeyDown(Keys.D) && Size.X < 100)
|
||||||
{
|
{
|
||||||
Size.X++;
|
Size.X++;
|
||||||
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
|
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
|
||||||
@ -31,16 +29,16 @@ class Controller
|
|||||||
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
|
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.IsKeyDown(Keys.W) && Size.Y < Math.Floor(WinForm.Screen.PrimaryScreen.Bounds.Height / (float)tileSize) - 7)
|
if (state.IsKeyDown(Keys.W) && Size.Y < 20)
|
||||||
{
|
{
|
||||||
Size.Y++;
|
Size.Y++;
|
||||||
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 380;
|
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.IsKeyDown(Keys.S) && Size.Y > 2)
|
if (state.IsKeyDown(Keys.S) && Size.Y > 2)
|
||||||
{
|
{
|
||||||
Size.Y--;
|
Size.Y--;
|
||||||
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 380;
|
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 100;
|
||||||
}
|
}
|
||||||
return Size;
|
return Size;
|
||||||
}
|
}
|
||||||
@ -61,7 +59,7 @@ class Controller
|
|||||||
public int controllSpeed(int Speed)
|
public int controllSpeed(int Speed)
|
||||||
{
|
{
|
||||||
KeyboardState state = Keyboard.GetState();
|
KeyboardState state = Keyboard.GetState();
|
||||||
if (state.IsKeyDown(Keys.Right) && Speed < 350)
|
if (state.IsKeyDown(Keys.Right))
|
||||||
{
|
{
|
||||||
Speed++;
|
Speed++;
|
||||||
}
|
}
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
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 string CropName;
|
|
||||||
public string[] Season = new string[5];
|
|
||||||
public float Temparature;
|
|
||||||
public float Humidity;
|
|
||||||
public float Moisture;
|
|
||||||
public float Nitrogen;
|
|
||||||
public float Potassium;
|
|
||||||
public float Phosphorous;
|
|
||||||
public float Area;
|
|
||||||
public int AreaMin;
|
|
||||||
public int AreaMax;
|
|
||||||
|
|
||||||
|
|
||||||
public CropTypes()
|
|
||||||
{
|
|
||||||
soilType = new string[3];
|
|
||||||
Times = new int[3];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,246 +0,0 @@
|
|||||||
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].CropName = "None";
|
|
||||||
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].CropName = "Barley";
|
|
||||||
cropTypes[1].Temparature = 30.1f;
|
|
||||||
cropTypes[1].Humidity = 59.0f;
|
|
||||||
cropTypes[1].Moisture = 41.7f;
|
|
||||||
cropTypes[1].Nitrogen = 21 + 12.6f;
|
|
||||||
cropTypes[1].Potassium = 10 + 5.3f;
|
|
||||||
cropTypes[1].Phosphorous = 20 + 26.0f;
|
|
||||||
cropTypes[1].Season[0] = "Spring";
|
|
||||||
cropTypes[1].Season[1] = "Autumn";
|
|
||||||
cropTypes[1].AreaMin = 1;
|
|
||||||
cropTypes[1].AreaMax = 8000;
|
|
||||||
|
|
||||||
|
|
||||||
// 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].CropName = "Cotton";
|
|
||||||
cropTypes[2].Temparature = 30.4f;
|
|
||||||
cropTypes[2].Humidity = 59.6f;
|
|
||||||
cropTypes[2].Moisture = 63.2f;
|
|
||||||
cropTypes[2].Nitrogen = 21 + 16.4f;
|
|
||||||
cropTypes[2].Potassium = 10 + 3.3f;
|
|
||||||
cropTypes[2].Phosphorous = 20 + 23.8f;
|
|
||||||
cropTypes[2].Season[0] = "Spring";
|
|
||||||
cropTypes[2].Season[1] = "Autumn";
|
|
||||||
cropTypes[2].Season[2] = "Whole Year";
|
|
||||||
cropTypes[2].AreaMin = 1;
|
|
||||||
cropTypes[2].AreaMax = 199000;
|
|
||||||
|
|
||||||
// Ground Nuts
|
|
||||||
cropTypes[3] = new CropTypes();
|
|
||||||
cropTypes[3].soilType[0] = "Red";
|
|
||||||
cropTypes[3].soilType[1] = null;
|
|
||||||
cropTypes[3].soilType[2] = null;
|
|
||||||
cropTypes[3].CropName = "Ground Nuts";
|
|
||||||
cropTypes[3].Temparature = 30.1f;
|
|
||||||
cropTypes[3].Humidity = 59.1f;
|
|
||||||
cropTypes[3].Moisture = 33.1f;
|
|
||||||
cropTypes[3].Nitrogen = 21 + 23.3f;
|
|
||||||
cropTypes[3].Potassium = 10 + 2.0f;
|
|
||||||
cropTypes[3].Phosphorous = 20 + 21.6f;
|
|
||||||
cropTypes[3].Season[0] = "Spring";
|
|
||||||
cropTypes[3].Season[1] = "Autumn";
|
|
||||||
cropTypes[3].Season[2] = "Whole Year";
|
|
||||||
cropTypes[3].Season[3] = "Winter";
|
|
||||||
cropTypes[3].Season[4] = "Summer";
|
|
||||||
cropTypes[3].AreaMin = 1;
|
|
||||||
cropTypes[3].AreaMax = 147000;
|
|
||||||
|
|
||||||
|
|
||||||
// Maize
|
|
||||||
cropTypes[4] = new CropTypes();
|
|
||||||
cropTypes[4].soilType[0] = "Sandy";
|
|
||||||
cropTypes[4].soilType[1] = null;
|
|
||||||
cropTypes[4].soilType[2] = null;
|
|
||||||
cropTypes[4].CropName = "Maize";
|
|
||||||
cropTypes[4].Temparature = 29.0f;
|
|
||||||
cropTypes[4].Humidity = 57.3f;
|
|
||||||
cropTypes[4].Moisture = 42.2f;
|
|
||||||
cropTypes[4].Nitrogen = 21 + 18.3f;
|
|
||||||
cropTypes[4].Potassium = 10 + 5.7f;
|
|
||||||
cropTypes[4].Phosphorous = 20 + 18.7f;
|
|
||||||
cropTypes[4].Season[0] = "Spring";
|
|
||||||
cropTypes[4].Season[1] = "Autumn";
|
|
||||||
cropTypes[4].Season[2] = "Whole Year";
|
|
||||||
cropTypes[4].Season[3] = "Winter";
|
|
||||||
cropTypes[4].Season[4] = "Summer";
|
|
||||||
cropTypes[4].AreaMin = 1;
|
|
||||||
cropTypes[4].AreaMax = 73000;
|
|
||||||
|
|
||||||
// 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].CropName = "Millets";
|
|
||||||
cropTypes[5].Temparature = 29.5f;
|
|
||||||
cropTypes[5].Humidity = 57.3f;
|
|
||||||
cropTypes[5].Moisture = 38.5f;
|
|
||||||
cropTypes[5].Nitrogen = 21 + 23.2f;
|
|
||||||
cropTypes[5].Potassium = 10 + 0.1f;
|
|
||||||
cropTypes[5].Phosphorous = 20 + 14.4f;
|
|
||||||
cropTypes[5].Season[0] = "Spring";
|
|
||||||
cropTypes[5].Season[1] = "Autumn";
|
|
||||||
cropTypes[5].Season[2] = "Whole Year";
|
|
||||||
cropTypes[5].AreaMin = 1;
|
|
||||||
cropTypes[5].AreaMax = 59000;
|
|
||||||
|
|
||||||
//Oil Seeds
|
|
||||||
cropTypes[6] = new CropTypes();
|
|
||||||
cropTypes[6].soilType[0] = "Black";
|
|
||||||
cropTypes[6].soilType[1] = null;
|
|
||||||
cropTypes[6].soilType[2] = null;
|
|
||||||
cropTypes[6].CropName = "Oil Seeds";
|
|
||||||
cropTypes[6].Temparature = 30.3f;
|
|
||||||
cropTypes[6].Humidity = 59.1f;
|
|
||||||
cropTypes[6].Moisture = 32.1f;
|
|
||||||
cropTypes[6].Nitrogen = 21 + 19.0f;
|
|
||||||
cropTypes[6].Potassium = 10 + 2.3f;
|
|
||||||
cropTypes[6].Phosphorous = 20 + 17.3f;
|
|
||||||
cropTypes[6].Season[0] = "Whole Year";
|
|
||||||
cropTypes[6].AreaMin = 25;
|
|
||||||
cropTypes[6].AreaMax = 25000;
|
|
||||||
|
|
||||||
//Paddys
|
|
||||||
cropTypes[7] = new CropTypes();
|
|
||||||
cropTypes[7].soilType[0] = "Clayey";
|
|
||||||
cropTypes[7].soilType[1] = null;
|
|
||||||
cropTypes[7].soilType[2] = null;
|
|
||||||
cropTypes[7].CropName = "Paddys";
|
|
||||||
cropTypes[7].Temparature = 31.2f;
|
|
||||||
cropTypes[7].Humidity = 60.4f;
|
|
||||||
cropTypes[7].Moisture = 41.5f;
|
|
||||||
cropTypes[7].Nitrogen = 21 + 20.8f;
|
|
||||||
cropTypes[7].Potassium = 10 + 3.7f;
|
|
||||||
cropTypes[7].Phosphorous = 20 + 16.3f;
|
|
||||||
cropTypes[7].Season[0] = "Autumn";
|
|
||||||
cropTypes[7].Season[1] = "Winter";
|
|
||||||
cropTypes[7].Season[2] = "Summer";
|
|
||||||
cropTypes[7].AreaMin = 200;
|
|
||||||
cropTypes[7].AreaMax = 270000;
|
|
||||||
|
|
||||||
//Pulses
|
|
||||||
cropTypes[8] = new CropTypes();
|
|
||||||
cropTypes[8].soilType[0] = "Clayey";
|
|
||||||
cropTypes[8].soilType[1] = null;
|
|
||||||
cropTypes[8].soilType[2] = null;
|
|
||||||
cropTypes[8].CropName = "Pulses";
|
|
||||||
cropTypes[8].Temparature = 27.8f;
|
|
||||||
cropTypes[8].Humidity = 54.9f;
|
|
||||||
cropTypes[8].Moisture = 34.1f;
|
|
||||||
cropTypes[8].Nitrogen = 21 + 18.4f;
|
|
||||||
cropTypes[8].Potassium = 10 + 4.2f;
|
|
||||||
cropTypes[8].Phosphorous = 20 + 17.5f;
|
|
||||||
cropTypes[8].Season[0] = "Spring";
|
|
||||||
cropTypes[8].Season[1] = "Autumn";
|
|
||||||
cropTypes[8].Season[2] = "Whole Year";
|
|
||||||
cropTypes[8].Season[3] = "Summer";
|
|
||||||
cropTypes[8].AreaMin = 40;
|
|
||||||
cropTypes[8].AreaMax = 140000;
|
|
||||||
|
|
||||||
//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].CropName = "Sugarcane";
|
|
||||||
cropTypes[9].Temparature = 30.0f;
|
|
||||||
cropTypes[9].Humidity = 58.6f;
|
|
||||||
cropTypes[9].Moisture = 51.2f;
|
|
||||||
cropTypes[9].Nitrogen = 21 + 14.6f;
|
|
||||||
cropTypes[9].Potassium = 10 + 4.2f;
|
|
||||||
cropTypes[9].Phosphorous = 20 + 17.6f;
|
|
||||||
cropTypes[9].Season[0] = "Spring";
|
|
||||||
cropTypes[9].Season[1] = "Autumn";
|
|
||||||
cropTypes[9].Season[2] = "Whole Year";
|
|
||||||
cropTypes[9].Season[3] = "Winter";
|
|
||||||
cropTypes[9].AreaMin = 1;
|
|
||||||
cropTypes[9].AreaMax = 23000;
|
|
||||||
|
|
||||||
|
|
||||||
//Tobacco
|
|
||||||
cropTypes[10] = new CropTypes();
|
|
||||||
cropTypes[10].soilType[0] = "Red";
|
|
||||||
cropTypes[10].soilType[1] = null;
|
|
||||||
cropTypes[10].soilType[2] = null;
|
|
||||||
cropTypes[10].CropName = "Tobacco";
|
|
||||||
cropTypes[10].Temparature = 31.9f;
|
|
||||||
cropTypes[10].Humidity = 62.4f;
|
|
||||||
cropTypes[10].Moisture = 31.6f;
|
|
||||||
cropTypes[10].Nitrogen = 21 + 19.1f;
|
|
||||||
cropTypes[10].Potassium = 10 + 4.9f;
|
|
||||||
cropTypes[10].Phosphorous = 20 + 19.3f;
|
|
||||||
cropTypes[10].Season[0] = "Spring";
|
|
||||||
cropTypes[10].Season[1] = "Autumn";
|
|
||||||
cropTypes[10].Season[2] = "Whole Year";
|
|
||||||
cropTypes[10].AreaMin = 1;
|
|
||||||
cropTypes[10].AreaMax = 9500;
|
|
||||||
|
|
||||||
|
|
||||||
//Wheat
|
|
||||||
cropTypes[11] = new CropTypes();
|
|
||||||
cropTypes[11].soilType[0] = "Loamy";
|
|
||||||
cropTypes[11].soilType[1] = null;
|
|
||||||
cropTypes[11].soilType[2] = null;
|
|
||||||
cropTypes[11].CropName = "Wheat";
|
|
||||||
cropTypes[11].Temparature = 33.1f;
|
|
||||||
cropTypes[11].Humidity = 63.8f;
|
|
||||||
cropTypes[11].Moisture = 50.0f;
|
|
||||||
cropTypes[11].Nitrogen = 21 + 23.3f;
|
|
||||||
cropTypes[11].Potassium = 10 + 2.9f;
|
|
||||||
cropTypes[11].Phosphorous = 20 + 14.4f;
|
|
||||||
cropTypes[11].Season[0] = "Spring";
|
|
||||||
cropTypes[11].Season[1] = "Autumn";
|
|
||||||
cropTypes[11].Season[2] = "Whole Year";
|
|
||||||
cropTypes[11].Season[3] = "Summer";
|
|
||||||
cropTypes[11].AreaMin = 1;
|
|
||||||
cropTypes[11].AreaMax = 266000;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public CropTypes getPresetCropTypes(int Index)
|
|
||||||
{
|
|
||||||
return cropTypes[Index];
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,143 +5,30 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
|
||||||
|
|
||||||
class Crops
|
class Crops
|
||||||
{
|
{
|
||||||
private int Status;
|
public int x;
|
||||||
private int originalStatus;
|
public int y;
|
||||||
private int cropType = 0;
|
public int Status;
|
||||||
private float Timer = 1;
|
private int cropType;
|
||||||
private int UpdateCrop;
|
private int Timer;
|
||||||
private float fullTimer = 1;
|
private Random r;
|
||||||
private bool housePos = false;
|
|
||||||
private Vector2 Size;
|
|
||||||
private Random r = new Random();
|
|
||||||
private CropTypes DataSet;
|
|
||||||
SoilProperties soilProperties = new SoilProperties();
|
|
||||||
private float ProductionRate;
|
|
||||||
private float tempRain;
|
|
||||||
private float prevpred;
|
|
||||||
private DayNightCycle Time = new DayNightCycle();
|
|
||||||
private int previousDay = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
public void updateCrop()
|
||||||
public void updateCrop(Vector2 newSize, DayNightCycle nTime)
|
|
||||||
{
|
{
|
||||||
Time = nTime;
|
if (Status != 0)
|
||||||
if (UpdateCrop == 60)
|
|
||||||
{
|
{
|
||||||
degradeSoil();
|
Timer--;
|
||||||
UpdateCrop = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Status == 3 && Timer != 1)
|
|
||||||
{
|
|
||||||
Timer = Timer - 1f * ProductionRate;
|
|
||||||
}
|
|
||||||
Size = newSize;
|
|
||||||
UpdateCrop++;
|
|
||||||
|
|
||||||
if (Timer < 1)
|
|
||||||
{
|
|
||||||
Timer = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateProductionRate()
|
public int getCropTimer()
|
||||||
{
|
|
||||||
getProductionRate(DataSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getSpeedFactor(float tractorSpeed)
|
|
||||||
{
|
|
||||||
if (getCostOnMovement() == 1)
|
|
||||||
return (1f * tractorSpeed);
|
|
||||||
return (1f * tractorSpeed) / (getCostOnMovement() / 5.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SoilProperties getSoilProperties()
|
|
||||||
{
|
|
||||||
return soilProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Fertilize(Fertilizer fertilizer)
|
|
||||||
{
|
|
||||||
soilProperties.Nitrogen += fertilizer.Nitrogen;
|
|
||||||
soilProperties.Phosphorous += fertilizer.Phosphorus;
|
|
||||||
soilProperties.Potassium += fertilizer.Potassium;
|
|
||||||
|
|
||||||
if (soilProperties.Nitrogen > 42)
|
|
||||||
soilProperties.Nitrogen = 42;
|
|
||||||
if (soilProperties.Phosphorous > 42)
|
|
||||||
soilProperties.Phosphorous = 42;
|
|
||||||
if (soilProperties.Potassium > 19)
|
|
||||||
soilProperties.Potassium = 19;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool isSaturated()
|
|
||||||
{
|
|
||||||
if (soilProperties.Nitrogen > 40 && (soilProperties.Phosphorous > 40 || soilProperties.Potassium > 17))
|
|
||||||
return true;
|
|
||||||
if (soilProperties.Phosphorous > 40 && soilProperties.Potassium > 17)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool isSaturated(int threshold)
|
|
||||||
{
|
|
||||||
if (soilProperties.Nitrogen > 40 - threshold && (soilProperties.Phosphorous > 40 - threshold || soilProperties.Potassium > 17 - (threshold * 17/40)))
|
|
||||||
return true;
|
|
||||||
if (soilProperties.Phosphorous > 40 - threshold && soilProperties.Potassium > 17 - (threshold *17/40))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getCropTimer()
|
|
||||||
{
|
{
|
||||||
return Timer;
|
return Timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCropTimerBar(int tileSize)
|
|
||||||
{
|
|
||||||
|
|
||||||
int x = (int)((1 - ((float)Timer / fullTimer)) * (tileSize - tileSize / 3));
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init()
|
|
||||||
{
|
|
||||||
soilProperties.setSoilProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Changes the time required for the crops to be harvestable
|
|
||||||
public void setCropTimer()
|
|
||||||
{
|
|
||||||
if (cropType == 1) // Barley
|
|
||||||
{
|
|
||||||
Timer = 300;
|
|
||||||
fullTimer = Timer;
|
|
||||||
}
|
|
||||||
else if (cropType == 1) // Wheat
|
|
||||||
{
|
|
||||||
Timer = 600;
|
|
||||||
fullTimer = Timer;
|
|
||||||
}
|
|
||||||
else if (cropType == 2) // Berries
|
|
||||||
{
|
|
||||||
Timer = 1200;
|
|
||||||
fullTimer = Timer;
|
|
||||||
}
|
|
||||||
else // Fruit Trees
|
|
||||||
{
|
|
||||||
Timer = 2400;
|
|
||||||
fullTimer = Timer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCostOnMovement()
|
public int getCostOnMovement()
|
||||||
{
|
{
|
||||||
if (Status == 1) //grass
|
if (Status == 1) //grass
|
||||||
@ -152,347 +39,25 @@ class Crops
|
|||||||
{
|
{
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
else
|
else if (Status == 3) //crops
|
||||||
{
|
{
|
||||||
if (cropType == 0)
|
return 15;
|
||||||
{
|
|
||||||
return 16; //Barley
|
|
||||||
}
|
|
||||||
if (cropType == 1)
|
|
||||||
{
|
|
||||||
return 16; //Barley
|
|
||||||
}
|
|
||||||
else if (cropType == 2)
|
|
||||||
{
|
|
||||||
return 16; //Cotton
|
|
||||||
}
|
|
||||||
else if (cropType == 3)
|
|
||||||
{
|
|
||||||
return 16; //Ground Nuts
|
|
||||||
}
|
|
||||||
else if (cropType == 4)
|
|
||||||
{
|
|
||||||
return 16; //Maize
|
|
||||||
}
|
|
||||||
else if (cropType == 5)
|
|
||||||
{
|
|
||||||
return 16; //Millets
|
|
||||||
}
|
|
||||||
else if (cropType == 6)
|
|
||||||
{
|
|
||||||
return 16; //Oil Seeds
|
|
||||||
}
|
|
||||||
else if (cropType == 7)
|
|
||||||
{
|
|
||||||
return 16; //Paddy
|
|
||||||
}
|
|
||||||
else if (cropType == 8)
|
|
||||||
{
|
|
||||||
return 16; //Pulses
|
|
||||||
}
|
|
||||||
else if (cropType == 9)
|
|
||||||
{
|
|
||||||
return 16; //Sugarcane
|
|
||||||
}
|
|
||||||
else if (cropType == 10)
|
|
||||||
{
|
|
||||||
return 16; //Wheat
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 16; //Tobacco
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void degradeSoil()
|
|
||||||
{
|
|
||||||
Random r = new Random();
|
|
||||||
if (soilProperties.Nitrogen > 4.0f)
|
|
||||||
{
|
|
||||||
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)) * (float)Math.Pow((r.NextDouble() + 0.5f), 2));
|
|
||||||
}
|
|
||||||
if (soilProperties.Potassium > 0.1f)
|
|
||||||
{
|
|
||||||
soilProperties.Potassium = soilProperties.Potassium - ((soilProperties.PotassiumDegradeRate * (float)Math.Pow(ProductionRate, 2)) * (float)Math.Pow((r.NextDouble() + 0.5f), 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateRainfall(float Rain)
|
|
||||||
{
|
|
||||||
if (Rain >= 0.45f)
|
|
||||||
{
|
|
||||||
soilProperties.Rainfall = soilProperties.Rainfall + Rain * 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrevRainfall()
|
|
||||||
{
|
|
||||||
|
|
||||||
soilProperties.prevRainfall = soilProperties.Rainfall;
|
|
||||||
if (soilProperties.prevRainfall > 3616)
|
|
||||||
soilProperties.prevRainfall = 3616;
|
|
||||||
else if (soilProperties.prevRainfall < 236)
|
|
||||||
soilProperties.prevRainfall = 236;
|
|
||||||
soilProperties.Rainfall = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setCropType(int Type, CropTypes nCropType)
|
|
||||||
{
|
|
||||||
if (Timer == fullTimer)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStatus()
|
|
||||||
{
|
|
||||||
if (Status != 3)
|
|
||||||
{
|
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Status; // + cropType; When unique crop textures have been added
|
return 30;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCropType()
|
|
||||||
|
public void setPosition(int newx, int newy)
|
||||||
{
|
{
|
||||||
return cropType;
|
x = newx;
|
||||||
|
y = newy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(int newStatus)
|
public void setCropType(int Type)
|
||||||
{
|
{
|
||||||
Status = newStatus;
|
|
||||||
Timer = getCropTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOriginalStatus()
|
|
||||||
{
|
|
||||||
originalStatus = Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setHousePos(bool state)
|
|
||||||
{
|
|
||||||
housePos = state;
|
|
||||||
if (state)
|
|
||||||
{
|
|
||||||
Timer = 1;
|
|
||||||
Status = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Status = originalStatus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool getHousePos()
|
|
||||||
{
|
|
||||||
return housePos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool belowCapacity()
|
|
||||||
{
|
|
||||||
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) * 4;
|
|
||||||
g = 0.0f + productionRate;
|
|
||||||
b = 0.0f + overhead * 3;
|
|
||||||
a = 255;
|
|
||||||
|
|
||||||
return new Vector4(r, g, b, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getProductionRate(CropTypes Sample)
|
|
||||||
{
|
|
||||||
float predProd = 1.0f;
|
|
||||||
if (Status > 1 && Time.getDays() != previousDay)
|
|
||||||
{
|
|
||||||
predProd = updateMLModel(Sample, predProd);
|
|
||||||
}
|
|
||||||
prevpred = predProd;
|
|
||||||
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));
|
|
||||||
if (DataSet.soilType[0] != null)
|
|
||||||
{
|
|
||||||
if (Sample.soilType[0] == soilProperties.soilType)
|
|
||||||
{
|
|
||||||
ProductionRate = ProductionRate + 0.1f;
|
|
||||||
}
|
|
||||||
if (DataSet.soilType[1] != null)
|
|
||||||
{
|
|
||||||
if (Sample.soilType[1] == soilProperties.soilType)
|
|
||||||
{
|
|
||||||
ProductionRate = ProductionRate + 0.08f;
|
|
||||||
}
|
|
||||||
if (DataSet.soilType[2] != null)
|
|
||||||
{
|
|
||||||
if (Sample.soilType[2] == soilProperties.soilType)
|
|
||||||
{
|
|
||||||
ProductionRate = ProductionRate + 0.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
min = Math.Min(compareToDatset(soilProperties.Phosphorous, Sample.Phosphorous), Math.Min(compareToDatset(soilProperties.Potassium, Sample.Potassium), compareToDatset(soilProperties.Nitrogen, Sample.Nitrogen)));
|
|
||||||
ProductionRate = ProductionRate + (ProductionRate * min);
|
|
||||||
if (ProductionRate < 0)
|
|
||||||
{
|
|
||||||
ProductionRate = 0;
|
|
||||||
}
|
|
||||||
ProductionRate = ProductionRate / 1.5f;
|
|
||||||
}
|
|
||||||
ProductionRate = (float)Math.Pow(ProductionRate, 2.5f);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
if (housePos)
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, "Tiletype: House", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.Teal);
|
|
||||||
}
|
|
||||||
else if (Status == 0)
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, "Tiletype: Boulders", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.Teal);
|
|
||||||
}
|
|
||||||
else if (Status == 1)
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, "Tiletype: Grassfield", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.Teal);
|
|
||||||
}
|
|
||||||
else if (Status == 2)
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, "Tiletype: Soil", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.Teal);
|
|
||||||
}
|
|
||||||
else if (Status == 3)
|
|
||||||
{
|
|
||||||
int x = (int)(((float)Timer / fullTimer) * 100);
|
|
||||||
x = 100 - x;
|
|
||||||
spriteBatch.DrawString(Bold, "Tiletype: Crop ", new Vector2(240, Size.Y * (tileSize + Spacing) + 42), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Completion: " + x + "%", new Vector2(240, Size.Y * (tileSize + Spacing) + 82), Color.Teal);
|
|
||||||
}
|
|
||||||
if (Status != 3)
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, "-------------", new Vector2(240, Size.Y * (tileSize + Spacing) + 82), Color.DarkRed);
|
|
||||||
}
|
|
||||||
if (Status > 1)
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, "Prefered Crop: " + cropTypesNames[cropType], new Vector2(240, Size.Y * (tileSize + Spacing) + 62), Color.Teal);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, "None", new Vector2(240, Size.Y * (tileSize + Spacing) + 62), Color.Teal);
|
|
||||||
}
|
|
||||||
spriteBatch.DrawString(Bold, "Soil Properties:", new Vector2(240, Size.Y * (tileSize + Spacing) + 122), Color.DarkRed);
|
|
||||||
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.Teal);
|
|
||||||
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.Teal);
|
|
||||||
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.Teal);
|
|
||||||
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.Teal);
|
|
||||||
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.Teal);
|
|
||||||
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.Teal);
|
|
||||||
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.Teal);
|
|
||||||
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.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Last Years Rainfall: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 302), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, Math.Round((soilProperties.prevRainfall), 1).ToString() + "mm", new Vector2(370, Size.Y * (tileSize + Spacing) + 302), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Rainfall: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 322), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, Math.Round((soilProperties.Rainfall), 1).ToString() + "mm", new Vector2(370, Size.Y * (tileSize + Spacing) + 322), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Rain mm/s: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 342), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, Math.Round((tempRain * 2), 2).ToString() + "mm", new Vector2(370, Size.Y * (tileSize + Spacing) + 342), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, "Area: ", new Vector2(240, Size.Y * (tileSize + Spacing) + 362), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, soilProperties.Area + "m^2", new Vector2(370, Size.Y * (tileSize + Spacing) + 362), Color.Teal);
|
|
||||||
spriteBatch.End();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -12,201 +10,63 @@ class Farm
|
|||||||
{
|
{
|
||||||
private Crops[,] crops;
|
private Crops[,] crops;
|
||||||
private Random r;
|
private Random r;
|
||||||
private CropTypesHolder PresetCrops = new CropTypesHolder();
|
|
||||||
private int Update;
|
|
||||||
private Astar astar = new Astar();
|
|
||||||
private PerlinNoise perlin = new PerlinNoise();
|
|
||||||
private Vector2 RainPosition;
|
|
||||||
private Vector2 WindSpeed = new Vector2(0,0);
|
|
||||||
private System.Drawing.Color[][] RainfallMap;
|
|
||||||
private float[][] whiteNoise;
|
|
||||||
private float[][] perlinNoise;
|
|
||||||
private DayNightCycle Time;
|
|
||||||
private float updatePerc = 0.01f;
|
|
||||||
private float updateProgress = 0;
|
|
||||||
private float nextUpdate = 0;
|
|
||||||
private int productionUpdate = 0;
|
|
||||||
private string path_base = FindPath();
|
|
||||||
|
|
||||||
|
|
||||||
//initializes the crops
|
//initializes the crops
|
||||||
public void init(Vector2 Size, Vector2 housepos)
|
public void init(Vector2 Size)
|
||||||
{
|
{
|
||||||
whiteNoise = PerlinNoise.GenerateWhiteNoise(100, 100);
|
|
||||||
perlinNoise = PerlinNoise.GeneratePerlinNoise(whiteNoise, 1);
|
|
||||||
PresetCrops.init();
|
|
||||||
r = new Random();
|
r = new Random();
|
||||||
crops = new Crops[100, 100];
|
crops = new Crops[100, 100];
|
||||||
int dirtCount = 0;
|
for (int i = 0; i < Size.X; i++)
|
||||||
for (int i = 0; i < 99; i++)
|
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 99; j++)
|
for (int j = 0; j < Size.Y; j++)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = r.Next(0, 3);
|
||||||
|
if (x == 0)
|
||||||
if (perlinNoise[i][j] > 0 && perlinNoise[i][j] < 0.15f)
|
{
|
||||||
x = 0;
|
x = r.Next(0, 2);
|
||||||
else if (perlinNoise[i][j] >= 0.15f && perlinNoise[i][j] < 0.8f)
|
}
|
||||||
x = 1;
|
if (x == 2)
|
||||||
else if (perlinNoise[i][j] >= 0.8f)
|
{
|
||||||
x = 2;
|
x = r.Next(1, 3);
|
||||||
|
}
|
||||||
crops[i, j] = new Crops();
|
crops[i, j] = new Crops();
|
||||||
crops[i, j].setStatus(x);
|
crops[i, j].Status = x;
|
||||||
crops[i, j].setOriginalStatus();
|
|
||||||
x = r.Next(1, 12);
|
|
||||||
crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x));
|
|
||||||
crops[i, j].init();
|
|
||||||
|
|
||||||
if (crops[i, j].getStatus() == 2)
|
|
||||||
{
|
|
||||||
dirtCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 99; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < 99; j++)
|
|
||||||
{
|
|
||||||
if (crops[i, j].getStatus() == 2)
|
|
||||||
{
|
|
||||||
if (!astar.isReachable(crops, new Vector2((int)i, (int)j), housepos))
|
|
||||||
{
|
|
||||||
dirtCount--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dirtCount != 0)
|
|
||||||
init(Size, housepos);
|
|
||||||
RainPosition.X = r.Next(0, 1900);
|
|
||||||
RainPosition.Y = r.Next(0, 1950);
|
|
||||||
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(System.IO.Path.Combine(path_base, "Content/Rainfall.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rectangle getRainPosition(int TileSize, int x, int y, Vector2 Size)
|
|
||||||
{
|
|
||||||
float xtrunc = RainPosition.X - (float)Math.Truncate(RainPosition.X);
|
|
||||||
float ytrunc = RainPosition.Y - (float)Math.Truncate(RainPosition.Y);
|
|
||||||
|
|
||||||
if (xtrunc > 0.5)
|
|
||||||
xtrunc = xtrunc - 1;
|
|
||||||
|
|
||||||
if (ytrunc > 0.5)
|
|
||||||
ytrunc = ytrunc - 1;
|
|
||||||
xtrunc = -xtrunc;
|
|
||||||
ytrunc = -ytrunc;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//return new Rectangle((int)(xtrunc * TileSize) + x * TileSize,(int)(ytrunc * TileSize) + y * TileSize, TileSize, TileSize);
|
|
||||||
return new Rectangle((int)(xtrunc * TileSize) + x * TileSize, (int)(ytrunc * TileSize) + y * TileSize, TileSize, TileSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rectangle getDestinationRectangle(int x, int y, Vector2 Size)
|
|
||||||
{
|
|
||||||
Vector2 temp = new Vector2((int)Math.Round(x + RainPosition.X), y + (int)Math.Round(RainPosition.Y));
|
|
||||||
if (temp.X >= 1999 - Size.X - 1)
|
|
||||||
temp.X = -(1999 - (int)Math.Round(RainPosition.X));
|
|
||||||
if (temp.Y >= 1999 - Size.Y - 1)
|
|
||||||
temp.Y = -(1999 - (int)Math.Round(RainPosition.Y));
|
|
||||||
return new Rectangle((int)temp.X, (int)temp.Y, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawWeatherInformation(SpriteBatch spriteBatch, SpriteFont Bold, Input input)
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, "WindSpeed: " + Math.Round(WindSpeed.X, 4), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 282), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, " : ", new Vector2(153, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 282), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, Math.Round(WindSpeed.Y, 4).ToString(), new Vector2(163, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 282), Color.Teal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFarm(Vector2 Size)
|
public void updateFarm(Vector2 Size)
|
||||||
{
|
{
|
||||||
Update++;
|
for (int i = 0; i > Size.X; i++)
|
||||||
if (Update == 30)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Size.X; i++)
|
for (int j = 0; j > Size.Y; j++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < Size.Y; j++)
|
crops[i, j].updateCrop();
|
||||||
{
|
|
||||||
Vector2 temp = new Vector2((int)Math.Round(i + RainPosition.X), j + (int)Math.Round(RainPosition.Y));
|
|
||||||
if (temp.X >= 1999 - Size.X - 1)
|
|
||||||
temp.X = i + ((1999 - (int)Math.Round(RainPosition.X)));
|
|
||||||
if (temp.Y >= 1999 - Size.Y - 1)
|
|
||||||
temp.Y = i + ((1999 - (int)Math.Round(RainPosition.Y)));
|
|
||||||
crops[i, j].updateCrop(Size, Time);
|
|
||||||
crops[i, j].updateRainfall(RainfallMap[(int)Math.Round(temp.X)][(int)Math.Round(temp.Y)].GetBrightness());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Update = 0;
|
|
||||||
}
|
|
||||||
updateRainMapPosition(Size);
|
|
||||||
if (productionUpdate == 2)
|
|
||||||
{
|
|
||||||
nextUpdate = updateProgress + updatePerc;
|
|
||||||
for (int i = (int)(updateProgress * Size.X); i < nextUpdate * Size.X; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < Size.Y; j++)
|
|
||||||
{
|
|
||||||
if (crops[i, j].getStatus() > 1)
|
|
||||||
{
|
|
||||||
int x = getHighestProductionRate(i, j);
|
|
||||||
crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x));
|
|
||||||
crops[i, j].updateProductionRate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateProgress = updateProgress + updatePerc;
|
|
||||||
if (updateProgress >= 1)
|
|
||||||
{
|
|
||||||
updateProgress = 0;
|
|
||||||
}
|
|
||||||
productionUpdate = 0;
|
|
||||||
nextUpdate = 0;
|
|
||||||
}
|
|
||||||
productionUpdate++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateRainFall(Vector2 Size, DayNightCycle nTime)
|
|
||||||
{
|
|
||||||
Time = nTime;
|
|
||||||
if (nTime.nDay())
|
|
||||||
{
|
|
||||||
for (int i = 0; i < Size.X; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < Size.Y; j++)
|
|
||||||
{
|
|
||||||
crops[i, j].setPrevRainfall();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Changes the properties of the tile when the tractor reaches this tile.
|
//Changes the properties of the tile when the tractor reaches this tile.
|
||||||
public void setCropStatus(float xfloat, float yfloat)
|
public void setCropStatus(float xfloat, float yfloat, int Spacing)
|
||||||
{
|
{
|
||||||
int x = (int)xfloat;
|
int x = (int)xfloat / Spacing;
|
||||||
int y = (int)yfloat;
|
int y = (int)yfloat / Spacing;
|
||||||
if (crops[x, y].getStatus() >= 3)
|
if (crops[x, y].Status == 4)
|
||||||
{
|
{
|
||||||
crops[x, y].setStatus(2);
|
crops[x, y].Status = 2;
|
||||||
}
|
}
|
||||||
else if(crops[x, y].getStatus() == 0)
|
else if(crops[x, y].Status == 0)
|
||||||
{
|
{
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
else if (crops[x, y].getStatus() == 2)
|
else if (crops[x, y].Status == 2)
|
||||||
{
|
{
|
||||||
|
crops[x, y].Status = 3;
|
||||||
crops[x, y].setStatus(3);
|
}
|
||||||
crops[x, y].setCropTimer();
|
else if (crops[x, y].Status == 3)
|
||||||
|
{
|
||||||
|
crops[x, y].Status = 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,130 +80,17 @@ class Farm
|
|||||||
return crops;
|
return crops;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRainMapPosition(Vector2 Size)
|
public void updateSize(Vector2 Size, int tileSize, int Spacing)
|
||||||
{
|
{
|
||||||
double x, y;
|
|
||||||
x = WindSpeed.X + GetRandomNumber(-1f, 1f) / 20000;
|
for (int i = 0; i < (int)Size.X; i++)
|
||||||
y = WindSpeed.Y + GetRandomNumber(-1f, 1f) / 20000;
|
|
||||||
if (x <= 0.02f && x >= -0.02f)
|
|
||||||
{
|
{
|
||||||
WindSpeed.X = (float)x;
|
for (int j = 0; j < (int)Size.Y; j++)
|
||||||
}
|
|
||||||
|
|
||||||
if (y < 0.02f && y > -0.02f)
|
|
||||||
{
|
|
||||||
WindSpeed.Y = (float)y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WindSpeed.X > 0 && RainPosition.X < 2000)
|
|
||||||
RainPosition.X = RainPosition.X + WindSpeed.X;
|
|
||||||
else if (WindSpeed.X < 0 && RainPosition.X > 0)
|
|
||||||
RainPosition.X = RainPosition.X + WindSpeed.X;
|
|
||||||
|
|
||||||
if (WindSpeed.Y > 0 && RainPosition.Y < 2000)
|
|
||||||
RainPosition.Y = RainPosition.Y + WindSpeed.Y;
|
|
||||||
else if (WindSpeed.Y < 0 && RainPosition.Y > 0)
|
|
||||||
RainPosition.Y = RainPosition.Y + WindSpeed.Y;
|
|
||||||
|
|
||||||
if (Math.Round(RainPosition.X) == 1999 && WindSpeed.X > 0)
|
|
||||||
RainPosition.X = 0;
|
|
||||||
else if (Math.Round(RainPosition.X) == 1 && WindSpeed.X < 0)
|
|
||||||
RainPosition.X = 1999;
|
|
||||||
|
|
||||||
if (Math.Round(RainPosition.Y) == 1999 && WindSpeed.Y > 0)
|
|
||||||
RainPosition.Y = 0;
|
|
||||||
else if (Math.Round(RainPosition.Y) == 1 && WindSpeed.Y < 0)
|
|
||||||
RainPosition.Y = 1999;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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++)
|
|
||||||
{
|
{
|
||||||
if (crops[i, j].getStatus() == 2)
|
crops[i, j].x = (tileSize + Spacing) * i;
|
||||||
{
|
crops[i, j].y = (tileSize + Spacing) * j;
|
||||||
int x = getHighestProductionRate(i, j);
|
|
||||||
crops[i, j].setCropType(x, PresetCrops.getPresetCropTypes(x));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getHighestProductionRate(int x, int y)
|
|
||||||
{
|
|
||||||
int i = 6, 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 Color getRainAmount(int x, int y, Color color, Vector2 Size)
|
|
||||||
{
|
|
||||||
Vector2 temp = new Vector2(x + (int)Math.Round(RainPosition.X), y + (int)Math.Round(RainPosition.Y));
|
|
||||||
if (temp.X >= 1999)
|
|
||||||
temp.X = -(1999 - (int)Math.Round(temp.X));
|
|
||||||
if (temp.Y >= 1999)
|
|
||||||
temp.Y = -(1999 - (int)Math.Round(temp.Y));
|
|
||||||
if (temp.X == -1)
|
|
||||||
temp.X = 1999;
|
|
||||||
if (temp.Y == -1)
|
|
||||||
temp.Y = 1999;
|
|
||||||
if (RainfallMap[(int)temp.X][(int)temp.Y].GetBrightness() < 0.45f)
|
|
||||||
{
|
|
||||||
return Color.FromNonPremultiplied(color.R, color.G, color.B, (int)(0));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Color.FromNonPremultiplied(color.R, color.G, color.B, (int)(255 * RainfallMap[(int)temp.X][(int)temp.Y].GetBrightness()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getProductionRate(int x, int y, int Type)
|
|
||||||
{
|
|
||||||
return crops[x, y]. getProductionRate(PresetCrops.getPresetCropTypes(Type));
|
|
||||||
}
|
|
||||||
|
|
||||||
public float GetRandomNumber(double minimum, double maximum)
|
|
||||||
{
|
|
||||||
return (float)(Math.Round(r.NextDouble() * (maximum - minimum) + minimum, 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string FindPath()
|
|
||||||
{
|
|
||||||
string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).ToString();
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
path = Directory.GetParent(path).ToString();
|
|
||||||
if (path.EndsWith("\\Game1"))
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,333 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Drawing.Imaging;
|
|
||||||
|
|
||||||
class PerlinNoise
|
|
||||||
{
|
|
||||||
#region Feilds
|
|
||||||
static Random random = new Random();
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Reusable Functions
|
|
||||||
|
|
||||||
public static float[][] GenerateWhiteNoise(int width, int height)
|
|
||||||
{
|
|
||||||
float[][] noise = GetEmptyArray<float>(width, height);
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
noise[i][j] = (float)random.NextDouble() % 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return noise;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float Interpolate(float x0, float x1, float alpha)
|
|
||||||
{
|
|
||||||
return x0 * (1 - alpha) + alpha * x1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Color Interpolate(Color col0, Color col1, float alpha)
|
|
||||||
{
|
|
||||||
float beta = 1 - alpha;
|
|
||||||
return Color.FromArgb(
|
|
||||||
255,
|
|
||||||
(int)(col0.R * alpha + col1.R * beta),
|
|
||||||
(int)(col0.G * alpha + col1.G * beta),
|
|
||||||
(int)(col0.B * alpha + col1.B * beta));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Color GetColor(Color gradientStart, Color gradientEnd, float t)
|
|
||||||
{
|
|
||||||
float u = 1 - t;
|
|
||||||
|
|
||||||
Color color = Color.FromArgb(
|
|
||||||
255,
|
|
||||||
(int)(gradientStart.R * u + gradientEnd.R * t),
|
|
||||||
(int)(gradientStart.G * u + gradientEnd.G * t),
|
|
||||||
(int)(gradientStart.B * u + gradientEnd.B * t));
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Color[][] MapGradient(Color gradientStart, Color gradientEnd, float[][] perlinNoise)
|
|
||||||
{
|
|
||||||
int width = perlinNoise.Length;
|
|
||||||
int height = perlinNoise[0].Length;
|
|
||||||
|
|
||||||
Color[][] image = GetEmptyArray<Color>(width, height); //an array of colours
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
image[i][j] = GetColor(gradientStart, gradientEnd, perlinNoise[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T[][] GetEmptyArray<T>(int width, int height)
|
|
||||||
{
|
|
||||||
T[][] image = new T[width][];
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
image[i] = new T[height];
|
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[][] GenerateSmoothNoise(float[][] baseNoise, int octave)
|
|
||||||
{
|
|
||||||
int width = baseNoise.Length;
|
|
||||||
int height = baseNoise[0].Length;
|
|
||||||
|
|
||||||
float[][] smoothNoise = GetEmptyArray<float>(width, height);
|
|
||||||
|
|
||||||
int samplePeriod = 1 << octave; // calculates 2 ^ k
|
|
||||||
float sampleFrequency = 1.0f / samplePeriod;
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
//calculate the horizontal sampling indices
|
|
||||||
int sample_i0 = (i / samplePeriod) * samplePeriod;
|
|
||||||
int sample_i1 = (sample_i0 + samplePeriod) % width; //wrap around
|
|
||||||
float horizontal_blend = (i - sample_i0) * sampleFrequency;
|
|
||||||
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
//calculate the vertical sampling indices
|
|
||||||
int sample_j0 = (j / samplePeriod) * samplePeriod;
|
|
||||||
int sample_j1 = (sample_j0 + samplePeriod) % height; //wrap around
|
|
||||||
float vertical_blend = (j - sample_j0) * sampleFrequency;
|
|
||||||
|
|
||||||
//blend the top two corners
|
|
||||||
float top = Interpolate(baseNoise[sample_i0][sample_j0],
|
|
||||||
baseNoise[sample_i1][sample_j0], horizontal_blend);
|
|
||||||
|
|
||||||
//blend the bottom two corners
|
|
||||||
float bottom = Interpolate(baseNoise[sample_i0][sample_j1],
|
|
||||||
baseNoise[sample_i1][sample_j1], horizontal_blend);
|
|
||||||
|
|
||||||
//final blend
|
|
||||||
smoothNoise[i][j] = Interpolate(top, bottom, vertical_blend);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return smoothNoise;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[][] GeneratePerlinNoise(float[][] baseNoise, int octaveCount)
|
|
||||||
{
|
|
||||||
int width = baseNoise.Length;
|
|
||||||
int height = baseNoise[0].Length;
|
|
||||||
|
|
||||||
float[][][] smoothNoise = new float[octaveCount][][]; //an array of 2D arrays containing
|
|
||||||
|
|
||||||
float persistance = 0.7f;
|
|
||||||
|
|
||||||
//generate smooth noise
|
|
||||||
for (int i = 0; i < octaveCount; i++)
|
|
||||||
{
|
|
||||||
smoothNoise[i] = GenerateSmoothNoise(baseNoise, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
float[][] perlinNoise = GetEmptyArray<float>(width, height); //an array of floats initialised to 0
|
|
||||||
|
|
||||||
float amplitude = 1.0f;
|
|
||||||
float totalAmplitude = 0.0f;
|
|
||||||
|
|
||||||
//blend noise together
|
|
||||||
for (int octave = octaveCount - 1; octave >= 0; octave--)
|
|
||||||
{
|
|
||||||
amplitude *= persistance;
|
|
||||||
totalAmplitude += amplitude;
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
perlinNoise[i][j] += smoothNoise[octave][i][j] * amplitude;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//normalisation
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
perlinNoise[i][j] /= totalAmplitude;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return perlinNoise;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[][] GeneratePerlinNoise(int width, int height, int octaveCount)
|
|
||||||
{
|
|
||||||
float[][] baseNoise = GenerateWhiteNoise(width, height);
|
|
||||||
|
|
||||||
return GeneratePerlinNoise(baseNoise, octaveCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Color[][] MapToGrey(float[][] greyValues)
|
|
||||||
{
|
|
||||||
int width = greyValues.Length;
|
|
||||||
int height = greyValues[0].Length;
|
|
||||||
|
|
||||||
Color[][] image = GetEmptyArray<Color>(width, height);
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
int grey = (int)(255 * greyValues[i][j]);
|
|
||||||
Color color = Color.FromArgb(255, grey, grey, grey);
|
|
||||||
|
|
||||||
image[i][j] = color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SaveImage(Color[][] image, string fileName)
|
|
||||||
{
|
|
||||||
int width = image.Length;
|
|
||||||
int height = image[0].Length;
|
|
||||||
|
|
||||||
Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
bitmap.SetPixel(i, j, image[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bitmap.Save(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Color[][] LoadImage(string fileName)
|
|
||||||
{
|
|
||||||
Bitmap bitmap = new Bitmap(fileName);
|
|
||||||
|
|
||||||
int width = bitmap.Width;
|
|
||||||
int height = bitmap.Height;
|
|
||||||
|
|
||||||
Color[][] image = GetEmptyArray<Color>(width, height);
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
image[i][j] = bitmap.GetPixel(i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Color[][] BlendImages(Color[][] image1, Color[][] image2, float[][] perlinNoise)
|
|
||||||
{
|
|
||||||
int width = image1.Length;
|
|
||||||
int height = image1[0].Length;
|
|
||||||
|
|
||||||
Color[][] image = GetEmptyArray<Color>(width, height); //an array of colours for the new image
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
image[i][j] = Interpolate(image1[i][j], image2[i][j], perlinNoise[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void DemoGradientMap()
|
|
||||||
{
|
|
||||||
int width = 256;
|
|
||||||
int height = 256;
|
|
||||||
int octaveCount = 8;
|
|
||||||
|
|
||||||
Color gradientStart = Color.FromArgb(255, 0, 0);
|
|
||||||
Color gradientEnd = Color.FromArgb(255, 0, 255);
|
|
||||||
|
|
||||||
float[][] perlinNoise = GeneratePerlinNoise(width, height, octaveCount);
|
|
||||||
Color[][] perlinImage = MapGradient(gradientStart, gradientEnd, perlinNoise);
|
|
||||||
SaveImage(perlinImage, "perlin_noise.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[][] AdjustLevels(float[][] image, float low, float high)
|
|
||||||
{
|
|
||||||
int width = image.Length;
|
|
||||||
int height = image[0].Length;
|
|
||||||
|
|
||||||
float[][] newImage = GetEmptyArray<float>(width, height);
|
|
||||||
|
|
||||||
for (int i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
float col = image[i][j];
|
|
||||||
|
|
||||||
if (col <= low)
|
|
||||||
{
|
|
||||||
newImage[i][j] = 0;
|
|
||||||
}
|
|
||||||
else if (col >= high)
|
|
||||||
{
|
|
||||||
newImage[i][j] = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newImage[i][j] = (col - low) / (high - low);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return newImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Color[][][] AnimateTransition(Color[][] image1, Color[][] image2, int frameCount)
|
|
||||||
{
|
|
||||||
Color[][][] animation = new Color[frameCount][][];
|
|
||||||
|
|
||||||
float low = 0;
|
|
||||||
float increment = 1.0f / frameCount;
|
|
||||||
float high = increment;
|
|
||||||
|
|
||||||
float[][] perlinNoise = AdjustLevels(
|
|
||||||
GeneratePerlinNoise(image1.Length, image1[0].Length, 9),
|
|
||||||
0.2f, 0.8f);
|
|
||||||
|
|
||||||
for (int i = 0; i < frameCount; i++)
|
|
||||||
{
|
|
||||||
AdjustLevels(perlinNoise, low, high);
|
|
||||||
float[][] blendMask = AdjustLevels(perlinNoise, low, high);
|
|
||||||
animation[i] = BlendImages(image1, image2, blendMask);
|
|
||||||
//SaveImage(animation[i], "blend_animation" + i + ".png");
|
|
||||||
SaveImage(MapToGrey(blendMask), "blend_mask" + i + ".png");
|
|
||||||
low = high;
|
|
||||||
high += increment;
|
|
||||||
}
|
|
||||||
|
|
||||||
return animation;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
|
|
||||||
class SoilProperties
|
|
||||||
{
|
|
||||||
static Random r = new Random();
|
|
||||||
|
|
||||||
|
|
||||||
public string soilType = "potato";
|
|
||||||
public float Temperature;
|
|
||||||
public float Humidity;
|
|
||||||
public float Moisture;
|
|
||||||
public float Nitrogen;
|
|
||||||
public float Potassium;
|
|
||||||
public float Phosphorous;
|
|
||||||
public float Rainfall;
|
|
||||||
public float prevRainfall;
|
|
||||||
public float NitrogenDegradeRate = 0.8f / 1.5f;
|
|
||||||
public float PotassiumDegradeRate = 0.3f / 1.5f;
|
|
||||||
public float PhosphorousDegradeRate = 0.6f / 1.5f;
|
|
||||||
public int Capacity = 80;
|
|
||||||
public int Area;
|
|
||||||
|
|
||||||
public void setSoilProperties()
|
|
||||||
{
|
|
||||||
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.9f, 2.1f);
|
|
||||||
Moisture = GetRandomNumber(20, 70);
|
|
||||||
Nitrogen = GetRandomNumber(4 , 42); //was 4, 60
|
|
||||||
Potassium = GetRandomNumber(0.01f, 19); // was 0, 28
|
|
||||||
Phosphorous = GetRandomNumber(0.01f, 42); // was 0, 60
|
|
||||||
prevRainfall = r.Next(247, 3617);
|
|
||||||
Area = r.Next(1, 270000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float GetRandomNumber(double minimum, double maximum)
|
|
||||||
{
|
|
||||||
return (float)(Math.Round(r.NextDouble() * (maximum - minimum) + minimum, 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
|||||||
Temparature,Humidity ,Moisture,Soil Type,Crop Type,Nitrogen,Potassium,Phosphorous,Fertilizer Name
|
|
||||||
26,52,38,Sandy,Maize,37,0,0,Urea
|
|
||||||
29,52,45,Loamy,Sugarcane,12,0,36,DAP
|
|
||||||
34,65,62,Black,Cotton,7,9,30,14-35-14
|
|
||||||
32,62,34,Red,Tobacco,22,0,20,28-28
|
|
||||||
28,54,46,Clayey,Paddy,35,0,0,Urea
|
|
||||||
26,52,35,Sandy,Barley,12,10,13,17-17-17
|
|
||||||
25,50,64,Red,Cotton,9,0,10,20-20
|
|
||||||
33,64,50,Loamy,Wheat,41,0,0,Urea
|
|
||||||
30,60,42,Sandy,Millets,21,0,18,28-28
|
|
||||||
29,58,33,Black,Oil seeds,9,7,30,14-35-14
|
|
||||||
27,54,28,Clayey,Pulses,13,0,40,DAP
|
|
||||||
31,62,48,Sandy,Maize,14,15,12,17-17-17
|
|
||||||
25,50,65,Loamy,Cotton,36,0,0,Urea
|
|
||||||
32,62,41,Clayey,Paddy,24,0,22,28-28
|
|
||||||
26,52,31,Red,Ground Nuts,14,0,41,DAP
|
|
||||||
31,62,49,Black,Sugarcane,10,13,14,17-17-17
|
|
||||||
33,64,34,Clayey,Pulses,38,0,0,Urea
|
|
||||||
25,50,39,Sandy,Barley,21,0,19,28-28
|
|
||||||
28,54,65,Black,Cotton,39,0,0,Urea
|
|
||||||
29,58,52,Loamy,Wheat,13,0,36,DAP
|
|
||||||
30,60,44,Sandy,Millets,10,0,9,20-20
|
|
||||||
34,65,53,Loamy,Sugarcane,12,14,12,17-17-17
|
|
||||||
35,68,33,Red,Tobacco,11,0,37,DAP
|
|
||||||
28,54,37,Black,Millets,36,0,0,Urea
|
|
||||||
33,64,39,Clayey,Paddy,13,0,10,20-20
|
|
||||||
26,52,44,Sandy,Maize,23,0,20,28-28
|
|
||||||
30,60,63,Red,Cotton,9,9,29,14-35-14
|
|
||||||
32,62,30,Loamy,Sugarcane,38,0,0,Urea
|
|
||||||
37,70,32,Black,Oil seeds,12,0,39,DAP
|
|
||||||
26,52,36,Clayey,Pulses,14,0,13,20-20
|
|
||||||
29,58,40,Red,Ground Nuts,24,0,23,28-28
|
|
||||||
30,60,27,Loamy,Sugarcane,12,0,40,DAP
|
|
||||||
34,65,38,Clayey,Paddy,39,0,0,Urea
|
|
||||||
36,68,38,Sandy,Barley,7,9,30,14-35-14
|
|
||||||
26,52,48,Loamy,Wheat,23,0,19,28-28
|
|
||||||
28,54,35,Black,Millets,41,0,0,Urea
|
|
||||||
30,60,61,Loamy,Cotton,8,10,31,14-35-14
|
|
||||||
37,70,37,Clayey,Paddy,12,0,41,DAP
|
|
||||||
25,50,26,Red,Ground Nuts,15,14,11,17-17-17
|
|
||||||
29,58,34,Sandy,Millets,15,0,37,DAP
|
|
||||||
27,54,30,Clayey,Pulses,13,0,13,20-20
|
|
||||||
30,60,58,Loamy,Sugarcane,10,7,32,14-35-14
|
|
||||||
32,62,34,Red,Tobacco,22,0,24,28-28
|
|
||||||
34,65,60,Black,Sugarcane,35,0,0,Urea
|
|
||||||
35,67,42,Sandy,Barley,10,0,35,DAP
|
|
||||||
38,70,48,Loamy,Wheat,8,8,28,14-35-14
|
|
||||||
26,52,32,Black,Oil seeds,12,0,8,20-20
|
|
||||||
29,58,43,Clayey,Paddy,24,0,18,28-28
|
|
||||||
30,60,29,Red,Ground Nuts,41,0,0,Urea
|
|
||||||
33,64,51,Sandy,Maize,5,9,29,14-35-14
|
|
||||||
34,65,31,Red,Tobacco,23,0,21,28-28
|
|
||||||
36,68,33,Black,Oil seeds,13,0,14,20-20
|
|
||||||
28,54,38,Clayey,Pulses,40,0,0,Urea
|
|
||||||
30,60,47,Sandy,Barley,12,0,42,DAP
|
|
||||||
31,62,63,Red,Cotton,11,12,15,17-17-17
|
|
||||||
27,53,43,Black,Millets,23,0,24,28-28
|
|
||||||
34,65,54,Loamy,Wheat,38,0,0,Urea
|
|
||||||
29,58,37,Sandy,Millets,8,0,15,20-20
|
|
||||||
25,50,56,Loamy,Sugarcane,11,13,15,17-17-17
|
|
||||||
32,62,34,Red,Ground Nuts,15,0,37,DAP
|
|
||||||
28,54,41,Clayey,Paddy,36,0,0,Urea
|
|
||||||
30,60,49,Loamy,Wheat,13,0,9,20-20
|
|
||||||
34,65,64,Black,Cotton,24,0,20,28-28
|
|
||||||
28,54,47,Sandy,Barley,5,18,15,10-26-26
|
|
||||||
27,53,35,Black,Oil seeds,37,0,0,Urea
|
|
||||||
36,68,62,Red,Cotton,15,0,40,DAP
|
|
||||||
34,65,57,Black,Sugarcane,9,0,13,20-20
|
|
||||||
29,58,55,Loamy,Sugarcane,8,8,33,14-35-14
|
|
||||||
25,50,40,Clayey,Pulses,6,19,16,10-26-26
|
|
||||||
30,60,38,Sandy,Millets,10,0,14,20-20
|
|
||||||
26,52,39,Clayey,Pulses,21,0,23,28-28
|
|
||||||
31,62,32,Red,Tobacco,39,0,0,Urea
|
|
||||||
34,65,48,Loamy,Wheat,23,0,19,28-28
|
|
||||||
27,53,34,Black,Oil seeds,42,0,0,Urea
|
|
||||||
33,64,31,Red,Ground Nuts,13,0,39,DAP
|
|
||||||
29,58,42,Clayey,Paddy,9,10,22,14-35-14
|
|
||||||
30,60,47,Sandy,Maize,22,0,21,28-28
|
|
||||||
27,53,59,Loamy,Sugarcane,10,0,15,20-20
|
|
||||||
26,52,36,Clayey,Pulses,7,16,20,10-26-26
|
|
||||||
34,65,63,Red,Cotton,14,0,38,DAP
|
|
||||||
28,54,43,Clayey,Paddy,10,8,29,14-35-14
|
|
||||||
30,60,40,Sandy,Millets,41,0,0,Urea
|
|
||||||
29,58,65,Black,Cotton,14,0,35,DAP
|
|
||||||
26,52,59,Loamy,Sugarcane,11,0,9,20-20
|
|
||||||
31,62,44,Sandy,Barley,21,0,28,28-28
|
|
||||||
35,67,28,Clayey,Pulses,8,7,31,14-35-14
|
|
||||||
29,58,30,Red,Tobacco,13,17,16,10-26-26
|
|
||||||
27,53,30,Black,Millets,35,0,0,Urea
|
|
||||||
36,68,50,Loamy,Wheat,12,18,19,10-26-26
|
|
||||||
29,58,61,Loamy,Cotton,11,0,38,DAP
|
|
||||||
30,60,26,Black,Oil seeds,8,9,30,14-35-14
|
|
||||||
34,65,45,Clayey,Paddy,6,19,21,10-26-26
|
|
||||||
36,68,41,Red,Ground Nuts,41,0,0,Urea
|
|
||||||
28,54,25,Sandy,Maize,9,10,30,14-35-14
|
|
||||||
25,50,32,Clayey,Pulses,24,0,19,28-28
|
|
||||||
30,60,27,Red,Tobacco,4,17,17,10-26-26
|
|
||||||
38,72,51,Loamy,Wheat,39,0,0,Urea
|
|
||||||
36,60,43,Sandy,Millets,15,0,41,DAP
|
|
||||||
29,58,57,Black,Sugarcane,12,0,10,20-20
|
|
|
@ -1,39 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML;
|
|
||||||
|
|
||||||
|
|
||||||
static class Engine
|
|
||||||
{
|
|
||||||
private static MLContext mlContext = new MLContext(seed: 1);
|
|
||||||
private static PredictionEngine<ModelInput, ModelOutput> PredictionEngine;
|
|
||||||
private static ModelOutput modelOutput;
|
|
||||||
|
|
||||||
public static void init()
|
|
||||||
{
|
|
||||||
PredictionEngine = MLModel.CreateEngine();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string PredictFertilizer(Crops crop, CropTypes cropTypes)
|
|
||||||
{
|
|
||||||
ModelInput modelInput = new ModelInput
|
|
||||||
{
|
|
||||||
Temperature = crop.getSoilProperties().Temperature,
|
|
||||||
Humidity = crop.getSoilProperties().Humidity,
|
|
||||||
Moisture = crop.getSoilProperties().Moisture,
|
|
||||||
Soil_Type = crop.getSoilProperties().soilType,
|
|
||||||
Crop_Type = cropTypes.CropName,
|
|
||||||
Nitrogen = crop.getSoilProperties().Nitrogen,
|
|
||||||
Potassium = crop.getSoilProperties().Potassium,
|
|
||||||
Phosporous = crop.getSoilProperties().Phosphorous
|
|
||||||
};
|
|
||||||
|
|
||||||
//ModelOutput modelOutput = new ModelOutput();
|
|
||||||
PredictionEngine.Predict(modelInput, ref modelOutput);
|
|
||||||
return modelOutput.Prediction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
|
|
||||||
|
|
||||||
class BigModelInput
|
|
||||||
{
|
|
||||||
[ColumnName("Ca"), LoadColumn(0)]
|
|
||||||
public float Ca { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Mg"), LoadColumn(1)]
|
|
||||||
public float Mg { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("K"), LoadColumn(2)]
|
|
||||||
public float K { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("S"), LoadColumn(3)]
|
|
||||||
public float S { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("N"), LoadColumn(4)]
|
|
||||||
public float N { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Lime"), LoadColumn(5)]
|
|
||||||
public float Lime { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("C"), LoadColumn(6)]
|
|
||||||
public float C { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("P"), LoadColumn(7)]
|
|
||||||
public float P { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Moisture"), LoadColumn(8)]
|
|
||||||
public float Moisture { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Class"), LoadColumn(9)]
|
|
||||||
public float Class { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
|
|
||||||
class BigModelOutput
|
|
||||||
{
|
|
||||||
[ColumnName("PredictedLabel")]
|
|
||||||
public float Prediction { get; set; }
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
|
|
||||||
|
|
||||||
class ModelInput
|
|
||||||
{
|
|
||||||
[ColumnName("Temperature"), LoadColumn(0)]
|
|
||||||
public float Temperature { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Humidity"), LoadColumn(1)]
|
|
||||||
public float Humidity { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Moisture"), LoadColumn(2)]
|
|
||||||
public float Moisture { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Soil_Type"), LoadColumn(3)]
|
|
||||||
public String Soil_Type { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Crop_Type"), LoadColumn(4)]
|
|
||||||
public String Crop_Type { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Nitrogen"), LoadColumn(5)]
|
|
||||||
public float Nitrogen { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Potassium"), LoadColumn(6)]
|
|
||||||
public float Potassium { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Phosphorous"), LoadColumn(7)]
|
|
||||||
public float Phosporous { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Fertilizer_Name"), LoadColumn(8)]
|
|
||||||
public String Fertilizer_Name { get; set; }
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
|
|
||||||
class ModelOutput
|
|
||||||
{
|
|
||||||
[ColumnName("PredictedLabel")]
|
|
||||||
public String Prediction { get; set; }
|
|
||||||
//public float[] Score { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,186 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
using Microsoft.ML.Trainers.LightGbm;
|
|
||||||
|
|
||||||
|
|
||||||
class MLModel
|
|
||||||
{
|
|
||||||
private static MLContext mlContext = new MLContext(seed: 1);
|
|
||||||
|
|
||||||
private static string path_base = FindPath();
|
|
||||||
|
|
||||||
private static string path = System.IO.Path.Combine(path_base, "Content/ML/Fertilizer_Prediction.csv");
|
|
||||||
private static string modelpath = System.IO.Path.Combine(path_base, "Content/ML/MLmodel");
|
|
||||||
private static string report = System.IO.Path.Combine(path_base, "Content/ML/report");
|
|
||||||
|
|
||||||
private static string pathBig = System.IO.Path.Combine(path_base, "Content/ML/BigFertPredict.csv");
|
|
||||||
private static string modelpathBig = System.IO.Path.Combine(path_base, "Content/ML/MLmodelBig");
|
|
||||||
private static string reportBig = System.IO.Path.Combine(path_base, "Content/ML/report_BigModel");
|
|
||||||
|
|
||||||
// Loading data, creatin and saving ML model for smaller dataset (100)
|
|
||||||
public static void CreateModel()
|
|
||||||
{
|
|
||||||
|
|
||||||
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<ModelInput>(
|
|
||||||
path: path,
|
|
||||||
hasHeader: true,
|
|
||||||
separatorChar: ',',
|
|
||||||
allowQuoting: true,
|
|
||||||
allowSparse: false);
|
|
||||||
|
|
||||||
ModelInput sample = mlContext.Data.CreateEnumerable<ModelInput>(trainingDataView, false).ElementAt(0);
|
|
||||||
ITransformer MLModel = BuildAndTrain(mlContext, trainingDataView, sample, report);
|
|
||||||
SaveModel(mlContext, MLModel, modelpath, trainingDataView.Schema);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ... for bigger dataset (1600)
|
|
||||||
public static void CreateBigModel()
|
|
||||||
{
|
|
||||||
|
|
||||||
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<BigModelInput>(
|
|
||||||
path: pathBig,
|
|
||||||
hasHeader: true,
|
|
||||||
separatorChar: ',',
|
|
||||||
allowQuoting: true,
|
|
||||||
allowSparse: false);
|
|
||||||
|
|
||||||
BigModelInput sample = mlContext.Data.CreateEnumerable<BigModelInput>(trainingDataView, false).ElementAt(0);
|
|
||||||
ITransformer MLModel = BuildAndTrain(mlContext, trainingDataView, sample, reportBig);
|
|
||||||
SaveModel(mlContext, MLModel, modelpathBig, trainingDataView.Schema);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Building and training ML model, very small dataset (100 entries)
|
|
||||||
public static ITransformer BuildAndTrain(MLContext mLContext, IDataView trainingDataView, ModelInput sample, string reportPath)
|
|
||||||
{
|
|
||||||
|
|
||||||
var options = new LightGbmMulticlassTrainer.Options
|
|
||||||
{
|
|
||||||
MaximumBinCountPerFeature = 8,
|
|
||||||
LearningRate = 0.00025,
|
|
||||||
NumberOfIterations = 40000,
|
|
||||||
NumberOfLeaves = 10,
|
|
||||||
LabelColumnName = "Fertilizer_NameF",
|
|
||||||
FeatureColumnName = "Features",
|
|
||||||
|
|
||||||
Booster = new DartBooster.Options()
|
|
||||||
{
|
|
||||||
MaximumTreeDepth = 10
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var pipeline = mlContext.Transforms
|
|
||||||
.Text.FeaturizeText("Soil_TypeF", "Soil_Type")
|
|
||||||
.Append(mlContext.Transforms.Text.FeaturizeText("Crop_TypeF", "Crop_Type"))
|
|
||||||
.Append(mlContext.Transforms.Concatenate("Features", "Temperature", "Humidity", "Moisture", "Soil_TypeF", "Crop_TypeF", "Nitrogen", "Potassium", "Phosphorous"))
|
|
||||||
.Append(mlContext.Transforms.Conversion.MapValueToKey("Fertilizer_NameF", "Fertilizer_Name"), TransformerScope.TrainTest)
|
|
||||||
.AppendCacheCheckpoint(mLContext)
|
|
||||||
.Append(mLContext.MulticlassClassification.Trainers.LightGbm(options))
|
|
||||||
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel", "PredictedLabel"));
|
|
||||||
|
|
||||||
Evaluate(mlContext, trainingDataView, pipeline, 10, reportPath, "Fertilizer_NameF");
|
|
||||||
ITransformer MLModel = pipeline.Fit(trainingDataView);
|
|
||||||
|
|
||||||
return MLModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Building and training ML model, moderate size dataset (1600 entries)
|
|
||||||
public static ITransformer BuildAndTrain(MLContext mLContext, IDataView trainingDataView, BigModelInput sample, string reportPath)
|
|
||||||
{
|
|
||||||
|
|
||||||
var options = new LightGbmMulticlassTrainer.Options
|
|
||||||
{
|
|
||||||
MaximumBinCountPerFeature = 10,
|
|
||||||
LearningRate = 0.001,
|
|
||||||
NumberOfIterations = 10000,
|
|
||||||
NumberOfLeaves = 12,
|
|
||||||
LabelColumnName = "ClassF",
|
|
||||||
FeatureColumnName = "Features",
|
|
||||||
|
|
||||||
Booster = new DartBooster.Options()
|
|
||||||
{
|
|
||||||
MaximumTreeDepth = 12
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var pipeline = mlContext.Transforms
|
|
||||||
.Concatenate("Features", "Ca", "Mg", "K", "S", "N", "Lime", "C", "P", "Moisture")
|
|
||||||
.Append(mLContext.Transforms.NormalizeMinMax("Features"))
|
|
||||||
.Append(mlContext.Transforms.Conversion.MapValueToKey("ClassF", "Class"), TransformerScope.TrainTest)
|
|
||||||
.AppendCacheCheckpoint(mLContext)
|
|
||||||
.Append(mLContext.MulticlassClassification.Trainers.LightGbm(options))
|
|
||||||
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel", "PredictedLabel"));
|
|
||||||
|
|
||||||
Evaluate(mlContext, trainingDataView, pipeline, 8, reportPath, "ClassF");
|
|
||||||
ITransformer MLModel = pipeline.Fit(trainingDataView);
|
|
||||||
|
|
||||||
return MLModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ITransformer TrainModel(MLContext mlContext, IDataView trainingDataView, IEstimator<ITransformer> trainingPipeline)
|
|
||||||
{
|
|
||||||
ITransformer model = trainingPipeline.Fit(trainingDataView);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate and save results to a text file
|
|
||||||
public static void Evaluate(MLContext mlContext, IDataView trainingDataView, IEstimator<ITransformer> trainingPipeline, int folds, string reportPath, string labelColumnName)
|
|
||||||
{
|
|
||||||
var crossVal = mlContext.MulticlassClassification.CrossValidate(trainingDataView, trainingPipeline, numberOfFolds: folds, labelColumnName: labelColumnName);
|
|
||||||
|
|
||||||
var metricsInMultipleFolds = crossVal.Select(r => r.Metrics);
|
|
||||||
|
|
||||||
var MicroAccuracyValues = metricsInMultipleFolds.Select(m => m.MicroAccuracy);
|
|
||||||
var LogLossValues = metricsInMultipleFolds.Select(m => m.LogLoss);
|
|
||||||
var LogLossReductionValues = metricsInMultipleFolds.Select(m => m.LogLossReduction);
|
|
||||||
string MicroAccuracyAverage = MicroAccuracyValues.Average().ToString("0.######");
|
|
||||||
string LogLossAvg = LogLossValues.Average().ToString("0.######");
|
|
||||||
string LogLossReductionAvg = LogLossReductionValues.Average().ToString("0.######");
|
|
||||||
|
|
||||||
var report = File.CreateText(reportPath);
|
|
||||||
report.Write("Micro Accuracy: " + MicroAccuracyAverage +'\n'+ "LogLoss Average: " + LogLossAvg +'\n'+ "LogLoss Reduction: " + LogLossReductionAvg, 0, 0);
|
|
||||||
report.Flush();
|
|
||||||
report.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void SaveModel(MLContext mlContext, ITransformer Model, string modelPath, DataViewSchema modelInputSchema)
|
|
||||||
{
|
|
||||||
mlContext.Model.Save(Model, modelInputSchema, modelPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ITransformer LoadModel(bool isBig)
|
|
||||||
{
|
|
||||||
if (isBig)
|
|
||||||
return mlContext.Model.Load(modelpathBig, out DataViewSchema inputSchema);
|
|
||||||
else
|
|
||||||
return mlContext.Model.Load(modelpath, out DataViewSchema inputSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PredictionEngine<ModelInput, ModelOutput> CreateEngine()
|
|
||||||
{
|
|
||||||
ITransformer mlModel = LoadModel(false);
|
|
||||||
return mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string FindPath()
|
|
||||||
{
|
|
||||||
string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).ToString();
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
path = Directory.GetParent(path).ToString();
|
|
||||||
if (path.EndsWith("\\Game1"))
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
|
|
||||||
namespace Game1.Sources.ML_Joel
|
|
||||||
{
|
|
||||||
class Input
|
|
||||||
{
|
|
||||||
[ColumnName("Season"), LoadColumn(0)]
|
|
||||||
public String Season { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Crop"), LoadColumn(1)]
|
|
||||||
public String Crop { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Rainfall"), LoadColumn(2)]
|
|
||||||
public float Rainfall { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Production"), LoadColumn(3)]
|
|
||||||
public float Production { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
|
|
||||||
namespace Game1.Sources.ML_Joel
|
|
||||||
{
|
|
||||||
class InputArea
|
|
||||||
{
|
|
||||||
[ColumnName("Season"), LoadColumn(0)]
|
|
||||||
public String Season { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Crop"), LoadColumn(1)]
|
|
||||||
public String Crop { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Area"), LoadColumn(2)]
|
|
||||||
public float Area { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Rainfall"), LoadColumn(3)]
|
|
||||||
public float Rainfall { get; set; }
|
|
||||||
|
|
||||||
[ColumnName("Production"), LoadColumn(4)]
|
|
||||||
public float Production { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
|
|
||||||
namespace Game1.Sources.ML_Joel
|
|
||||||
{
|
|
||||||
class Output
|
|
||||||
{
|
|
||||||
//[ColumnName("PredictedLabel")]
|
|
||||||
public float Prediction { get; set; }
|
|
||||||
public float Score { get; set; }
|
|
||||||
|
|
||||||
//[ColumnName("Score")]
|
|
||||||
// public float[] Score { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
|
|
||||||
namespace Game1.Sources.ML_Joel
|
|
||||||
{
|
|
||||||
class OutputArea
|
|
||||||
{
|
|
||||||
public float Prediction { get; set; }
|
|
||||||
public float Score { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Game1.Sources.ML_Joel
|
|
||||||
{
|
|
||||||
static class Engine
|
|
||||||
{
|
|
||||||
private static MLContext mlContext = new MLContext(seed: 1);
|
|
||||||
private static PredictionEngine<Input, Output> PredictionEngine;
|
|
||||||
private static PredictionEngine<InputArea, OutputArea> PredictionEngineArea;
|
|
||||||
private static OutputArea modelOutput;
|
|
||||||
|
|
||||||
|
|
||||||
public static void CreateModel()
|
|
||||||
{
|
|
||||||
Model.CreateModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CreateModelArea()
|
|
||||||
{
|
|
||||||
Model.CreateModelArea();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init()
|
|
||||||
{
|
|
||||||
PredictionEngine = Model.CreateEngine();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initArea()
|
|
||||||
{
|
|
||||||
PredictionEngineArea = Model.CreateEngineArea();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float PredictProductionwithRainfall(SoilProperties soilProperties, DayNightCycle Time)
|
|
||||||
{
|
|
||||||
InputArea modelInput = new InputArea
|
|
||||||
{
|
|
||||||
Season = Time.getTimeOfYear(),
|
|
||||||
Area = soilProperties.Area,
|
|
||||||
Rainfall = soilProperties.prevRainfall,
|
|
||||||
};
|
|
||||||
|
|
||||||
//OutputArea modelOutput = new OutputArea();
|
|
||||||
PredictionEngineArea.Predict(modelInput, ref modelOutput);
|
|
||||||
return modelOutput.Score;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,190 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.ML;
|
|
||||||
using Microsoft.ML.Data;
|
|
||||||
using Microsoft.ML.Trainers.LightGbm;
|
|
||||||
|
|
||||||
namespace Game1.Sources.ML_Joel
|
|
||||||
{
|
|
||||||
class Model
|
|
||||||
{
|
|
||||||
private static MLContext mlContext = new MLContext(seed: 1);
|
|
||||||
|
|
||||||
private static string path_base = FindPath();
|
|
||||||
|
|
||||||
private static string path = System.IO.Path.Combine(path_base, "Content/ML/Rainfall.csv");
|
|
||||||
private static string modelpath = System.IO.Path.Combine(path_base, "Content/ML/MLmodel_Joel");
|
|
||||||
private static string report = System.IO.Path.Combine(path_base, "Content/ML/report_Joel");
|
|
||||||
|
|
||||||
private static string path_area = System.IO.Path.Combine(path_base, "Content/ML/Rainfall_area.csv");
|
|
||||||
private static string modelpath_area = System.IO.Path.Combine(path_base, "Content/ML/MLmodel_Joel_area");
|
|
||||||
private static string report_area = System.IO.Path.Combine(path_base, "Content/ML/report_Joel_area");
|
|
||||||
|
|
||||||
// Loading data, creatin and saving ML model for smaller dataset (100)
|
|
||||||
public static void CreateModel()
|
|
||||||
{
|
|
||||||
|
|
||||||
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<Input>(
|
|
||||||
path: path,
|
|
||||||
hasHeader: true,
|
|
||||||
separatorChar: ',',
|
|
||||||
allowQuoting: true,
|
|
||||||
allowSparse: false);
|
|
||||||
|
|
||||||
var splitData = mlContext.Data.TrainTestSplit(trainingDataView, testFraction: 0.2);
|
|
||||||
trainingDataView = splitData.TrainSet;
|
|
||||||
IDataView testDataView = splitData.TestSet;
|
|
||||||
Input sample = mlContext.Data.CreateEnumerable<Input>(trainingDataView, false).ElementAt(0);
|
|
||||||
ITransformer MLModel = BuildAndTrain(mlContext, trainingDataView, testDataView, sample, report);
|
|
||||||
SaveModel(mlContext, MLModel, modelpath, trainingDataView.Schema);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Building and training ML model
|
|
||||||
public static ITransformer BuildAndTrain(MLContext mLContext, IDataView trainingDataView, IDataView testDataView, Input sample, string reportPath)
|
|
||||||
{
|
|
||||||
|
|
||||||
var options = new LightGbmRegressionTrainer.Options
|
|
||||||
{
|
|
||||||
MaximumBinCountPerFeature = 40,
|
|
||||||
LearningRate = 0.00020,
|
|
||||||
NumberOfIterations = 20000,
|
|
||||||
NumberOfLeaves = 55,
|
|
||||||
LabelColumnName = "Production",
|
|
||||||
FeatureColumnName = "Features",
|
|
||||||
|
|
||||||
Booster = new DartBooster.Options()
|
|
||||||
{
|
|
||||||
MaximumTreeDepth = 10
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var pipeline = mlContext.Transforms
|
|
||||||
.Text.FeaturizeText("SeasonF", "Season")
|
|
||||||
.Append(mlContext.Transforms.Text.FeaturizeText("CropF", "Crop"))
|
|
||||||
.Append(mlContext.Transforms.Concatenate("Features", "SeasonF", "CropF", "Rainfall"))
|
|
||||||
.AppendCacheCheckpoint(mLContext)
|
|
||||||
.Append(mLContext.Regression.Trainers.LightGbm(options));
|
|
||||||
|
|
||||||
ITransformer MLModel = pipeline.Fit(trainingDataView);
|
|
||||||
var testEval = MLModel.Transform(testDataView);
|
|
||||||
|
|
||||||
Evaluate(mlContext, testEval, pipeline, 10, reportPath, "Production");
|
|
||||||
|
|
||||||
return MLModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CreateModelArea()
|
|
||||||
{
|
|
||||||
|
|
||||||
IDataView trainingDataView = mlContext.Data.LoadFromTextFile<InputArea>(
|
|
||||||
path: path_area,
|
|
||||||
hasHeader: true,
|
|
||||||
separatorChar: ',',
|
|
||||||
allowQuoting: true,
|
|
||||||
allowSparse: false);
|
|
||||||
|
|
||||||
var splitData = mlContext.Data.TrainTestSplit(trainingDataView, testFraction: 0.2);
|
|
||||||
trainingDataView = splitData.TrainSet;
|
|
||||||
IDataView testDataView = splitData.TestSet;
|
|
||||||
ITransformer MLModel = BuildAndTrainArea(mlContext, trainingDataView, testDataView, report_area);
|
|
||||||
SaveModel(mlContext, MLModel, modelpath_area, trainingDataView.Schema);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Building and training ML model
|
|
||||||
public static ITransformer BuildAndTrainArea(MLContext mLContext, IDataView trainingDataView, IDataView testDataView, string reportPath)
|
|
||||||
{
|
|
||||||
|
|
||||||
var options = new LightGbmRegressionTrainer.Options
|
|
||||||
{
|
|
||||||
MaximumBinCountPerFeature = 40,
|
|
||||||
LearningRate = 0.00020,
|
|
||||||
NumberOfIterations = 20000,
|
|
||||||
NumberOfLeaves = 55,
|
|
||||||
LabelColumnName = "Production",
|
|
||||||
FeatureColumnName = "Features",
|
|
||||||
|
|
||||||
Booster = new DartBooster.Options()
|
|
||||||
{
|
|
||||||
MaximumTreeDepth = 10
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var pipeline = mlContext.Transforms
|
|
||||||
.Text.FeaturizeText("SeasonF", "Season")
|
|
||||||
.Append(mlContext.Transforms.Text.FeaturizeText("CropF", "Crop"))
|
|
||||||
.Append(mlContext.Transforms.Concatenate("Features", "SeasonF", "CropF", "Area", "Rainfall"))
|
|
||||||
.AppendCacheCheckpoint(mLContext)
|
|
||||||
.Append(mLContext.Regression.Trainers.LightGbm(options));
|
|
||||||
|
|
||||||
ITransformer MLModel = pipeline.Fit(trainingDataView);
|
|
||||||
var testEval = MLModel.Transform(testDataView);
|
|
||||||
|
|
||||||
Evaluate(mlContext, testEval, pipeline, 10, reportPath, "Production");
|
|
||||||
|
|
||||||
return MLModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ITransformer TrainModel(MLContext mlContext, IDataView trainingDataView, IEstimator<ITransformer> trainingPipeline)
|
|
||||||
{
|
|
||||||
ITransformer model = trainingPipeline.Fit(trainingDataView);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate and save results to a text file
|
|
||||||
public static void Evaluate(MLContext mlContext, IDataView trainingDataView, IEstimator<ITransformer> trainingPipeline, int folds, string reportPath, string labelColumnName)
|
|
||||||
{
|
|
||||||
var eval = mlContext.Regression.Evaluate(trainingDataView, labelColumnName: labelColumnName);
|
|
||||||
|
|
||||||
var report = File.CreateText(reportPath);
|
|
||||||
report.Write("Mean Absolute Error: " + eval.MeanAbsoluteError + '\n' + "R Squared: " + eval.RSquared, 0, 0);
|
|
||||||
report.Flush();
|
|
||||||
report.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void SaveModel(MLContext mlContext, ITransformer Model, string modelPath, DataViewSchema modelInputSchema)
|
|
||||||
{
|
|
||||||
mlContext.Model.Save(Model, modelInputSchema, modelPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ITransformer LoadModel()
|
|
||||||
{
|
|
||||||
return mlContext.Model.Load(modelpath, out DataViewSchema inputSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PredictionEngine<Input, Output> CreateEngine()
|
|
||||||
{
|
|
||||||
ITransformer mlModel = LoadModel();
|
|
||||||
return mlContext.Model.CreatePredictionEngine<Input, Output>(mlModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ITransformer LoadModelArea()
|
|
||||||
{
|
|
||||||
return mlContext.Model.Load(modelpath_area, out DataViewSchema inputSchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PredictionEngine<InputArea, OutputArea> CreateEngineArea()
|
|
||||||
{
|
|
||||||
ITransformer mlModel = LoadModelArea();
|
|
||||||
return mlContext.Model.CreatePredictionEngine<InputArea, OutputArea>(mlModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string FindPath()
|
|
||||||
{
|
|
||||||
string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).ToString();
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
path = Directory.GetParent(path).ToString();
|
|
||||||
if (path.EndsWith("\\Game1"))
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,162 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
|
|
||||||
class DayNightCycle
|
|
||||||
{
|
|
||||||
private bool Time = true;
|
|
||||||
private bool Day = true;
|
|
||||||
private int nightTime = 0;
|
|
||||||
private int dayTime = 0;
|
|
||||||
private int lengthOfDay = 20000;
|
|
||||||
private int lengthOfNight = 20000;
|
|
||||||
private int Days = 1;
|
|
||||||
private int DaysOfYear = 0;
|
|
||||||
private int speed = 1;
|
|
||||||
private bool nextDay = true;
|
|
||||||
|
|
||||||
|
|
||||||
public void updateTime(int Speed)
|
|
||||||
{
|
|
||||||
speed = Speed;
|
|
||||||
Time = false;
|
|
||||||
for (int i = 0; i < Speed; i++)
|
|
||||||
{
|
|
||||||
if (Day)
|
|
||||||
{
|
|
||||||
dayTime++;
|
|
||||||
if (dayTime == lengthOfDay)
|
|
||||||
{
|
|
||||||
Time = false;
|
|
||||||
Day = false;
|
|
||||||
dayTime = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nightTime++;
|
|
||||||
if (nightTime == lengthOfNight)
|
|
||||||
{
|
|
||||||
Time = true;
|
|
||||||
Day = true;
|
|
||||||
nightTime = 0;
|
|
||||||
Days++;
|
|
||||||
DaysOfYear++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (DaysOfYear == 48)
|
|
||||||
{
|
|
||||||
DaysOfYear = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Season:
|
|
||||||
//0 - Whole Year
|
|
||||||
//1 - Spring
|
|
||||||
//2 - Summer
|
|
||||||
//3 - Autumn
|
|
||||||
//4 - Winter
|
|
||||||
|
|
||||||
public string getTimeOfYear()
|
|
||||||
{
|
|
||||||
if (DaysOfYear < 12)
|
|
||||||
return "Spring";
|
|
||||||
else if (DaysOfYear < 24)
|
|
||||||
return "Summer";
|
|
||||||
else if (DaysOfYear < 36)
|
|
||||||
return "Autumn";
|
|
||||||
else
|
|
||||||
return "Winter";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color GetTimeOfDay()
|
|
||||||
{
|
|
||||||
int blue, red, brightness, green, potatorate = 255;
|
|
||||||
if (nightTime == 0 && dayTime == 0)
|
|
||||||
{
|
|
||||||
red = 1;
|
|
||||||
blue = 1;
|
|
||||||
green = 1;
|
|
||||||
brightness = 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((float)dayTime / lengthOfDay < 0.5)
|
|
||||||
{
|
|
||||||
blue = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)((1.0f - (float)dayTime / lengthOfDay) * potatorate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
blue = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((float)nightTime / lengthOfNight < 0.5)
|
|
||||||
{
|
|
||||||
red = (int)((1.0 - (float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
red = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((float)nightTime / lengthOfNight < 0.5)
|
|
||||||
{
|
|
||||||
green = (int)((1.0 - (float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
green = (int)(((float)nightTime / lengthOfNight) * potatorate) + (int)(((float)dayTime / lengthOfDay) * potatorate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Time)
|
|
||||||
{
|
|
||||||
brightness = 255;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((float)nightTime / lengthOfNight < 0.5)
|
|
||||||
{
|
|
||||||
brightness = (int)((1.0 - (float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
brightness = (int)(((float)nightTime / lengthOfNight) * 255) + (int)(((float)dayTime / lengthOfDay) * 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Color.FromNonPremultiplied(red, green, blue, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool nDay()
|
|
||||||
{
|
|
||||||
if (Time)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetTimeOfDayInt()
|
|
||||||
{
|
|
||||||
if (Day)
|
|
||||||
{
|
|
||||||
return (int)(100 * ((float)(dayTime + nightTime) / (lengthOfDay + lengthOfNight))) + 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return (int)(100 * ((float)(lengthOfDay + nightTime) / (lengthOfDay + lengthOfNight))) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDays()
|
|
||||||
{
|
|
||||||
return Days;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
|
|
||||||
class Fertilizer
|
|
||||||
{
|
|
||||||
public int ID { get; set; }
|
|
||||||
public string Name { get; set; }
|
|
||||||
public float Nitrogen { get; set; }
|
|
||||||
public float Phosphorus { get; set; }
|
|
||||||
public float Potassium { get; set; }
|
|
||||||
}
|
|
@ -1,181 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
|
|
||||||
class FertilizerHolder
|
|
||||||
{
|
|
||||||
private Fertilizer[] FertilizerType = new Fertilizer[8];
|
|
||||||
|
|
||||||
public void init()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
FertilizerType[0] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 999,
|
|
||||||
Name = "None",
|
|
||||||
Nitrogen = 0.0f / 2,
|
|
||||||
Phosphorus = 0 * 0.436f / 2,
|
|
||||||
Potassium = 0 * 0.83f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[1] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 0,
|
|
||||||
Name = "10-26-26",
|
|
||||||
Nitrogen = 10.0f / 2,
|
|
||||||
Phosphorus = 26 * 0.436f / 2,
|
|
||||||
Potassium = 26 * 0.83f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[2] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 1,
|
|
||||||
Name = "14-35-14",
|
|
||||||
Nitrogen = 14.0f / 2,
|
|
||||||
Phosphorus = 35 * 0.436f / 2,
|
|
||||||
Potassium = 14 * 0.83f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[3] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 2,
|
|
||||||
Name = "17-17-17",
|
|
||||||
Nitrogen = 17.0f / 2,
|
|
||||||
Phosphorus = 17 * 0.436f / 2,
|
|
||||||
Potassium = 17 * 0.83f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[4] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 3,
|
|
||||||
Name = "20-20",
|
|
||||||
Nitrogen = 20.0f / 2,
|
|
||||||
Phosphorus = 20 * 0.436f / 2,
|
|
||||||
Potassium = 0 * 0.83f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[5] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 4,
|
|
||||||
Name = "28-28",
|
|
||||||
Nitrogen = 28.0f / 2,
|
|
||||||
Phosphorus = 28 * 0.436f / 2,
|
|
||||||
Potassium = 0 * 0.83f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[6] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 5,
|
|
||||||
Name = "DAP",
|
|
||||||
Nitrogen = 18.0f / 2,
|
|
||||||
Phosphorus = 46 * 0.436f / 2,
|
|
||||||
Potassium = 0 * 0.83f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[7] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 6,
|
|
||||||
Name = "Urea",
|
|
||||||
Nitrogen = 46.0f / 2,
|
|
||||||
Phosphorus = 0 * 0.436f / 2,
|
|
||||||
Potassium = 0 * 0.83f / 2
|
|
||||||
};
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
FertilizerType[0] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 999,
|
|
||||||
Name = "None",
|
|
||||||
Nitrogen = 0.0f / 2,
|
|
||||||
Phosphorus = 0 * 0.436f / 2,
|
|
||||||
Potassium = 0 * 0.83f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[1] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 0,
|
|
||||||
Name = "10-26-26",
|
|
||||||
Nitrogen = 17.21f / 2,
|
|
||||||
Phosphorus = 12.14f / 2,
|
|
||||||
Potassium = 0.64f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[2] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 1,
|
|
||||||
Name = "14-35-14",
|
|
||||||
Nitrogen = 16.89f / 2,
|
|
||||||
Phosphorus = 6.21f / 2,
|
|
||||||
Potassium = 5.21f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[3] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 2,
|
|
||||||
Name = "17-17-17",
|
|
||||||
Nitrogen = 14.92f / 2,
|
|
||||||
Phosphorus = 14.42f / 2,
|
|
||||||
Potassium = 3.0f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[4] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 3,
|
|
||||||
Name = "20-20",
|
|
||||||
Nitrogen = 15.39f / 2,
|
|
||||||
Phosphorus = 15.21f / 2,
|
|
||||||
Potassium = 9.5f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[5] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 4,
|
|
||||||
Name = "28-28",
|
|
||||||
Nitrogen = 9.67f / 2,
|
|
||||||
Phosphorus = 10.47f / 2,
|
|
||||||
Potassium = 9.5f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[6] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 5,
|
|
||||||
Name = "DAP",
|
|
||||||
Nitrogen = 14.52f / 2,
|
|
||||||
Phosphorus = 1.77f / 2,
|
|
||||||
Potassium = 9.5f / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
FertilizerType[7] = new Fertilizer
|
|
||||||
{
|
|
||||||
ID = 6,
|
|
||||||
Name = "Urea",
|
|
||||||
Nitrogen = 1.81f / 2,
|
|
||||||
Phosphorus = 21.0f / 2,
|
|
||||||
Potassium = 9.5f / 2
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int GetFertilizerID(string name)
|
|
||||||
{
|
|
||||||
foreach (Fertilizer fertilizer in FertilizerType)
|
|
||||||
{
|
|
||||||
if (fertilizer.Name == name)
|
|
||||||
return fertilizer.ID;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Fertilizer GetFertilizer(string name)
|
|
||||||
{
|
|
||||||
foreach (Fertilizer fertilizer in FertilizerType)
|
|
||||||
{
|
|
||||||
if (fertilizer.Name == name)
|
|
||||||
return fertilizer;
|
|
||||||
}
|
|
||||||
return FertilizerType[0];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,136 +0,0 @@
|
|||||||
using Microsoft.Xna.Framework;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
class HandleRotation
|
|
||||||
{
|
|
||||||
int rotationSpeed = 5, Rotation = 180;
|
|
||||||
private float oldSpeed, movementSpeed;
|
|
||||||
private Vector2 oldTile, oldPosition, oldMovementSpeed;
|
|
||||||
private Vector2 Direction;
|
|
||||||
|
|
||||||
public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position, Crops crops, Vector2 oldDeltaPosition, Vector2 Target)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (oldSpeed != crops.getSpeedFactor(tractorSpeed))
|
|
||||||
{
|
|
||||||
Position = new Vector2((int)Math.Round(Position.X), (int)Math.Round(Position.Y));
|
|
||||||
}
|
|
||||||
if (Destination == 0) // down
|
|
||||||
{
|
|
||||||
if (Rotation == 0)
|
|
||||||
{
|
|
||||||
Direction = new Vector2(0, 1) * movementSpeed;
|
|
||||||
Position = Position + Direction;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Rotation > 180)
|
|
||||||
{
|
|
||||||
if (Rotation >= 360)
|
|
||||||
{
|
|
||||||
Rotation = 0;
|
|
||||||
}
|
|
||||||
Rotation = Rotation + rotationSpeed;
|
|
||||||
}
|
|
||||||
else if (Rotation <= 180 && Rotation > 0)
|
|
||||||
{
|
|
||||||
Rotation = Rotation - rotationSpeed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Destination == 1) // up
|
|
||||||
{
|
|
||||||
if (Rotation == 180)
|
|
||||||
{
|
|
||||||
Direction = new Vector2(0, -1) * movementSpeed;
|
|
||||||
Position = Position + Direction;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Rotation >= 0 && Rotation < 180)
|
|
||||||
{
|
|
||||||
Rotation = Rotation + rotationSpeed;
|
|
||||||
}
|
|
||||||
else if (Rotation < 360 && Rotation > 180)
|
|
||||||
{
|
|
||||||
Rotation = Rotation - rotationSpeed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (Destination == 2) // right
|
|
||||||
{
|
|
||||||
if (Rotation == 270)
|
|
||||||
{
|
|
||||||
Direction = new Vector2(1, 0) * movementSpeed;
|
|
||||||
Position = Position + Direction;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Rotation > 90 && Rotation < 270)
|
|
||||||
{
|
|
||||||
Rotation = Rotation + rotationSpeed;
|
|
||||||
}
|
|
||||||
else if (Rotation < 90 || Rotation < 360)
|
|
||||||
{
|
|
||||||
if (Rotation <= 0)
|
|
||||||
{
|
|
||||||
Rotation = 360;
|
|
||||||
}
|
|
||||||
Rotation = Rotation - rotationSpeed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Destination == 3) // left
|
|
||||||
{
|
|
||||||
if (Rotation == 90)
|
|
||||||
{
|
|
||||||
Direction = new Vector2(-1, 0) * movementSpeed;
|
|
||||||
Position = Position + Direction;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Rotation < 270 && Rotation > 90)
|
|
||||||
{
|
|
||||||
Rotation = Rotation - rotationSpeed;
|
|
||||||
}
|
|
||||||
else if (Rotation >= 0 || Rotation > 270)
|
|
||||||
{
|
|
||||||
if (Rotation >= 360)
|
|
||||||
{
|
|
||||||
Rotation = 0;
|
|
||||||
}
|
|
||||||
Rotation = Rotation + rotationSpeed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
oldSpeed = crops.getSpeedFactor(tractorSpeed);
|
|
||||||
if (oldDeltaPosition.X < 1 && oldDeltaPosition.X > -1 && oldDeltaPosition.Y < 1 && oldDeltaPosition.Y > -1)
|
|
||||||
{
|
|
||||||
Position = Target;
|
|
||||||
}
|
|
||||||
oldMovementSpeed = Direction;
|
|
||||||
return Position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRotation()
|
|
||||||
{
|
|
||||||
return Rotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool checkTile(Vector2 Position, int tileSize, int Spacing, float tractorSpeed, Crops crop)
|
|
||||||
{
|
|
||||||
Vector2 newTile = new Vector2((float)Math.Round(Position.X / (tileSize + Spacing)), (float)Math.Round(Position.Y / (tileSize + Spacing)));
|
|
||||||
if (oldTile != newTile)
|
|
||||||
{
|
|
||||||
oldTile = newTile;
|
|
||||||
movementSpeed = crop.getSpeedFactor(tractorSpeed);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,7 +19,7 @@ class House
|
|||||||
int y = r.Next(0, 8);
|
int y = r.Next(0, 8);
|
||||||
|
|
||||||
pos = new Vector2(x, y);
|
pos = new Vector2(x, y);
|
||||||
housePos = new Rectangle(x * (tileSize + Spacing), y * (tileSize + Spacing), tileSize, tileSize);
|
housePos = new Rectangle((x * tileSize + Spacing), y * (tileSize + Spacing), tileSize, tileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -37,18 +37,12 @@ class House
|
|||||||
housePos = new Rectangle((int)pos.X * (tileSize + Spacing), (int)pos.Y * (tileSize + Spacing), tileSize, tileSize);
|
housePos = new Rectangle((int)pos.X * (tileSize + Spacing), (int)pos.Y * (tileSize + Spacing), tileSize, tileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Returns house Rectangle
|
|
||||||
public Rectangle GetRectangle()
|
public Rectangle GetRectangle()
|
||||||
{
|
{
|
||||||
return housePos;
|
return housePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRectangle(int x, int y, int tileSize, int Spacing)
|
|
||||||
{
|
|
||||||
pos = new Vector2(x, y);
|
|
||||||
housePos = new Rectangle(x * (tileSize + Spacing), y * (tileSize + Spacing), tileSize, tileSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2 getVector()
|
public Vector2 getVector()
|
||||||
{
|
{
|
||||||
return new Vector2(housePos.X, housePos.Y);
|
return new Vector2(housePos.X, housePos.Y);
|
||||||
|
@ -1,117 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
|
|
||||||
class Cargo
|
|
||||||
{
|
|
||||||
private Items[,] items = new Items[2, 281];
|
|
||||||
private int[] Count = new int[2];
|
|
||||||
|
|
||||||
|
|
||||||
// Creation of the house stock
|
|
||||||
public void initStorageItems()
|
|
||||||
{
|
|
||||||
// Name, Weight, Index
|
|
||||||
// Fertilizer Storage
|
|
||||||
items[0, 0] = new Items("10-26-26", 1, 0);
|
|
||||||
items[0, 1] = new Items("14-35-14", 1, 1);
|
|
||||||
items[0, 2] = new Items("17-17-17", 1, 2);
|
|
||||||
items[0, 3] = new Items("20-20", 1, 3);
|
|
||||||
items[0, 4] = new Items("28-28", 1, 4);
|
|
||||||
items[0, 5] = new Items("DAP", 1, 5);
|
|
||||||
items[0, 6] = new Items("Urea", 1, 6);
|
|
||||||
|
|
||||||
//Crop Seed Storage
|
|
||||||
items[1, 0] = new Items("Barley", 2, 0);
|
|
||||||
items[1, 1] = new Items("Cotton", 1, 1);
|
|
||||||
items[1, 2] = new Items("Ground Nuts", 5, 2);
|
|
||||||
items[1, 3] = new Items("Maize", 3, 3);
|
|
||||||
items[1, 4] = new Items("Millets", 4, 4);
|
|
||||||
items[1, 5] = new Items("Oil Seeds", 4, 5);
|
|
||||||
items[1, 6] = new Items("Paddy", 5, 6);
|
|
||||||
items[1, 7] = new Items("Pulses", 5, 7);
|
|
||||||
items[1, 8] = new Items("Sugarcane", 3, 8);
|
|
||||||
items[1, 9] = new Items("Tobacco", 2, 9);
|
|
||||||
items[1, 10] = new Items("Wheat", 2, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addItem(Items item, int Type)
|
|
||||||
{
|
|
||||||
items[Type, Count[Type]] = item;
|
|
||||||
Count[Type]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Items getItemByIndex(int i, int Type)
|
|
||||||
{
|
|
||||||
return items[Type, i];
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool itemExists(int Index, int type)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (Count[type] == 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (items[type, i].getIndex() == Index)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
} while (items[type, i] != null && Count[type] > i);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeItem(int Index, int type)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
if (itemExists(Index, type))
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (items[type, i].getIndex() == Index)
|
|
||||||
{
|
|
||||||
sortBackInPlace(i, type);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
} while (items[type, i] != null && Count[type] > i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sortBackInPlace(int i, int type)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
items[type, i] = items[type, i + 1];
|
|
||||||
i++;
|
|
||||||
} while (items[type, i] != null && Count[type] > i);
|
|
||||||
items[type, i] = null;
|
|
||||||
Count[type]--;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCount(int Index, int Type)
|
|
||||||
{
|
|
||||||
int Count = 0;
|
|
||||||
int i = 0;
|
|
||||||
if (items[Type, 0] != null)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (items[Type, i].getIndex() == Index)
|
|
||||||
{
|
|
||||||
Count++;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
} while (items[Type, i] != null);
|
|
||||||
}
|
|
||||||
return Count;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,223 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
using Microsoft.Xna.Framework.Input;
|
|
||||||
|
|
||||||
|
|
||||||
class Inventory
|
|
||||||
{
|
|
||||||
private int Weight = 0;
|
|
||||||
private int maxWeight = 280;
|
|
||||||
private int[] totalHarvested = new int[11];
|
|
||||||
private int[] totalFertilizerUsed = new int[8];
|
|
||||||
private Cargo cargo = new Cargo();
|
|
||||||
private Cargo itemStorage = new Cargo();
|
|
||||||
private int Refills = 0;
|
|
||||||
|
|
||||||
// Item list by index:
|
|
||||||
// ---------------------------------------
|
|
||||||
// (0) Fertilizers
|
|
||||||
// 1: 10-26-26
|
|
||||||
// 2: 14-35-14
|
|
||||||
// 3: 17-17-17
|
|
||||||
// 4: 20-20
|
|
||||||
// 5: 28-28
|
|
||||||
// 6: DAP
|
|
||||||
// 7: Urea
|
|
||||||
// (1) Crops:
|
|
||||||
// 1: Barley
|
|
||||||
// 2: Cotton
|
|
||||||
// 3: Ground Nuts
|
|
||||||
// 4: Maize
|
|
||||||
// 5: Millets
|
|
||||||
// 6: Oil Seeds
|
|
||||||
// 7: Paddy
|
|
||||||
// 8: Pulses
|
|
||||||
// 9: Sugarcane
|
|
||||||
// 10: Tobacco
|
|
||||||
// 11: Wheat
|
|
||||||
//
|
|
||||||
// Number - 1 to get the index in the array
|
|
||||||
|
|
||||||
|
|
||||||
// Adds all the items to the houses inventory for pickup at the houses position
|
|
||||||
public void initInventorySystem()
|
|
||||||
{
|
|
||||||
itemStorage.initStorageItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWeight()
|
|
||||||
{
|
|
||||||
return Weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Adds item to the tractor.
|
|
||||||
// 0 = Fertilizer
|
|
||||||
// 1 = Crops
|
|
||||||
public bool addItem(int newItemIndex, int Type)
|
|
||||||
{
|
|
||||||
Items newItem;
|
|
||||||
if (Type == 1)
|
|
||||||
{
|
|
||||||
totalHarvested[newItemIndex]++;
|
|
||||||
}
|
|
||||||
newItem = itemStorage.getItemByIndex(newItemIndex, Type);
|
|
||||||
if (maxWeight >= Weight + newItem.getWeight())
|
|
||||||
{
|
|
||||||
cargo.addItem(newItem, Type);
|
|
||||||
Weight = Weight + newItem.getWeight();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Uses an item from the tractor.
|
|
||||||
// 0 = Fertilizer
|
|
||||||
// 1 = Crops
|
|
||||||
public bool useItem(int Index, int Type, bool isClearing)
|
|
||||||
{
|
|
||||||
if (cargo.itemExists(Index, Type))
|
|
||||||
{
|
|
||||||
if (Type == 0 && !isClearing)
|
|
||||||
{
|
|
||||||
totalFertilizerUsed[Index]++;
|
|
||||||
}
|
|
||||||
removeItem(Index, Type);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxWeight()
|
|
||||||
{
|
|
||||||
return maxWeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks whether or not the tractor has the item in its inventory.
|
|
||||||
// 0 = Fertilizer
|
|
||||||
// 1 = Crops
|
|
||||||
public bool itemExists(int Index, int Type)
|
|
||||||
{
|
|
||||||
return cargo.itemExists(Index, Type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeItem(int Index, int Type)
|
|
||||||
{
|
|
||||||
|
|
||||||
Weight = Weight - itemStorage.getItemByIndex(Index, Type).getWeight();
|
|
||||||
cargo.removeItem(Index, Type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cargo getPredefinedItems()
|
|
||||||
{
|
|
||||||
return itemStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearInventory()
|
|
||||||
{
|
|
||||||
for (int i = 0; i <= 6; i++)
|
|
||||||
while (useItem(i, 0, true)) ;
|
|
||||||
|
|
||||||
for (int i = 0; i <= 10; i++)
|
|
||||||
while (useItem(i, 1, true)) ;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fillWithFertilizer()
|
|
||||||
{
|
|
||||||
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 (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()
|
|
||||||
{
|
|
||||||
for (int i = 0; i <= 6; i++)
|
|
||||||
{
|
|
||||||
if (!itemExists(i, 0))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void printItems(Input input, SpriteBatch spriteBatch, SpriteFont Bold)
|
|
||||||
{
|
|
||||||
|
|
||||||
spriteBatch.DrawString(Bold, "Crops: ", new Vector2(470, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, "Harvested:", new Vector2(600, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
|
|
||||||
for (int i = 0; i < 11; i++) //Print Crops
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, cargo.getCount(i, 1) + " " + itemStorage.getItemByIndex(i, 1).getItemType(), new Vector2(470, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, totalHarvested[i].ToString(), new Vector2(620, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.Teal);
|
|
||||||
}
|
|
||||||
|
|
||||||
spriteBatch.DrawString(Bold, "Fertilizers: ", new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
|
|
||||||
spriteBatch.DrawString(Bold, "Used ", new Vector2(830, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
|
|
||||||
for (int i = 0; i < 7; i++) //Print Fertilizers
|
|
||||||
{
|
|
||||||
spriteBatch.DrawString(Bold, cargo.getCount(i, 0) + " " + itemStorage.getItemByIndex(i, 0).getItemType(), new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.Teal);
|
|
||||||
spriteBatch.DrawString(Bold, totalFertilizerUsed[i].ToString(), new Vector2(835, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.Teal);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
|
|
||||||
class Items
|
|
||||||
{
|
|
||||||
private String itemType;
|
|
||||||
private int Weight;
|
|
||||||
private int Index;
|
|
||||||
|
|
||||||
|
|
||||||
public Items(String newItemType, int newWeight, int newIndex)
|
|
||||||
{
|
|
||||||
itemType = newItemType;
|
|
||||||
Weight = newWeight;
|
|
||||||
Index = newIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItem(Items newItem)
|
|
||||||
{
|
|
||||||
itemType = newItem.itemType;
|
|
||||||
Weight = newItem.Weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getItemType()
|
|
||||||
{
|
|
||||||
return itemType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWeight()
|
|
||||||
{
|
|
||||||
return Weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIndex()
|
|
||||||
{
|
|
||||||
return Index;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +1,51 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
|
||||||
class Tractor
|
class Tractor
|
||||||
{
|
{
|
||||||
private int Spacing, sizeTile, Speed = 1;
|
|
||||||
|
|
||||||
|
|
||||||
|
private int Spacing, sizeTile, Speed = 1, Rotation = 180, rotationSpeed = 5;
|
||||||
private float tractorSpeed = 1;
|
private float tractorSpeed = 1;
|
||||||
private Vector2 Position, TargetPosition, Size, housePos, DeltaPosition;
|
private String currentTask;
|
||||||
|
|
||||||
|
private Vector2 Position, TargetPosition, Direction, Size, housePos;
|
||||||
|
|
||||||
private Path path = new Path();
|
private Path path = new Path();
|
||||||
|
private Random r = new Random();
|
||||||
|
private Farm farm = new Farm();
|
||||||
|
|
||||||
private SmartTractor smartTractor = new SmartTractor();
|
private SmartTractor smartTractor = new SmartTractor();
|
||||||
private HandleRotation handleRotation = new HandleRotation();
|
private ScoreSystem scoreSystem = new ScoreSystem();
|
||||||
private int j;
|
|
||||||
|
|
||||||
|
|
||||||
|
public void updateSizing(Input input, int Status, Vector2 newHousePos)
|
||||||
public void updateSizing(Input input, int Status, Vector2 newHousePos, DayNightCycle Time)
|
|
||||||
{
|
{
|
||||||
Spacing = input.getSpacing();
|
Spacing = input.getSpacing();
|
||||||
sizeTile = input.getTileSize();
|
sizeTile = input.getTileSize();
|
||||||
Size = input.getSize();
|
Size = input.getSize();
|
||||||
updatePosition(input.getSize(), Status);
|
updatePosition(input.getSize(), Status);
|
||||||
housePos = newHousePos;
|
housePos = newHousePos;
|
||||||
smartTractor.UpdateCrops(Speed, Time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void init(Rectangle house, Input input)
|
public void init(Rectangle house, Input input)
|
||||||
{
|
{
|
||||||
sizeTile = input.getTileSize();
|
sizeTile = input.getTileSize();
|
||||||
Spacing = input.getSpacing();
|
Spacing = input.getSpacing();
|
||||||
|
farm.init(new Vector2(100, (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / sizeTile) - 125 / sizeTile));
|
||||||
Position = housePos;
|
Position = housePos;
|
||||||
TargetPosition = new Vector2(house.X, house.Y);
|
TargetPosition = new Vector2(house.X, house.Y);
|
||||||
smartTractor.init(new Vector2(house.X, house.Y));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs when the tractor reaches a tile
|
// Runs when the tractor reaches a tile
|
||||||
private void updateDirection(Vector2 Size, Vector2 newPosition)
|
private void updateDirection(Vector2 Size, Vector2 newPosition)
|
||||||
{
|
{
|
||||||
DeltaPosition = TargetPosition - Position;
|
Vector2 DeltaPosition = TargetPosition - Position;
|
||||||
handleRotation.checkTile(Position, sizeTile, Spacing, tractorSpeed, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))));
|
|
||||||
|
|
||||||
if (DeltaPosition.X == 0)
|
if (DeltaPosition.X == 0)
|
||||||
{
|
{
|
||||||
@ -47,66 +55,62 @@ class Tractor
|
|||||||
}
|
}
|
||||||
else if (DeltaPosition.Y > 0)
|
else if (DeltaPosition.Y > 0)
|
||||||
{
|
{
|
||||||
Position = handleRotation.UpdatePosition(0, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))), DeltaPosition, TargetPosition);
|
updateRotation(0);
|
||||||
}
|
}
|
||||||
else if (DeltaPosition.Y < 0)
|
else if (DeltaPosition.Y < 0)
|
||||||
{
|
{
|
||||||
Position = handleRotation.UpdatePosition(1, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))), DeltaPosition, TargetPosition);
|
updateRotation(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (DeltaPosition.X > 0)
|
else if (DeltaPosition.X > 0)
|
||||||
{
|
{
|
||||||
Position = handleRotation.UpdatePosition(2, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))), DeltaPosition, TargetPosition);
|
updateRotation(2);
|
||||||
}
|
}
|
||||||
else if (DeltaPosition.X < 0)
|
else if (DeltaPosition.X < 0)
|
||||||
{
|
{
|
||||||
Position = handleRotation.UpdatePosition(3, tractorSpeed, Position, smartTractor.getFarm().getCrop((int)Math.Round(Position.X / (sizeTile + Spacing)), (int)Math.Round(Position.Y / (sizeTile + Spacing))), DeltaPosition, TargetPosition);
|
updateRotation(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Moves the tractor
|
||||||
public void updatePosition(Vector2 Size, int Status) // updates the position
|
public void updatePosition(Vector2 Size, int Status) /// updates the position
|
||||||
{
|
{
|
||||||
|
|
||||||
//farm.updateSize(Size, sizeTile, Spacing);
|
farm.updateSize(Size, sizeTile, Spacing);
|
||||||
for (int i = 0; i < Speed; i++)
|
for (int i = 0; i < Speed; i++) //Where all the choices the tractor does comes from
|
||||||
{
|
{
|
||||||
|
smartTractor.updateMap(Position, housePos, farm.getCrops(), Size, sizeTile, Spacing, scoreSystem.getScore(), Rotation);
|
||||||
|
|
||||||
updateDirection(Size, Position);
|
updateDirection(Size, Position);
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (!smartTractor.getWaitTwoFrames())
|
|
||||||
{
|
|
||||||
updateDirection(Size, Position);
|
|
||||||
j = WaitFrame;
|
|
||||||
}
|
|
||||||
else if (j != 0)
|
|
||||||
{
|
|
||||||
j--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
smartTractor.setWaitTwoFrames(false);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculateNewPath(Vector2 newPosition)
|
public void calculateNewPath(Vector2 newPosition)
|
||||||
{
|
{
|
||||||
if (path.getCount() == 0)
|
if (path.getCount() == 0)
|
||||||
{
|
{
|
||||||
if (Position.X / (sizeTile + Spacing) > Size.X)
|
if (housePos != Position)
|
||||||
{
|
{
|
||||||
Position.X = (Size.X - 1) * (sizeTile + Spacing);
|
//Returns to the farm
|
||||||
|
int x = (int)Position.X / (sizeTile + Spacing);
|
||||||
|
int y = (int)Position.Y / (sizeTile + Spacing);
|
||||||
|
currentTask = scoreSystem.MessageAndScore(farm.getCrop(x, y).Status, 0);
|
||||||
|
farm.setCropStatus(x, y, Spacing);
|
||||||
|
path = smartTractor.returnChoice(0);
|
||||||
}
|
}
|
||||||
else if (Position.Y / (sizeTile + Spacing) > Size.Y)
|
else
|
||||||
{
|
{
|
||||||
Position.Y = (Size.Y - 1) * (sizeTile + Spacing);
|
//Sets a random Target
|
||||||
|
int xTarget = (int)TargetPosition.X / (sizeTile + Spacing);
|
||||||
|
int yTarget = (int)TargetPosition.Y / (sizeTile + Spacing);
|
||||||
|
currentTask = scoreSystem.MessageAndScore(farm.getCrop(xTarget, yTarget).Status, 1);
|
||||||
|
path = smartTractor.returnChoice(1);
|
||||||
}
|
}
|
||||||
smartTractor.updateMap(Position, housePos, Size, sizeTile, Spacing, handleRotation.getRotation());
|
|
||||||
path = smartTractor.returnChoice();
|
|
||||||
TargetPosition = path.Reduce().getCords() * (sizeTile + Spacing);
|
TargetPosition = path.Reduce().getCords() * (sizeTile + Spacing);
|
||||||
updateDirection(Size, newPosition);
|
updateDirection(Size, newPosition);
|
||||||
}
|
}
|
||||||
@ -117,6 +121,141 @@ class Tractor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateRotation(int Destination)
|
||||||
|
{
|
||||||
|
if (Destination == 0)
|
||||||
|
{
|
||||||
|
if (Rotation == 0)
|
||||||
|
{
|
||||||
|
Direction = new Vector2(0, 1) * tractorSpeed;
|
||||||
|
Position = Position + Direction;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Rotation == 0)
|
||||||
|
{
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
|
else if (Rotation > 180)
|
||||||
|
{
|
||||||
|
if (Rotation >= 360)
|
||||||
|
{
|
||||||
|
Rotation = 0;
|
||||||
|
}
|
||||||
|
Rotation = Rotation + rotationSpeed;
|
||||||
|
}
|
||||||
|
else if (Rotation <= 180 && Rotation > 0)
|
||||||
|
{
|
||||||
|
Rotation = Rotation - rotationSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Destination == 1)
|
||||||
|
{
|
||||||
|
if (Rotation == 180)
|
||||||
|
{
|
||||||
|
Direction = new Vector2(0, -1) * tractorSpeed;
|
||||||
|
Position = Position + Direction;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Rotation == 180)
|
||||||
|
{
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
|
else if (Rotation >= 0 && Rotation < 180)
|
||||||
|
{
|
||||||
|
Rotation = Rotation + rotationSpeed;
|
||||||
|
}
|
||||||
|
else if (Rotation < 360 && Rotation > 180)
|
||||||
|
{
|
||||||
|
Rotation = Rotation - rotationSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (Destination == 2)
|
||||||
|
{
|
||||||
|
if (Rotation == 270)
|
||||||
|
{
|
||||||
|
Direction = new Vector2(1, 0) * tractorSpeed;
|
||||||
|
Position = Position + Direction;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Rotation == 270)
|
||||||
|
{
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
|
else if (Rotation > 90 && Rotation < 270)
|
||||||
|
{
|
||||||
|
Rotation = Rotation + rotationSpeed;
|
||||||
|
}
|
||||||
|
else if (Rotation < 90 || Rotation < 360)
|
||||||
|
{
|
||||||
|
if (Rotation <= 0)
|
||||||
|
{
|
||||||
|
Rotation = 360;
|
||||||
|
}
|
||||||
|
Rotation = Rotation - rotationSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Destination == 3)
|
||||||
|
{
|
||||||
|
if (Rotation == 90)
|
||||||
|
{
|
||||||
|
Direction = new Vector2(-1, 0) * tractorSpeed;
|
||||||
|
Position = Position + Direction;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Rotation == 90)
|
||||||
|
{
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
|
else if ( Rotation < 270 && Rotation > 90)
|
||||||
|
{
|
||||||
|
Rotation = Rotation - rotationSpeed;
|
||||||
|
}
|
||||||
|
else if (Rotation >= 0 || Rotation > 270)
|
||||||
|
{
|
||||||
|
if (Rotation >= 360)
|
||||||
|
{
|
||||||
|
Rotation = 0;
|
||||||
|
}
|
||||||
|
Rotation = Rotation + rotationSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRotation()
|
||||||
|
{
|
||||||
|
return MathHelper.ToRadians(Rotation);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector2 getPos()
|
||||||
|
{
|
||||||
|
return Position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void increaseSpeed()
|
||||||
|
{
|
||||||
|
Speed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decreaseSpeed()
|
||||||
|
{
|
||||||
|
if (Speed > 0)
|
||||||
|
{
|
||||||
|
Speed--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void setSpeed(int newSpeed)
|
public void setSpeed(int newSpeed)
|
||||||
{
|
{
|
||||||
Speed = newSpeed;
|
Speed = newSpeed;
|
||||||
@ -128,32 +267,6 @@ class Tractor
|
|||||||
Position = corrector.getPosition();
|
Position = corrector.getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setPos(Vector2 newPos)
|
|
||||||
{
|
|
||||||
Position = newPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNewHousePos(Vector2 pos, bool newState)
|
|
||||||
{
|
|
||||||
smartTractor.setNewHousePos(pos, newState);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getRotation()
|
|
||||||
{
|
|
||||||
return MathHelper.ToRadians(handleRotation.getRotation());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Farm getFarm()
|
|
||||||
{
|
|
||||||
return smartTractor.getFarm();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector2 getPos()
|
|
||||||
{
|
|
||||||
return Position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSpeed()
|
public int getSpeed()
|
||||||
{
|
{
|
||||||
return Speed;
|
return Speed;
|
||||||
@ -164,23 +277,33 @@ class Tractor
|
|||||||
return tractorSpeed;
|
return tractorSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPos(Vector2 newPos)
|
||||||
|
{
|
||||||
|
Position = newPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Farm getFarm()
|
||||||
|
{
|
||||||
|
return farm;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector2 getTargetPosition()
|
public Vector2 getTargetPosition()
|
||||||
{
|
{
|
||||||
return TargetPosition;
|
return TargetPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCurrentTask()
|
||||||
|
{
|
||||||
|
return currentTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScore()
|
||||||
|
{
|
||||||
|
return scoreSystem.getScore();
|
||||||
|
}
|
||||||
|
|
||||||
public Path getPath()
|
public Path getPath()
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawInventory(Input input, SpriteBatch spriteBatch, SpriteFont Bold, Cargo itemStorageDefined)
|
|
||||||
{
|
|
||||||
smartTractor.drawInventory(input, spriteBatch, Bold, itemStorageDefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Inventory getInventory()
|
|
||||||
{
|
|
||||||
return smartTractor.getInventory();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,47 +4,42 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using C5;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
class Astar
|
class Astar
|
||||||
{
|
{
|
||||||
|
|
||||||
private Vector2 tractorPos;
|
private Vector2 tractorPos;
|
||||||
private Vector2 housePos;
|
private Vector2 housePos;
|
||||||
private static Crops[,] crops;
|
private Crops[,] crops;
|
||||||
private Vector2 Size;
|
private Vector2 Size;
|
||||||
|
private PriorityQueue allPaths;
|
||||||
private Vector2 targetPos;
|
private Vector2 targetPos;
|
||||||
private int Rotation;
|
private int Rotation;
|
||||||
|
|
||||||
public void update(Crops[,] newCrops, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, int rotation)
|
public void update(Crops[,] newCrops, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, Vector2 newtargetPos, int rotation)
|
||||||
{
|
{
|
||||||
tractorPos = new Vector2((int)newTractorPos.X, (int)newTractorPos.Y);
|
tractorPos = new Vector2((int)newTractorPos.X, (int)newTractorPos.Y);
|
||||||
housePos = new Vector2((int)newHousePos.X, (int)newHousePos.Y);
|
housePos = new Vector2((int)newHousePos.X, (int)newHousePos.Y);
|
||||||
|
targetPos = newtargetPos;
|
||||||
crops = newCrops;
|
crops = newCrops;
|
||||||
Size = newSize;
|
Size = newSize;
|
||||||
Rotation = rotation;
|
Rotation = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(Crops[,] newCrops, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, Vector2 newTargetPos, int rotation)
|
public Nodes getOptimalPath()
|
||||||
{
|
{
|
||||||
tractorPos = new Vector2((int)newTractorPos.X, (int)newTractorPos.Y);
|
return allPaths.Peek();
|
||||||
housePos = new Vector2((int)newHousePos.X, (int)newHousePos.Y);
|
|
||||||
crops = newCrops;
|
|
||||||
Size = newSize;
|
|
||||||
Rotation = rotation;
|
|
||||||
targetPos = newTargetPos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all adjacent nodes
|
// Get all adjacent nodes
|
||||||
public List<Nodes> GetAdjacentNodes(Vector2 currentPos)
|
private List<Nodes> GetAdjacentNodes(Vector2 currentPos)
|
||||||
{
|
{
|
||||||
var adjacentNodes = new List<Nodes>()
|
var adjacentNodes = new List<Nodes>()
|
||||||
|
|
||||||
{
|
{
|
||||||
new Nodes(new Vector2(currentPos.X, currentPos.Y - 1), 0),
|
new Nodes(new Vector2(currentPos.X, currentPos.Y+1), 0),
|
||||||
new Nodes(new Vector2(currentPos.X + 1, currentPos.Y), 1),
|
new Nodes(new Vector2(currentPos.X + 1, currentPos.Y), 1),
|
||||||
new Nodes(new Vector2(currentPos.X, currentPos.Y + 1), 2),
|
new Nodes(new Vector2(currentPos.X, currentPos.Y - 1), 2),
|
||||||
new Nodes(new Vector2(currentPos.X - 1, currentPos.Y), -1),
|
new Nodes(new Vector2(currentPos.X - 1, currentPos.Y), -1),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -61,7 +56,7 @@ class Astar
|
|||||||
}
|
}
|
||||||
// return if not an obstacle
|
// return if not an obstacle
|
||||||
return adjacentNodes.Where(
|
return adjacentNodes.Where(
|
||||||
item => (crops[(int)item.getCords().X, (int)item.getCords().Y].getStatus()) != 0).ToList();
|
item => crops[(int)item.getCords().X, (int)item.getCords().Y].Status != 0).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Heuristic function, Manhattan method.
|
// Heuristic function, Manhattan method.
|
||||||
@ -75,7 +70,7 @@ class Astar
|
|||||||
if (currDir == newDir)
|
if (currDir == newDir)
|
||||||
return 0;
|
return 0;
|
||||||
else if (Math.Abs(currDir - newDir) == 1 || Math.Abs(currDir - newDir) == 3)
|
else if (Math.Abs(currDir - newDir) == 1 || Math.Abs(currDir - newDir) == 3)
|
||||||
return 3;
|
return 2;
|
||||||
else if (Math.Abs(currDir - newDir) == 0 || Math.Abs(currDir - newDir) == 2)
|
else if (Math.Abs(currDir - newDir) == 0 || Math.Abs(currDir - newDir) == 2)
|
||||||
return 9;
|
return 9;
|
||||||
return 0;
|
return 0;
|
||||||
@ -85,19 +80,19 @@ class Astar
|
|||||||
public int ConvertRotation()
|
public int ConvertRotation()
|
||||||
{
|
{
|
||||||
int rotation = 0;
|
int rotation = 0;
|
||||||
if (Rotation > 135 && Rotation < 225)
|
if (Rotation == 180)
|
||||||
rotation = 0;
|
rotation = 0;
|
||||||
else if (Rotation > 225 && Rotation < 315)
|
else if (Rotation == 270)
|
||||||
rotation = 1;
|
rotation = 1;
|
||||||
else if (Rotation > 315 && Rotation < 45)
|
else if (Rotation == 0)
|
||||||
rotation = 2;
|
rotation = 2;
|
||||||
else if (Rotation > 45 && Rotation < 135)
|
else if (Rotation == 90)
|
||||||
rotation = -1;
|
rotation = -1;
|
||||||
return rotation;
|
return rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main function of A* algorithm
|
// Main function of A* algorithm
|
||||||
public Path FindPath(bool flipArray)
|
public Path FindPath()
|
||||||
{
|
{
|
||||||
int g = 0;
|
int g = 0;
|
||||||
int direction = ConvertRotation();
|
int direction = ConvertRotation();
|
||||||
@ -128,6 +123,7 @@ 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
|
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
|
if (!(openList.Exists(adjacentNode.getCords()))) // if adjacent node is not on open list, add it
|
||||||
{
|
{
|
||||||
|
|
||||||
adjacentNode.setG(g);
|
adjacentNode.setG(g);
|
||||||
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), target.getCords()));
|
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), target.getCords()));
|
||||||
adjacentNode.calculateF();
|
adjacentNode.calculateF();
|
||||||
@ -153,81 +149,11 @@ class Astar
|
|||||||
path.AddNode(current);
|
path.AddNode(current);
|
||||||
current = current.getParent();
|
current = current.getParent();
|
||||||
}
|
}
|
||||||
|
path = path.FlipArray();
|
||||||
if (flipArray)
|
|
||||||
path = path.FlipArray();
|
|
||||||
|
|
||||||
openList.deleteHeap();
|
openList.deleteHeap();
|
||||||
closedList.deleteHeap();
|
closedList.deleteHeap();
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool isReachable(Crops[,] crops, Vector2 targetPos, Vector2 start)
|
|
||||||
{
|
|
||||||
Rotation = 0;
|
|
||||||
int g = 0;
|
|
||||||
int direction = ConvertRotation();
|
|
||||||
Path path = new Path();
|
|
||||||
MinHeap openList = new MinHeap();
|
|
||||||
MinHeap closedList = new MinHeap();
|
|
||||||
Nodes target = new Nodes(targetPos);
|
|
||||||
Nodes startPos = new Nodes(tractorPos, direction);
|
|
||||||
Nodes current = null;
|
|
||||||
|
|
||||||
openList.Insert(startPos);
|
|
||||||
|
|
||||||
while (openList.GetSize() > 0)
|
|
||||||
{
|
|
||||||
current = openList.getMin();
|
|
||||||
closedList.Insert(current);
|
|
||||||
openList.removeMin();
|
|
||||||
direction = current.getDirection();
|
|
||||||
|
|
||||||
if (current.getCords() == target.getCords())
|
|
||||||
break;
|
|
||||||
|
|
||||||
var adjacentNodes = GetAdjacentNodes(current.getCords());
|
|
||||||
foreach (var adjacentNode in adjacentNodes)
|
|
||||||
{
|
|
||||||
if (closedList.Exists(adjacentNode.getCords())) // check if adjacent node is on closed list, if it is, skip it
|
|
||||||
continue;
|
|
||||||
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();
|
|
||||||
adjacentNode.setParent(current);
|
|
||||||
openList.Insert(adjacentNode);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (g + adjacentNode.getH() < adjacentNode.getF()) // check if adjacent node is a better path than the current one
|
|
||||||
{
|
|
||||||
adjacentNode.setG(g);
|
|
||||||
adjacentNode.calculateF();
|
|
||||||
adjacentNode.setParent(current);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (current != null)
|
|
||||||
{
|
|
||||||
path.AddNode(current);
|
|
||||||
current = current.getParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
openList.deleteHeap();
|
|
||||||
closedList.deleteHeap();
|
|
||||||
|
|
||||||
if (path.getByIndex(0).getCords() != targetPos)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -6,9 +6,8 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using C5;
|
|
||||||
|
|
||||||
class Nodes : IComparable<Nodes>, IEqualityComparer<Nodes>, IPriorityQueueHandle<Nodes>
|
class Nodes
|
||||||
{
|
{
|
||||||
private int F = 0;
|
private int F = 0;
|
||||||
private int G = 0;
|
private int G = 0;
|
||||||
@ -28,12 +27,6 @@ class Nodes : IComparable<Nodes>, IEqualityComparer<Nodes>, IPriorityQueueHandle
|
|||||||
Direction = direction;
|
Direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Nodes(int f, Vector2 coordinates)
|
|
||||||
{
|
|
||||||
Coordinates = coordinates;
|
|
||||||
F = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Nodes(Nodes node)
|
public Nodes(Nodes node)
|
||||||
{
|
{
|
||||||
F = node.F;
|
F = node.F;
|
||||||
@ -101,24 +94,4 @@ class Nodes : IComparable<Nodes>, IEqualityComparer<Nodes>, IPriorityQueueHandle
|
|||||||
{
|
{
|
||||||
return Direction;
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
88
Game1/Sources/Pathing/A-Star/PathSaver/PriorityQueue.cs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|