Merge old branches to refactor due to merge it with master #22

Merged
s481825 merged 20 commits from tree into refactor 2024-06-04 11:36:14 +02:00
6 changed files with 63 additions and 49 deletions
Showing only changes of commit 51fe19a071 - Show all commits

2
App.py
View File

@ -119,7 +119,7 @@ def init_demo(): #Demo purpose
if(TreeFlag): if(TreeFlag):
drzewo.treeLearn() drzewo.treeLearn()
drzewo.plotTree() drzewo.plotTree()
print("Decyzja to: ",drzewo.makeDecision([[10,60,0,1,0,20,1,20]])) print("Decyzja to: ",drzewo.makeDecision([[10,60,0,1,1,0,20,1,20]]))
#do moves and condtion cycles #do moves and condtion cycles
start_flag=False start_flag=False
# demo_move() # demo_move()

View File

@ -1,40 +1,49 @@
#THESE DICTIONARIES ARE USED FOR DISPLAY AND FOR DOCUMENTATION PURPOSES
seasons={ seasons={
0:"winter", 0:"zima",
1:"spring", 1:"wiosna",
2:"summer", 2:"lato",
3:"fall"} 3:"jesien"}
time={ time={
0:"morning", 0:"rano",
1:"noon", 1:"poludnie",
2:"afternoon", 2:"wieczor",
3:"night"} 3:"noc"}
weather={ rain={
0:"perfect", 0:"brak",
1:"hot", 1:"lekki deszcz",
2:"cold", 2:"normalny deszcz",
3:"freezing", 3:"ulewa"
4:"rainy", }
5:"snowy",
6:"storm"} temperature={
0:"bardzo zimno",
1:"zimno",
2:"przecietnie",
3:"cieplo",
4:"upal",}
def getNextSeason(season): def getNextSeason(season):
if(season=="winter"): if(season==3):
return seasons[1] return 0
if(season=="spring"): else:
return seasons[2] return season+1
if(season=="summer"):
return seasons[3]
if(season=="fall"):
return seasons[0]
def getNextTime(currentTime): def getNextTime(currentTime):
if(currentTime=="morning"): if(currentTime==3):
return time[1] return 0
if(currentTime=="noon"): else:
return time[2] return currentTime+1
if(currentTime=="afternoon"):
return time[3] def getAmount(type):
if(currentTime=="night"): if(type=="seasons"):
return time[0] return len(seasons)
if(type=="rain"):
return len(rain)
if(type=="time"):
return len(time)
if(type=="temperature"):
return len(temperature)

View File

@ -5,34 +5,39 @@ class Condition:
def __init__(self): def __init__(self):
self.season=self.setRandomSeason() self.season=self.setRandomSeason()
self.currentTime=self.setRandomTime() self.currentTime=self.setRandomTime()
self.weather=self.setRandomWeather() self.rain=self.setRandomRain()
self.temperature=self.setRandomRain()
self.clock=0 self.clock=0
def setRandomSeason(self): def setRandomSeason(self):
return Climate.seasons[self.randomizer(3)] return self.randomizer(Climate.getAmount("seasons"))
def setRandomTime(self): def setRandomTime(self):
return Climate.time[self.randomizer(3)] return self.randomizer(Climate.getAmount("time"))
def setRandomWeather(self): def setRandomRain(self):
return Climate.weather[self.randomizer(6)] return self.randomizer(Climate.getAmount("rain"))
def setRandomTemperature(self):
return self.randomizer(Climate.getAmount("temperature"))
def randomizer(self,maxIndex): def randomizer(self,max):
return random.randint(0,maxIndex) return random.randint(0,max-1)
def cycle(self): def cycle(self):
if(self.clock==12): if(self.clock==12):
self.currentTime=Climate.time[0] self.currentTime=0
self.weather=self.setRandomWeather() self.rain=self.setRandomRain()
self.temperature=self.setRandomTemperature()
self.season=Climate.getNextSeason(self.season) self.season=Climate.getNextSeason(self.season)
self.clock=0 self.clock=0
return return
else: else:
self.currentTime=Climate.getNextTime(self.currentTime) self.currentTime=Climate.getNextTime(self.currentTime)
self.weather=self.setRandomWeather() self.rain=self.setRandomRain()
self.temperature=self.setRandomTemperature()
self.clock=self.clock+1 self.clock=self.clock+1
def getCondition(self): def getCondition(self):
print(f"Aktualny czas: {self.currentTime},pogoda: {self.weather}, pora roku: {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]}")

View File

@ -1,3 +1,3 @@
plant_water_lever,tractor_water_lever,weather,season,current_time,growth,disease,fertility,action plant_water_level,tractor_water_level,temperature,rain,season,current_time,growth,disease,fertility,action
80,60,0,1,0,20,1,20,0 80,60,3,2,1,0,20,1,20,0
20,60,0,1,0,20,1,20,1 20,60,3,0,1,0,20,1,20,1
1 plant_water_level tractor_water_level temperature rain season current_time growth disease fertility action
2 80 60 3 2 1 0 20 1 20 0
3 20 60 3 0 1 0 20 1 20 1

View File

@ -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_lever','tractor_water_lever','weather','season','current_time','growth','disease','fertility'] #Columns in CSV file should 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()

View File

@ -39,7 +39,7 @@ class Tractor:
self.clock=clock self.clock=clock
self.slot_hydrate_dict={} self.slot_hydrate_dict={}
self.bfs2_flag=bfs2_flag self.bfs2_flag=bfs2_flag
self.waterLevel=random.randint(0,100)
def draw_tractor(self): def draw_tractor(self):
self.screen.blit(self.current_tractor_image, (self.slot.x_axis * dCon.CUBE_SIZE, self.slot.y_axis * dCon.CUBE_SIZE)) self.screen.blit(self.current_tractor_image, (self.slot.x_axis * dCon.CUBE_SIZE, self.slot.y_axis * dCon.CUBE_SIZE))