diff --git a/source/__pycache__/main.cpython-311.pyc b/source/__pycache__/main.cpython-311.pyc new file mode 100644 index 0000000..6bf2826 Binary files /dev/null and b/source/__pycache__/main.cpython-311.pyc differ diff --git a/source/area/__pycache__/tractor.cpython-311.pyc b/source/area/__pycache__/tractor.cpython-311.pyc index 5986299..d2eccf8 100644 Binary files a/source/area/__pycache__/tractor.cpython-311.pyc and b/source/area/__pycache__/tractor.cpython-311.pyc differ diff --git a/source/area/tractor.py b/source/area/tractor.py index d3e0d07..9542f7a 100644 --- a/source/area/tractor.py +++ b/source/area/tractor.py @@ -1,5 +1,6 @@ +from NN.neural_network import clear_text_area from crop_protection_product import CropProtectionProduct -from area.constants import TILE_SIZE, DIRECTION_EAST, DIRECTION_SOUTH, DIRECTION_WEST, DIRECTION_NORTH +from area.constants import TILE_SIZE, DIRECTION_EAST, DIRECTION_SOUTH, DIRECTION_WEST, DIRECTION_NORTH, WIDTH from area.field import fieldX, fieldY, tiles import pygame import time @@ -38,16 +39,19 @@ class Tractor: self.image = pygame.image.load('resources/images/tractor_left.png').convert_alpha() - def work_on_field(self, tile, ground, plant1): + def work_on_field(self, screen, tile, ground, plant1): + results = [] if plant1 is None: tile.randomizeContent() # sprobuj zasadzic cos print("Tarctor planted something") + results.append("Tarctor planted something") elif plant1.growth_level == 100: tile.plant = None ground.nutrients_level -= 40 ground.water_level -= 40 print("Tractor collected something") + results.append("Tractor collected something") else: plant1.try_to_grow(50,50) #mozna dostosowac jeszcze ground.nutrients_level -= 11 @@ -61,6 +65,7 @@ class Tractor: elif plant1.plant_type == self.spinosad.plant_type: t = "Tractor used Spinosad" print(t) + results.append(t) ground.pest = False if ground.weed: # traktor pozbywa siÄ™ chwastow @@ -71,13 +76,21 @@ class Tractor: elif plant1.plant_type == self.metazachlor.plant_type: t = "Tractor used Metazachlor" print(t) + results.append(t) ground.weed = False if ground.water_level < plant1.water_requirements: ground.water_level += 20 print("Tractor watered the plant") + results.append("Tractor watered the plant") if ground.nutrients_level < plant1.nutrients_requirements: ground.nutrients_level += 20 print("Tractor added some nutrients") + results.append("Tractor added some nutrients") + + clear_text_area(screen, WIDTH-90, 100, 400, 100) + for idx, result in enumerate(results): + display_work_results(screen, result, (WIDTH-90, 100 + idx * 30)) + @@ -158,4 +171,11 @@ def do_actions(tractor, WIN, move_list): pygame.display.update() time.sleep(0.5) +#displays results of the "work_on_field" function next to the field: +def display_work_results(screen, text, position): + font = pygame.font.Font(None, 30) + displayed_text = font.render(text, 1, (255,255,255)) + screen.blit(displayed_text, position) + pygame.display.update() + diff --git a/source/main.py b/source/main.py index 17ac8f6..b08e7fb 100644 --- a/source/main.py +++ b/source/main.py @@ -5,7 +5,7 @@ import pandas as pd import joblib from area.constants import WIDTH, HEIGHT, TILE_SIZE from area.field import drawWindow -from area.tractor import Tractor, do_actions +from area.tractor import Tractor, do_actions, display_work_results from area.field import tiles, fieldX, fieldY from area.field import get_tile_coordinates, get_tile_index from ground import Dirt @@ -106,8 +106,9 @@ def main(): goalTile.ground=d1 #getting the name and type of the recognized plant: p1.update_name(prediction) - - #decission tree test: + + +#decission tree test: if d1.pest: pe = 1 else: @@ -136,19 +137,71 @@ def main(): t3 = True t4 = False + weather_n = random.randint(1, 4) + if weather_n == 1: + h1 = True + h2 = False + h3 = False + h4 = False + else: + h1 = False + if weather_n == 2: + h2 = True + h3 = False + h4 = False + else: + h2 = False + if weather_n == 3: + h3 = True + h4 = False + else: + h3 = False + h4 = True + + season_n = random.randint(1,4) + if season_n == 1: + s1 = True + s2 = False + s3 = False + s4 = False + temp_n = random.randint(0,22) + else: + s1 = False + if season_n == 2: + s2 = True + s3 = False + s4 = False + temp_n = random.randint(0,22) + else: + s2 = False + if season_n == 3: + s3 = True + s4 = False + temp_n = random.randint(20,39) + else: + s3 = False + s4 = True + temp_n = random.randint(-20, 10) + + anomaly_n = random.randint(1, 10) + if anomaly_n == 1: + a1 = True + else: + a1 = False dane = { - 'anomalies': [True], - 'temp': [17], - 'water': [d1.water_level], - 'nutri': [d1.nutrients_level], - 'pests': [pe], - 'weeds': [we], - 'ripeness': [p1.growth_level], - 'season_autumn': [True], 'season_spring': [False], 'season_summer': [False], 'season_winter': [False], - 'weather_heavyCloudy': [False], 'weather_partCloudy': [False], 'weather_precipitation': [False], - 'weather_sunny': [True], - 'type_cereal': [t1], 'type_fruit': [t2], 'type_none': [t3], 'type_vegetable': [t4] + 'anomalies': [a1], + 'temp': [temp_n], + 'water': [d1.water_level], + 'nutri': [d1.nutrients_level], + 'pests': [pe], + 'weeds': [we], + 'ripeness': [p1.growth_level], + 'season_autumn': [s1], 'season_spring': [s2], 'season_summer': [s3], 'season_winter': [s4], + 'weather_heavyCloudy': [h1], 'weather_partCloudy': [h2], 'weather_precipitation': [h3], + 'weather_sunny': [h4], + 'type_cereal': [t1], 'type_fruit': [t2], 'type_none': [t3], 'type_vegetable': [t4] } + df = pd.DataFrame(dane) df.to_csv('model_data.csv', index=False) @@ -159,11 +212,11 @@ def main(): #work on field: if predykcje == 'work': - tractor.work_on_field(goalTile, d1, p1) - + tractor.work_on_field(WIN, goalTile, d1, p1) + #update the initial state for the next target: istate = Istate(tile_x, tile_y, tractor.direction) - time.sleep(5) + time.sleep(2) print("\n")