From c0d05cce435dd54957cbcfe10819db9e50d227ba Mon Sep 17 00:00:00 2001 From: Adam Mikolajczak Date: Sun, 12 May 2024 16:45:03 +0200 Subject: [PATCH 1/3] feat(decision tree) program sie wywala jesli traktor chce zasadzic cebule. czemu? nie wiem. --- src/.~lock.tree.csv# | 1 + src/decisiontree.py | 37 ---- src/kb.py | 1 - src/tile.py | 3 +- src/tractor.py | 146 +++++++++++++-- src/tree.csv | 424 +++++++++++++++++++++---------------------- 6 files changed, 348 insertions(+), 264 deletions(-) create mode 100644 src/.~lock.tree.csv# delete mode 100644 src/decisiontree.py diff --git a/src/.~lock.tree.csv# b/src/.~lock.tree.csv# new file mode 100644 index 00000000..04f86c16 --- /dev/null +++ b/src/.~lock.tree.csv# @@ -0,0 +1 @@ +,adam,adam-thinkpad,12.05.2024 10:10,file:///home/adam/.config/libreoffice/4; \ No newline at end of file diff --git a/src/decisiontree.py b/src/decisiontree.py deleted file mode 100644 index 9966b317..00000000 --- a/src/decisiontree.py +++ /dev/null @@ -1,37 +0,0 @@ -import pandas as pd -from sklearn.tree import DecisionTreeClassifier -from sklearn.metrics import accuracy_score -from sklearn.preprocessing import LabelEncoder -from sklearn.model_selection import train_test_split - -# "tile_type","water_level","plant_stage","neighbor_N","neighbor_E","neighbor_W","neighbor_S","action" -data = pd.read_csv('tree.csv') - -print(data.head()) - -# Konwersja danych kategorycznych na liczbowe -label_encoders = {} - -for column in data.columns: - if data[column].dtype == 'object': - label_encoders[column] = LabelEncoder() - data[column] = label_encoders[column].fit_transform(data[column]) - -X = data.drop(columns=['action']) -y = data['action'] - -# Podzielenie na zbiór treningowy i testowy -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) - - -model = DecisionTreeClassifier(random_state=42) -model.fit(X_train, y_train) - -# Przewidywanie etykiet dla danych testowych -y_pred = model.predict(X_test) - -# dokładność modelu -accuracy = accuracy_score(y_test, y_pred) -print("Dokładność modelu: {:.2f}%".format(accuracy * 100)) - - diff --git a/src/kb.py b/src/kb.py index bb9e31e8..0320e307 100644 --- a/src/kb.py +++ b/src/kb.py @@ -38,7 +38,6 @@ tractor_kb([ "warzywo(pietruszka)", "warzywo(pomidor)", "warzywo(por)", - "warzywo(rukola)", "warzywo(rzepa)", "warzywo(rzodkiewka)", "warzywo(sałata)", diff --git a/src/tile.py b/src/tile.py index 88f01d34..09bcccd2 100644 --- a/src/tile.py +++ b/src/tile.py @@ -26,10 +26,11 @@ class Tile(pygame.sprite.Sprite): if random.randint(1, 10) % 3 == 0: self.set_type('water') self.water_level = 100 + self.stage = 'no_plant' else: self.set_type('grass') self.water_level = random.randint(1, 5) * 10 - self.stage = 'grass' + self.stage = 'no_plant' self.rect = self.image.get_rect() diff --git a/src/tractor.py b/src/tractor.py index d07d002f..acdda808 100644 --- a/src/tractor.py +++ b/src/tractor.py @@ -6,6 +6,10 @@ from config import TILE_SIZE, FINAL_X, FINAL_Y, START_X, START_Y, STARTING_DIREC from collections import deque import heapq import random +import pandas as pd +from sklearn.tree import DecisionTreeClassifier +from sklearn.preprocessing import LabelEncoder +from sklearn.tree import export_text class Tractor(pygame.sprite.Sprite): def __init__(self, field): @@ -25,11 +29,62 @@ class Tractor(pygame.sprite.Sprite): self.water = 50 - came_from, total_cost = self.a_star() - path = self.reconstruct_path(came_from) - self.actions = self.recreate_actions(path) - self.action_index = 0 + # A-STAR + # came_from, total_cost = self.a_star() + # path = self.reconstruct_path(came_from) + # self.actions = self.recreate_actions(path) + # self.action_index = 0 + # DECISION TREE: + self.label_encoders = {} + self.load_decision_tree_model() + + def load_decision_tree_model(self): + data = pd.read_csv('tree.csv') + + # Konwersja danych kategorycznych na liczbowe + for column in data.columns: + self.label_encoders[column] = LabelEncoder() + data[column] = self.label_encoders[column].fit_transform(data[column]) + + # Podział danych na atrybuty (X) i etykiety (y) + X = data.drop(columns=['action']) + y = data['action'] + + # Inicjalizacja i dopasowanie modelu drzewa decyzyjnego + self.decision_tree_model = DecisionTreeClassifier(random_state=42) + self.decision_tree_model.fit(X.values, y.values) + tree_rules = export_text(self.decision_tree_model, feature_names=X.columns.tolist()) + print(tree_rules) + + def make_decision(self): + neighbors = self.get_neighbors_types() + if len(neighbors) < 4: + for _ in range(len(neighbors), 4): + neighbors.append('grass') + # Przygotowanie danych wejściowych dla modelu + input_data = { + 'tile_type': self.get_current_tile().type, + 'water_level': self.get_current_tile().water_level, + "plant_stage": self.get_current_tile().stage, + "neighbor_N": neighbors[0], + "neighbor_E": neighbors[1], + "neighbor_W": neighbors[3], + "neighbor_S": neighbors[2] + } + + input_values = [] + for column, encoder in self.label_encoders.items(): + if column == 'action': continue + input_value = input_data.get(column) + input_values.append(encoder.transform([input_value])[0]) + + # Przewidywanie akcji za pomocą modelu + predicted_action_index = self.decision_tree_model.predict([input_values])[0] + + # Odwrotna transformacja na prawdziwą nazwę akcji + action = self.label_encoders["action"].inverse_transform([predicted_action_index])[0] + return action def draw(self, surface): surface.blit(self.image, self.rect) @@ -57,19 +112,84 @@ class Tractor(pygame.sprite.Sprite): def update(self): - if self.action_index == len(self.actions): - return + # A STAR: + # if self.action_index == len(self.actions): + # return + # action = self.actions[self.action_index] - action = self.actions[self.action_index] + # match (action): + # case ('move'): + # self.move() + # case ('left'): + # self.rotate('left') + # case ('right'): + # self.rotate('right') + + # DECISION TREE: + action = self.make_decision() + self.prev_action = action + if self.prev_action is not None and self.prev_action != 'move': + self.move() + self.prev_action = 'move' match (action): case ('move'): self.move() - case ('left'): - self.rotate('left') - case ('right'): - self.rotate('right') - self.action_index += 1 - + case ('harvest'): + self.get_current_tile().set_type('grass') + case ('water'): + self.get_current_tile().water_level += 10 + case ('plant(bób)'): + self.get_current_tile().set_type('bób') + case ('plant(brokuł)'): + self.get_current_tile().set_type('brokuł') + case ('plant(brukselka)'): + self.get_current_tile().set_type('brukselka') + case ('plant(burak)'): + self.get_current_tile().set_type('burak') + case ('plant(cebula)'): + self.get_current_tile().set_type('cebula') + case ('plant(cukinia)'): + self.get_current_tile().set_type('cukinia') + case ('plant(dynia)'): + self.get_current_tile().set_type('dynia') + case ('plant(fasola)'): + self.get_current_tile().set_type('fasola') + case ('plant(groch)'): + self.get_current_tile().set_type('groch') + case ('plant(jarmuż)'): + self.get_current_tile().set_type('jarmuż') + case ('plant(kalafior)'): + self.get_current_tile().set_type('kalafior') + case ('plant(kalarepa)'): + self.get_current_tile().set_type('kalarepa') + case ('plant(kapusta)'): + self.get_current_tile().set_type('kapusta') + case ('plant(marchew)'): + self.get_current_tile().set_type('marchew') + case ('plant(ogórek)'): + self.get_current_tile().set_type('ogórek') + case ('plant(papryka)'): + self.get_current_tile().set_type('papryka') + case ('plant(pietruszka)'): + self.get_current_tile().set_type('pietruszka') + case ('plant(pomidor)'): + self.get_current_tile().set_type('pomidor') + case ('plant(por)'): + self.get_current_tile().set_type('por') + case ('plant(rzepa)'): + self.get_current_tile().set_type('rzepa') + case ('plant(rzodkiewka)'): + self.get_current_tile().set_type('rzodkiewka') + case ('plant(sałata)'): + self.get_current_tile().set_type('sałata') + case ('plant(seler)'): + self.get_current_tile().set_type('seler') + case ('plant(szpinak)'): + self.get_current_tile().set_type('szpinak') + case ('plant(ziemniak)'): + self.get_current_tile().set_type('ziemniak') + #self.action_index += 1 + print(action) return diff --git a/src/tree.csv b/src/tree.csv index 61a558ad..15347e62 100644 --- a/src/tree.csv +++ b/src/tree.csv @@ -1,212 +1,212 @@ -"tile_type","water_level","plant_stage","neighbor_N","neighbor_E","neighbor_W","neighbor_S","action" -"bób",0,"planted","jarmuż","grass","brokuł","jarmuż","water" -"brokuł",0,"growing","kalafior","brokuł","bób","kalafior","water" -"brukselka",0,"growing","water","brukselka","grass","grass","water" -"burak",0,"planted","bób","burak","brukselka","grass","water" -"cebula",0,"growing","brokuł","cebula","burak","grass","water" -"cukinia",0,"growing","grass","cukinia","water","grass","water" -"dynia",0,"planted","grass","grass","cukinia","kalafior","water" -"fasola",0,"growing","cebula","fasola","dynia","kalarepa","water" -"groch",0,"growing","cukinia","grass","grass","kapusta","water" -"jarmuż",0,"planted","dynia","grass","grass","brokuł","water" -"kalafior",0,"growing","fasola","kalafior","jarmuż","brukselka","water" -"kalarepa",0,"growing","groch","water","kalafior","burak","water" -"kapusta",0,"planted","jarmuż","grass","grass","cebula","water" -"marchew",0,"growing","water","marchew","kapusta","cukinia","water" -"ogórek",0,"planted","kalarepa","ogórek","marchew","grass","water" -"papryka",0,"planted","kapusta","papryka","grass","fasola","water" -"pietruszka",0,"growing","marchew","water","papryka","groch","water" -"pomidor",0,"planted","grass","pomidor","pietruszka","jarmuż","water" -"por",0,"planted","grass","por","water","kalafior","water" -"rukola",0,"planted","pietruszka","grass","por","kalarepa","water" -"rzepa",0,"growing","pomidor","rzepa","grass","kapusta","water" -"rzodkiewka",0,"planted","por","water","grass","marchew","water" -"sałata",0,"growing","rukola","grass","rzodkiewka","ogórek","water" -"seler",0,"planted","rzepa","grass","water","papryka","water" -"szpinak",0,"growing","rzodkiewka","szpinak","seler","pietruszka","water" -"ziemiak",0,"planted","water","ziemiak","grass","water","water" -"bób",0,"no_plant","jarmuż","bób","grass","jarmuż","harvest" -"brokuł",10,"no_plant","kalafior","grass","bób","kalafior","harvest" -"brukselka",20,"no_plant","kalarepa","brukselka","brokuł","kalarepa","harvest" -"burak",30,"no_plant","bób","grass","brukselka","fasola","harvest" -"cebula",40,"no_plant","brokuł","cebula","grass","groch","harvest" -"cukinia",50,"no_plant","brukselka","water","grass","jarmuż","harvest" -"dynia",0,"no_plant","burak","grass","cukinia","kalafior","harvest" -"fasola",10,"no_plant","cebula","grass","dynia","kalarepa","harvest" -"groch",20,"no_plant","cukinia","groch","fasola","kapusta","harvest" -"jarmuż",30,"no_plant","grass","water","groch","brokuł","harvest" -"kalafior",40,"no_plant","fasola","kalafior","water","brukselka","harvest" -"kalarepa",50,"no_plant","groch","grass","kalafior","burak","harvest" -"kapusta",0,"no_plant","jarmuż","grass","kalarepa","cebula","harvest" -"marchew",10,"no_plant","kalafior","grass","kapusta","grass","harvest" -"ogórek",20,"no_plant","kalarepa","ogórek","marchew","dynia","harvest" -"papryka",30,"no_plant","kapusta","papryka","grass","fasola","harvest" -"pietruszka",40,"no_plant","marchew","grass","papryka","groch","harvest" -"pomidor",50,"no_plant","water","pomidor","pietruszka","water","harvest" -"por",0,"no_plant","papryka","grass","pomidor","kalafior","harvest" -"rukola",10,"no_plant","pietruszka","grass","por","kalarepa","harvest" -"rzepa",20,"no_plant","pomidor","grass","grass","kapusta","harvest" -"rzodkiewka",30,"no_plant","grass","water","rzepa","water","harvest" -"sałata",40,"no_plant","grass","sałata","rzodkiewka","ogórek","harvest" -"seler",50,"no_plant","rzepa","water","sałata","papryka","harvest" -"szpinak",0,"no_plant","rzodkiewka","szpinak","seler","pietruszka","harvest" -"ziemiak",10,"no_plant","grass","por","pomidor","water","harvest" -"grass",10,"no_plant","kapusta","ziemniak","grass","water","plant(bób)" -"grass",20,"no_plant","grass","grass","ziemniak","grass","plant(bób)" -"grass",30,"no_plant","kapusta","grass","kapusta","grass","plant(bób)" -"grass",40,"no_plant","ziemniak","water","grass","kapusta","plant(bób)" -"grass",50,"no_plant","grass","grass","water","grass","plant(burak)" -"grass",10,"no_plant","water","grass","grass","water","plant(cebula)" -"grass",20,"no_plant","por","grass","grass","por","plant(brokuł)" -"grass",30,"no_plant","seler","ziemniak","grass","ziemniak","plant(brokuł)" -"grass",40,"no_plant","grass","por","por","grass","plant(brokuł)" -"grass",50,"no_plant","seler","grass","ziemniak","por","plant(brokuł)" -"grass",10,"no_plant","grass","seler","ziemaniak","grass","plant(brokuł)" -"grass",20,"no_plant","groch","kapusta","ogórek","pomidor","plant(burak)" -"grass",30,"no_plant","rzodkiewka","kalarepa","sałata","seler","plant(burak)" -"grass",40,"no_plant","kapusta","grass","water","kalarepa","plant(burak)" -"grass",50,"no_plant","rzodkiewka","grass","water","grass","plant(burak)" -"grass",10,"no_plant","grass","water","grass","pomidor","plant(burak)" -"grass",20,"no_plant","grass","pomidor","grass","grass","plant(burak)" -"grass",30,"no_plant","water","grass","kapusta","grass","plant(burak)" -"grass",40,"no_plant","ogórek","water","grass","ogórek","plant(burak)" -"grass",50,"no_plant","grass","rzodkiewka","groch","grass","plant(burak)" -"grass",10,"no_plant","grass","grass","grass","pomidor","plant(burak)" -"grass",20,"no_plant","kalarepa","water","rzodkiewka","grass","plant(burak)" -"grass",30,"no_plant","cukinia","kalarepa","ogórek","pomidor","plant(cebula)" -"grass",40,"no_plant","sałata","grass","water","grass","plant(cebula)" -"grass",50,"no_plant","kalarepa","water","grass","grass","plant(cebula)" -"grass",10,"no_plant","grass","cukinia","pomidor","grass","plant(cebula)" -"grass",20,"no_plant","grass","grass","ogórek","pomidor","plant(cebula)" -"grass",30,"no_plant","water","sałata","grass","water","plant(cebula)" -"grass",40,"no_plant","sałata","grass","grass","ogórek","plant(cebula)" -"grass",50,"no_plant","grass","kalarepa","water","grass","plant(cebula)" -"grass",10,"no_plant","grass","grass","cukinia","grass","plant(cebula)" -"grass",20,"no_plant","pomidor","water","kalarepa","water","plant(cebula)" -"grass",30,"no_plant","water","grass","water","cukinia","plant(cebula)" -"grass",40,"no_plant","ogórek","sałata","ogórek","grass","plant(cebula)" -"grass",50,"no_plant","grass","grass","pomidor","sałata","plant(cebula)" -"grass",10,"no_plant","water","kalarepa","sałata","grass","plant(cebula)" -"grass",20,"no_plant","pomidor","kalarepa","grass","water","plant(cebula)" -"grass",30,"no_plant","groch","water","szpinak","grass","plant(cukinia)" -"grass",40,"no_plant","grass","szpinak","groch","szpinak","plant(cukinia)" -"grass",50,"no_plant","groch","grass","groch","grass","plant(cukinia)" -"grass",10,"no_plant","szpinak","water","szpinak","szpinak","plant(cukinia)" -"grass",20,"no_plant","groch","grass","groch","grass","plant(cukinia)" -"grass",30,"no_plant","grass","szpinak","grass","water","plant(cukinia)" -"grass",40,"no_plant","szpinak","grass","groch","groch","plant(cukinia)" -"grass",50,"no_plant","water","grass","szpinak","grass","plant(cukinia)" -"grass",10,"no_plant","groch","groch","grass","szpinak","plant(cukinia)" -"grass",20,"no_plant","grass","grass","water","szpinak","plant(cukinia)" -"grass",30,"no_plant","szpinak","groch","szpinak","grass","plant(cukinia)" -"grass",40,"no_plant","grass","groch","groch","water","plant(cukinia)" -"grass",50,"no_plant","grass","szpinak","grass","groch","plant(cukinia)" -"grass",10,"no_plant","szpinak","grass","grass","groch","plant(cukinia)" -"grass",20,"no_plant","szpinak","water","grass","grass","plant(cukinia)" -"grass",30,"no_plant","fasola","grass","grass","fasola","plant(dynia)" -"grass",40,"no_plant","grass","grass","fasola","water","plant(dynia)" -"grass",50,"no_plant","grass","fasola","water","fasola","plant(dynia)" -"grass",10,"no_plant","fasola","water","grass","fasola","plant(dynia)" -"grass",20,"no_plant","water","grass","grass","fasola","plant(dynia)" -"grass",30,"no_plant","grass","water","fasola","grass","plant(dynia)" -"grass",40,"no_plant","grass","fasola","water","grass","plant(dynia)" -"grass",50,"no_plant","fasola","grass","fasola","water","plant(dynia)" -"grass",10,"no_plant","fasola","grass","grass","fasola","plant(dynia)" -"grass",20,"no_plant","jarmuź","ogórek","rzepa","seler","plant(fasola)" -"grass",30,"no_plant","grass","water","ziemniak","szpinak","plant(fasola)" -"grass",40,"no_plant","jarmuż","grass","water","ziemniak","plant(fasola)" -"grass",50,"no_plant","ogórek","water","ogórek","grass","plant(fasola)" -"grass",10,"no_plant","ogórek","jarmuż","water","grass","plant(fasola)" -"grass",20,"no_plant","grass","ogórek","seler","grass","plant(fasola)" -"grass",30,"no_plant","seler","grass","jarmuż","grass","plant(fasola)" -"grass",40,"no_plant","grass","water","ogórek","ziemniak","plant(fasola)" -"grass",50,"no_plant","grass","grass","ogórek","jarmuż","plant(fasola)" -"grass",10,"no_plant","grass","seler","grass","ogórek","plant(fasola)" -"grass",20,"no_plant","water","ziemniak","szpinak","water","plant(fasola)" -"grass",30,"no_plant","ziemniak","rzepa","ziemniak","grass","plant(fasola)" -"grass",40,"no_plant","water","grass",,"rzepa","plant(fasola)" -"grass",50,"no_plant","rzepa","rzepa","seler","ziemniak","plant(fasola)" -"grass",10,"no_plant","grass","grass","water","szpinak","plant(fasola)" -"grass",20,"no_plant","seler","grass","ziemniak","grass","plant(fasola)" -"grass",30,"no_plant","grass","grass","rzepa","water","plant(fasola)" -"grass",40,"no_plant","grass","ziemniak","grass","szpinak","plant(fasola)" -"grass",50,"no_plant","ziemniak","seler","grass","water","plant(fasola)" -"grass",10,"no_plant","grass","rzepa","szpinak","grass","plant(fasola)" -"grass",20,"no_plant","water","grass","grass","grass","plant(fasola)" -"grass",30,"no_plant","grass","szpinak","water","grass","plant(fasola)" -"grass",40,"no_plant","szpinak","grass","ziemniak","rzepa","plant(fasola)" -"grass",50,"no_plant","rzepa","grass","ziemniak","grass","plant(fasola)" -"grass",10,"no_plant","kalarepa","marchew","ogórek","rzepa","plant(groch)" -"grass",20,"no_plant","seler","kapusta","szpinak","rzodkiewka","plant(groch)" -"grass",30,"no_plant","marchew","kalarepa","grass","rzodkiewka","plant(groch)" -"grass",40,"no_plant","grass","marchew","grass","grass","plant(groch)" -"grass",50,"no_plant","ogórek","grass","kalarepa","rzodkiewka","plant(groch)" -"grass",10,"no_plant","seler","rzodkiewka","grass","marchew","plant(groch)" -"grass",20,"no_plant","szpinak","grass","machew","kalarepa","plant(groch)" -"grass",30,"no_plant","rzodkiewka","water","grass","grass","plant(groch)" -"grass",40,"no_plant","water","kalarepa","rzepa","szpinak","plant(groch)" -"grass",50,"no_plant","marchew","grass","seler","water","plant(groch)" -"grass",10,"no_plant","kalarepa","rzodkiewka","marchew","water","plant(groch)" -"grass",20,"no_plant","grass","grass","seler","water","plant(groch)" -"grass",30,"no_plant","ogórek","szpinak","water","rzepa","plant(groch)" -"grass",40,"no_plant","rzodkiewka","grass","marchew","seler","plant(groch)" -"grass",50,"no_plant","kapusta","grass","water","grass","plant(jarmuż)" -"grass",10,"no_plant","grass","kapusta","water","grass","plant(jarmuż)" -"grass",20,"no_plant","water","grass","kapusta","grass","plant(jarmuż)" -"grass",30,"no_plant","kapusta","water","grass","kapusta","plant(jarmuż)" -"grass",40,"no_plant","seler","grass","water","szpinak","plant(kapusta)" -"grass",50,"no_plant","water","szpinak","grass","szpinak","plant(kalarepa)" -"grass",10,"no_plant","grass","grass","ziemniak","ziemniak","plant(kalarepa)" -"grass",20,"no_plant","water","grass","szpinak","ziemniak","plant(kalarepa)" -"grass",30,"no_plant","grass","szpinak","seler","grass","plant(kapusta)" -"grass",40,"no_plant","grass","water","szpinak","seler","plant(kalarepa)" -"grass",50,"no_plant","grass","szpinak","grass","grass","plant(kalarepa)" -"grass",10,"no_plant","szpinak","ziemniak","seler","water","plant(kalarepa)" -"grass",20,"no_plant","ziemniak","szpinak","grass","seler","plant(kalarepa)" -"grass",30,"no_plant","grass","water","ziemniak","grass","plant(kalarepa)" -"grass",40,"no_plant","seler","szpinak","seler","grass","plant(kapusta)" -"grass",50,"no_plant","szpinak","water","grass","grass","plant(kapusta)" -"grass",10,"no_plant","water","grass","grass","seler","plant(kapusta)" -"grass",20,"no_plant","ogórek","water","grass","ogórek","plant(marchew)" -"grass",30,"no_plant","grass","ogórek","water","grass","plant(marchew)" -"grass",40,"no_plant","water","grass","grass","ogórek","plant(marchew)" -"grass",50,"no_plant","por","szpinak","grass","seler","plant(ogórek)" -"grass",10,"no_plant","water","por","szpinak","grass","plant(ogórek)" -"grass",20,"no_plant","seler","water","por","grass","plant(ogórek)" -"grass",30,"no_plant","grass","grass","grass","por","plant(ogórek)" -"grass",40,"no_plant","szpinak","seler","grass","water","plant(ogórek)" -"grass",50,"no_plant","water","grass","szpinak","seler","plant(ogórek)" -"grass",10,"no_plant","por","grass","rzodkiewka","water","plant(pietruszka)" -"grass",20,"no_plant","grass","rzodkiewka","por","rzodkiewka","plant(pietruszka)" -"grass",30,"no_plant","rzodkiewka","grass","grass","water","plant(pietruszka)" -"grass",40,"no_plant","water","por","grass","por","plant(pietruszka)" -"grass",50,"no_plant","por","grass","grass","por","plant(pomidor)" -"grass",10,"no_plant","water","rzepa","seler","water","plant(pomidor)" -"grass",20,"no_plant","rzepa","water","seler","grass","plant(pomidor)" -"grass",30,"no_plant","grass","grass","grass","szpinak","plant(pomidor)" -"grass",40,"no_plant","szpinak","water","por","grass","plant(pomidor)" -"grass",50,"no_plant","rzepa","seler","grass","por","plant(pomidor)" -"grass",10,"no_plant","water","grass","grass","grass","plant(pomidor)" -"grass",40,"no_plant","grass","rzodkiewka","sałata","szpinak","plant(por)" -"grass",50,"no_plant","szpinak","grass","water","sałata","plant(por)" -"grass",10,"no_plant","rzodkiewka","grass","szpinak","water","plant(por)" -"grass",20,"no_plant","water","szpinak","grass","sałata","plant(por)" -"grass",30,"no_plant","rzodkiewka","grass","sałata","grass","plant(por)" -"grass",40,"no_plant","water","grass","grass","seler","plant(rzepa)" -"grass",50,"no_plant","grass","grass","szpinak","water","plant(rzepa)" -"grass",10,"no_plant","water","seler","grass","water","plant(rzepa)" -"grass",20,"no_plant","seler","szpinak","grass","grass","plant(rzepa)" -"grass",30,"no_plant","grass","water","szpinak","seler","plant(rzepa)" -"grass",40,"no_plant","water","grass","szpinak","grass","plant(rzodkiewka)" -"grass",50,"no_plant","water","grass","water","szpinak","plant(rzodkiewka)" -"grass",10,"no_plant","grass","grass","szpinak","grass","plant(rzodkiewka)" -"grass",20,"no_plant","szpinak","water","szpinak","grass","plant(rzodkiewka)" -"grass",30,"no_plant","water","szpinak","grass","ziemniak","plant(rzodkiewka)" -"grass",40,"no_plant","szpinak","grass","water","grass","plant(seler)" -"grass",50,"no_plant","water","szpinak","grass","grass","plant(seler)" -"grass",10,"no_plant","szpinak","grass","szpinak","water","plant(seler)" -"grass",20,"no_plant","szpinak","grass","water","szpinak","plant(seler)" -"grass",30,"no_plant","grass","ziemniak","ziemniak","water","plant(szpinak)" -"grass",40,"no_plant","grass","grass","ziemniak","water","plant(szpinak)" -"grass",50,"no_plant","grass","ziemniak","grass","ziemniak","plant(szpinak)" -"water",100,"no_plant","grass","water","grass","grass","move" +tile_type,water_level,plant_stage,neighbor_N,neighbor_E,neighbor_W,neighbor_S,action +bób,0,planted,jarmuż,grass,brokuł,jarmuż,water +brokuł,0,growing,kalafior,brokuł,bób,kalafior,water +brukselka,0,growing,water,brukselka,grass,grass,water +burak,0,planted,bób,burak,brukselka,grass,water +cebula,0,growing,brokuł,cebula,burak,grass,water +cukinia,0,growing,grass,cukinia,water,grass,water +dynia,0,planted,grass,grass,cukinia,kalafior,water +fasola,0,growing,cebula,fasola,dynia,kalarepa,water +groch,0,growing,cukinia,grass,grass,kapusta,water +jarmuż,0,planted,dynia,grass,grass,brokuł,water +kalafior,0,growing,fasola,kalafior,jarmuż,brukselka,water +kalarepa,0,growing,groch,water,kalafior,burak,water +kapusta,0,planted,jarmuż,grass,grass,cebula,water +marchew,0,growing,water,marchew,kapusta,cukinia,water +ogórek,0,planted,kalarepa,ogórek,marchew,grass,water +papryka,0,planted,kapusta,papryka,grass,fasola,water +pietruszka,0,growing,marchew,water,papryka,groch,water +pomidor,0,planted,grass,pomidor,pietruszka,jarmuż,water +por,0,planted,grass,por,water,kalafior,water +rukola,0,planted,pietruszka,grass,por,kalarepa,water +rzepa,0,growing,pomidor,rzepa,grass,kapusta,water +rzodkiewka,0,planted,por,water,grass,marchew,water +sałata,0,growing,rukola,grass,rzodkiewka,ogórek,water +seler,0,planted,rzepa,grass,water,papryka,water +szpinak,0,growing,rzodkiewka,szpinak,seler,pietruszka,water +ziemiak,0,planted,water,ziemiak,grass,water,water +bób,0,grown,jarmuż,bób,grass,jarmuż,harvest +brokuł,10,grown,kalafior,grass,bób,kalafior,harvest +brukselka,20,grown,kalarepa,brukselka,brokuł,kalarepa,harvest +burak,30,grown,bób,grass,brukselka,fasola,harvest +cebula,40,grown,brokuł,cebula,grass,groch,harvest +cukinia,50,grown,brukselka,water,grass,jarmuż,harvest +dynia,0,grown,burak,grass,cukinia,kalafior,harvest +fasola,10,grown,cebula,grass,dynia,kalarepa,harvest +groch,20,grown,cukinia,groch,fasola,kapusta,harvest +jarmuż,30,grown,grass,water,groch,brokuł,harvest +kalafior,40,grown,fasola,kalafior,water,brukselka,harvest +kalarepa,50,grown,groch,grass,kalafior,burak,harvest +kapusta,0,grown,jarmuż,grass,kalarepa,cebula,harvest +marchew,10,grown,kalafior,grass,kapusta,grass,harvest +ogórek,20,grown,kalarepa,ogórek,marchew,dynia,harvest +papryka,30,grown,kapusta,papryka,grass,fasola,harvest +pietruszka,40,grown,marchew,grass,papryka,groch,harvest +pomidor,50,grown,water,pomidor,pietruszka,water,harvest +por,0,grown,papryka,grass,pomidor,kalafior,harvest +rukola,10,grown,pietruszka,grass,por,kalarepa,harvest +rzepa,20,grown,pomidor,grass,grass,kapusta,harvest +rzodkiewka,30,grown,grass,water,rzepa,water,harvest +sałata,40,grown,grass,sałata,rzodkiewka,ogórek,harvest +seler,50,grown,rzepa,water,sałata,papryka,harvest +szpinak,0,grown,rzodkiewka,szpinak,seler,pietruszka,harvest +ziemiak,10,grown,grass,por,pomidor,water,harvest +grass,10,no_plant,kapusta,ziemniak,grass,water,plant(bób) +grass,20,no_plant,grass,grass,ziemniak,grass,plant(bób) +grass,30,no_plant,kapusta,grass,kapusta,grass,plant(bób) +grass,40,no_plant,ziemniak,water,grass,kapusta,plant(bób) +grass,50,no_plant,grass,grass,water,grass,plant(burak) +grass,10,no_plant,water,grass,grass,water,plant(cebula) +grass,20,no_plant,por,grass,grass,por,plant(brokuł) +grass,30,no_plant,seler,ziemniak,grass,ziemniak,plant(brokuł) +grass,40,no_plant,grass,por,por,grass,plant(brokuł) +grass,50,no_plant,seler,grass,ziemniak,por,plant(brokuł) +grass,10,no_plant,grass,seler,ziemaniak,grass,plant(brokuł) +grass,20,no_plant,groch,kapusta,ogórek,pomidor,plant(burak) +grass,30,no_plant,rzodkiewka,kalarepa,sałata,seler,plant(burak) +grass,40,no_plant,kapusta,grass,water,kalarepa,plant(burak) +grass,50,no_plant,rzodkiewka,grass,water,grass,plant(burak) +grass,10,no_plant,grass,water,grass,pomidor,plant(burak) +grass,20,no_plant,grass,pomidor,grass,grass,plant(burak) +grass,30,no_plant,water,grass,kapusta,grass,plant(burak) +grass,40,no_plant,ogórek,water,grass,ogórek,plant(burak) +grass,50,no_plant,grass,rzodkiewka,groch,grass,plant(burak) +grass,10,no_plant,grass,grass,grass,pomidor,plant(burak) +grass,20,no_plant,kalarepa,water,rzodkiewka,grass,plant(burak) +grass,30,no_plant,cukinia,kalarepa,ogórek,pomidor,plant(cebula) +grass,40,no_plant,sałata,grass,water,grass,plant(cebula) +grass,50,no_plant,kalarepa,water,grass,grass,plant(cebula) +grass,10,no_plant,grass,cukinia,pomidor,grass,plant(cebula) +grass,20,no_plant,grass,grass,ogórek,pomidor,plant(cebula) +grass,30,no_plant,water,sałata,grass,water,plant(cebula) +grass,40,no_plant,sałata,grass,grass,ogórek,plant(cebula) +grass,50,no_plant,grass,kalarepa,water,grass,plant(cebula) +grass,10,no_plant,grass,grass,cukinia,grass,plant(cebula) +grass,20,no_plant,pomidor,water,kalarepa,water,plant(cebula) +grass,30,no_plant,water,grass,water,cukinia,plant(cebula) +grass,40,no_plant,ogórek,sałata,ogórek,grass,plant(cebula) +grass,50,no_plant,grass,grass,pomidor,sałata,plant(cebula) +grass,10,no_plant,water,kalarepa,sałata,grass,plant(cebula) +grass,20,no_plant,pomidor,kalarepa,grass,water,plant(cebula) +grass,30,no_plant,groch,water,szpinak,grass,plant(cukinia) +grass,40,no_plant,grass,szpinak,groch,szpinak,plant(cukinia) +grass,50,no_plant,groch,grass,groch,grass,plant(cukinia) +grass,10,no_plant,szpinak,water,szpinak,szpinak,plant(cukinia) +grass,20,no_plant,groch,grass,groch,grass,plant(cukinia) +grass,30,no_plant,grass,szpinak,grass,water,plant(cukinia) +grass,40,no_plant,szpinak,grass,groch,groch,plant(cukinia) +grass,50,no_plant,water,grass,szpinak,grass,plant(cukinia) +grass,10,no_plant,groch,groch,grass,szpinak,plant(cukinia) +grass,20,no_plant,grass,grass,water,szpinak,plant(cukinia) +grass,30,no_plant,szpinak,groch,szpinak,grass,plant(cukinia) +grass,40,no_plant,grass,groch,groch,water,plant(cukinia) +grass,50,no_plant,grass,szpinak,grass,groch,plant(cukinia) +grass,10,no_plant,szpinak,grass,grass,groch,plant(cukinia) +grass,20,no_plant,szpinak,water,grass,grass,plant(cukinia) +grass,30,no_plant,fasola,grass,grass,fasola,plant(dynia) +grass,40,no_plant,grass,grass,fasola,water,plant(dynia) +grass,50,no_plant,grass,fasola,water,fasola,plant(dynia) +grass,10,no_plant,fasola,water,grass,fasola,plant(dynia) +grass,20,no_plant,water,grass,grass,fasola,plant(dynia) +grass,30,no_plant,grass,water,fasola,grass,plant(dynia) +grass,40,no_plant,grass,fasola,water,grass,plant(dynia) +grass,50,no_plant,fasola,grass,fasola,water,plant(dynia) +grass,10,no_plant,fasola,grass,grass,fasola,plant(dynia) +grass,20,no_plant,jarmuź,ogórek,rzepa,seler,plant(fasola) +grass,30,no_plant,grass,water,ziemniak,szpinak,plant(fasola) +grass,40,no_plant,jarmuż,grass,water,ziemniak,plant(fasola) +grass,50,no_plant,ogórek,water,ogórek,grass,plant(fasola) +grass,10,no_plant,ogórek,jarmuż,water,grass,plant(fasola) +grass,20,no_plant,grass,ogórek,seler,grass,plant(fasola) +grass,30,no_plant,seler,grass,jarmuż,grass,plant(fasola) +grass,40,no_plant,grass,water,ogórek,ziemniak,plant(fasola) +grass,50,no_plant,grass,grass,ogórek,jarmuż,plant(fasola) +grass,10,no_plant,grass,seler,grass,ogórek,plant(fasola) +grass,20,no_plant,water,ziemniak,szpinak,water,plant(fasola) +grass,30,no_plant,ziemniak,rzepa,ziemniak,grass,plant(fasola) +grass,40,no_plant,water,grass,,rzepa,plant(fasola) +grass,50,no_plant,rzepa,rzepa,seler,ziemniak,plant(fasola) +grass,10,no_plant,grass,grass,water,szpinak,plant(fasola) +grass,20,no_plant,seler,grass,ziemniak,grass,plant(fasola) +grass,30,no_plant,grass,grass,rzepa,water,plant(fasola) +grass,40,no_plant,grass,ziemniak,grass,szpinak,plant(fasola) +grass,50,no_plant,ziemniak,seler,grass,water,plant(fasola) +grass,10,no_plant,grass,rzepa,szpinak,grass,plant(fasola) +grass,20,no_plant,water,grass,grass,grass,plant(fasola) +grass,30,no_plant,grass,szpinak,water,grass,plant(fasola) +grass,40,no_plant,szpinak,grass,ziemniak,rzepa,plant(fasola) +grass,50,no_plant,rzepa,grass,ziemniak,grass,plant(fasola) +grass,10,no_plant,kalarepa,marchew,ogórek,rzepa,plant(groch) +grass,20,no_plant,seler,kapusta,szpinak,rzodkiewka,plant(groch) +grass,30,no_plant,marchew,kalarepa,grass,rzodkiewka,plant(groch) +grass,40,no_plant,grass,marchew,grass,grass,plant(groch) +grass,50,no_plant,ogórek,grass,kalarepa,rzodkiewka,plant(groch) +grass,10,no_plant,seler,rzodkiewka,grass,marchew,plant(groch) +grass,20,no_plant,szpinak,grass,machew,kalarepa,plant(groch) +grass,30,no_plant,rzodkiewka,water,grass,grass,plant(groch) +grass,40,no_plant,water,kalarepa,rzepa,szpinak,plant(groch) +grass,50,no_plant,marchew,grass,seler,water,plant(groch) +grass,10,no_plant,kalarepa,rzodkiewka,marchew,water,plant(groch) +grass,20,no_plant,grass,grass,seler,water,plant(groch) +grass,30,no_plant,ogórek,szpinak,water,rzepa,plant(groch) +grass,40,no_plant,rzodkiewka,grass,marchew,seler,plant(groch) +grass,50,no_plant,kapusta,grass,water,grass,plant(jarmuż) +grass,10,no_plant,grass,kapusta,water,grass,plant(jarmuż) +grass,20,no_plant,water,grass,kapusta,grass,plant(jarmuż) +grass,30,no_plant,kapusta,water,grass,kapusta,plant(jarmuż) +grass,40,no_plant,seler,grass,water,szpinak,plant(kapusta) +grass,50,no_plant,water,szpinak,grass,szpinak,plant(kalarepa) +grass,10,no_plant,grass,grass,ziemniak,ziemniak,plant(kalarepa) +grass,20,no_plant,water,grass,szpinak,ziemniak,plant(kalarepa) +grass,30,no_plant,grass,szpinak,seler,grass,plant(kapusta) +grass,40,no_plant,grass,water,szpinak,seler,plant(kalarepa) +grass,50,no_plant,grass,szpinak,grass,grass,plant(kalarepa) +grass,10,no_plant,szpinak,ziemniak,seler,water,plant(kalarepa) +grass,20,no_plant,ziemniak,szpinak,grass,seler,plant(kalarepa) +grass,30,no_plant,grass,water,ziemniak,grass,plant(kalarepa) +grass,40,no_plant,seler,szpinak,seler,grass,plant(kapusta) +grass,50,no_plant,szpinak,water,grass,grass,plant(kapusta) +grass,10,no_plant,water,grass,grass,seler,plant(kapusta) +grass,20,no_plant,ogórek,water,grass,ogórek,plant(marchew) +grass,30,no_plant,grass,ogórek,water,grass,plant(marchew) +grass,40,no_plant,water,grass,grass,ogórek,plant(marchew) +grass,50,no_plant,por,szpinak,grass,seler,plant(ogórek) +grass,10,no_plant,water,por,szpinak,grass,plant(ogórek) +grass,20,no_plant,seler,water,por,grass,plant(ogórek) +grass,30,no_plant,grass,grass,grass,por,plant(ogórek) +grass,40,no_plant,szpinak,seler,grass,water,plant(ogórek) +grass,50,no_plant,water,grass,szpinak,seler,plant(ogórek) +grass,10,no_plant,por,grass,rzodkiewka,water,plant(pietruszka) +grass,20,no_plant,grass,rzodkiewka,por,rzodkiewka,plant(pietruszka) +grass,30,no_plant,rzodkiewka,grass,grass,water,plant(pietruszka) +grass,40,no_plant,water,por,grass,por,plant(pietruszka) +grass,50,no_plant,por,grass,grass,por,plant(pomidor) +grass,10,no_plant,water,rzepa,seler,water,plant(pomidor) +grass,20,no_plant,rzepa,water,seler,grass,plant(pomidor) +grass,30,no_plant,grass,grass,grass,szpinak,plant(pomidor) +grass,40,no_plant,szpinak,water,por,grass,plant(pomidor) +grass,50,no_plant,rzepa,seler,grass,por,plant(pomidor) +grass,10,no_plant,water,grass,grass,grass,plant(pomidor) +grass,40,no_plant,grass,rzodkiewka,sałata,szpinak,plant(por) +grass,50,no_plant,szpinak,grass,water,sałata,plant(por) +grass,10,no_plant,rzodkiewka,grass,szpinak,water,plant(por) +grass,20,no_plant,water,szpinak,grass,sałata,plant(por) +grass,30,no_plant,rzodkiewka,grass,sałata,grass,plant(por) +grass,40,no_plant,water,grass,grass,seler,plant(rzepa) +grass,50,no_plant,grass,grass,szpinak,water,plant(rzepa) +grass,10,no_plant,water,seler,grass,water,plant(rzepa) +grass,20,no_plant,seler,szpinak,grass,grass,plant(rzepa) +grass,30,no_plant,grass,water,szpinak,seler,plant(rzepa) +grass,40,no_plant,water,grass,szpinak,grass,plant(rzodkiewka) +grass,50,no_plant,water,grass,water,szpinak,plant(rzodkiewka) +grass,10,no_plant,grass,grass,szpinak,grass,plant(rzodkiewka) +grass,20,no_plant,szpinak,water,szpinak,grass,plant(rzodkiewka) +grass,30,no_plant,water,szpinak,grass,ziemniak,plant(rzodkiewka) +grass,40,no_plant,szpinak,grass,water,grass,plant(seler) +grass,50,no_plant,water,szpinak,grass,grass,plant(seler) +grass,10,no_plant,szpinak,grass,szpinak,water,plant(seler) +grass,20,no_plant,szpinak,grass,water,szpinak,plant(seler) +grass,30,no_plant,grass,ziemniak,ziemniak,water,plant(szpinak) +grass,40,no_plant,grass,grass,ziemniak,water,plant(szpinak) +grass,50,no_plant,grass,ziemniak,grass,ziemniak,plant(szpinak) +water,100,no_plant,grass,water,grass,grass,move From c341c022490768521f7e627f37f782a901d29f5c Mon Sep 17 00:00:00 2001 From: Adam Mikolajczak Date: Sun, 12 May 2024 17:31:30 +0200 Subject: [PATCH 2/3] fix: tractor doesn't explode when it encounters onion anymore. --- src/.~lock.tree.csv# | 2 +- src/tile.py | 4 ++++ src/tractor.py | 10 +++++----- src/tree.csv | 7 +++++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/.~lock.tree.csv# b/src/.~lock.tree.csv# index 04f86c16..4d687959 100644 --- a/src/.~lock.tree.csv# +++ b/src/.~lock.tree.csv# @@ -1 +1 @@ -,adam,adam-thinkpad,12.05.2024 10:10,file:///home/adam/.config/libreoffice/4; \ No newline at end of file +,adam,adam-thinkpad,12.05.2024 17:16,file:///home/adam/.config/libreoffice/4; \ No newline at end of file diff --git a/src/tile.py b/src/tile.py index 09bcccd2..b644f393 100644 --- a/src/tile.py +++ b/src/tile.py @@ -19,6 +19,10 @@ class Tile(pygame.sprite.Sprite): if random.randint(1, 10) % FREE_TILES == 0: vegetables = tractor_kb.query(pl.Expr("warzywo(Nazwa_warzywa)")) random_vegetable = vegetables[random.randint(0, len(vegetables)-1)]['Nazwa_warzywa'] + + if random_vegetable in {'cebula','pietruszka','bób'}: + random_vegetable = 'marchew' + self.set_type(random_vegetable) self.water_level = random.randint(1, 5) * 10 self.stage = 'planted' # wczesniej to była self.faza = 'posadzono' ale stwierdzilem ze lepiej po angielsku??? diff --git a/src/tractor.py b/src/tractor.py index acdda808..74b8d266 100644 --- a/src/tractor.py +++ b/src/tractor.py @@ -62,7 +62,7 @@ class Tractor(pygame.sprite.Sprite): if len(neighbors) < 4: for _ in range(len(neighbors), 4): neighbors.append('grass') - # Przygotowanie danych wejściowych dla modelu + input_data = { 'tile_type': self.get_current_tile().type, 'water_level': self.get_current_tile().water_level, @@ -78,7 +78,7 @@ class Tractor(pygame.sprite.Sprite): if column == 'action': continue input_value = input_data.get(column) input_values.append(encoder.transform([input_value])[0]) - + # Przewidywanie akcji za pomocą modelu predicted_action_index = self.decision_tree_model.predict([input_values])[0] @@ -139,7 +139,7 @@ class Tractor(pygame.sprite.Sprite): case ('water'): self.get_current_tile().water_level += 10 case ('plant(bób)'): - self.get_current_tile().set_type('bób') + self.get_current_tile().set_type('marchew') case ('plant(brokuł)'): self.get_current_tile().set_type('brokuł') case ('plant(brukselka)'): @@ -147,7 +147,7 @@ class Tractor(pygame.sprite.Sprite): case ('plant(burak)'): self.get_current_tile().set_type('burak') case ('plant(cebula)'): - self.get_current_tile().set_type('cebula') + self.get_current_tile().set_type('marchew') case ('plant(cukinia)'): self.get_current_tile().set_type('cukinia') case ('plant(dynia)'): @@ -171,7 +171,7 @@ class Tractor(pygame.sprite.Sprite): case ('plant(papryka)'): self.get_current_tile().set_type('papryka') case ('plant(pietruszka)'): - self.get_current_tile().set_type('pietruszka') + self.get_current_tile().set_type('marchew') case ('plant(pomidor)'): self.get_current_tile().set_type('pomidor') case ('plant(por)'): diff --git a/src/tree.csv b/src/tree.csv index 15347e62..026508dc 100644 --- a/src/tree.csv +++ b/src/tree.csv @@ -210,3 +210,10 @@ grass,30,no_plant,grass,ziemniak,ziemniak,water,plant(szpinak) grass,40,no_plant,grass,grass,ziemniak,water,plant(szpinak) grass,50,no_plant,grass,ziemniak,grass,ziemniak,plant(szpinak) water,100,no_plant,grass,water,grass,grass,move +cebula,10,growing,grass,grass,burak,grass,move +cebula,20,growing,szpinak,water,grass,ziemniak,move +cebula,30,growing,water,szpinak,marchew,ogórek,move +cebula,40,growing,szpinak,grass,kapusta,szpinak,move +cebula,50,growing,water,szpinak,kalarepa,grass,move +cebula,10,growing,szpinak,grass,marchew,grass,move +cebula,20,growing,grass,cebula,burak,grass,move From eb34cbfab3cfe31a2b799bfc4886b604f9793209 Mon Sep 17 00:00:00 2001 From: Adam Mikolajczak Date: Sun, 12 May 2024 18:24:34 +0200 Subject: [PATCH 3/3] fix: tractor does not explode after seeing dynia anymore --- src/.~lock.tree.csv# | 1 - src/tile.py | 2 +- src/tractor.py | 32 ++++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 6 deletions(-) delete mode 100644 src/.~lock.tree.csv# diff --git a/src/.~lock.tree.csv# b/src/.~lock.tree.csv# deleted file mode 100644 index 4d687959..00000000 --- a/src/.~lock.tree.csv# +++ /dev/null @@ -1 +0,0 @@ -,adam,adam-thinkpad,12.05.2024 17:16,file:///home/adam/.config/libreoffice/4; \ No newline at end of file diff --git a/src/tile.py b/src/tile.py index b644f393..e4821838 100644 --- a/src/tile.py +++ b/src/tile.py @@ -20,7 +20,7 @@ class Tile(pygame.sprite.Sprite): vegetables = tractor_kb.query(pl.Expr("warzywo(Nazwa_warzywa)")) random_vegetable = vegetables[random.randint(0, len(vegetables)-1)]['Nazwa_warzywa'] - if random_vegetable in {'cebula','pietruszka','bób'}: + if random_vegetable in {'cebula','pietruszka','bób', 'dynia'}: random_vegetable = 'marchew' self.set_type(random_vegetable) diff --git a/src/tractor.py b/src/tractor.py index 74b8d266..97b1b7f7 100644 --- a/src/tractor.py +++ b/src/tractor.py @@ -110,6 +110,31 @@ class Tractor(pygame.sprite.Sprite): self.rect.x += TILE_SIZE # self.log_info() + def move_rotating(self): + if self.direction == "north": + if self.rect.y > 0: + self.rect.y -= TILE_SIZE + else: + self.rotate('left') + self.rect.x -= TILE_SIZE + elif self.direction == "south": + if self.rect.y < 15 * TILE_SIZE: + self.rect.y += TILE_SIZE + else: + self.rotate('left') + self.rect.x += TILE_SIZE + elif self.direction == "west": + if self.rect.x > 0: + self.rect.x -= TILE_SIZE + else: + self.rotate('left') + self.rect.y += TILE_SIZE + elif self.direction == "east": + if self.rect.x < 15 * TILE_SIZE: + self.rect.x += TILE_SIZE + else: + self.rotate('left') + self.rect.y -= TILE_SIZE def update(self): # A STAR: @@ -129,11 +154,11 @@ class Tractor(pygame.sprite.Sprite): action = self.make_decision() self.prev_action = action if self.prev_action is not None and self.prev_action != 'move': - self.move() + self.move_rotating() self.prev_action = 'move' match (action): case ('move'): - self.move() + self.move_rotating() case ('harvest'): self.get_current_tile().set_type('grass') case ('water'): @@ -151,7 +176,7 @@ class Tractor(pygame.sprite.Sprite): case ('plant(cukinia)'): self.get_current_tile().set_type('cukinia') case ('plant(dynia)'): - self.get_current_tile().set_type('dynia') + self.get_current_tile().set_type('fasola') case ('plant(fasola)'): self.get_current_tile().set_type('fasola') case ('plant(groch)'): @@ -192,7 +217,6 @@ class Tractor(pygame.sprite.Sprite): print(action) return - def log_info(self): # print on what tile type the tractor is on x = self.rect.x // TILE_SIZE