From dc4a34e9302531516ff1f042a5be542b162b5278 Mon Sep 17 00:00:00 2001 From: JakubStac Date: Fri, 22 Mar 2024 22:12:44 +0100 Subject: [PATCH 1/6] Added fields and methods to classes: plant, field, tractor, crop protection products --- .idea/Traktor AI.iml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.idea/Traktor AI.iml b/.idea/Traktor AI.iml index d9e6024..078ddf5 100644 --- a/.idea/Traktor AI.iml +++ b/.idea/Traktor AI.iml @@ -1,8 +1,10 @@ - - + + + + \ No newline at end of file From 679b8ca1b8499ffa31404a9861e1f62395d296c8 Mon Sep 17 00:00:00 2001 From: JakubStac Date: Fri, 22 Mar 2024 22:14:05 +0100 Subject: [PATCH 2/6] Added fields and methods to classes: plant, field, tractor, crop protection products --- .idea/misc.xml | 2 +- source/area/constants.py | 2 +- source/area/field.py | 5 ++--- source/area/tractor.py | 17 ++++++++++++++++- source/crop_protection_product.py | 3 +++ source/ground.py | 24 ++++++++++++++++++++++-- source/plant.py | 18 ++++++++++++++++-- source/tile.py | 6 +++--- 8 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 source/crop_protection_product.py diff --git a/.idea/misc.xml b/.idea/misc.xml index 8d93904..6c75bb3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/source/area/constants.py b/source/area/constants.py index 99a9fcd..1aff5be 100644 --- a/source/area/constants.py +++ b/source/area/constants.py @@ -3,7 +3,7 @@ import pygame WIDTH, HEIGHT = 1000, 1000 FIELD_WIDTH, FIELD_HEIGHT = 660, 330 -ROWS, COLS = 10, 5 +ROWS, COLS = 20, 20 # number of tiles in a row and column TILE_SIZE = FIELD_WIDTH//ROWS PLANT = "" diff --git a/source/area/field.py b/source/area/field.py index a17e679..99f57bd 100644 --- a/source/area/field.py +++ b/source/area/field.py @@ -21,10 +21,9 @@ def positionFieldElements(): tractor.y += fieldY def createTiles(): - for y in range (0,COLS): - for x in range (0,ROWS): + for y in range(0, COLS): + for x in range(0, ROWS): tile = Tile(x*TILE_SIZE, y*TILE_SIZE) - tile.randomize_photo() tile.randomizeContent() tiles.append(tile) positionFieldElements() diff --git a/source/area/tractor.py b/source/area/tractor.py index 5e1c355..71b0380 100644 --- a/source/area/tractor.py +++ b/source/area/tractor.py @@ -2,8 +2,23 @@ class Tractor: x = None y = None image = None + # etc - def __init__(self,x,y): + def __init__(self, x, y): self.x = x self.y = y self.image = 'resources/images/tractor.png' + + def work_on_field(self, ground, plant): + if plant is None: + pass # zasadz cos + if ground.pest == True: + # traktor pozbywa sie szkodnikow + ground.pest = False + if ground.weed == True: + # traktor pozbywa się chwastow + ground.weed = False + if ground.water < plant.water_requirements: + ground.water += 20 + if ground.nutrients < plant.nutrients_requirements: + ground.nutrients += 20 diff --git a/source/crop_protection_product.py b/source/crop_protection_product.py new file mode 100644 index 0000000..941d36e --- /dev/null +++ b/source/crop_protection_product.py @@ -0,0 +1,3 @@ +class CropProtectionProduct: + def __init__(self, strong_against): + self.strong_against = strong_against # pestycyd, herbicyd diff --git a/source/ground.py b/source/ground.py index a564c4c..ccd1292 100644 --- a/source/ground.py +++ b/source/ground.py @@ -1,6 +1,26 @@ +import random + + class Dirt: - state = None + def __init__(self, water_level, nutrients_level): + self.water_level = water_level + self.nutrients_level = nutrients_level + self.pest = False + self.weed = False + self.obstacle = False + self.pests_and_weeds() # add a couple new properties -# add init, getters,setters + def pests_and_weeds(self): + i = random.randint(1, 20) # 5% szans na szkodniki, 10% na chwasty, 5 na obydwa 15 na kamien + if i == 1: + self.pest = True + elif i == 2 or i == 3: + self.weed = True + elif i == 4: + self.weed = True + self.pest = True + elif i == 5 or i == 6 or i == 7: + self.obstacle = True +# add init, getters,setters diff --git a/source/plant.py b/source/plant.py index 39f1a6c..1488bd0 100644 --- a/source/plant.py +++ b/source/plant.py @@ -1,8 +1,22 @@ +import random + class Plant: - name = None + def __init__(self, name, plant_type, water_requirements, nutrients_requirements, growth_level): + self.name = name + self.plant_type = plant_type + self.water_requirements = water_requirements + self.nutrients_requirements = nutrients_requirements + self.growth_level = growth_level + + def try_to_grow(self, water, nutrients): + if (water >= self.water_requirements) and (nutrients >= self.nutrients_requirements): + i = random.randint(5, 12) + if self.growth_level+i > 100: + i = self.growth_level - 100 + self.growth_level += i + # more properties # add init, getters,setters - diff --git a/source/tile.py b/source/tile.py index 1971f7f..fb813ea 100644 --- a/source/tile.py +++ b/source/tile.py @@ -1,7 +1,7 @@ import random import os -#path to plant images folder (used in randomize_photo function) +# path to plant images folder (used in randomize_photo function) folder_path = "resources\images\plant_photos" @@ -26,7 +26,7 @@ class Tile: # called on a created tile - #choose random photo from the folder: + # choose random photo from the folder: def randomize_photo(self): random_photo = random.choice(os.listdir(folder_path)) @@ -39,7 +39,7 @@ class Tile: if i == 1: self.image = "resources/images/sampling.png" self.photo = photo_path - #self.photo losuje dodatkowo zdjecie jakies rosliny do danego rzędu + # self.photo losuje dodatkowo zdjecie jakies rosliny do danego rzędu else: self.image = "resources/images/dirt.png" self.photo = "resources/images/background.jpg" From 6e3e042a93492a2d3fac6ca2c90c3ae1f46c1a72 Mon Sep 17 00:00:00 2001 From: JakubStac Date: Sat, 23 Mar 2024 22:54:51 +0100 Subject: [PATCH 3/6] Added some crop protection products to tractor and finished some of its functions --- source/area/tractor.py | 48 +++++++++++++++++++++++++------ source/crop_protection_product.py | 3 +- source/tile.py | 5 ++-- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/source/area/tractor.py b/source/area/tractor.py index 71b0380..cc76559 100644 --- a/source/area/tractor.py +++ b/source/area/tractor.py @@ -1,24 +1,56 @@ +from crop_protection_product import CropProtectionProduct + + class Tractor: x = None y = None image = None - + cypermetryna = CropProtectionProduct("pests", "cereal") + diflufenikan = CropProtectionProduct("weeds", "cereal") + spirotetramat = CropProtectionProduct("pests", "fruit") + oksadiargyl = CropProtectionProduct("weeds", "fruit") + spinosad = CropProtectionProduct("pests", "vegetable") + metazachlor = CropProtectionProduct("weeds", "vegetable") # etc + def __init__(self, x, y): self.x = x self.y = y self.image = 'resources/images/tractor.png' - def work_on_field(self, ground, plant): - if plant is None: - pass # zasadz cos - if ground.pest == True: + def work_on_field(self, tile, ground, plant1): + if plant1 is None: + tile.randomizeContent() + # sprobuj zasadzic cos + elif plant1.growth_level == 100: + tile.plant = None + ground.nutrients -= 40 + ground.water -= 40 + else: + plant1.try_to_grow() + ground.nutrients -= 11 + ground.water -= 11 + if ground.pest: # traktor pozbywa sie szkodnikow + if plant1.plant_type == self.cypermetryna.plant_type: + t = "Tractor used Cypermetryna" + elif plant1.plant_type == self.spirotetramat.plant_type: + t = "Tractor used Spirotetramat" + elif plant1.plant_type == self.spinosad.plant_type: + t = "Tractor used Spinosad" + print(t) ground.pest = False - if ground.weed == True: + if ground.weed: # traktor pozbywa się chwastow + if plant1.plant_type == self.diflufenikan.plant_type: + t = "Tractor used Diflufenikan" + elif plant1.plant_type == self.oksadiargyl.plant_type: + t = "Tractor used Oksadiargyl" + elif plant1.plant_type == self.metazachlor.plant_type: + t = "Tractor used Metazachlor" + print(t) ground.weed = False - if ground.water < plant.water_requirements: + if ground.water < plant1.water_requirements: ground.water += 20 - if ground.nutrients < plant.nutrients_requirements: + if ground.nutrients < plant1.nutrients_requirements: ground.nutrients += 20 diff --git a/source/crop_protection_product.py b/source/crop_protection_product.py index 941d36e..448591b 100644 --- a/source/crop_protection_product.py +++ b/source/crop_protection_product.py @@ -1,3 +1,4 @@ class CropProtectionProduct: - def __init__(self, strong_against): + def __init__(self, strong_against, plant_type): self.strong_against = strong_against # pestycyd, herbicyd + self.plant_type = plant_type diff --git a/source/tile.py b/source/tile.py index fb813ea..aa2ca51 100644 --- a/source/tile.py +++ b/source/tile.py @@ -35,7 +35,7 @@ class Tile: def randomizeContent(self): photo_path = self.randomize_photo() - i = random.randint(1, 3) #szansa 1/3 + i = random.randint(1, 3) # szansa 1/3 if i == 1: self.image = "resources/images/sampling.png" self.photo = photo_path @@ -44,5 +44,4 @@ class Tile: self.image = "resources/images/dirt.png" self.photo = "resources/images/background.jpg" -# DISCLAMER check column and choose plant type ("potato","wheat" etc) - +# DISCLAMER check column and choose plant type ("potato","wheat" etc.) From 1d713864f3208d5116a007a9e5d6f577684e8010 Mon Sep 17 00:00:00 2001 From: JakubStac Date: Sun, 24 Mar 2024 16:12:50 +0100 Subject: [PATCH 4/6] Bug fix --- source/plant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/plant.py b/source/plant.py index 1488bd0..30deb91 100644 --- a/source/plant.py +++ b/source/plant.py @@ -13,7 +13,7 @@ class Plant: if (water >= self.water_requirements) and (nutrients >= self.nutrients_requirements): i = random.randint(5, 12) if self.growth_level+i > 100: - i = self.growth_level - 100 + i = 100 - self.growth_level self.growth_level += i # more properties From ffb64ccbc0077f5387661f35d7b7219bab4ced4e Mon Sep 17 00:00:00 2001 From: Marek Date: Mon, 25 Mar 2024 01:02:03 +0100 Subject: [PATCH 5/6] small bug fixes --- source/area/tractor.py | 22 +++++++++++++--------- source/plant.py | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/source/area/tractor.py b/source/area/tractor.py index cc76559..dc27ee8 100644 --- a/source/area/tractor.py +++ b/source/area/tractor.py @@ -22,14 +22,16 @@ class Tractor: if plant1 is None: tile.randomizeContent() # sprobuj zasadzic cos + print("Tarctor planted something") elif plant1.growth_level == 100: tile.plant = None - ground.nutrients -= 40 - ground.water -= 40 + ground.nutrients_level -= 40 + ground.water_level -= 40 + print("Tractor collected something") else: - plant1.try_to_grow() - ground.nutrients -= 11 - ground.water -= 11 + plant1.try_to_grow(50,50) #mozna dostosowac jeszcze + ground.nutrients_level -= 11 + ground.water_level -= 11 if ground.pest: # traktor pozbywa sie szkodnikow if plant1.plant_type == self.cypermetryna.plant_type: @@ -50,7 +52,9 @@ class Tractor: t = "Tractor used Metazachlor" print(t) ground.weed = False - if ground.water < plant1.water_requirements: - ground.water += 20 - if ground.nutrients < plant1.nutrients_requirements: - ground.nutrients += 20 + if ground.water_level < plant1.water_requirements: + ground.water_level += 20 + print("Tractor watered the plant") + if ground.nutrients_level < plant1.nutrients_requirements: + ground.nutrients_level += 20 + print("Tractor added some nutrients") diff --git a/source/plant.py b/source/plant.py index 30deb91..0072b54 100644 --- a/source/plant.py +++ b/source/plant.py @@ -15,6 +15,9 @@ class Plant: if self.growth_level+i > 100: i = 100 - self.growth_level self.growth_level += i + print("The plant is growing") + else: + print("Unable to grow due to bad condition of the ground") # more properties From 7579eed90187ba8796605e02a429c30648f55d0c Mon Sep 17 00:00:00 2001 From: Marek Date: Mon, 25 Mar 2024 01:03:25 +0100 Subject: [PATCH 6/6] test of the knowledge base --- .../crop_protection_product.cpython-311.pyc | Bin 0 -> 651 bytes source/__pycache__/ground.cpython-311.pyc | Bin 0 -> 1341 bytes source/__pycache__/plant.cpython-311.pyc | Bin 0 -> 1424 bytes source/__pycache__/tile.cpython-311.pyc | Bin 1714 -> 1714 bytes .../area/__pycache__/__init__.cpython-311.pyc | Bin 178 -> 178 bytes .../__pycache__/constants.cpython-311.pyc | Bin 451 -> 451 bytes source/area/__pycache__/field.cpython-311.pyc | Bin 3303 -> 3228 bytes .../area/__pycache__/tractor.cpython-311.pyc | Bin 689 -> 3224 bytes source/main.py | 19 ++++++++++++++++++ 9 files changed, 19 insertions(+) create mode 100644 source/__pycache__/crop_protection_product.cpython-311.pyc create mode 100644 source/__pycache__/ground.cpython-311.pyc create mode 100644 source/__pycache__/plant.cpython-311.pyc diff --git a/source/__pycache__/crop_protection_product.cpython-311.pyc b/source/__pycache__/crop_protection_product.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d4e10b42977eef6edebb799c7ba61069314f1050 GIT binary patch literal 651 zcmZuuJxc>Y5S`t-$Qjf$+9*iyqc{*-LBvME$|$H!I9QImHH0L0=kBIZQlvmP{3%F3BsE=@Aay?L{<^JZu7WqG*>Xzx#O`+@$Og52y08I_R?fWsMt z(1VaYbAUJeGOI$!ufVl}e1klj1fx|X1CUT2Qywf;nw`63rcdh(}iIq??iSxkIaa#q_ z3vdLHOlKfUL+mH_sUt)^sv995Hs=nypXX^vy@t?*ug$%_{poCct?%^h$5J2H2oq3o zZPJVUmJ}i_3emzgP2x*J+_n8?mQjm%_7xQUQ{@oQbYq}*(%T5#=^Aog*d4+wWc5^9 qaaks@LON5~Kj$dBz_BV}Vyu0DWN0zQhTLK(I}1Ow_d6#s7XAky9hr^* literal 0 HcmV?d00001 diff --git a/source/__pycache__/ground.cpython-311.pyc b/source/__pycache__/ground.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..440582acd744a9f98e4a6077af280327370cee5a GIT binary patch literal 1341 zcmZuwy>HV%6u+~b)JdHds;Fuqv5w#N;g~Ol9FcCw3E>yZGJvxc7Tsm(QtGlEC`FFVxTHSQT>$2o=tQR`DH4G^C%SMzbnz5C&fx2+JSF_Hi#OT8v;lnI^+jZlusZiqL!;#O;^#v^P(ql!`x(Xh{48ya7-|p&0a2-AC_KmgYnX;#*D4fidC*x zF+gdJXZaXe+;Ba+}rmY z=|Y}y=NIwJxanC(I!c7c%pH(YuB`l!GvDRRxjc6v&wUGjU4S6vsMR1~GlRi+z#J2M z!1gBMb*c-)&*U9#z(d&z#>5i3I5aY7H&~^fmB)dP4c)vNXYXdbZ@m%VTvw36pqN+P}&FonirXN)Ig#>=Ra-o6rbs~>w<+{5K)L|gCE&OLSis68Z?^tkr*W;!og*ertTCeEbTJwifq<| z0|yQqJea_dlg4=Q;@v-Cm-Nsy;bc6JcvyocPrf&0tDE4o{mpxC-kbNEH?JRhdb$aW z*)L>%Iz`AgRN6y65)ShqY!gNpEt3L~$Rom}4Z>3IB|<*I7mosE^cm6R15~F zBjs=ygl%FG@FfL_(G5~a;a&xqr7$*9rpu<|m(u@4V*;Q?4xfnNI;|5US*}ZQ^ zr|NSX#ZJ5WlDn(^f>E|!S!F#P$(~i7=SZKQK*%6;Az+<7T+qb$eYTH=ea9@kbozzn`2w|xuVd34ZW3>haME}>cBccab zOMmaxKN)95Wb%7p_98S%ez=4Xu0BQp>3zjBoui2i4cWyf`Yu9ES z^F`Uxd{>w>Ru%FKlW8T_VYY9(j^@s5J_JKd)nR)2Z%0IFZaU0ej!xigJHBXso4LzD?(*inFncPZy==ab&4&YL zb}j|OSDOP@-_lUcHPn$n9RU}0G#2;OzD9q(sp^5MH`?!aG(Kpm4+HgKqy6$;AcTJ( zv@!mFh7ole#q_`fP!}eU_E(SlA`D>l0a`p zc|=>}c#QYNU37_`YVXQNP(qp_-S5m~%s&6?=e6tMJWwQ&$@V8=^VvG$Ky|7 K|Mj0$k?Rk2rA2=L literal 0 HcmV?d00001 diff --git a/source/__pycache__/tile.cpython-311.pyc b/source/__pycache__/tile.cpython-311.pyc index 2a1b0b4f3b0853b2f5429a6849651b6826ea1984..afdea507b858812fdbd011e7231cc317a3250209 100644 GIT binary patch delta 30 kcmdnQyNQ=?IWI340}$+3$dD$$x{=R{kuiC*Cu1fn0B<`6^#A|> delta 30 kcmdnQyNQ=?IWI340}y;NeUWh0*zBctpF diff --git a/source/area/__pycache__/__init__.cpython-311.pyc b/source/area/__pycache__/__init__.cpython-311.pyc index ff938c742f8b2269e7b72020d869486cb872975b..a319c592373413ccf52f095dfa274696da8b635f 100644 GIT binary patch delta 24 ecmdnQxQUT_IWI340}xa_eKnEWj4^qlQvm=_qXz!~ delta 24 ecmdnQxQUT_IWI340}!}=eL0cajL~_bQvm=@a|XEp diff --git a/source/area/__pycache__/constants.cpython-311.pyc b/source/area/__pycache__/constants.cpython-311.pyc index 78daa343522594d1e486e49ad690597d22ff34ed..fc5dca7db6e4a764e825e1088e3e6f827af8ea9f 100644 GIT binary patch delta 73 zcmX@ie3+ScIWI340}$+3$dG0-k+(@w1js330TQN5&Wp3SJjA_kNL0G9U^!D0F4p{;^KB7(ZFz*S7?Ia z)RfM+p12PTEUfZiqJ#0SpxA`MxhfOorpSF@VCDo01BnjDyTal#80Tuv@(OMxH3gt(5lA;! qekDVZ6o?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