diff --git a/App.py b/App.py index 36f4428..e591717 100644 --- a/App.py +++ b/App.py @@ -9,9 +9,7 @@ import Osprzet import Ui import BFS import AStar -import random -import Condition -import Drzewo + bfs1_flag=False bfs2_flag=False #Change this lines to show different bfs implementation @@ -36,8 +34,7 @@ ui=Ui.Ui(screen) #Tractor creation traktor_slot = pole.get_slot_from_cord((0, 0)) traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.opryskiwacz,clock,bfs2_flag) -condition=Condition.Condition() -drzewo=Drzewo.Drzewo() + def init_demo(): #Demo purpose old_info="" @@ -117,14 +114,10 @@ def init_demo(): #Demo purpose print_to_console("Nie można znaleźć ścieżki A*") # Wyświetl komunikat, jeśli nie znaleziono ścieżki if(TreeFlag): - drzewo.treeLearn() - drzewo.plotTree() - print("Decyzja to: ",drzewo.makeDecision([[10,60,0,1,1,0,20,1,20]])) - #do moves and condtion cycles + traktor.move_forward(pole) + traktor.tree_move() start_flag=False # demo_move() - condition.cycle() #powinno zostac wrzucone razem z getCondition do ruchu traktora. Aktualnie tutaj by zobaczyc czy dziala - condition.getCondition() old_info=get_info(old_info) for event in pygame.event.get(): if event.type == pygame.QUIT: diff --git a/Condition.py b/Condition.py index 4cff640..e8d662a 100644 --- a/Condition.py +++ b/Condition.py @@ -38,6 +38,10 @@ class Condition: self.temperature=self.setRandomTemperature() self.clock=self.clock+1 + def return_condition(self): + return [self.temperature,self.rain,self.season,self.currentTime] + + def getCondition(self): print(f"Aktualny czas: {Climate.time[self.currentTime]},opady: {Climate.rain[self.rain]},temperatura: {Climate.temperature[self.temperature]}, pora roku: {Climate.seasons[self.season]}") \ No newline at end of file diff --git a/Data/dataTree.csv b/Data/dataTree.csv index 08b4186..d7e9089 100644 --- a/Data/dataTree.csv +++ b/Data/dataTree.csv @@ -1,3 +1,3 @@ -plant_water_level,tractor_water_level,temperature,rain,season,current_time,growth,disease,fertility,action -80,60,3,2,1,0,20,1,20,0 -20,60,3,0,1,0,20,1,20,1 \ No newline at end of file +plant_water_level,growth,disease,fertility,tractor_water_level,temperature,rain,season,current_time,action +80,20,0,90,40,2,0,1,0,0 +50,20,0,90,80,2,0,1,0,1 \ No newline at end of file diff --git a/Drzewo.py b/Drzewo.py index c883c1a..37da039 100644 --- a/Drzewo.py +++ b/Drzewo.py @@ -2,7 +2,7 @@ from sklearn import tree as skltree import pandas,os import matplotlib.pyplot as plt -atributes=['plant_water_level','tractor_water_level','temperature','rain','season','current_time','growth','disease','fertility'] #Columns in CSV file should be in the same order +atributes=['plant_water_level','growth','disease','fertility','tractor_water_level','temperature','rain','season','current_time'] #Columns in CSV file has to be in the same order class Drzewo: def __init__(self): self.tree=self.treeLearn() @@ -12,14 +12,14 @@ class Drzewo: x=csvdata[atributes] decision=csvdata['action'] self.tree=skltree.DecisionTreeClassifier() - self.tree=self.tree.fit(x,decision) + self.tree=self.tree.fit(x.values,decision) def plotTree(self): plt.figure() skltree.plot_tree(self.tree,filled=True,feature_names=atributes) plt.title("Drzewo decyzyjne wytrenowane na przygotowanych danych") + plt.savefig('tree.png') plt.show() - def makeDecision(self,values): - action=self.tree.predict(values) #0- nie podlewac, 1-podlewac + action=self.tree.predict([values]) #0- nie podlewac, 1-podlewac return action \ No newline at end of file diff --git a/Image.py b/Image.py index 3a8557d..a755f0a 100644 --- a/Image.py +++ b/Image.py @@ -37,7 +37,7 @@ class Image: self.gasStation_image=pygame.transform.scale(gasStation,(dCon.CUBE_SIZE,dCon.CUBE_SIZE)) def return_random_plant(self): - x=random.randint(0,7) + x=random.randint(0,5) #disabled dirt and mud generation keys=list(self.plants_image_dict.keys()) plant=keys[x] return (plant,self.plants_image_dict[plant]) diff --git a/Roslina.py b/Roslina.py index 103fd03..b63acb7 100644 --- a/Roslina.py +++ b/Roslina.py @@ -110,6 +110,9 @@ class Roslina: def return_stan(self): return self.stan + def return_stan_for_tree(self): + return self.stan.return_stan_for_tree() + def get_hydrate_stats(self): return self.stan.return_hydrate() diff --git a/Slot.py b/Slot.py index a29b815..3b07fb6 100644 --- a/Slot.py +++ b/Slot.py @@ -82,4 +82,6 @@ class Slot: self.plant.stan.nawodnienie=random.randint(61,100) elif(index==-1): pass - \ No newline at end of file + + def return_stan_for_tree(self): + return self.plant.return_stan_for_tree() \ No newline at end of file diff --git a/Stan.py b/Stan.py index cad76a1..d64047a 100644 --- a/Stan.py +++ b/Stan.py @@ -57,5 +57,9 @@ class Stan: return "Zdrowa" if(self.choroba==1): return "Chora" + + def return_stan_for_tree(self): + return [self.nawodnienie,self.wzrost,self.choroba,self.zyznosc] + def report_all(self): return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.return_disease_as_string()}" \ No newline at end of file diff --git a/Tractor.py b/Tractor.py index a55fcc1..df49982 100644 --- a/Tractor.py +++ b/Tractor.py @@ -7,6 +7,12 @@ import displayControler as dCon import Slot import Osprzet import Node +import Condition +import Drzewo + +condition=Condition.Condition() +drzewo=Drzewo.Drzewo() + tab = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, @@ -57,6 +63,17 @@ class Tractor: self.current_tractor_image = self.tractor_images[self.direction] self.draw_tractor() + def tree_move(self): + drzewo.treeLearn() + drzewo.plotTree() + slot_attributes=self.slot.return_stan_for_tree() + climate_attributes=condition.return_condition() + attributes=[] + attributes=attributes+slot_attributes+[self.waterLevel]+climate_attributes + print("Decyzja czy podlac:",drzewo.makeDecision(attributes),"Atrybuty tego stanu to:",attributes) + #TODO SNAKE MOVE AND USING drzewo.makeDecision(attributes)for each slot. Also we need to cycle climate for each slot change by + #condition.cycle() + #condition.getCondition() def turn_right(self): # zmiana kierunku w prawo direction_map = {