Compare commits
No commits in common. "master" and "master" have entirely different histories.
63
.gitattributes
vendored
@ -1,63 +0,0 @@
|
||||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
261
.gitignore
vendored
@ -1,261 +0,0 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
#*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
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)
|
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 |
@ -1,418 +0,0 @@
|
||||
|
||||
#----------------------------- Global Properties ----------------------------#
|
||||
|
||||
/outputDir:bin/$(Platform)
|
||||
/intermediateDir:obj/$(Platform)
|
||||
/platform:Windows
|
||||
/config:
|
||||
/profile:Reach
|
||||
/compress:False
|
||||
|
||||
#-------------------------------- References --------------------------------#
|
||||
|
||||
|
||||
#---------------------------------- 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
|
||||
/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:Crop.png
|
||||
|
||||
#begin Font.spritefont
|
||||
/importer:FontDescriptionImporter
|
||||
/processor:FontDescriptionProcessor
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Font.spritefont
|
||||
|
||||
#begin GroundNutsIcon.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:GroundNutsIcon.png
|
||||
|
||||
#begin house.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/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: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
|
||||
/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:Markers.png
|
||||
|
||||
#begin MilletsIcon.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:ColorKeyColor=255,0,255,255
|
||||
/processorParam:ColorKeyEnabled=True
|
||||
/processorParam:GenerateMipmaps=False
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:ResizeToPowerOfTwo=False
|
||||
/processorParam:MakeSquare=False
|
||||
/processorParam:TextureFormat=Color
|
||||
/build:MilletsIcon.png
|
||||
|
||||
#begin Mountain.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/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: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
|
||||
/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:Plantable.png
|
||||
|
||||
#begin ProgressionBar.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:ProgressionBar.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
|
||||
/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:Tile.png
|
||||
|
||||
#begin tileunplantable.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: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
|
||||
/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: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 |
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 |
Before Width: | Height: | Size: 578 B |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 18 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 |
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: 828 B |
Before Width: | Height: | Size: 747 B |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 3.8 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 |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 7.5 KiB |
351
Game1/Game1.cs
@ -1,351 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.IO;
|
||||
using WinForm = System.Windows.Forms;
|
||||
|
||||
namespace Game1
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the main type for your game.
|
||||
/// </summary>
|
||||
public class Game1 : Game
|
||||
{
|
||||
GraphicsDeviceManager graphics;
|
||||
SpriteBatch spriteBatch;
|
||||
SpriteFont Bold;
|
||||
private Texture2D[] tile = new Texture2D[5];
|
||||
private Texture2D[] tileConnected = new Texture2D[5];
|
||||
private Texture2D[] Crops = new Texture2D[12];
|
||||
private Texture2D tractor;
|
||||
private Texture2D Background;
|
||||
private Texture2D house;
|
||||
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 Input input = new Input();
|
||||
private House houseUnit = new House();
|
||||
private Rectangle 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()
|
||||
{
|
||||
graphics = new GraphicsDeviceManager(this);
|
||||
Content.RootDirectory = "Content";
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
// TODO: Add your initialization logic here
|
||||
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
|
||||
inventory.initInventorySystem();
|
||||
|
||||
|
||||
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
|
||||
tractorUnit.init(houseUnit.GetRectangle(), input); //Generates the Tractor
|
||||
tractorUnit.updateSizing(input, 0, houseUnit.getVector(), Time); //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.setNewHousePos(houseUnit.getVector() / input.getSpacingTile(), true);
|
||||
|
||||
|
||||
|
||||
graphics.PreferredBackBufferWidth = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().X;
|
||||
graphics.PreferredBackBufferHeight = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().Y + 380;
|
||||
graphics.ApplyChanges();
|
||||
}
|
||||
|
||||
protected override void LoadContent()
|
||||
{
|
||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
|
||||
|
||||
|
||||
|
||||
//Loads the PNG content and Fonts
|
||||
tile[0] = Content.Load<Texture2D>("Mountain");
|
||||
tile[1] = Content.Load<Texture2D>("tileunplantable");
|
||||
tile[2] = Content.Load<Texture2D>("Plantable");
|
||||
tile[3] = 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");
|
||||
mouseCursor = Content.Load<Texture2D>("MouseCursor");
|
||||
Bold = Content.Load<SpriteFont>("Font");
|
||||
house = Content.Load<Texture2D>("house");
|
||||
markers = Content.Load<Texture2D>("Markers");
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void UnloadContent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected override void Update(GameTime gameTime) //updates every 60 seconds
|
||||
{
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
||||
Exit();
|
||||
|
||||
|
||||
state = Mouse.GetState();
|
||||
mousePosition = new Rectangle(state.X, state.Y, 1, 1);
|
||||
|
||||
tractorUnit.updateSizing(input, 0, houseUnit.getVector(), Time); //Updates the size
|
||||
tractorUnit.setSpeed(input.changeSpeed(tractorUnit.getSpeed())); //Updates the Simulation 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
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
protected override void Draw(GameTime gameTime) //Draw Function
|
||||
{
|
||||
GraphicsDevice.Clear(Color.FromNonPremultiplied(255,255,255,140));
|
||||
|
||||
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 < 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++)
|
||||
{
|
||||
|
||||
|
||||
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(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 = -1; i < input.getSize().X + 1; i++) //Draw the tiles
|
||||
{
|
||||
for (int j = -1; j < input.getSize().Y + 1; j++)
|
||||
{
|
||||
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.DrawString(Bold, "Selected tile: (" + x.ToString() + ", " + y.ToString() + ")", new Vector2(240, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 22), Color.Teal);
|
||||
tractorUnit.getFarm().getCrop(x, y).Inspect(input.getTileSize(), input.getSpacing(), Bold, new SpriteBatch(GraphicsDevice), cropTypesNames);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,278 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.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')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Game1</RootNamespace>
|
||||
<AssemblyName>Game1</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MonoGamePlatform>Windows</MonoGamePlatform>
|
||||
<TargetFrameworkVersion>v4.6.1</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 Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
|
||||
<DefineConstants>TRACE;WINDOWS</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</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>
|
||||
<Compile Include="Game1.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Sources\Crops\CropType.cs" />
|
||||
<Compile Include="Sources\Crops\CropTypesHolder.cs" />
|
||||
<Compile Include="Sources\Crops\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\Crops\Crops.cs" />
|
||||
<Compile Include="Sources\Crops\Farm.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\Pathing\A-Star\Astar.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\Path.cs" />
|
||||
<Compile Include="Sources\Controlls\Controller.cs" />
|
||||
<Compile Include="Sources\Pathing\PQEntry.cs" />
|
||||
<Compile Include="Sources\Pathing\PriorityQueueC5.cs" />
|
||||
<Compile Include="Sources\Smart\AI.cs" />
|
||||
<Compile Include="Sources\Smart\ScoreSystem.cs" />
|
||||
<Compile Include="Sources\Smart\SmartTractor.cs" />
|
||||
<Compile Include="Sources\Objects\Tractor.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MonoGame.Framework">
|
||||
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Content\Crop.png" />
|
||||
<Content Include="Content\house.png" />
|
||||
<Content Include="Content\ProgressionBarStatus.png" />
|
||||
<Content Include="Content\ProgressionBar.png" />
|
||||
<Content Include="Content\Markers.png" />
|
||||
<Content Include="Content\Mountain.png" />
|
||||
<Content Include="Content\Planted.png" />
|
||||
<Content Include="Content\Tile.png" />
|
||||
<Content Include="Content\tileunplantable.png" />
|
||||
<Content Include="Content\Tractor.png" />
|
||||
<Content Include="Icon.ico" />
|
||||
<None Include="Resources\TextFile1.txt" />
|
||||
<None Include="Sources\ML\Data\FertPredictDataset.csv" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<MonoGameContentReference Include="Content\Content.mgcb" />
|
||||
<None Include="app.config" />
|
||||
<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>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
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>
|
@ -1,102 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using WinForm = System.Windows.Forms;
|
||||
|
||||
class Controller
|
||||
{
|
||||
private KeyboardState state = Keyboard.GetState();
|
||||
private GraphicsDeviceManager graphics;
|
||||
private bool heldUp = false;
|
||||
|
||||
public void init(GraphicsDeviceManager Graphics)
|
||||
{
|
||||
graphics = Graphics;
|
||||
}
|
||||
|
||||
public Vector2 updateWindow(int tileSize, int Spacing, Vector2 Size)
|
||||
{
|
||||
KeyboardState state = Keyboard.GetState();
|
||||
if (state.IsKeyDown(Keys.D) && Size.X < Math.Floor(WinForm.Screen.PrimaryScreen.Bounds.Width / (float)tileSize))
|
||||
{
|
||||
Size.X++;
|
||||
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
|
||||
}
|
||||
|
||||
if (state.IsKeyDown(Keys.A) && Size.X > 2)
|
||||
{
|
||||
Size.X--;
|
||||
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)
|
||||
{
|
||||
Size.Y++;
|
||||
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 380;
|
||||
}
|
||||
|
||||
if (state.IsKeyDown(Keys.S) && Size.Y > 2)
|
||||
{
|
||||
Size.Y--;
|
||||
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 380;
|
||||
}
|
||||
return Size;
|
||||
}
|
||||
|
||||
public int controllTileSize(Vector2 Size, int tileSize)
|
||||
{
|
||||
if (Size.X * tileSize + 5 > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width)
|
||||
{
|
||||
tileSize--;
|
||||
}
|
||||
if (Size.X * tileSize - 5 < GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width && tileSize < 56)
|
||||
{
|
||||
tileSize++;
|
||||
}
|
||||
return tileSize;
|
||||
}
|
||||
|
||||
public int controllSpeed(int Speed)
|
||||
{
|
||||
KeyboardState state = Keyboard.GetState();
|
||||
if (state.IsKeyDown(Keys.Right) && Speed < 350)
|
||||
{
|
||||
Speed++;
|
||||
}
|
||||
|
||||
if (state.IsKeyDown(Keys.Left) && Speed > 0)
|
||||
{
|
||||
Speed--;
|
||||
}
|
||||
|
||||
return Speed;
|
||||
}
|
||||
|
||||
public tractorPositionCorrector controllTractorSpeed(float tractorSpeed, Vector2 Position)
|
||||
{
|
||||
KeyboardState state = Keyboard.GetState();
|
||||
tractorPositionCorrector Corrector = new tractorPositionCorrector(Position, tractorSpeed);
|
||||
if (!heldUp)
|
||||
{
|
||||
if (state.IsKeyDown(Keys.Up) && tractorSpeed < 1)
|
||||
{
|
||||
Corrector.setTractorSpeed(tractorSpeed * 2);
|
||||
heldUp = true;
|
||||
}
|
||||
else if (state.IsKeyDown(Keys.Down) && tractorSpeed > 0.0009765625)
|
||||
{
|
||||
Corrector.setTractorSpeed(tractorSpeed / 2);
|
||||
heldUp = true;
|
||||
}
|
||||
}
|
||||
else if (heldUp && !(state.IsKeyDown(Keys.Down) || state.IsKeyDown(Keys.Up)))
|
||||
{
|
||||
heldUp = false;
|
||||
Corrector.setPosition((float)Math.Ceiling(Position.X), (float)Math.Ceiling(Position.Y));
|
||||
}
|
||||
|
||||
return Corrector;
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
|
||||
|
||||
class Input
|
||||
{
|
||||
private KeyboardState state = Keyboard.GetState();
|
||||
private GraphicsDeviceManager graphics;
|
||||
private Vector2 Size;
|
||||
private int tileSize;
|
||||
private int Spacing;
|
||||
private Controller controller = new Controller();
|
||||
|
||||
public void init(GraphicsDeviceManager Graphics, Vector2 size, int TileSize, int SPacing)
|
||||
{
|
||||
graphics = Graphics;
|
||||
tileSize = TileSize;
|
||||
Spacing = SPacing;
|
||||
Size = size;
|
||||
|
||||
controller.init(Graphics);
|
||||
}
|
||||
|
||||
public int changeSpeed(int Speed)
|
||||
{
|
||||
return controller.controllSpeed(Speed);
|
||||
}
|
||||
|
||||
public tractorPositionCorrector changeTractorSpeed(float tractorSpeed, Vector2 Position)
|
||||
{
|
||||
return controller.controllTractorSpeed(tractorSpeed, Position);
|
||||
}
|
||||
|
||||
private void changeSize()
|
||||
{
|
||||
Size = controller.updateWindow(tileSize, Spacing, Size);
|
||||
}
|
||||
|
||||
public void controlWindowSize()
|
||||
{
|
||||
tileSize = controller.controllTileSize(Size, tileSize);
|
||||
changeSize();
|
||||
graphics.ApplyChanges();
|
||||
}
|
||||
|
||||
public int getTileSize()
|
||||
{
|
||||
return tileSize;
|
||||
}
|
||||
|
||||
public int getSpacing()
|
||||
{
|
||||
return Spacing;
|
||||
}
|
||||
|
||||
public Vector2 getSize()
|
||||
{
|
||||
return Size;
|
||||
}
|
||||
|
||||
public int getSpacingTile()
|
||||
{
|
||||
return Spacing + tileSize;
|
||||
}
|
||||
|
||||
public void setTileSize(int newTileSize)
|
||||
{
|
||||
tileSize = newTileSize;
|
||||
}
|
||||
}
|
@ -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];
|
||||
}
|
||||
}
|
@ -1,498 +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 Crops
|
||||
{
|
||||
private int Status;
|
||||
private int originalStatus;
|
||||
private int cropType = 0;
|
||||
private float Timer = 1;
|
||||
private int UpdateCrop;
|
||||
private float fullTimer = 1;
|
||||
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(Vector2 newSize, DayNightCycle nTime)
|
||||
{
|
||||
Time = nTime;
|
||||
if (UpdateCrop == 60)
|
||||
{
|
||||
degradeSoil();
|
||||
UpdateCrop = 0;
|
||||
}
|
||||
|
||||
if (Status == 3 && Timer != 1)
|
||||
{
|
||||
Timer = Timer - 1f * ProductionRate;
|
||||
}
|
||||
Size = newSize;
|
||||
UpdateCrop++;
|
||||
|
||||
if (Timer < 1)
|
||||
{
|
||||
Timer = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateProductionRate()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
if (Status == 1) //grass
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (Status == 2) //dirt
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cropType == 0)
|
||||
{
|
||||
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
|
||||
{
|
||||
return Status; // + cropType; When unique crop textures have been added
|
||||
}
|
||||
}
|
||||
|
||||
public int getCropType()
|
||||
{
|
||||
return cropType;
|
||||
}
|
||||
|
||||
public void setStatus(int newStatus)
|
||||
{
|
||||
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,349 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
class Farm
|
||||
{
|
||||
private Crops[,] crops;
|
||||
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
|
||||
public void init(Vector2 Size, Vector2 housepos)
|
||||
{
|
||||
whiteNoise = PerlinNoise.GenerateWhiteNoise(100, 100);
|
||||
perlinNoise = PerlinNoise.GeneratePerlinNoise(whiteNoise, 1);
|
||||
PresetCrops.init();
|
||||
r = new Random();
|
||||
crops = new Crops[100, 100];
|
||||
int dirtCount = 0;
|
||||
for (int i = 0; i < 99; i++)
|
||||
{
|
||||
for (int j = 0; j < 99; j++)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if (perlinNoise[i][j] > 0 && perlinNoise[i][j] < 0.15f)
|
||||
x = 0;
|
||||
else if (perlinNoise[i][j] >= 0.15f && perlinNoise[i][j] < 0.8f)
|
||||
x = 1;
|
||||
else if (perlinNoise[i][j] >= 0.8f)
|
||||
x = 2;
|
||||
crops[i, j] = new Crops();
|
||||
crops[i, j].setStatus(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)
|
||||
{
|
||||
Update++;
|
||||
if (Update == 30)
|
||||
{
|
||||
for (int i = 0; i < Size.X; i++)
|
||||
{
|
||||
for (int j = 0; j < Size.Y; j++)
|
||||
{
|
||||
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.
|
||||
public void setCropStatus(float xfloat, float yfloat)
|
||||
{
|
||||
int x = (int)xfloat;
|
||||
int y = (int)yfloat;
|
||||
if (crops[x, y].getStatus() >= 3)
|
||||
{
|
||||
crops[x, y].setStatus(2);
|
||||
}
|
||||
else if(crops[x, y].getStatus() == 0)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
else if (crops[x, y].getStatus() == 2)
|
||||
{
|
||||
|
||||
crops[x, y].setStatus(3);
|
||||
crops[x, y].setCropTimer();
|
||||
}
|
||||
}
|
||||
|
||||
public Crops getCrop(int x, int y)
|
||||
{
|
||||
return crops[x,y];
|
||||
}
|
||||
|
||||
public Crops[,] getCrops()
|
||||
{
|
||||
return crops;
|
||||
}
|
||||
|
||||
private void updateRainMapPosition(Vector2 Size)
|
||||
{
|
||||
double x, y;
|
||||
x = WindSpeed.X + GetRandomNumber(-1f, 1f) / 20000;
|
||||
y = WindSpeed.Y + GetRandomNumber(-1f, 1f) / 20000;
|
||||
if (x <= 0.02f && x >= -0.02f)
|
||||
{
|
||||
WindSpeed.X = (float)x;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
class House
|
||||
{
|
||||
|
||||
private Rectangle housePos;
|
||||
private Vector2 pos;
|
||||
private Random r = new Random();
|
||||
|
||||
//initializes the house
|
||||
public void init(int tileSize, int Spacing)
|
||||
{
|
||||
int x = r.Next(0, 8);
|
||||
int y = r.Next(0, 8);
|
||||
|
||||
pos = new Vector2(x, y);
|
||||
housePos = new Rectangle(x * (tileSize + Spacing), y * (tileSize + Spacing), tileSize, tileSize);
|
||||
}
|
||||
|
||||
|
||||
//Moves the house if it is currently out of matrix.
|
||||
public void updateRectangle(Vector2 Size, int tileSize, int Spacing)
|
||||
{
|
||||
if (pos.X + 1 > Size.X)
|
||||
{
|
||||
pos = new Vector2(pos.X - 1, pos.Y);
|
||||
}
|
||||
if (pos.Y + 1 > Size.Y)
|
||||
{
|
||||
pos = new Vector2(pos.X, pos.Y - 1);
|
||||
}
|
||||
housePos = new Rectangle((int)pos.X * (tileSize + Spacing), (int)pos.Y * (tileSize + Spacing), tileSize, tileSize);
|
||||
}
|
||||
|
||||
//Returns house Rectangle
|
||||
public Rectangle GetRectangle()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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,186 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
class Tractor
|
||||
{
|
||||
private int Spacing, sizeTile, Speed = 1;
|
||||
private float tractorSpeed = 1;
|
||||
private Vector2 Position, TargetPosition, Size, housePos, DeltaPosition;
|
||||
private Path path = new Path();
|
||||
private SmartTractor smartTractor = new SmartTractor();
|
||||
private HandleRotation handleRotation = new HandleRotation();
|
||||
private int j;
|
||||
|
||||
|
||||
|
||||
public void updateSizing(Input input, int Status, Vector2 newHousePos, DayNightCycle Time)
|
||||
{
|
||||
Spacing = input.getSpacing();
|
||||
sizeTile = input.getTileSize();
|
||||
Size = input.getSize();
|
||||
updatePosition(input.getSize(), Status);
|
||||
housePos = newHousePos;
|
||||
smartTractor.UpdateCrops(Speed, Time);
|
||||
}
|
||||
|
||||
public void init(Rectangle house, Input input)
|
||||
{
|
||||
sizeTile = input.getTileSize();
|
||||
Spacing = input.getSpacing();
|
||||
Position = housePos;
|
||||
TargetPosition = new Vector2(house.X, house.Y);
|
||||
smartTractor.init(new Vector2(house.X, house.Y));
|
||||
}
|
||||
|
||||
// Runs when the tractor reaches a tile
|
||||
private void updateDirection(Vector2 Size, Vector2 newPosition)
|
||||
{
|
||||
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.Y == 0)
|
||||
{
|
||||
calculateNewPath(newPosition);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updatePosition(Vector2 Size, int Status) // updates the position
|
||||
{
|
||||
|
||||
//farm.updateSize(Size, sizeTile, Spacing);
|
||||
for (int i = 0; i < Speed; i++)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
if (path.getCount() == 0)
|
||||
{
|
||||
if (Position.X / (sizeTile + Spacing) > Size.X)
|
||||
{
|
||||
Position.X = (Size.X - 1) * (sizeTile + Spacing);
|
||||
}
|
||||
else if (Position.Y / (sizeTile + Spacing) > Size.Y)
|
||||
{
|
||||
Position.Y = (Size.Y - 1) * (sizeTile + Spacing);
|
||||
}
|
||||
smartTractor.updateMap(Position, housePos, Size, sizeTile, Spacing, handleRotation.getRotation());
|
||||
path = smartTractor.returnChoice();
|
||||
TargetPosition = path.Reduce().getCords() * (sizeTile + Spacing);
|
||||
updateDirection(Size, newPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
TargetPosition = path.Reduce().getCords() * (sizeTile + Spacing);
|
||||
updateDirection(Size, newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSpeed(int newSpeed)
|
||||
{
|
||||
Speed = newSpeed;
|
||||
}
|
||||
|
||||
public void setTractorSpeed(tractorPositionCorrector corrector)
|
||||
{
|
||||
tractorSpeed = corrector.getTractorSpeed();
|
||||
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()
|
||||
{
|
||||
return Speed;
|
||||
}
|
||||
|
||||
public float getTractorSpeed()
|
||||
{
|
||||
return tractorSpeed;
|
||||
}
|
||||
|
||||
public Vector2 getTargetPosition()
|
||||
{
|
||||
return TargetPosition;
|
||||
}
|
||||
|
||||
public Path getPath()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
class tractorPositionCorrector
|
||||
{
|
||||
|
||||
Vector2 mPosition;
|
||||
float mTractorSpeed;
|
||||
|
||||
public tractorPositionCorrector(Vector2 position, float TractorSpeed)
|
||||
{
|
||||
mPosition = position;
|
||||
mTractorSpeed = TractorSpeed;
|
||||
}
|
||||
|
||||
public Vector2 getPosition()
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
public float getTractorSpeed()
|
||||
{
|
||||
return mTractorSpeed;
|
||||
}
|
||||
|
||||
public void setPosition(float x, float y)
|
||||
{
|
||||
mPosition = new Vector2(x,y);
|
||||
}
|
||||
|
||||
public void setTractorSpeed(float newSpeed)
|
||||
{
|
||||
mTractorSpeed = newSpeed;
|
||||
}
|
||||
}
|
@ -1,233 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using C5;
|
||||
using System.Diagnostics;
|
||||
|
||||
class Astar
|
||||
{
|
||||
|
||||
private Vector2 tractorPos;
|
||||
private Vector2 housePos;
|
||||
private static Crops[,] crops;
|
||||
private Vector2 Size;
|
||||
private Vector2 targetPos;
|
||||
private int Rotation;
|
||||
|
||||
public void update(Crops[,] newCrops, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, int rotation)
|
||||
{
|
||||
tractorPos = new Vector2((int)newTractorPos.X, (int)newTractorPos.Y);
|
||||
housePos = new Vector2((int)newHousePos.X, (int)newHousePos.Y);
|
||||
crops = newCrops;
|
||||
Size = newSize;
|
||||
Rotation = 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);
|
||||
housePos = new Vector2((int)newHousePos.X, (int)newHousePos.Y);
|
||||
crops = newCrops;
|
||||
Size = newSize;
|
||||
Rotation = rotation;
|
||||
targetPos = newTargetPos;
|
||||
}
|
||||
|
||||
// Get all adjacent nodes
|
||||
public List<Nodes> GetAdjacentNodes(Vector2 currentPos)
|
||||
{
|
||||
var adjacentNodes = new List<Nodes>()
|
||||
|
||||
{
|
||||
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, currentPos.Y + 1), 2),
|
||||
new Nodes(new Vector2(currentPos.X - 1, currentPos.Y), -1),
|
||||
};
|
||||
|
||||
//check if out of range
|
||||
for (int i = 3; i >= 0; i--)
|
||||
{
|
||||
if (adjacentNodes[i].getCords().X < 0 || adjacentNodes[i].getCords().Y < 0)
|
||||
adjacentNodes.Remove(adjacentNodes[i]);
|
||||
else
|
||||
{
|
||||
if (adjacentNodes[i].getCords().X > Size.X - 1 || adjacentNodes[i].getCords().Y > Size.Y - 1)
|
||||
adjacentNodes.Remove(adjacentNodes[i]);
|
||||
}
|
||||
}
|
||||
// return if not an obstacle
|
||||
return adjacentNodes.Where(
|
||||
item => (crops[(int)item.getCords().X, (int)item.getCords().Y].getStatus()) != 0).ToList();
|
||||
}
|
||||
|
||||
// Heuristic function, Manhattan method.
|
||||
public int ComputeHScore(Vector2 currentNode, Vector2 endNote)
|
||||
{
|
||||
return (int)(Math.Abs(endNote.X - currentNode.X) + Math.Abs(endNote.Y - currentNode.Y));
|
||||
}
|
||||
// Rotation Cost
|
||||
public int CalculateRotationCost(int currDir, int newDir)
|
||||
{
|
||||
if (currDir == newDir)
|
||||
return 0;
|
||||
else if (Math.Abs(currDir - newDir) == 1 || Math.Abs(currDir - newDir) == 3)
|
||||
return 3;
|
||||
else if (Math.Abs(currDir - newDir) == 0 || Math.Abs(currDir - newDir) == 2)
|
||||
return 9;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert rotation used by sprite, to get direction of first node in next path
|
||||
public int ConvertRotation()
|
||||
{
|
||||
int rotation = 0;
|
||||
if (Rotation > 135 && Rotation < 225)
|
||||
rotation = 0;
|
||||
else if (Rotation > 225 && Rotation < 315)
|
||||
rotation = 1;
|
||||
else if (Rotation > 315 && Rotation < 45)
|
||||
rotation = 2;
|
||||
else if (Rotation > 45 && Rotation < 135)
|
||||
rotation = -1;
|
||||
return rotation;
|
||||
}
|
||||
|
||||
// Main function of A* algorithm
|
||||
public Path FindPath(bool flipArray)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// backtrack to create path
|
||||
while (current != null)
|
||||
{
|
||||
path.AddNode(current);
|
||||
current = current.getParent();
|
||||
}
|
||||
|
||||
if (flipArray)
|
||||
path = path.FlipArray();
|
||||
|
||||
openList.deleteHeap();
|
||||
closedList.deleteHeap();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,193 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class MinHeap
|
||||
{
|
||||
List<Nodes> arr = new List<Nodes>();
|
||||
public MinHeap()
|
||||
{
|
||||
arr = new List<Nodes>();
|
||||
}
|
||||
|
||||
public void Insert(Nodes value)
|
||||
{
|
||||
arr.Add(value);
|
||||
siftUp(arr.Count - 1);
|
||||
}
|
||||
|
||||
public void removeMin()
|
||||
{
|
||||
if (arr.Count == 0)
|
||||
{
|
||||
throw new Exception("Heap is empty!");
|
||||
}
|
||||
else
|
||||
{
|
||||
arr[0] = arr[arr.Count - 1];
|
||||
arr.RemoveAt(arr.Count - 1);
|
||||
if (arr.Count > 0)
|
||||
{
|
||||
siftDown(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void siftUp(int index)
|
||||
{
|
||||
int parentIndex;
|
||||
Nodes temp;
|
||||
if (index != 0)
|
||||
{
|
||||
parentIndex = getParentIndex(index);
|
||||
if (arr[parentIndex].getF() > arr[index].getF())
|
||||
{
|
||||
temp = arr[parentIndex];
|
||||
arr[parentIndex] = arr[index];
|
||||
arr[index] = temp;
|
||||
siftUp(parentIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getParentIndex(int index)
|
||||
{
|
||||
return (index - 1) / 2;
|
||||
}
|
||||
|
||||
private void siftDown(int nodeIndex)
|
||||
{
|
||||
int leftChildIndex, rightChildIndex, minIndex;
|
||||
Nodes tmp;
|
||||
|
||||
leftChildIndex = getLeftChildIndex(nodeIndex);
|
||||
|
||||
rightChildIndex = getRightChildIndex(nodeIndex);
|
||||
|
||||
if (rightChildIndex >= arr.Count)
|
||||
{
|
||||
if (leftChildIndex >= arr.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
minIndex = leftChildIndex;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (arr[leftChildIndex].getF() <= arr[rightChildIndex].getF())
|
||||
{
|
||||
minIndex = leftChildIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
minIndex = rightChildIndex;
|
||||
}
|
||||
}
|
||||
if (arr[nodeIndex].getF() > arr[minIndex].getF())
|
||||
{
|
||||
tmp = arr[minIndex];
|
||||
|
||||
arr[minIndex] = arr[nodeIndex];
|
||||
|
||||
arr[nodeIndex] = tmp;
|
||||
|
||||
siftDown(minIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private int getRightChildIndex(int nodeIndex)
|
||||
{
|
||||
return (2 * nodeIndex) + 2;
|
||||
}
|
||||
|
||||
private int getLeftChildIndex(int nodeIndex)
|
||||
{
|
||||
return (2 * nodeIndex) + 1;
|
||||
}
|
||||
|
||||
public Nodes getMin()
|
||||
{
|
||||
return arr[0];
|
||||
}
|
||||
|
||||
public void BuildMinHeap(List<Nodes> input)
|
||||
{
|
||||
if (arr.Count > 0)
|
||||
{
|
||||
//clear the current heap
|
||||
for (int i = 0; i < arr.Count; i++)
|
||||
{
|
||||
arr[i] = input[i];
|
||||
}
|
||||
}
|
||||
for (int i = arr.Count - 1 / 2; i >= 0; i--)
|
||||
{
|
||||
MinHeapify(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void MinHeapify(int index)
|
||||
{
|
||||
int left = 2 * index;
|
||||
int right = (2 * index) + 1;
|
||||
int smallest = index;
|
||||
if (left < arr.Count && arr[left].getF() < arr[index].getF())
|
||||
{
|
||||
smallest = left;
|
||||
}
|
||||
else
|
||||
{
|
||||
smallest = index;
|
||||
}
|
||||
if (right < arr.Count && arr[right].getF() < arr[smallest].getF())
|
||||
{
|
||||
smallest = right;
|
||||
}
|
||||
if (smallest != index)
|
||||
{
|
||||
swap(ref arr, index, smallest);
|
||||
MinHeapify(smallest);
|
||||
}
|
||||
}
|
||||
|
||||
private void swap(ref List<Nodes> input, int a, int b)
|
||||
{
|
||||
Nodes temp = input[a];
|
||||
input[a] = input[b];
|
||||
input[b] = temp;
|
||||
}
|
||||
|
||||
public int GetSize()
|
||||
{
|
||||
return arr.Count;
|
||||
}
|
||||
|
||||
public Boolean Exists(Vector2 coordinates)
|
||||
{
|
||||
if (arr.Count == 0)
|
||||
return false;
|
||||
foreach (Nodes node in arr)
|
||||
{
|
||||
if (node.getCords() == coordinates)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Nodes> GetList()
|
||||
{
|
||||
return arr;
|
||||
}
|
||||
|
||||
public void deleteHeap()
|
||||
{
|
||||
arr.Clear();
|
||||
}
|
||||
|
||||
}
|