1
0
forked from s425077/PotatoPlan

Compare commits

..

184 Commits

Author SHA1 Message Date
BOTLester
48da4d4736 doc updates 2020-06-15 11:47:47 +02:00
BOTLester
8efb2d2d38 doc update 2020-06-15 11:45:38 +02:00
BOTLester
5dd6cd0020 docs 2020-06-15 11:37:24 +02:00
BOTLester
df77db10af docs 2020-06-15 11:35:38 +02:00
BOTLester
c1ef96716f doc updates 2020-06-15 11:34:11 +02:00
BOTLester
7211266f90 doc updates 2020-06-15 11:29:37 +02:00
BOTLester
43001006b8 final project report 2020-06-15 11:25:16 +02:00
BOTLester
48c90afe77 Window fixes 2020-06-15 09:52:17 +02:00
BOTLester
412a0969f0 Dynamic max window size 2020-06-15 02:51:44 +02:00
BOTLester
72a7a8aab3 Proper files paths for debug only 2020-06-15 01:45:16 +02:00
BOTLester
9e07e0f6bd Fixes and fixes 2020-06-15 00:59:39 +02:00
BOTLester
ad92969137 Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML 2020-06-14 18:02:02 +02:00
BOTLester
2e96d5a2d5 fixes 2020-06-14 18:01:51 +02:00
Joel
cb5a4ea733 Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML 2020-05-25 13:13:25 +02:00
Joel
b6078e14ac fixed the croptype change and runs the ML for those that change in the middle of the day with no lag 2020-05-25 13:13:11 +02:00
0d4c1a0276 Upload files to '' 2020-05-25 09:57:22 +00:00
3b733f9d20 Upload files to '' 2020-05-25 09:57:11 +00:00
ef1c8c4386 Delete 'Example.png' 2020-05-25 09:52:19 +00:00
bf86c760b1 Delete 'Joels Individual Report.md' 2020-05-25 09:52:03 +00:00
5a6d7ecb48 Upload files to '' 2020-05-25 09:50:02 +00:00
49c41e3594 Delete 'Joels Individual Report.md' 2020-05-25 09:49:50 +00:00
1bbd343e74 Upload files to '' 2020-05-25 09:48:22 +00:00
d19c3cbc41 Delete 'Joels Individual Report.md' 2020-05-25 09:48:13 +00:00
9f57f7b00c Upload files to '' 2020-05-25 09:46:32 +00:00
cdc23ff3ed Delete 'Joel Individual Report.md' 2020-05-25 09:46:23 +00:00
3114994c8b Upload files to '' 2020-05-25 09:41:11 +00:00
daf7810dac Upload files to '' 2020-05-25 09:36:34 +00:00
670acee8f2 Delete 'Game1/Joel Individual Report.docx' 2020-05-25 09:30:51 +00:00
d8246cce37 Upload files to 'Game1' 2020-05-25 09:30:24 +00:00
Joel
631ad7c12f Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML 2020-05-25 11:08:14 +02:00
Joel
8b115ec1f5 fixed everything 2020-05-25 11:07:58 +02:00
Joel
090a612660 asd 2020-05-25 10:59:17 +02:00
BOTLester
561287f99e merge 2020-05-25 00:05:11 +02:00
BOTLester
0b7ff8a949 fixes 2020-05-25 00:03:32 +02:00
Joel
c89fee6b05 asd 2020-05-25 00:03:26 +02:00
Joel
8ab1d77d9c asd 2020-05-24 23:10:51 +02:00
Joel
94c2792ef3 asd 2020-05-24 22:24:32 +02:00
Joel
5e9c9f503d asd 2020-05-24 22:22:09 +02:00
BOTLester
e406823e47 ml implement 2020-05-24 22:21:49 +02:00
BOTLester
6bb5073048 Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML 2020-05-24 21:22:50 +02:00
BOTLester
fe04a5cd07 enigne 2020-05-24 21:22:47 +02:00
Joel
10e58f984f Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML 2020-05-24 21:22:26 +02:00
Joel
14e0e92f9b zxdfzdf 2020-05-24 21:22:17 +02:00
BOTLester
c858261c89 merge 2020-05-24 21:02:46 +02:00
BOTLester
cfbe80cb25 ML update 2020-05-24 21:00:54 +02:00
Joel
5e907deca7 asd 2020-05-24 21:00:24 +02:00
BOTLester
0dfef73667 MERGIN 2020-05-24 18:50:47 +02:00
BOTLester
585522b4df changes 2020-05-24 18:50:01 +02:00
Joel
50fd54ee3b asd 2020-05-24 18:49:23 +02:00
Joel
0a31c36c93 asd 2020-05-24 17:08:41 +02:00
Joel
f63bdcee77 Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML 2020-05-24 16:51:40 +02:00
Joel
eb99fd3f02 gtyhsy 2020-05-24 16:51:29 +02:00
BOTLester
5a208e116f merge 2020-05-24 16:27:28 +02:00
BOTLester
8b84387c81 asdasd 2020-05-24 16:26:28 +02:00
Joel
64aaef69dd asd 2020-05-24 16:26:04 +02:00
Joel
2e48e49239 Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML 2020-05-24 13:39:32 +02:00
Joel
46d27ab057 asd 2020-05-24 13:36:31 +02:00
BOTLester
38df90d9b5 merge 2020-05-24 13:27:09 +02:00
BOTLester
ec0819a337 lol 2020-05-24 13:25:46 +02:00
Joel
700979aded asd 2020-05-24 13:24:15 +02:00
Joel
9b99e0e710 added clouds 2020-05-24 13:21:17 +02:00
BOTLester
848cd6598a ml model created 2020-05-24 01:57:27 +02:00
Joel
444b5b0585 Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML 2020-05-23 20:55:55 +02:00
Joel
ba557d98f6 asd 2020-05-23 20:55:45 +02:00
BOTLester
57a9076771 rainfall noisemap 2020-05-23 20:55:38 +02:00
BOTLester
4a786a166e Merge branch 'Joel-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Joel-ML 2020-05-23 20:39:08 +02:00
BOTLester
2a7c06fbd2 ML 2020-05-23 20:39:05 +02:00
Joel
32370470b5 yolo 2020-05-23 20:37:11 +02:00
Joel
710cd8581e asd 2020-05-23 14:13:31 +02:00
Joel
a656d768f6 Merge branch 'dev' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into dev 2020-05-23 13:57:59 +02:00
Joel
037f15f2e4 joined textures 2020-05-23 13:54:47 +02:00
BOTLester
7a520ab7b4 updated connected textures 2020-05-17 01:37:16 +02:00
BOTLester
122f957673 updated contect file 2020-05-12 16:40:45 +02:00
BOTLester
40996b3cdf Merging Oskar into dev 2020-05-12 16:37:53 +02:00
BOTLester
81cac7f8cf cleaning 2020-05-12 16:32:32 +02:00
BOTLester
046dbed742 Added joint textures, deleted old ones 2020-05-12 16:30:01 +02:00
BOTLester
184ca0f8d7 Messing with textures 2020-05-12 15:43:03 +02:00
BOTLester
c0af96fc28 new textures 2020-05-12 01:46:16 +02:00
BOTLester
93802f3331 small adjustments 2020-05-11 01:54:47 +02:00
BOTLester
14490daf9f new UI wip 2020-05-11 01:48:10 +02:00
BOTLester
5293312938 Merge branch 'Oskar-ML' into dev 2020-05-11 01:47:24 +02:00
BOTLester
b21fc0776e UI fix 2020-05-11 01:45:41 +02:00
BOTLester
e4568f2c81 correcting paths 2020-05-11 01:41:38 +02:00
Joel
7691828cae UI 2020-05-11 01:30:18 +02:00
BOTLester
70be7e0151 PerlinNoise map generator 2020-05-11 01:16:01 +02:00
Joel
c3048700f2 Merge branch 'Oskar-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Oskar-ML 2020-05-11 01:11:07 +02:00
Joel
e2ac5f3572 More UI 2020-05-11 01:11:00 +02:00
BOTLester
8c976c4beb updating dev branch 2020-05-11 00:29:09 +02:00
BOTLester
9fd8bd6e9c fixing paths 2020-05-11 00:25:41 +02:00
Joel
dd96c58976 fixed typo 2020-05-11 00:04:59 +02:00
Joel
42e1212b0b Merge branch 'Oskar-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Oskar-ML 2020-05-10 23:57:11 +02:00
Joel
e868578f9b fixed map generation 2020-05-10 23:56:52 +02:00
4c18222a53 Fixing docs 2020-05-10 21:51:12 +00:00
BOTLester
f933f7c13a Final corrections 2020-05-10 23:40:55 +02:00
BOTLester
099a40be9f docs 2020-05-10 23:36:05 +02:00
BOTLester
2383ac5b9a Fixing documentation 2020-05-10 23:33:39 +02:00
BOTLester
d4f5c25d3b Fixing documentation 2020-05-10 23:31:30 +02:00
BOTLester
aa2ec07c35 Fixing documentation 2020-05-10 23:29:40 +02:00
BOTLester
a90602b9c6 Fixing documentation 2020-05-10 23:25:03 +02:00
BOTLester
af0a2bbefa document update 2020-05-10 23:24:06 +02:00
BOTLester
e84c9b897a more fixes 2020-05-10 23:23:18 +02:00
BOTLester
eba969f076 Fixing documenation 2020-05-10 23:21:03 +02:00
BOTLester
5424c2c66a Merge branch 'Oskar-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Oskar-ML 2020-05-10 23:11:18 +02:00
BOTLester
4cbebfe8fd Creating documentation, small fixes 2020-05-10 23:11:15 +02:00
Joel
4aaf7077a9 Merge branch 'Oskar-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Oskar-ML 2020-05-10 21:31:12 +02:00
Joel
97e3ed9a1c Fixed dynamic matrix 2020-05-10 21:31:06 +02:00
BOTLester
9e2636641f Merge branch 'Oskar-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Oskar-ML 2020-05-10 21:16:51 +02:00
BOTLester
34233f92d2 fixing 2020-05-10 21:16:24 +02:00
Joel
e4d2086bf9 Fix 2020-05-10 21:07:03 +02:00
Joel
c17adf52cd Fixed tile speed 2020-05-10 19:39:38 +02:00
Joel
b083ae4293 Merge branch 'Oskar-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Oskar-ML 2020-05-10 19:22:33 +02:00
Joel
913f813895 Somewhat finished 2020-05-10 19:21:52 +02:00
BOTLester
49182f0fd0 Merge branch 'Oskar-ML' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into Oskar-ML 2020-05-10 18:18:16 +02:00
BOTLester
ef1e640f9e bugfixes, finetuning 2020-05-10 18:17:53 +02:00
Joel
f39f27ba4e Squared ProductionRate 2020-05-10 16:42:25 +02:00
Joel
e2f903eb8c Strange results 2020-05-10 16:00:39 +02:00
BOTLester
aee7262c45 small update 2020-05-10 15:02:22 +02:00
BOTLester
2375a52cd4 some fixes, optimized AI 2020-05-10 13:51:19 +02:00
BOTLester
3647b10dc5 ML fixes 2020-05-10 12:55:13 +02:00
BOTLester
34a0e8bd3a working ML, RC0.1 2020-05-10 01:38:08 +02:00
BOTLester
f475f5bab5 merge with dev 2020-05-09 15:59:12 +02:00
BOTLester
3134ce7d3a Merge branch 'dev' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into dev 2020-05-09 15:54:59 +02:00
BOTLester
3566a7af2e Some cleaning, error corrections 2020-05-09 15:54:53 +02:00
Joel
4173b26d30 Inventory System added into ai 2020-05-09 13:48:28 +02:00
BOTLester
e1b4dec764 Damn it works 2020-05-08 00:35:53 +02:00
BOTLester
3e034cf958 merge Joel to dev 2020-05-07 22:12:30 +02:00
BOTLester
7a35bb09fe Target Selection 2020-05-07 22:09:45 +02:00
Joel
fe35083968 Final ProductionRate 2020-05-07 21:46:33 +02:00
Joel
bfad241a74 fix 2020-05-07 20:07:11 +02:00
Joel
a54a7f914c implemented getHighestProductionRate(x, y) per tile 2020-05-07 20:06:34 +02:00
Joel
4ab4abaa89 Last Images and at last fixed the Production System 2020-05-07 14:51:52 +02:00
Joel
095ccc0fc6 Production System fixed 2020-05-07 13:53:07 +02:00
Joel
da7a7822d4 ProductionRate 2020-05-07 01:55:52 +02:00
BOTLester
2e9b78f1a0 corrections 2020-05-06 22:55:40 +02:00
BOTLester
e44dd6fed3 merging 2020-05-06 22:55:33 +02:00
BOTLester
d4acf1cc78 Soil properites 2020-05-06 22:47:56 +02:00
Joel
a439485bf2 idk 2020-05-06 22:37:04 +02:00
Joel
e14d4c3602 potato 2020-05-06 22:02:31 +02:00
BOTLester
3bae81f270 merging, again 2020-05-06 21:58:30 +02:00
BOTLester
8ba385b759 Added Day-night cycle 2020-05-06 20:50:23 +02:00
BOTLester
745ff2e590 hand merging cause its stupid 2020-05-06 20:48:20 +02:00
BOTLester
7809c46bdc Added CreateEngine() in ML 2020-05-06 17:48:11 +02:00
BOTLester
ccf064ca06 Merge dev to ML development branch 2020-05-06 16:52:25 +02:00
BOTLester
c4fb3c2b7b Changed from x86 to x64 2020-05-06 16:40:35 +02:00
BOTLester
d9ff997ea3 Implemented Tree based ML algorithm 2020-05-06 16:27:14 +02:00
96b1e1a663 Merge branch 'dev' of s444524/JoelForkTest into dev 2020-05-06 14:24:33 +00:00
Joel
5ca81367f0 asdasdasdasd 2020-05-06 16:22:30 +02:00
BOTLester
4ea129f803 merge dev to OskarML 2020-05-05 17:50:54 +02:00
0bf4d4380f Merge branch 'dev' of s444524/JoelForkTest into dev 2020-05-05 15:45:57 +00:00
Joel
c143ae6ade asd 2020-05-05 16:27:45 +02:00
BOTLester
a46956cbd0 Create new branch for ML 2020-05-05 16:09:47 +02:00
BOTLester
28f5031ba8 Removing old files 2020-05-04 11:37:20 +02:00
740730958b small correction 2020-05-04 09:27:26 +00:00
a25e05cc3c Merge branch 'dev' of s425077/PotatoPlan into master 2020-05-04 00:00:00 +00:00
BOTLester
673ff157ba docs touchup 2020-05-04 01:58:05 +02:00
BOTLester
e5a15185cb updated docs 2020-05-04 01:56:37 +02:00
BOTLester
73b078ec7a A* implemented and working, Task2 Ready 2020-05-04 01:50:43 +02:00
BOTLester
5af50f8d3b added rotation and rotation cost, RC for T2 2020-05-04 01:17:10 +02:00
BOTLester
8433934bcd implement direction cost 2020-05-03 23:40:40 +02:00
BOTLester
1015886a71 MinHeap added, A* working 2020-05-03 22:28:52 +02:00
BOTLester
54205f0d7f damnbroken 2020-05-03 19:30:41 +02:00
BOTLester
8db46409f1 still doesnt work 2020-05-03 17:52:35 +02:00
BOTLester
dfbe50ee10 A* workin, broke the rest 2020-05-03 17:06:03 +02:00
BOTLester
6e4199eb47 Broken A*, but implemented 2020-05-03 16:35:46 +02:00
BOTLester
8bf82380ab A* framework, not implemented yet 2020-05-03 13:05:05 +02:00
BOTLester
a41c675c08 framework for A*, not implemented yet 2020-05-03 12:58:47 +02:00
90d7f1afbd Merge branch 'master' of s425077/PotatoPlan into dev 2020-04-08 18:24:40 +00:00
BOTLester
938be83d9c update to stable 2020-04-08 20:23:27 +02:00
BOTLester
8483a5e947 Create environment.md
reupload
2020-04-08 20:20:20 +02:00
595fccd370 Usuń 'environment.md' 2020-04-08 18:13:04 +00:00
91332ea088 Usuń 'description' 2020-04-08 18:11:06 +00:00
5c41ef9259 Usuń 'config' 2020-04-08 18:11:03 +00:00
282f0225cf Usuń 'FETCH_HEAD' 2020-04-08 18:10:59 +00:00
a7052ba5cd Usuń 'COMMIT_EDITMSG' 2020-04-08 18:10:55 +00:00
0ced6dd435 Usuń 'Tractor_VS/TextFile1.txt' 2020-04-08 18:10:09 +00:00
40af471180 Merge branch 'dev' of s425077/PotatoPlan into master 2020-04-08 18:06:28 +00:00
BOTLester
4d1b20b32f done by hand, but works eh.
First stable. RC_01
2020-04-08 20:04:31 +02:00
BOTLester
363f3fe1d1 Merge branch 'dev' of https://git.wmi.amu.edu.pl/s425077/PotatoPlan into dev 2020-04-08 19:41:36 +02:00
BOTLester
b062332ad9 TEST 2020-04-08 19:40:54 +02:00
8db4c1b88f plz 2020-04-08 19:38:44 +02:00
57c08fd077 Merge branch 'potato' of s444524/Master into master 2020-04-08 17:28:53 +00:00
78b9849d95 Ladda upp filer till '' 2020-04-08 16:38:56 +00:00
1a16c72efe Merge branch 'master' of s425077/PotatoPlan into dev 2020-04-08 16:21:35 +00:00
f60aa329b3 Merge branch 'master' of s449854/PotatoPlan into master 2020-04-08 16:20:36 +00:00
177 changed files with 2107587 additions and 222615 deletions

63
.gitattributes vendored Normal file
View File

@ -0,0 +1,63 @@
###############################################################################
# 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 Normal file
View File

@ -0,0 +1,261 @@
## 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

BIN
Example.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 KiB

38
Final_evaluation.md Normal file
View File

@ -0,0 +1,38 @@
# 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)

BIN
Game1.bnp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 MiB

View File

@ -7,12 +7,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game1", "Game1\Game1.csproj
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x64.ActiveCfg = Debug|x64
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x64.Build.0 = Debug|x64
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x86.ActiveCfg = Debug|x86
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Debug|x86.Build.0 = Debug|x86
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x64.ActiveCfg = Release|x64
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x64.Build.0 = Release|x64
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x86.ActiveCfg = Release|x86
{650E4519-2DEF-496F-AC3B-3C794DC7CF0D}.Release|x86.Build.0 = Release|x86
EndGlobalSection

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
Game1/Content/Bottom.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
Game1/Content/Cloud.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
Game1/Content/Clouds Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
Game1/Content/Clouds.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 MiB

418
Game1/Content/Content.mgcb Normal file
View File

@ -0,0 +1,418 @@
#----------------------------- 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
Game1/Content/Crop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
Game1/Content/Example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
Game1/Content/Left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,100 @@
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 Temparature Humidity Moisture Soil Type Crop Type Nitrogen Potassium Phosphorous Fertilizer Name
2 26 52 38 Sandy Maize 37 0 0 Urea
3 29 52 45 Loamy Sugarcane 12 0 36 DAP
4 34 65 62 Black Cotton 7 9 30 14-35-14
5 32 62 34 Red Tobacco 22 0 20 28-28
6 28 54 46 Clayey Paddy 35 0 0 Urea
7 26 52 35 Sandy Barley 12 10 13 17-17-17
8 25 50 64 Red Cotton 9 0 10 20-20
9 33 64 50 Loamy Wheat 41 0 0 Urea
10 30 60 42 Sandy Millets 21 0 18 28-28
11 29 58 33 Black Oil seeds 9 7 30 14-35-14
12 27 54 28 Clayey Pulses 13 0 40 DAP
13 31 62 48 Sandy Maize 14 15 12 17-17-17
14 25 50 65 Loamy Cotton 36 0 0 Urea
15 32 62 41 Clayey Paddy 24 0 22 28-28
16 26 52 31 Red Ground Nuts 14 0 41 DAP
17 31 62 49 Black Sugarcane 10 13 14 17-17-17
18 33 64 34 Clayey Pulses 38 0 0 Urea
19 25 50 39 Sandy Barley 21 0 19 28-28
20 28 54 65 Black Cotton 39 0 0 Urea
21 29 58 52 Loamy Wheat 13 0 36 DAP
22 30 60 44 Sandy Millets 10 0 9 20-20
23 34 65 53 Loamy Sugarcane 12 14 12 17-17-17
24 35 68 33 Red Tobacco 11 0 37 DAP
25 28 54 37 Black Millets 36 0 0 Urea
26 33 64 39 Clayey Paddy 13 0 10 20-20
27 26 52 44 Sandy Maize 23 0 20 28-28
28 30 60 63 Red Cotton 9 9 29 14-35-14
29 32 62 30 Loamy Sugarcane 38 0 0 Urea
30 37 70 32 Black Oil seeds 12 0 39 DAP
31 26 52 36 Clayey Pulses 14 0 13 20-20
32 29 58 40 Red Ground Nuts 24 0 23 28-28
33 30 60 27 Loamy Sugarcane 12 0 40 DAP
34 34 65 38 Clayey Paddy 39 0 0 Urea
35 36 68 38 Sandy Barley 7 9 30 14-35-14
36 26 52 48 Loamy Wheat 23 0 19 28-28
37 28 54 35 Black Millets 41 0 0 Urea
38 30 60 61 Loamy Cotton 8 10 31 14-35-14
39 37 70 37 Clayey Paddy 12 0 41 DAP
40 25 50 26 Red Ground Nuts 15 14 11 17-17-17
41 29 58 34 Sandy Millets 15 0 37 DAP
42 27 54 30 Clayey Pulses 13 0 13 20-20
43 30 60 58 Loamy Sugarcane 10 7 32 14-35-14
44 32 62 34 Red Tobacco 22 0 24 28-28
45 34 65 60 Black Sugarcane 35 0 0 Urea
46 35 67 42 Sandy Barley 10 0 35 DAP
47 38 70 48 Loamy Wheat 8 8 28 14-35-14
48 26 52 32 Black Oil seeds 12 0 8 20-20
49 29 58 43 Clayey Paddy 24 0 18 28-28
50 30 60 29 Red Ground Nuts 41 0 0 Urea
51 33 64 51 Sandy Maize 5 9 29 14-35-14
52 34 65 31 Red Tobacco 23 0 21 28-28
53 36 68 33 Black Oil seeds 13 0 14 20-20
54 28 54 38 Clayey Pulses 40 0 0 Urea
55 30 60 47 Sandy Barley 12 0 42 DAP
56 31 62 63 Red Cotton 11 12 15 17-17-17
57 27 53 43 Black Millets 23 0 24 28-28
58 34 65 54 Loamy Wheat 38 0 0 Urea
59 29 58 37 Sandy Millets 8 0 15 20-20
60 25 50 56 Loamy Sugarcane 11 13 15 17-17-17
61 32 62 34 Red Ground Nuts 15 0 37 DAP
62 28 54 41 Clayey Paddy 36 0 0 Urea
63 30 60 49 Loamy Wheat 13 0 9 20-20
64 34 65 64 Black Cotton 24 0 20 28-28
65 28 54 47 Sandy Barley 5 18 15 10-26-26
66 27 53 35 Black Oil seeds 37 0 0 Urea
67 36 68 62 Red Cotton 15 0 40 DAP
68 34 65 57 Black Sugarcane 9 0 13 20-20
69 29 58 55 Loamy Sugarcane 8 8 33 14-35-14
70 25 50 40 Clayey Pulses 6 19 16 10-26-26
71 30 60 38 Sandy Millets 10 0 14 20-20
72 26 52 39 Clayey Pulses 21 0 23 28-28
73 31 62 32 Red Tobacco 39 0 0 Urea
74 34 65 48 Loamy Wheat 23 0 19 28-28
75 27 53 34 Black Oil seeds 42 0 0 Urea
76 33 64 31 Red Ground Nuts 13 0 39 DAP
77 29 58 42 Clayey Paddy 9 10 22 14-35-14
78 30 60 47 Sandy Maize 22 0 21 28-28
79 27 53 59 Loamy Sugarcane 10 0 15 20-20
80 26 52 36 Clayey Pulses 7 16 20 10-26-26
81 34 65 63 Red Cotton 14 0 38 DAP
82 28 54 43 Clayey Paddy 10 8 29 14-35-14
83 30 60 40 Sandy Millets 41 0 0 Urea
84 29 58 65 Black Cotton 14 0 35 DAP
85 26 52 59 Loamy Sugarcane 11 0 9 20-20
86 31 62 44 Sandy Barley 21 0 28 28-28
87 35 67 28 Clayey Pulses 8 7 31 14-35-14
88 29 58 30 Red Tobacco 13 17 16 10-26-26
89 27 53 30 Black Millets 35 0 0 Urea
90 36 68 50 Loamy Wheat 12 18 19 10-26-26
91 29 58 61 Loamy Cotton 11 0 38 DAP
92 30 60 26 Black Oil seeds 8 9 30 14-35-14
93 34 65 45 Clayey Paddy 6 19 21 10-26-26
94 36 68 41 Red Ground Nuts 41 0 0 Urea
95 28 54 25 Sandy Maize 9 10 30 14-35-14
96 25 50 32 Clayey Pulses 24 0 19 28-28
97 30 60 27 Red Tobacco 4 17 17 10-26-26
98 38 72 51 Loamy Wheat 39 0 0 Urea
99 36 60 43 Sandy Millets 15 0 41 DAP
100 29 58 57 Black Sugarcane 12 0 10 20-20

BIN
Game1/Content/ML/MLmodel Normal file

Binary file not shown.

BIN
Game1/Content/ML/MLmodelBig Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

1048576
Game1/Content/ML/Rainfall.csv Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

3
Game1/Content/ML/report Normal file
View File

@ -0,0 +1,3 @@
Micro Accuracy: 0.95829
LogLoss Average: 0.100171
LogLoss Reduction: 0.933795

View File

@ -0,0 +1,3 @@
Micro Accuracy: 1
LogLoss Average: 0.002345
LogLoss Reduction: 0.998302

View File

@ -0,0 +1,3 @@
Mean Absolute Error: 0.0108015636096701
Mean Squared Error: 0.0434908452113952
R Squared: 0.702723944791744

View File

@ -0,0 +1,2 @@
Mean Absolute Error: 187.060835104336
R Squared: 0.913526230109177

BIN
Game1/Content/MaizeIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
Game1/Content/Markers.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
Game1/Content/Mountain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
Game1/Content/PaddyIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
Game1/Content/Plantable.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
Game1/Content/Rainfall.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 MiB

BIN
Game1/Content/Rainfall.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

BIN
Game1/Content/Right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
Game1/Content/Tile.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

BIN
Game1/Content/Top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
Game1/Content/Tractor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
Game1/Content/WheatIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
Game1/Content/house.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
Game1/Content/house2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
Game1/Content/rain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

351
Game1/Game1.cs Normal file
View File

@ -0,0 +1,351 @@
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);
}
}
}

278
Game1/Game1.csproj Normal file
View File

@ -0,0 +1,278 @@
<?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>

View File

Before

Width:  |  Height:  |  Size: 144 KiB

After

Width:  |  Height:  |  Size: 144 KiB

84
Game1/Properties/Resources.Designer.cs generated Normal file
View File

@ -0,0 +1,84 @@
//------------------------------------------------------------------------------
// <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]&quot;;.
/// </summary>
internal static string Fertilizer_Prediction {
get {
return ResourceManager.GetString("Fertilizer_Prediction", resourceCulture);
}
}
}
}

View File

@ -0,0 +1,124 @@
<?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>

View File

@ -0,0 +1,102 @@
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;
}
}

View File

@ -0,0 +1,72 @@
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;
}
}

View File

@ -0,0 +1,36 @@
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];
}
}

View File

@ -0,0 +1,246 @@
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];
}
}

View File

@ -0,0 +1,498 @@
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();
}
}

349
Game1/Sources/Crops/Farm.cs Normal file
View File

@ -0,0 +1,349 @@
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;
}
}
}
}

View File

@ -0,0 +1,333 @@
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
}

View File

@ -0,0 +1,67 @@
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));
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,100 @@
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 Temparature Humidity Moisture Soil Type Crop Type Nitrogen Potassium Phosphorous Fertilizer Name
2 26 52 38 Sandy Maize 37 0 0 Urea
3 29 52 45 Loamy Sugarcane 12 0 36 DAP
4 34 65 62 Black Cotton 7 9 30 14-35-14
5 32 62 34 Red Tobacco 22 0 20 28-28
6 28 54 46 Clayey Paddy 35 0 0 Urea
7 26 52 35 Sandy Barley 12 10 13 17-17-17
8 25 50 64 Red Cotton 9 0 10 20-20
9 33 64 50 Loamy Wheat 41 0 0 Urea
10 30 60 42 Sandy Millets 21 0 18 28-28
11 29 58 33 Black Oil seeds 9 7 30 14-35-14
12 27 54 28 Clayey Pulses 13 0 40 DAP
13 31 62 48 Sandy Maize 14 15 12 17-17-17
14 25 50 65 Loamy Cotton 36 0 0 Urea
15 32 62 41 Clayey Paddy 24 0 22 28-28
16 26 52 31 Red Ground Nuts 14 0 41 DAP
17 31 62 49 Black Sugarcane 10 13 14 17-17-17
18 33 64 34 Clayey Pulses 38 0 0 Urea
19 25 50 39 Sandy Barley 21 0 19 28-28
20 28 54 65 Black Cotton 39 0 0 Urea
21 29 58 52 Loamy Wheat 13 0 36 DAP
22 30 60 44 Sandy Millets 10 0 9 20-20
23 34 65 53 Loamy Sugarcane 12 14 12 17-17-17
24 35 68 33 Red Tobacco 11 0 37 DAP
25 28 54 37 Black Millets 36 0 0 Urea
26 33 64 39 Clayey Paddy 13 0 10 20-20
27 26 52 44 Sandy Maize 23 0 20 28-28
28 30 60 63 Red Cotton 9 9 29 14-35-14
29 32 62 30 Loamy Sugarcane 38 0 0 Urea
30 37 70 32 Black Oil seeds 12 0 39 DAP
31 26 52 36 Clayey Pulses 14 0 13 20-20
32 29 58 40 Red Ground Nuts 24 0 23 28-28
33 30 60 27 Loamy Sugarcane 12 0 40 DAP
34 34 65 38 Clayey Paddy 39 0 0 Urea
35 36 68 38 Sandy Barley 7 9 30 14-35-14
36 26 52 48 Loamy Wheat 23 0 19 28-28
37 28 54 35 Black Millets 41 0 0 Urea
38 30 60 61 Loamy Cotton 8 10 31 14-35-14
39 37 70 37 Clayey Paddy 12 0 41 DAP
40 25 50 26 Red Ground Nuts 15 14 11 17-17-17
41 29 58 34 Sandy Millets 15 0 37 DAP
42 27 54 30 Clayey Pulses 13 0 13 20-20
43 30 60 58 Loamy Sugarcane 10 7 32 14-35-14
44 32 62 34 Red Tobacco 22 0 24 28-28
45 34 65 60 Black Sugarcane 35 0 0 Urea
46 35 67 42 Sandy Barley 10 0 35 DAP
47 38 70 48 Loamy Wheat 8 8 28 14-35-14
48 26 52 32 Black Oil seeds 12 0 8 20-20
49 29 58 43 Clayey Paddy 24 0 18 28-28
50 30 60 29 Red Ground Nuts 41 0 0 Urea
51 33 64 51 Sandy Maize 5 9 29 14-35-14
52 34 65 31 Red Tobacco 23 0 21 28-28
53 36 68 33 Black Oil seeds 13 0 14 20-20
54 28 54 38 Clayey Pulses 40 0 0 Urea
55 30 60 47 Sandy Barley 12 0 42 DAP
56 31 62 63 Red Cotton 11 12 15 17-17-17
57 27 53 43 Black Millets 23 0 24 28-28
58 34 65 54 Loamy Wheat 38 0 0 Urea
59 29 58 37 Sandy Millets 8 0 15 20-20
60 25 50 56 Loamy Sugarcane 11 13 15 17-17-17
61 32 62 34 Red Ground Nuts 15 0 37 DAP
62 28 54 41 Clayey Paddy 36 0 0 Urea
63 30 60 49 Loamy Wheat 13 0 9 20-20
64 34 65 64 Black Cotton 24 0 20 28-28
65 28 54 47 Sandy Barley 5 18 15 10-26-26
66 27 53 35 Black Oil seeds 37 0 0 Urea
67 36 68 62 Red Cotton 15 0 40 DAP
68 34 65 57 Black Sugarcane 9 0 13 20-20
69 29 58 55 Loamy Sugarcane 8 8 33 14-35-14
70 25 50 40 Clayey Pulses 6 19 16 10-26-26
71 30 60 38 Sandy Millets 10 0 14 20-20
72 26 52 39 Clayey Pulses 21 0 23 28-28
73 31 62 32 Red Tobacco 39 0 0 Urea
74 34 65 48 Loamy Wheat 23 0 19 28-28
75 27 53 34 Black Oil seeds 42 0 0 Urea
76 33 64 31 Red Ground Nuts 13 0 39 DAP
77 29 58 42 Clayey Paddy 9 10 22 14-35-14
78 30 60 47 Sandy Maize 22 0 21 28-28
79 27 53 59 Loamy Sugarcane 10 0 15 20-20
80 26 52 36 Clayey Pulses 7 16 20 10-26-26
81 34 65 63 Red Cotton 14 0 38 DAP
82 28 54 43 Clayey Paddy 10 8 29 14-35-14
83 30 60 40 Sandy Millets 41 0 0 Urea
84 29 58 65 Black Cotton 14 0 35 DAP
85 26 52 59 Loamy Sugarcane 11 0 9 20-20
86 31 62 44 Sandy Barley 21 0 28 28-28
87 35 67 28 Clayey Pulses 8 7 31 14-35-14
88 29 58 30 Red Tobacco 13 17 16 10-26-26
89 27 53 30 Black Millets 35 0 0 Urea
90 36 68 50 Loamy Wheat 12 18 19 10-26-26
91 29 58 61 Loamy Cotton 11 0 38 DAP
92 30 60 26 Black Oil seeds 8 9 30 14-35-14
93 34 65 45 Clayey Paddy 6 19 21 10-26-26
94 36 68 41 Red Ground Nuts 41 0 0 Urea
95 28 54 25 Sandy Maize 9 10 30 14-35-14
96 25 50 32 Clayey Pulses 24 0 19 28-28
97 30 60 27 Red Tobacco 4 17 17 10-26-26
98 38 72 51 Loamy Wheat 39 0 0 Urea
99 36 60 43 Sandy Millets 15 0 41 DAP
100 29 58 57 Black Sugarcane 12 0 10 20-20

View File

@ -0,0 +1,39 @@
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;
}
}

View File

@ -0,0 +1,42 @@
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; }
}

View File

@ -0,0 +1,13 @@
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; }
}

View File

@ -0,0 +1,39 @@
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; }
}

View File

@ -0,0 +1,15 @@
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; }
}

186
Game1/Sources/ML/MLModel.cs Normal file
View File

@ -0,0 +1,186 @@
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;
}
}
}
}

View File

@ -0,0 +1,24 @@
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; }
}
}

View File

@ -0,0 +1,27 @@
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; }
}
}

View File

@ -0,0 +1,20 @@
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; }
}
}

View File

@ -0,0 +1,15 @@
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; }
}
}

View File

@ -0,0 +1,55 @@
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;
}
}
}

View File

@ -0,0 +1,190 @@
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;
}
}
}
}
}

View File

@ -0,0 +1,162 @@
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;
}
}

View File

@ -0,0 +1,15 @@
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; }
}

View File

@ -0,0 +1,181 @@
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];
}
}

View File

@ -0,0 +1,136 @@
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;
}
}
}

Some files were not shown because too many files have changed in this diff Show More