Compare commits
No commits in common. "12d2ba0d8111040e7d7b8c28863b3d27a0897e3e" and "de695926129afac563f8bb75649b7805e9286f58" have entirely different histories.
12d2ba0d81
...
de69592612
15
App.py
15
App.py
@ -9,7 +9,9 @@ import Osprzet
|
|||||||
import Ui
|
import Ui
|
||||||
import BFS
|
import BFS
|
||||||
import AStar
|
import AStar
|
||||||
|
import random
|
||||||
|
import Condition
|
||||||
|
import Drzewo
|
||||||
|
|
||||||
bfs1_flag=False
|
bfs1_flag=False
|
||||||
bfs2_flag=False #Change this lines to show different bfs implementation
|
bfs2_flag=False #Change this lines to show different bfs implementation
|
||||||
@ -34,7 +36,8 @@ ui=Ui.Ui(screen)
|
|||||||
#Tractor creation
|
#Tractor creation
|
||||||
traktor_slot = pole.get_slot_from_cord((0, 0))
|
traktor_slot = pole.get_slot_from_cord((0, 0))
|
||||||
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.opryskiwacz,clock,bfs2_flag)
|
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.opryskiwacz,clock,bfs2_flag)
|
||||||
|
condition=Condition.Condition()
|
||||||
|
drzewo=Drzewo.Drzewo()
|
||||||
|
|
||||||
def init_demo(): #Demo purpose
|
def init_demo(): #Demo purpose
|
||||||
old_info=""
|
old_info=""
|
||||||
@ -114,10 +117,14 @@ def init_demo(): #Demo purpose
|
|||||||
print_to_console("Nie można znaleźć ścieżki A*") # Wyświetl komunikat, jeśli nie znaleziono ścieżki
|
print_to_console("Nie można znaleźć ścieżki A*") # Wyświetl komunikat, jeśli nie znaleziono ścieżki
|
||||||
|
|
||||||
if(TreeFlag):
|
if(TreeFlag):
|
||||||
traktor.move_forward(pole)
|
drzewo.treeLearn()
|
||||||
traktor.tree_move()
|
drzewo.plotTree()
|
||||||
|
print("Decyzja to: ",drzewo.makeDecision([[10,60,0,1,1,0,20,1,20]]))
|
||||||
|
#do moves and condtion cycles
|
||||||
start_flag=False
|
start_flag=False
|
||||||
# demo_move()
|
# 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)
|
old_info=get_info(old_info)
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
|
@ -38,10 +38,6 @@ class Condition:
|
|||||||
self.temperature=self.setRandomTemperature()
|
self.temperature=self.setRandomTemperature()
|
||||||
self.clock=self.clock+1
|
self.clock=self.clock+1
|
||||||
|
|
||||||
def return_condition(self):
|
|
||||||
return [self.temperature,self.rain,self.season,self.currentTime]
|
|
||||||
|
|
||||||
|
|
||||||
def getCondition(self):
|
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]}")
|
print(f"Aktualny czas: {Climate.time[self.currentTime]},opady: {Climate.rain[self.rain]},temperatura: {Climate.temperature[self.temperature]}, pora roku: {Climate.seasons[self.season]}")
|
||||||
|
|
@ -1,3 +1,3 @@
|
|||||||
plant_water_level,growth,disease,fertility,tractor_water_level,temperature,rain,season,current_time,action
|
plant_water_level,tractor_water_level,temperature,rain,season,current_time,growth,disease,fertility,action
|
||||||
80,20,0,90,40,2,0,1,0,0
|
80,60,3,2,1,0,20,1,20,0
|
||||||
50,20,0,90,80,2,0,1,0,1
|
20,60,3,0,1,0,20,1,20,1
|
|
@ -2,7 +2,7 @@ from sklearn import tree as skltree
|
|||||||
import pandas,os
|
import pandas,os
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
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
|
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
|
||||||
class Drzewo:
|
class Drzewo:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.tree=self.treeLearn()
|
self.tree=self.treeLearn()
|
||||||
@ -12,14 +12,14 @@ class Drzewo:
|
|||||||
x=csvdata[atributes]
|
x=csvdata[atributes]
|
||||||
decision=csvdata['action']
|
decision=csvdata['action']
|
||||||
self.tree=skltree.DecisionTreeClassifier()
|
self.tree=skltree.DecisionTreeClassifier()
|
||||||
self.tree=self.tree.fit(x.values,decision)
|
self.tree=self.tree.fit(x,decision)
|
||||||
|
|
||||||
def plotTree(self):
|
def plotTree(self):
|
||||||
plt.figure()
|
plt.figure()
|
||||||
skltree.plot_tree(self.tree,filled=True,feature_names=atributes)
|
skltree.plot_tree(self.tree,filled=True,feature_names=atributes)
|
||||||
plt.title("Drzewo decyzyjne wytrenowane na przygotowanych danych")
|
plt.title("Drzewo decyzyjne wytrenowane na przygotowanych danych")
|
||||||
plt.savefig('tree.png')
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
def makeDecision(self,values):
|
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
|
return action
|
2
Image.py
2
Image.py
@ -37,7 +37,7 @@ class Image:
|
|||||||
self.gasStation_image=pygame.transform.scale(gasStation,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
self.gasStation_image=pygame.transform.scale(gasStation,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||||
|
|
||||||
def return_random_plant(self):
|
def return_random_plant(self):
|
||||||
x=random.randint(0,5) #disabled dirt and mud generation
|
x=random.randint(0,7)
|
||||||
keys=list(self.plants_image_dict.keys())
|
keys=list(self.plants_image_dict.keys())
|
||||||
plant=keys[x]
|
plant=keys[x]
|
||||||
return (plant,self.plants_image_dict[plant])
|
return (plant,self.plants_image_dict[plant])
|
||||||
|
@ -110,9 +110,6 @@ class Roslina:
|
|||||||
def return_stan(self):
|
def return_stan(self):
|
||||||
return self.stan
|
return self.stan
|
||||||
|
|
||||||
def return_stan_for_tree(self):
|
|
||||||
return self.stan.return_stan_for_tree()
|
|
||||||
|
|
||||||
def get_hydrate_stats(self):
|
def get_hydrate_stats(self):
|
||||||
return self.stan.return_hydrate()
|
return self.stan.return_hydrate()
|
||||||
|
|
||||||
|
2
Slot.py
2
Slot.py
@ -83,5 +83,3 @@ class Slot:
|
|||||||
elif(index==-1):
|
elif(index==-1):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def return_stan_for_tree(self):
|
|
||||||
return self.plant.return_stan_for_tree()
|
|
19
Stan.py
19
Stan.py
@ -5,7 +5,7 @@ class Stan:
|
|||||||
nawodnienie = None #[int] 0-100 (0-60: trzeba podlać), spada w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
nawodnienie = None #[int] 0-100 (0-60: trzeba podlać), spada w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
||||||
zyznosc = None #[int] 0-100 (0-60: trzeba użyźnić), spada w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
zyznosc = None #[int] 0-100 (0-60: trzeba użyźnić), spada w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
||||||
wzrost = None #[int] 0-100 (75-100: scinanie), wzrasta w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
wzrost = None #[int] 0-100 (75-100: scinanie), wzrasta w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
||||||
choroba = None #[int] brak-0,choroba-1
|
choroba = None #[string] brak, grzyb, bakteria, pasożyt
|
||||||
akcja = None #[Akcja]
|
akcja = None #[Akcja]
|
||||||
koszt = None #[int] 0-15, im więcej tym trudniej wjechać
|
koszt = None #[int] 0-15, im więcej tym trudniej wjechać
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class Stan:
|
|||||||
self.nawodnienie=random.randint(0,100)
|
self.nawodnienie=random.randint(0,100)
|
||||||
self.zyznosc=random.randint(0,100)
|
self.zyznosc=random.randint(0,100)
|
||||||
self.wzrost=random.randint(0,100)
|
self.wzrost=random.randint(0,100)
|
||||||
self.choroba=random.randint(0,1)
|
self.choroba=random.choice(["brak","grzyb","bakteria","pasozyt"])
|
||||||
|
|
||||||
def checkStan(self):
|
def checkStan(self):
|
||||||
# sprawdza stan rośliny i podejmuje akcje jeśli potrzebna
|
# sprawdza stan rośliny i podejmuje akcje jeśli potrzebna
|
||||||
@ -48,18 +48,5 @@ class Stan:
|
|||||||
def return_hydrate(self):
|
def return_hydrate(self):
|
||||||
return self.nawodnienie
|
return self.nawodnienie
|
||||||
|
|
||||||
|
|
||||||
def return_disease(self):
|
|
||||||
return self.choroba
|
|
||||||
|
|
||||||
def return_disease_as_string(self):
|
|
||||||
if(self.choroba==0):
|
|
||||||
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):
|
def report_all(self):
|
||||||
return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.return_disease_as_string()}"
|
return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.choroba} Koszt wejścia: {self.koszt}"
|
17
Tractor.py
17
Tractor.py
@ -7,12 +7,6 @@ import displayControler as dCon
|
|||||||
import Slot
|
import Slot
|
||||||
import Osprzet
|
import Osprzet
|
||||||
import Node
|
import Node
|
||||||
import Condition
|
|
||||||
import Drzewo
|
|
||||||
|
|
||||||
condition=Condition.Condition()
|
|
||||||
drzewo=Drzewo.Drzewo()
|
|
||||||
|
|
||||||
|
|
||||||
tab = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
|
tab = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
|
1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
|
||||||
@ -63,17 +57,6 @@ class Tractor:
|
|||||||
self.current_tractor_image = self.tractor_images[self.direction]
|
self.current_tractor_image = self.tractor_images[self.direction]
|
||||||
self.draw_tractor()
|
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):
|
def turn_right(self):
|
||||||
# zmiana kierunku w prawo
|
# zmiana kierunku w prawo
|
||||||
direction_map = {
|
direction_map = {
|
||||||
|
Loading…
Reference in New Issue
Block a user