poprawiona mapka, zmowyfikowane drzewo, wypisuje decyzje

This commit is contained in:
Paulina J 2019-06-08 17:48:36 +02:00
parent 4cd8951b2b
commit e60ee962d3
6 changed files with 141 additions and 62 deletions

View File

@ -3,13 +3,13 @@ from Plant import Plant
class Cucumber(Plant):
name = 0
is_alive = True
ttl = 10000
hydration = 40
soil_level = 40
dehydration_ratio = 2
ttl = 100000 #21474836
hydration = 900 #70
soil_level = 800 #70
dehydration_ratio = 1
desoil_ratio = 1
max_soil_lvl = 40
max_soil_lvl = 990 #40
optimal_soil_ratio = 2
max_hydration_lvl = 40
max_hydration_lvl = 990 # 40
optimal_hydration_ratio = 2
ready = 11
ready = 300

View File

@ -53,13 +53,21 @@ class Plant():
def get_symbol(self):
if not self.is_alive:
return ('x', None)
elif self.hydration > (self.max_hydration_lvl / self.optimal_hydration_ratio) \
and self.soil_level > (self.max_soil_lvl / self.optimal_soil_ratio):
if self.name == 1 and self.hydration > (500) and self.soil_level > (400):
# (self.max_soil_lvl / self.optimal_soil_ratio):
return ('p', "green") if (self.ttl > self.ready) \
else ('P', "green")
elif self.name == 0 and self.hydration > (600) and self.soil_level > (500):
return ('o', "green") if (self.ttl > self.ready) \
else ('O', "green")
else:
if self.name == 1:
return ('p', "yellow") if (self.ttl > self.ready) \
else ('P', "yellow")
else:
return ('o', "yellow") if (self.ttl > self.ready) \
else ('O', "yellow")
def tick(self, n):
self.decrease_ttl(n)
@ -70,6 +78,8 @@ class Plant():
self.ttl -= n
if self.ttl == 0:
self.is_alive = False
if n==0:
self.is_alive = False
def increase_hydration(self, n):
@ -78,7 +88,7 @@ class Plant():
self.is_alive = False
def decrase_hydration(self, n):
self.hydration -= n * self.dehydration_ratio
self.hydration -= (n * self.dehydration_ratio)
if self.hydration < 1:
self.is_alive = False
@ -88,6 +98,8 @@ class Plant():
self.is_alive = False
def decrease_soillevel(self, n):
self.soil_level -= n * self.desoil_ratio
self.soil_level -= (n * self.desoil_ratio)
if self.soil_level < 1:
self.is_alive = False

View File

@ -3,13 +3,13 @@ from Plant import Plant
class Tomato(Plant):
name = 1
is_alive = True
ttl = 12000
hydration = 41
soil_level = 41
ttl = 1000 #21474836
hydration = 500 #80
soil_level = 400
dehydration_ratio = 1
desoil_ratio = 2
max_soil_lvl = 40
desoil_ratio = 1
max_soil_lvl = 990 #40
optimal_soil_ratio = 2
max_hydration_lvl = 100
max_hydration_lvl = 990 #100
optimal_hydration_ratio = 2
ready = 10
ready = 200

122
Tree.py
View File

@ -27,45 +27,93 @@ class TreeClass:
def make_tree(self, plant, pl_stats):
features = [
[1, True, 60, 90, 95],
[1, True, 60, 84, 88],
[1, True, 50, 78, 77],
[1, True, 45, 63, 68],
[1, True, 37, 54, 59],
[1, True, 20, 31, 62],
[1, True, 18, 75, 39],
[1, True, 19, 24, 74],
[1, True, 24, 69, 25],
[1, True, 15, 45, 85],
[1, True, 23, 85, 48],
[1, True, 26, 41, 45],
[1, True, 21, 35, 32],
[1, True, 49, 24, 28],
[1, True, 64, 15, 14],
[1, True, 84, 4, 8],
[1, True, 199, 900, 950],
[1, True, 150, 840, 880],
[1, True, 149, 780, 770],
[1, True, 133, 630, 680],
[1, True, 185, 540, 590],
[1, True, 123, 310, 620],
[0, True, 55, 89, 84],
[0, True, 76, 91, 95],
[0, True, 45, 72, 71],
[0, True, 37, 64, 68],
[0, True, 26, 54, 59],
[0, True, 58, 42, 46],
[0, True, 20, 31, 62],
[0, True, 18, 75, 39],
[0, True, 19, 24, 74],
[0, True, 24, 69, 25],
[0, True, 15, 12, 85],
[0, True, 23, 85, 18],
[0, True, 34, 38, 36],
[0, True, 41, 24, 22],
[0, True, 34, 38, 36],
[0, True, 74, 26, 23],
[0, True, 84, 14, 19],
[0, True, 95, 7, 4]
[1, True, 3800, 450, 490],
[1, True, 290, 240, 740],
[1, True, 240, 490, 550],
[1, True, 350, 350, 850],
[1, True, 230, 349, 400],
[1, True, 260, 410, 400],
[1, True, 260, 510, 399],
[1, True, 210, 550, 320],
[1, True, 490, 740, 280],
[1, True, 640, 500, 140],
[1, True, 840, 867, 80],
[1, True, 6789, 555, 159],
[1, True, 37812, 489, 368],
[1, True, 3728, 387, 278],
[1, True, 1934, 134, 334],
[1, True, 13562, 499, 233],
[1, True, 1789, 289, 399],
[1, True, 201, 478, 340],
[1, True, 1892, 996, 865],
[1, True, 6789, 555, 459],
[1, True, 37812, 789, 768],
[1, True, 3728, 987, 678],
[1, True, 199, 500, 555],
[1, True, 1892, 502, 400],
[1, False, 6789, 672, 405],
[1, False, 37812, 589, 420],
[1, False, 3728, 890, 778],
[1, False, 799, 734, 634],
[1, False, 799, 734, 634],
[1, False, 799, 734, 634],
[0, True, 299, 890, 840],
[0, True, 134, 910, 950],
[0, True, 256, 720, 710],
[0, True, 87, 640, 680],
[0, True, 189, 540, 590],
[0, True, 222, 420, 460],
[0, True, 300, 310, 620],
[0, True, 4580, 550, 590],
[0, True, 1290, 240, 740],
[0, True, 340, 290, 650],
[0, True, 7650, 120, 850],
[0, True, 3455, 599, 501],
[0, True, 3040, 680, 360],
[0, True, 410, 740, 220],
[0, True, 340, 880, 360],
[0, True, 740, 960, 499],
[0, True, 840, 601, 190],
[0, True, 950, 765, 400],
[0, True, 3400, 550, 360],
[0, True, 740, 260, 230],
[0, True, 840, 300, 190],
[0, True, 950, 199, 100],
[0, True, 340, 380, 460],
[0, True, 740, 560, 499],
[0, True, 840, 690, 790],
[0, True, 950, 800, 550],
[0, True, 340, 799, 599],
[0, True, 740, 900, 501],
[0, True, 840, 645, 785],
[0, True, 950, 700, 650],
[0, False, 190, 240, 740],
[0, False, 240, 690, 250],
[0, False, 150, 120, 850],
[0, False, 230, 850, 180],
[0, False, 2345, 21, 342],
[0, False, 2561, 244, 532]
]
labels = [0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2, 3, 3, 3, 3, 3, 3]
labels = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]
#utwórz drzewo decyzyjne
t = tree.DecisionTreeClassifier()
@ -91,7 +139,7 @@ class TreeClass:
# plant.increase_soillevel(plant.max_soil_lvl - plant.soil_level)
#wyświetlamy dopasowaną wartość
print(p)
# print(p)
T = TreeClass()

8
env.py
View File

@ -159,11 +159,15 @@ if __name__ == "__main__":
elif message[0] == "inc_soil":
x = int(message[1])
y = int(message[2])
field[x][y].increase_soillevel(1)
field[x][y].increase_soillevel(field[x][y].max_soil_lvl - field[x][y].soil_level)
elif message[0] == "inc_hydration":
x = int(message[1])
y = int(message[2])
field[x][y].increase_hydration(1)
field[x][y].increase_hydration(field[x][y].max_hydration_lvl - field[x][y].hydration)
elif message[0] == "dec_ttl":
x = int(message[1])
y = int(message[2])
field[x][y].decrease_ttl(0)
print_field(field, tractor)

View File

@ -38,6 +38,14 @@ class Tractor(TreeClass):
time.sleep(self.sleep_time)
writer.close()
async def decrease_ttl(self, location):
reader, writer = await asyncio.open_connection('127.0.0.1', 8887)
writer.write(("dec_ttl " + str(location[0]) + " " + str(location[1]) + "\n").encode())
await reader.readline()
time.sleep(self.sleep_time)
writer.close()
async def rotate(self, direction):
reader, writer = await asyncio.open_connection('127.0.0.1', 8887)
writer.write(("rotate " + direction + "\n").encode())
@ -243,14 +251,21 @@ class Tractor(TreeClass):
if p == 0:
print("Ready to cut")
# t.Harvest()
await self.decrease_ttl(i)
elif p == 1:
print("I'm increasing hydration")
await self.increase_hydration(i)
elif p == 2:
print("I'm increasing soil level")
await self.increase_soil_lvl(i)
elif p == 3:
print("I'm increasing hydration and soil level")
await self.increase_hydration(i)
await self.increase_soil_lvl(i)
elif p == 4:
print ("Nothing to do")
elif p == 5:
print ("There's nothing here")
"tutaj trzeba zapytac env z jakimi roslinami sie styka traktor i je obsłuzyc"