This commit is contained in:
xkamikoo 2020-05-17 20:24:15 +02:00
parent 18d05c29f0
commit 3666bd3079

109
Kamila.py
View File

@ -4,33 +4,57 @@ from sklearn.model_selection import train_test_split
from sklearn import metrics
import numpy
header = ["ready", "hydration", "weeds", "planted"]
header = ["ready", "hydration", "weeds", "empty", "TODO"]
work = ["Zebrac","Podlac","Odchwascic","Zasadzic"]
#0 - 3
#1 - 0
#2 - 1
#3 - 2
def check_p(field):
if field == 0:
return [0, 0, 0, 0, "Zasadzic"]
elif field == 1:
return [0, 0, 1, 0, "Odchwascic"]
elif field == 2:
return [0, 0, 0, 1, "Podlac"]
elif field == 3:
return [0, 0, 1, 1, "Odchwascic"]
elif field == 4:
return [0, 1, 0, 0, "Zasadzic"]
elif field == 5:
return [0, 1, 1, 0, "Odchwascic"]
elif field == 6:
return [0, 1, 0, 1, "Ignoruj"]
elif field == 7:
return [0, 1, 1, 1, "Odchwascic"]
elif field == 8:
return [1, 0, 0, 1, "Zebrac"]
else:
print("wrong field number")
def check(field):
if field == 0:
return [0, 0, 0, 'N']
return [[0, 0, 0, 1, "Zasadzic"],[0,0,0,1,"Podlac"]]
elif field == 1:
return [0, 0, 1, 'N']
return [[0, 0, 1, 1, "Odchwascic"], [0,0,1,1,"Podlac"], [0,0,1,1,"Zasadzic"]]
elif field == 2:
return [0, 0, 0, 'Y']
return [[0, 0, 0, 0, "Podlac"]]
elif field == 3:
return [0, 0, 1, 'Y']
return [[0, 0, 1, 0, "Odchwascic"],[0,0,1,0,"Podlac"]]
elif field == 4:
return [0, 1, 0, 'N']
return [[0, 1, 0, 1, "Zasadzic"]]
elif field == 5:
return [0, 1, 1, 'N']
return [[0, 1, 1, 1, "Odchwascic"],[0,1,1,1,"Zasadzic"]]
elif field == 6:
return [0, 1, 0, 'Y']
return []
elif field == 7:
return [0, 1, 1, 'Y']
return [[0, 1, 1, 0, "Odchwascic"]]
elif field == 8:
return [1, 0, 0, 'N']
return [[1, 0, 0, 0, "Zebrac"],[1, 0, 0, 0, "Potem podlac"],[1, 0, 0, 0, "Potem zasadzic"]]
else:
print("wrong field number")
def un_values(rows, col):
return set([row[col] for row in rows])
@ -177,8 +201,8 @@ class main():
self.field = field
self.ui = ui
self.path = path
def tree(field):
self.best_action = 0
def main(self):
array = ([[8, 8, 8, 8, 8, 8, 8, 8, 8, 8],
[7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
[6, 6, 6, 6, 6, 6, 6, 6, 6, 6],
@ -189,15 +213,58 @@ class main():
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
while (self.best_action != -1):
self.find_best_action()
self.do_best_action()
print("Koniec roboty")
def find_best_action(self):
testing_data = []
matrix = self.field.get_matrix()
matrix_todo = []
#print(self.field)
for i in range(10):
verse = field[i]
for j in verse:
matrix_todo.append([])
verse = matrix[i]
for j in range(len(verse)):
coord = (i, j)
current_field = check(verse[j])
testing_data.append(current_field)
current_field = check(verse[j]) #czynnosci ktore trzeba jeszcze zrobic na kazdym polu
matrix_todo[i].append([])
for action in current_field:
matrix_todo[i][j].append(action[-1])
testing_data.extend(current_field)
#testing_data.append(current_field)
if len(testing_data) > 0:
x = build_tree(testing_data)
print_tree(x)
if isinstance(x, Leaf):
self.best_action = self.find_remaining_action(matrix_todo)
return
self.best_action = x.question.column
print(header[x.question.column])
print(x.question.value)
else:
self.best_action = self.find_remaining_action(matrix_todo)
return
#for row in testing_data:
# print("Actual: %s. Predicted %s" %
# (row[-1], print_leaf(classify(row, x))))
#for row in matrix_todo:
# print(row)
x = build_tree(testing_data)
print_tree(x)
def do_best_action(self):
self.traktor.set_mode((self.best_action+3) % 4)
while self.path.pathfinding(self.traktor,self.field,self.ui) != 0:
pass
# 0 - 3
# 1 - 0
# 2 - 1
# 3 - 2
def find_remaining_action(self, matrix_todo):
for row in matrix_todo:
for field in row:
for action in field:
print(action)
return work.index(action)
return -1