This: -switched data for tree from strings to int -broke weather atributte to temperature and rain -added waterLevel for tractor

This commit is contained in:
jakzar 2024-05-11 13:24:09 +02:00
parent f8a3156678
commit 51fe19a071
6 changed files with 63 additions and 49 deletions

2
App.py
View File

@ -119,7 +119,7 @@ def init_demo(): #Demo purpose
if(TreeFlag):
drzewo.treeLearn()
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
start_flag=False
# demo_move()

View File

@ -1,40 +1,49 @@
#THESE DICTIONARIES ARE USED FOR DISPLAY AND FOR DOCUMENTATION PURPOSES
seasons={
0:"winter",
1:"spring",
2:"summer",
3:"fall"}
0:"zima",
1:"wiosna",
2:"lato",
3:"jesien"}
time={
0:"morning",
1:"noon",
2:"afternoon",
3:"night"}
0:"rano",
1:"poludnie",
2:"wieczor",
3:"noc"}
weather={
0:"perfect",
1:"hot",
2:"cold",
3:"freezing",
4:"rainy",
5:"snowy",
6:"storm"}
rain={
0:"brak",
1:"lekki deszcz",
2:"normalny deszcz",
3:"ulewa"
}
temperature={
0:"bardzo zimno",
1:"zimno",
2:"przecietnie",
3:"cieplo",
4:"upal",}
def getNextSeason(season):
if(season=="winter"):
return seasons[1]
if(season=="spring"):
return seasons[2]
if(season=="summer"):
return seasons[3]
if(season=="fall"):
return seasons[0]
if(season==3):
return 0
else:
return season+1
def getNextTime(currentTime):
if(currentTime=="morning"):
return time[1]
if(currentTime=="noon"):
return time[2]
if(currentTime=="afternoon"):
return time[3]
if(currentTime=="night"):
return time[0]
if(currentTime==3):
return 0
else:
return currentTime+1
def getAmount(type):
if(type=="seasons"):
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):
self.season=self.setRandomSeason()
self.currentTime=self.setRandomTime()
self.weather=self.setRandomWeather()
self.rain=self.setRandomRain()
self.temperature=self.setRandomRain()
self.clock=0
def setRandomSeason(self):
return Climate.seasons[self.randomizer(3)]
return self.randomizer(Climate.getAmount("seasons"))
def setRandomTime(self):
return Climate.time[self.randomizer(3)]
return self.randomizer(Climate.getAmount("time"))
def setRandomWeather(self):
return Climate.weather[self.randomizer(6)]
def setRandomRain(self):
return self.randomizer(Climate.getAmount("rain"))
def setRandomTemperature(self):
return self.randomizer(Climate.getAmount("temperature"))
def randomizer(self,maxIndex):
return random.randint(0,maxIndex)
def randomizer(self,max):
return random.randint(0,max-1)
def cycle(self):
if(self.clock==12):
self.currentTime=Climate.time[0]
self.weather=self.setRandomWeather()
self.currentTime=0
self.rain=self.setRandomRain()
self.temperature=self.setRandomTemperature()
self.season=Climate.getNextSeason(self.season)
self.clock=0
return
else:
self.currentTime=Climate.getNextTime(self.currentTime)
self.weather=self.setRandomWeather()
self.rain=self.setRandomRain()
self.temperature=self.setRandomTemperature()
self.clock=self.clock+1
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
80,60,0,1,0,20,1,20,0
20,60,0,1,0,20,1,20,1
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
1 plant_water_lever plant_water_level tractor_water_lever tractor_water_level weather temperature rain season current_time growth disease fertility action
2 80 80 60 60 0 3 2 1 0 20 1 20 0
3 20 20 60 60 0 3 0 1 0 20 1 20 1

View File

@ -2,7 +2,7 @@ from sklearn import tree as skltree
import pandas,os
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:
def __init__(self):
self.tree=self.treeLearn()

View File

@ -39,7 +39,7 @@ class Tractor:
self.clock=clock
self.slot_hydrate_dict={}
self.bfs2_flag=bfs2_flag
self.waterLevel=random.randint(0,100)
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))