Compare commits
No commits in common. "master" and "cleaning" have entirely different histories.
.gitignoreAStar.pyAkcja.pyApp.pyBFS.pyClimate.pyCondition.py
Data
Drzewo.pyGeneticAccuracy.pyGeneticAlgorithm.pyGeneticAlgorithm2.pyGeneticAlgorithm3.pyImage.pyNode.pyOsprzet.pyPole.pyRoslina.pySlot.pySrodek.pyStan.pyTractor.pyUi.pydisplayControler.pyimages
main.pymodel_2_crops.pthmodel_500_hidden.pthneuralnetwork.pypole2_pop120_iter2500_True.jsonpole3_pop120_365_True.jsonpole_pop120_iter2500_True.jsonreadme.txttestModels
treeData.py
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,5 +1 @@
|
||||
__pycache__/
|
||||
.idea/
|
||||
tree.png
|
||||
dataset/
|
||||
dataset.zip
|
||||
__pycache__/
|
284
AStar.py
284
AStar.py
@ -1,284 +0,0 @@
|
||||
"""
|
||||
f(n) = g(n) + h(n)
|
||||
g(n) = dotychczasowy koszt -> dodać currentCost w Node lub brać koszt na nowo przy oddtawrzaniu ścieżki
|
||||
h(n) = abs(state['x'] - goalTreassure[0]) + abs(state['y'] - goalTreassure[1]) -> odległość Manhatan -> można zrobić jeszcze drugą wersje gdzie mnoży się razy 5.5 ze wzgledu na średni koszt przejścia
|
||||
Należy zaimplementować kolejkę priorytetową oraz zaimplementować algorytm przeszukiwania grafu stanów z uwzględnieniem kosztu za pomocą przerobienia algorytmu przeszukiwania grafu stanów
|
||||
"""
|
||||
import random
|
||||
import pygame
|
||||
import Node
|
||||
import BFS
|
||||
from displayControler import NUM_X, NUM_Y
|
||||
from Pole import stoneList
|
||||
from queue import PriorityQueue
|
||||
|
||||
|
||||
def getRandomGoalTreasure():
|
||||
while True:
|
||||
goalTreasure = (random.randint(0, NUM_X - 1), random.randint(0, NUM_Y - 1)) # Współrzędne celu
|
||||
if goalTreasure not in stoneList:
|
||||
break
|
||||
return goalTreasure
|
||||
|
||||
|
||||
def heuristic(state, goal):
|
||||
# Oblicz odległość Manhattanowską między aktualnym stanem a celem
|
||||
manhattan_distance = abs(state['x'] - goal[0]) + abs(state['y'] - goal[1])
|
||||
return manhattan_distance
|
||||
|
||||
|
||||
'''def get_cost_for_plant(plant_name):
|
||||
plant_costs = {
|
||||
"pszenica": 7,
|
||||
"kukurydza": 9,
|
||||
"ziemniak": 2,
|
||||
"slonecznik": 5,
|
||||
"borowka": 3,
|
||||
"winogrono": 4,
|
||||
"mud": 15,
|
||||
"dirt": 0,
|
||||
}
|
||||
if plant_name in plant_costs:
|
||||
return plant_costs[plant_name]
|
||||
else:
|
||||
# Jeśli nazwa rośliny nie istnieje w słowniku, zwróć domyślną wartość
|
||||
return 0
|
||||
'''
|
||||
|
||||
def A_star(istate, pole, goalTreasure):
|
||||
# goalTreasure = (random.randint(0,NUM_X-1), random.randint(0,NUM_Y-1))
|
||||
# #jeśli chcemy używać random musimy wykreslić sloty z kamieniami, ponieważ tez mogą się wylosować i wtedy traktor w ogóle nie rusza
|
||||
#lub zrobić to jakoś inaczej, np. funkcja szukająca najmniej nawodnionej rośliny
|
||||
|
||||
# przeniesione wyżej do funkcji getRandomGoalTreasure, wykorzystywana jest w App.py
|
||||
# while True:
|
||||
# goalTreasure = (random.randint(0, NUM_X - 1), random.randint(0, NUM_Y - 1)) # Współrzędne celu
|
||||
# if goalTreasure not in stoneList:
|
||||
# break
|
||||
|
||||
fringe = PriorityQueue() # Kolejka priorytetowa dla wierzchołków do rozpatrzenia
|
||||
explored = [] # Lista odwiedzonych stanów
|
||||
obrot = 1
|
||||
|
||||
# Tworzenie węzła początkowego
|
||||
x = Node.Node(istate)
|
||||
x.g = 0
|
||||
x.h = heuristic(x.state, goalTreasure)
|
||||
fringe.put((x.g + x.h, x)) # Dodanie węzła do kolejki
|
||||
total_cost = 0
|
||||
|
||||
while not fringe.empty():
|
||||
_, elem = fringe.get() # Pobranie węzła z najniższym priorytetem
|
||||
|
||||
if BFS.goalTest3(elem.state, goalTreasure): # Sprawdzenie, czy osiągnięto cel
|
||||
path = []
|
||||
cost_list=[]
|
||||
while elem.parent is not None: # Odtworzenie ścieżki
|
||||
path.append([elem.parent, elem.action])
|
||||
elem = elem.parent
|
||||
for node, action in path:
|
||||
# Obliczanie kosztu ścieżki dla każdego pola i wyświetlanie
|
||||
plant_cost = get_plant_name_and_cost_from_coordinates(node.state['x'],node.state['y'], pole)
|
||||
if action == "left" or action == "right": # Liczenie kosztu tylko dla pól nie będących obrotami
|
||||
total_cost += obrot
|
||||
cost_list.append(obrot)
|
||||
else:
|
||||
total_cost += plant_cost
|
||||
cost_list.append(plant_cost)
|
||||
return path,cost_list,total_cost
|
||||
|
||||
explored.append(elem.state)
|
||||
|
||||
for resp in succ3A(elem.state):
|
||||
child_state = resp[1]
|
||||
if child_state not in explored:
|
||||
child = Node.Node(child_state)
|
||||
child.parent = elem
|
||||
child.action = resp[0]
|
||||
|
||||
# Pobranie nazwy rośliny z danego slotu na podstawie współrzędnych
|
||||
plant_cost = get_plant_name_and_cost_from_coordinates(child_state['x'], child_state['y'], pole)
|
||||
# Pobranie kosztu dla danej rośliny
|
||||
#plant_cost = get_cost_for_plant(plant_name)
|
||||
|
||||
if child.action == "left" or child.action == "right":
|
||||
child.g = elem.g + obrot
|
||||
else:
|
||||
child.g = elem.g + plant_cost
|
||||
|
||||
# Obliczenie heurystyki dla dziecka
|
||||
child.h = heuristic(child.state, goalTreasure)
|
||||
|
||||
in_fringe = False
|
||||
for priority, item in fringe.queue:
|
||||
if item.state == child.state:
|
||||
in_fringe = True
|
||||
if priority > child.g + child.h:
|
||||
# Jeśli znaleziono węzeł w kolejce o gorszym priorytecie, zastąp go nowym
|
||||
fringe.queue.remove((priority, item))
|
||||
fringe.put((child.g + child.h, child))
|
||||
break
|
||||
|
||||
if not in_fringe:
|
||||
# Jeśli stan dziecka nie jest w kolejce, dodaj go do kolejki
|
||||
fringe.put((child.g + child.h, child))
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_plant_name_and_cost_from_coordinates(x, y, pole):
|
||||
if (x, y) in pole.slot_dict: # Sprawdzenie, czy podane współrzędne znajdują się na polu
|
||||
slot = pole.slot_dict[(x, y)] # Pobranie slotu na podstawie współrzędnych
|
||||
if slot.plant: # Sprawdzenie, czy na slocie znajduje się roślina
|
||||
return slot.plant.stan.koszt # Zwrócenie nazwy rośliny na slocie
|
||||
else:
|
||||
return 0 # jeśli na slocie nie ma rośliny
|
||||
else:
|
||||
return 0 # jeśli podane współrzędne są poza polem
|
||||
|
||||
|
||||
#to ogólnie identyczna funkcja jak w BFS ale nie chciałam tam ruszać, żeby przypadkiem nie zapsuć do BFS,
|
||||
#tylko musiałam dodac sprawdzenie kolizji, bo traktor brał sloty z Y których nie ma na planszy
|
||||
def succ3A(state):
|
||||
resp = []
|
||||
if state["direction"] == "N":
|
||||
if state["y"] > 0 and (state['x'], state["y"] - 1) not in stoneList:
|
||||
resp.append(["forward", {'x': state["x"], 'y': state["y"]-1, 'direction': state["direction"]}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "E"}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "W"}])
|
||||
elif state["direction"] == "S":
|
||||
if state["y"] < NUM_Y - 1 and (state['x'], state["y"] + 1) not in stoneList:
|
||||
resp.append(["forward", {'x': state["x"], 'y': state["y"]+1, 'direction': state["direction"]}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "W"}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "E"}])
|
||||
elif state["direction"] == "E":
|
||||
if state["x"] < NUM_X - 1 and (state['x'] + 1, state["y"]) not in stoneList:
|
||||
resp.append(["forward", {'x': state["x"]+1, 'y': state["y"], 'direction': state["direction"]}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "S"}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "N"}])
|
||||
else: #state["direction"] == "W"
|
||||
if state["x"] > 0 and (state['x'] - 1, state["y"]) not in stoneList:
|
||||
resp.append(["forward", {'x': state["x"]-1, 'y': state["y"], 'direction': state["direction"]}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "N"}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "S"}])
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
|
||||
def heuristic2(state, goal):
|
||||
# Oblicz odległość Manhattanowską między aktualnym stanem a celem
|
||||
manhattan_distance = (abs(state['x'] - goal[0]) + abs(state['y'] - goal[1])) * 2.5
|
||||
return manhattan_distance
|
||||
|
||||
|
||||
def A_star2(istate, pole, goalTreasure):
|
||||
# goalTreasure = (random.randint(0,NUM_X-1), random.randint(0,NUM_Y-1))
|
||||
# #jeśli chcemy używać random musimy wykreslić sloty z kamieniami, ponieważ tez mogą się wylosować i wtedy traktor w ogóle nie rusza
|
||||
#lub zrobić to jakoś inaczej, np. funkcja szukająca najmniej nawodnionej rośliny
|
||||
|
||||
# przeniesione wyżej do funkcji getRandomGoalTreasure, wykorzystywana jest w App.py
|
||||
# while True:
|
||||
# goalTreasure = (random.randint(0, NUM_X - 1), random.randint(0, NUM_Y - 1)) # Współrzędne celu
|
||||
# if goalTreasure not in stoneList:
|
||||
# break
|
||||
fringe = PriorityQueue() # Kolejka priorytetowa dla wierzchołków do rozpatrzenia
|
||||
explored = [] # Lista odwiedzonych stanów
|
||||
obrot = 1
|
||||
|
||||
# Tworzenie węzła początkowego
|
||||
x = Node.Node(istate)
|
||||
x.g = 0
|
||||
x.h = heuristic2(x.state, goalTreasure)
|
||||
fringe.put((x.g + x.h, x)) # Dodanie węzła do kolejki
|
||||
total_cost=0
|
||||
|
||||
while not fringe.empty():
|
||||
_, elem = fringe.get() # Pobranie węzła z najniższym priorytetem
|
||||
|
||||
if BFS.goalTest3(elem.state, goalTreasure): # Sprawdzenie, czy osiągnięto cel
|
||||
path = []
|
||||
cost_list=[]
|
||||
while elem.parent is not None: # Odtworzenie ścieżki
|
||||
path.append([elem.parent, elem.action])
|
||||
elem = elem.parent
|
||||
for node, action in path:
|
||||
# Obliczanie kosztu ścieżki dla każdego pola i wyświetlanie
|
||||
plant_cost = get_plant_name_and_cost_from_coordinates(node.state['x'],node.state['y'], pole)
|
||||
if action == "left" or action == "right": # Liczenie kosztu tylko dla pól nie będących obrotami
|
||||
total_cost += obrot
|
||||
cost_list.append(obrot)
|
||||
else:
|
||||
total_cost += plant_cost
|
||||
cost_list.append(plant_cost)
|
||||
return path,cost_list,total_cost
|
||||
|
||||
explored.append(elem.state)
|
||||
|
||||
for resp in succ3A(elem.state):
|
||||
child_state = resp[1]
|
||||
if child_state not in explored:
|
||||
child = Node.Node(child_state)
|
||||
child.parent = elem
|
||||
child.action = resp[0]
|
||||
|
||||
# Pobranie nazwy rośliny z danego slotu na podstawie współrzędnych
|
||||
plant_cost = get_plant_name_and_cost_from_coordinates(child_state['x'], child_state['y'], pole)
|
||||
|
||||
if child.action == "left" or child.action == "right":
|
||||
child.g = elem.g + obrot
|
||||
else:
|
||||
child.g = elem.g + plant_cost
|
||||
# Obliczenie heurystyki dla dziecka
|
||||
child.h = heuristic2(child.state, goalTreasure)
|
||||
|
||||
in_fringe = False
|
||||
for priority, item in fringe.queue:
|
||||
if item.state == child.state:
|
||||
in_fringe = True
|
||||
if priority > child.g + child.h:
|
||||
# Jeśli znaleziono węzeł w kolejce o gorszym priorytecie, zastąp go nowym
|
||||
fringe.queue.remove((priority, item))
|
||||
fringe.put((child.g + child.h, child))
|
||||
break
|
||||
|
||||
if not in_fringe:
|
||||
# Jeśli stan dziecka nie jest w kolejce, dodaj go do kolejki
|
||||
fringe.put((child.g + child.h, child))
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
|
||||
return False
|
||||
|
||||
"""
|
||||
TO TEST SPEED OF ASTAR
|
||||
|
||||
test_speed = False
|
||||
|
||||
if test_speed:
|
||||
time1 = 0
|
||||
time2 = 0
|
||||
cost1 = 0
|
||||
cost2 = 0
|
||||
for i in range(500):
|
||||
print(i)
|
||||
start = time.time()
|
||||
aStarRoot, cost_list, total_cost = AStar.A_star({'x': 0, 'y': 0, 'direction': "E"}, pole, goalTreasure)
|
||||
end = time.time()
|
||||
time1 += end - start
|
||||
cost1 += total_cost
|
||||
start = time.time()
|
||||
aStarRoot2, cost_list, total_cost = AStar.A_star2({'x': 0, 'y': 0, 'direction': "E"}, pole, goalTreasure)
|
||||
end = time.time()
|
||||
time2 += end - start
|
||||
cost2 += total_cost
|
||||
print(time1, time2)
|
||||
print(float(cost1 / 1000), float(cost2 / 1000))
|
||||
"""
|
47
Akcja.py
47
Akcja.py
@ -1,47 +0,0 @@
|
||||
import Srodek
|
||||
|
||||
|
||||
#w przyszłości trzeba przenieść definicję środków do innego pliku inicjalizującego
|
||||
class Akcja:
|
||||
srodki = [] #lista obiektów klasy Srodek
|
||||
benefits = [] #lista przechowująca benefity płynące z wykonania akcji
|
||||
|
||||
def __init__(self, typ):
|
||||
self.typ = typ
|
||||
if self.typ == "nawodnienie":
|
||||
self.srodki.append(Srodek.Srodek(1, "woda", "woda"))
|
||||
self.srodki.append(Srodek.Srodek(1.5, "powerade", "woda")) #nawadnia lepiej niż woda
|
||||
self.benefits.append(typ)
|
||||
self.benefits.append(100)
|
||||
if self.typ == "zyznosc":
|
||||
self.srodki.append(Srodek.Srodek(2, "obornik", "nawoz"))
|
||||
self.srodki.append(Srodek.Srodek(3, "azotan", "nawoz"))
|
||||
self.srodki.append(Srodek.Srodek(4, "wapno", "nawoz"))
|
||||
self.srodki.append(Srodek.Srodek(5, "superfosfat", "nawoz"))
|
||||
self.benefits.append(typ)
|
||||
self.benefits.append(100)
|
||||
if self.typ == "wzrost":
|
||||
self.srodki.append(Srodek.Srodek(6, "witaminy", "odzywka"))
|
||||
self.srodki.append(Srodek.Srodek(7, "aminokwasy", "odzywka"))
|
||||
self.srodki.append(Srodek.Srodek(8, "algi morskie", "odzywka"))
|
||||
self.benefits.append(typ)
|
||||
self.benefits.append(20)
|
||||
if self.typ == "grzyb":
|
||||
self.srodki.append(Srodek.Srodek(9, "mankozeb", "ochrona"))
|
||||
self.srodki.append(Srodek.Srodek(10, "czosnek", "ochrona")) #tak czosnek zabija grzyby
|
||||
self.benefits.append("choroba")
|
||||
self.benefits.append("brak")
|
||||
if self.typ == "bakteria":
|
||||
self.srodki.append(Srodek.Srodek(11, "miedź", "ochrona"))
|
||||
self.srodki.append(Srodek.Srodek(12, "streptomycyna ", "ochrona"))
|
||||
self.benefits.append("choroba")
|
||||
self.benefits.append("brak")
|
||||
if self.typ == "pasożyt":
|
||||
self.srodki.append(Srodek.Srodek(13, "Cyjantraniliprol", "ochrona"))
|
||||
self.srodki.append(Srodek.Srodek(14, "Permetryna", "ochrona"))
|
||||
self.srodki.append(Srodek.Srodek(15, "Abamektyna", "ochrona"))
|
||||
self.benefits.append("choroba")
|
||||
self.benefits.append("brak")
|
||||
|
||||
def getBenefit(self):
|
||||
return self.benefits
|
267
BFS.py
267
BFS.py
@ -1,267 +0,0 @@
|
||||
import random
|
||||
|
||||
import pygame
|
||||
import Node
|
||||
from displayControler import NUM_X, NUM_Y
|
||||
from Pole import stoneList
|
||||
|
||||
|
||||
def goalTest1(hIndex):
|
||||
for i in list(hIndex.values()):
|
||||
if i == 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def succ1(state):
|
||||
resp = []
|
||||
hIndex = state["hydradeIndex"].copy()
|
||||
if state["direction"] == "N":
|
||||
if state["y"] > 0:
|
||||
if hIndex[state["x"], state["y"]-1] == 0:
|
||||
hIndex[state["x"], state["y"] - 1] = 1
|
||||
resp.append(["forward", {'x': state["x"], 'y': state["y"]-1, 'direction': state["direction"], 'hydradeIndex': hIndex}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "E", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "W", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
elif state["direction"] == "S":
|
||||
if state["y"] < NUM_Y-1:
|
||||
if hIndex[state["x"], state["y"]+1] == 0:
|
||||
hIndex[state["x"], state["y"] + 1] = 1
|
||||
resp.append(["forward", {'x': state["x"], 'y': state["y"]+1, 'direction': state["direction"], 'hydradeIndex': hIndex}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "W", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "E", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
elif state["direction"] == "E":
|
||||
if state["x"] < NUM_X-1:
|
||||
if hIndex[state["x"]+1, state["y"]] == 0:
|
||||
hIndex[state["x"] + 1, state["y"]] = 1
|
||||
resp.append(["forward", {'x': state["x"]+1, 'y': state["y"], 'direction': state["direction"], 'hydradeIndex': hIndex}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "S", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "N", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
else: #state["zwrot"] == "W"
|
||||
if state["x"] > 0:
|
||||
if hIndex[state["x"]-1, state["y"]] == 0:
|
||||
hIndex[state["x"] - 1, state["y"]] = 1
|
||||
resp.append(["forward", {'x': state["x"]-1, 'y': state["y"], 'direction': state["direction"], 'hydradeIndex': hIndex}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "N", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "S", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
def check1(tab, state):
|
||||
for i in tab:
|
||||
if i.state == state:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def BFS1(istate):
|
||||
|
||||
|
||||
fringe = []
|
||||
explored = []
|
||||
|
||||
x = Node.Node(istate)
|
||||
fringe.append(x)
|
||||
|
||||
while True:
|
||||
|
||||
|
||||
if fringe == []:
|
||||
return False
|
||||
|
||||
elem = fringe.pop(0)
|
||||
|
||||
if goalTest1(elem.state["hydradeIndex"]):
|
||||
x = elem
|
||||
tab = []
|
||||
while x.parent != None:
|
||||
tab.append([x.parent, x.action])
|
||||
x = x.parent
|
||||
return tab
|
||||
explored.append(elem)
|
||||
|
||||
for resp in succ1(elem.state):
|
||||
if check1(fringe, resp[1]) and check1(explored, resp[1]):
|
||||
x = Node.Node(resp[1])
|
||||
x.parent = elem
|
||||
x.action = resp[0]
|
||||
fringe.append(x)
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
|
||||
|
||||
|
||||
|
||||
def goalTest3(state, goalTreassure):
|
||||
if state["x"] == goalTreassure[0] and state["y"] == goalTreassure[1]:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def succ3(state):
|
||||
resp = []
|
||||
if state["direction"] == "N":
|
||||
if state["y"] > 0 and (state['x'], state["y"] - 1) not in stoneList:
|
||||
resp.append(["forward", {'x': state["x"], 'y': state["y"]-1, 'direction': state["direction"]}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "E"}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "W"}])
|
||||
elif state["direction"] == "S":
|
||||
if state["y"] < NUM_Y - 1 and (state['x'], state["y"] + 1) not in stoneList:
|
||||
resp.append(["forward", {'x': state["x"], 'y': state["y"]+1, 'direction': state["direction"]}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "W"}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "E"}])
|
||||
elif state["direction"] == "E":
|
||||
if state["x"] < NUM_X - 1 and (state['x'] + 1, state["y"]) not in stoneList:
|
||||
resp.append(["forward", {'x': state["x"]+1, 'y': state["y"], 'direction': state["direction"]}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "S"}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "N"}])
|
||||
else: #state["zwrot"] == "W"
|
||||
if state["x"] > 0 and (state['x'] - 1, state["y"]) not in stoneList:
|
||||
resp.append(["forward", {'x': state["x"]-1, 'y': state["y"], 'direction': state["direction"]}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "N"}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "S"}])
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
def check3(tab, state):
|
||||
for i in tab:
|
||||
if i.state == state:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def BFS3(istate,GT):
|
||||
randomGT=False
|
||||
if(randomGT==True):
|
||||
goalTreassuere = (random.randint(0,NUM_X-1), random.randint(0,NUM_Y-1))
|
||||
else:
|
||||
goalTreassuere=GT
|
||||
print(goalTreassuere)
|
||||
fringe = []
|
||||
explored = []
|
||||
|
||||
x = Node.Node(istate)
|
||||
fringe.append(x)
|
||||
|
||||
while True:
|
||||
|
||||
if fringe == []:
|
||||
return False
|
||||
|
||||
elem = fringe.pop(0)
|
||||
|
||||
if goalTest3(elem.state, goalTreassuere):
|
||||
x = elem
|
||||
tab = []
|
||||
while x.parent != None:
|
||||
tab.append([x.parent, x.action])
|
||||
x = x.parent
|
||||
return tab
|
||||
|
||||
explored.append(elem)
|
||||
|
||||
for resp in succ3(elem.state):
|
||||
if check3(fringe, resp[1]) and check3(explored, resp[1]):
|
||||
x = Node.Node(resp[1])
|
||||
x.parent = elem
|
||||
x.action = resp[0]
|
||||
fringe.append(x)
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
def goalTest(hIndex):
|
||||
for i in list(hIndex.values()):
|
||||
if i == 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def succ(state):
|
||||
resp = []
|
||||
hIndex = state["hydradeIndex"].copy()
|
||||
|
||||
if state["direction"] == "N":
|
||||
if state["y"] > 0:
|
||||
if hIndex[state["x"], state["y"]-1] == 0:
|
||||
hIndex[state["x"], state["y"] - 1] = 1
|
||||
resp.append(["forward", {'x': state["x"], 'y': state["y"]-1, 'direction': state["direction"], 'hydradeIndex': hIndex}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "E", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "W", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
elif state["direction"] == "S":
|
||||
if state["y"] < dCon.NUM_Y-1:
|
||||
if hIndex[state["x"], state["y"]+1] == 0:
|
||||
hIndex[state["x"], state["y"] + 1] = 1
|
||||
resp.append(["forward", {'x': state["x"], 'y': state["y"]+1, 'direction': state["direction"], 'hydradeIndex': hIndex}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "W", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "E", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
elif state["direction"] == "E":
|
||||
if state["x"] < dCon.NUM_X-1:
|
||||
if hIndex[state["x"]+1, state["y"]] == 0:
|
||||
hIndex[state["x"] + 1, state["y"]] = 1
|
||||
resp.append(["forward", {'x': state["x"]+1, 'y': state["y"], 'direction': state["direction"], 'hydradeIndex': hIndex}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "S", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "N", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
else: #state["direction"] == "W"
|
||||
if state["x"] > 0:
|
||||
if hIndex[state["x"]-1, state["y"]] == 0:
|
||||
hIndex[state["x"] - 1, state["y"]] = 1
|
||||
resp.append(["forward", {'x': state["x"]-1, 'y': state["y"], 'direction': state["direction"], 'hydradeIndex': hIndex}])
|
||||
resp.append(["right", {'x': state["x"], 'y': state["y"], 'direction': "N", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
resp.append(["left", {'x': state["x"], 'y': state["y"], 'direction': "S", 'hydradeIndex': state["hydradeIndex"].copy()}])
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
def check(tab, state):
|
||||
for i in tab:
|
||||
if i.state == state:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def BFS(istate):
|
||||
fringe = []
|
||||
explored = []
|
||||
|
||||
x = Node.Node(istate)
|
||||
fringe.append(x)
|
||||
|
||||
while True:
|
||||
if fringe == []:
|
||||
return False
|
||||
|
||||
elem = fringe.pop(0)
|
||||
|
||||
if goalTest(elem.state["hydradeIndex"]):
|
||||
x = elem
|
||||
tab = []
|
||||
while x.parent != None:
|
||||
tab.append(x.action)
|
||||
x = x.parent
|
||||
return tab
|
||||
|
||||
explored.append(elem)
|
||||
|
||||
for resp in succ(elem.state):
|
||||
if check(fringe, resp[1]) and check(explored, resp[1]):
|
||||
x = Node.Node(resp[1])
|
||||
x.parent = elem
|
||||
x.action = resp[0]
|
||||
fringe.append(x)
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
49
Climate.py
49
Climate.py
@ -1,49 +0,0 @@
|
||||
#THESE DICTIONARIES ARE USED FOR DISPLAY AND FOR DOCUMENTATION PURPOSES
|
||||
|
||||
seasons={
|
||||
0:"zima",
|
||||
1:"wiosna",
|
||||
2:"lato",
|
||||
3:"jesien"}
|
||||
|
||||
time={
|
||||
0:"rano",
|
||||
1:"poludnie",
|
||||
2:"wieczor",
|
||||
3:"noc"}
|
||||
|
||||
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==3):
|
||||
return 0
|
||||
else:
|
||||
return season+1
|
||||
|
||||
def getNextTime(currentTime):
|
||||
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)
|
47
Condition.py
47
Condition.py
@ -1,47 +0,0 @@
|
||||
import random
|
||||
import Climate
|
||||
import Ui
|
||||
|
||||
class Condition:
|
||||
def __init__(self):
|
||||
self.season=self.setRandomSeason()
|
||||
self.currentTime=self.setRandomTime()
|
||||
self.rain=self.setRandomRain()
|
||||
self.temperature=self.setRandomRain()
|
||||
self.clock=0
|
||||
|
||||
def setRandomSeason(self):
|
||||
return self.randomizer(Climate.getAmount("seasons"))
|
||||
|
||||
def setRandomTime(self):
|
||||
return self.randomizer(Climate.getAmount("time"))
|
||||
|
||||
def setRandomRain(self):
|
||||
return self.randomizer(Climate.getAmount("rain"))
|
||||
|
||||
def setRandomTemperature(self):
|
||||
return self.randomizer(Climate.getAmount("temperature"))
|
||||
|
||||
def randomizer(self,max):
|
||||
return random.randint(0,max-1)
|
||||
|
||||
def cycle(self):
|
||||
if(self.clock==11):
|
||||
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.rain=self.setRandomRain()
|
||||
self.temperature=self.setRandomTemperature()
|
||||
self.clock=self.clock+1
|
||||
|
||||
def return_condition(self):
|
||||
return [self.temperature,self.rain,self.season,self.currentTime]
|
||||
|
||||
|
||||
def getCondition(self):
|
||||
return ([Climate.temperature[self.temperature],Climate.rain[self.rain],Climate.seasons[self.season],Climate.time[self.currentTime]])
|
9219
Data/dataTree.csv
9219
Data/dataTree.csv
File diff suppressed because it is too large
Load Diff
@ -1,248 +0,0 @@
|
||||
plant_water_level,growth,disease,fertility,tractor_water_level,temperature,rain,season,current_time,action
|
||||
1,20,0,40,60,2,0,2,1,1
|
||||
20,40,0,40,60,2,0,2,1,1
|
||||
87,20,0,40,60,2,0,2,1,0
|
||||
27,43,1,40,60,2,0,2,1,0
|
||||
89,56,1,40,60,2,1,1,1,0
|
||||
67,100,1,37,55,1,3,3,3,0
|
||||
67,40,1,87,90,4,0,1,0,0
|
||||
1,20,0,40,60,2,0,0,1,0
|
||||
20,40,0,40,60,2,0,0,1,0
|
||||
87,20,0,56,45,2,0,0,2,0
|
||||
27,43,1,40,60,2,0,0,3,0
|
||||
89,56,1,40,89,2,1,0,1,0
|
||||
67,100,1,37,55,1,3,0,3,0
|
||||
67,40,1,87,90,4,0,0,0,0
|
||||
1,100,0,45,20,2,0,2,1,0
|
||||
20,100,0,40,34,0,1,2,0,0
|
||||
87,100,0,56,60,2,0,1,1,0
|
||||
27,100,0,89,67,1,2,2,2,0
|
||||
89,100,0,40,60,2,1,1,1,0
|
||||
76,100,0,37,55,1,3,3,3,0
|
||||
67,100,0,87,90,4,0,1,0,0
|
||||
1,20,0,40,0,2,0,2,1,0
|
||||
20,40,0,40,0,2,0,2,1,0
|
||||
87,20,0,40,0,2,0,2,1,0
|
||||
27,43,1,40,0,2,0,2,1,0
|
||||
89,56,1,40,0,2,1,1,1,0
|
||||
67,100,1,37,0,1,3,3,3,0
|
||||
67,40,1,87,0,4,0,1,0,0
|
||||
1,20,0,40,0,2,0,0,1,0
|
||||
20,40,0,40,0,2,0,0,1,0
|
||||
87,20,0,56,0,2,0,0,2,0
|
||||
27,43,1,40,0,2,0,0,3,0
|
||||
89,56,1,40,0,2,1,0,1,0
|
||||
67,100,1,37,0,1,3,0,3,0
|
||||
67,40,1,87,0,4,0,0,0,0
|
||||
1,100,0,45,0,2,0,2,1,0
|
||||
20,100,0,40,0,0,1,2,0,0
|
||||
87,100,0,56,0,2,0,1,1,0
|
||||
27,100,0,89,0,1,2,2,2,0
|
||||
89,100,0,40,0,2,1,1,1,0
|
||||
76,100,0,37,0,1,3,3,3,0
|
||||
67,100,0,87,0,4,0,1,0,0
|
||||
1,45,0,56,44,2,1,1,1,1
|
||||
20,55,0,43,34,2,0,2,2,1
|
||||
15,23,0,23,26,2,1,3,3,1
|
||||
45,67,0,12,67,3,0,1,0,1
|
||||
59,88,0,34,87,3,0,2,1,1
|
||||
32,32,0,32,90,3,0,3,2,1
|
||||
44,43,0,19,27,2,0,1,3,1
|
||||
33,11,0,28,76,2,0,2,0,1
|
||||
54,90,0,44,5,3,0,3,1,1
|
||||
21,76,0,50,25,3,1,1,2,1
|
||||
29,64,0,38,36,2,0,2,3,1
|
||||
11,54,0,65,44,3,1,1,2,1
|
||||
23,55,0,34,43,3,0,2,1,1
|
||||
51,32,0,32,62,3,1,3,3,1
|
||||
54,76,0,21,76,2,0,1,2,1
|
||||
95,88,0,43,78,2,0,2,1,0
|
||||
23,23,0,23,9,2,0,3,3,1
|
||||
44,34,0,91,72,3,0,1,0,1
|
||||
33,11,0,82,67,3,0,2,2,1
|
||||
45,9,0,44,50,2,0,3,3,1
|
||||
21,67,0,50,52,2,1,1,0,1
|
||||
92,46,0,83,63,3,0,2,1,0
|
||||
20,55,1,43,34,0,0,2,2,0
|
||||
15,23,1,23,26,0,1,3,3,0
|
||||
45,67,1,12,67,0,0,1,0,0
|
||||
59,88,1,34,87,0,0,2,1,0
|
||||
32,32,0,32,90,0,0,3,2,0
|
||||
44,43,0,19,27,4,0,1,3,0
|
||||
33,11,0,28,76,4,0,2,0,0
|
||||
54,90,0,44,5,4,0,3,1,0
|
||||
21,76,0,50,25,4,1,1,2,0
|
||||
29,64,0,38,36,4,0,2,3,0
|
||||
11,54,0,65,44,0,1,1,2,0
|
||||
23,55,0,34,43,0,0,2,1,0
|
||||
51,32,0,32,62,0,1,3,3,0
|
||||
80,76,1,39,7,3,0,1,0,0
|
||||
98,77,0,15,91,1,3,2,3,0
|
||||
3,48,1,73,41,2,2,0,3,0
|
||||
20,15,1,97,87,4,1,2,1,0
|
||||
93,6,0,37,0,0,1,0,1,0
|
||||
4,31,0,1,5,2,3,1,2,0
|
||||
42,52,0,33,19,3,2,3,0,0
|
||||
76,43,0,77,18,4,0,0,3,0
|
||||
31,13,1,21,42,0,1,2,3,0
|
||||
96,65,1,63,35,1,3,3,2,0
|
||||
29,39,0,40,37,3,3,0,0,0
|
||||
82,53,0,55,9,0,1,3,2,0
|
||||
21,35,0,58,1,1,2,2,0,0
|
||||
92,98,0,69,16,3,0,0,1,0
|
||||
34,23,0,95,2,2,3,0,3,0
|
||||
36,28,0,62,22,0,1,1,1,0
|
||||
66,88,1,10,85,3,1,2,3,0
|
||||
53,51,0,79,90,2,2,3,2,0
|
||||
9,74,0,60,4,4,1,2,3,1
|
||||
17,0,0,38,58,1,2,3,0,0
|
||||
12,76,0,50,25,3,1,1,2,1
|
||||
92,64,0,38,36,2,0,2,3,0
|
||||
11,54,0,65,44,3,1,1,2,1
|
||||
32,55,0,34,43,3,0,2,1,1
|
||||
15,32,0,32,62,3,1,3,3,1
|
||||
45,76,0,21,76,2,0,1,2,1
|
||||
59,88,0,43,78,2,0,2,1,1
|
||||
32,23,0,23,9,2,0,3,3,1
|
||||
14,34,0,91,72,3,0,1,0,1
|
||||
13,11,0,82,67,3,0,2,2,1
|
||||
45,9,0,44,50,2,0,3,3,1
|
||||
21,67,0,50,52,2,1,1,0,1
|
||||
92,46,0,83,63,3,0,2,1,0
|
||||
2,40,1,34,43,1,3,2,2,0
|
||||
51,32,1,32,62,2,1,3,3,0
|
||||
54,76,1,21,76,3,0,1,0,0
|
||||
98,38,0,50,44,4,0,1,0,0
|
||||
63,7,0,93,79,2,0,2,1,1
|
||||
91,59,0,94,24,4,0,3,2,0
|
||||
11,49,0,54,76,2,0,1,3,1
|
||||
33,31,0,59,39,3,0,1,3,1
|
||||
28,50,0,26,0,4,0,2,2,0
|
||||
54,83,0,36,0,3,0,2,1,0
|
||||
49,78,0,68,0,2,0,3,2,0
|
||||
59,21,0,43,100,1,0,3,2,1
|
||||
1,30,0,52,100,2,0,0,3,0
|
||||
60,9,0,40,40,3,0,0,3,0
|
||||
85,94,0,87,85,4,0,1,3,0
|
||||
79,68,0,56,90,1,0,2,2,1
|
||||
75,22,0,25,95,1,0,3,2,1
|
||||
100,51,0,33,12,0,0,2,2,0
|
||||
90,70,0,71,81,0,0,2,1,0
|
||||
47,26,0,6,78,4,0,1,1,1
|
||||
14,89,0,70,18,4,0,1,0,1
|
||||
99,19,0,74,91,2,0,3,0,0
|
||||
18,48,0,15,32,2,0,3,0,1
|
||||
5,57,0,14,34,0,1,1,3,1
|
||||
22,67,0,9,5,0,1,2,2,0
|
||||
95,81,0,46,86,1,1,3,1,0
|
||||
39,65,0,84,0,1,1,0,0,0
|
||||
84,75,0,30,0,2,1,1,1,0
|
||||
86,41,0,2,67,2,1,2,2,0
|
||||
64,53,0,53,47,1,1,3,3,1
|
||||
69,61,0,0,73,2,1,0,0,0
|
||||
94,40,1,0,18,3,1,1,2,0
|
||||
62,82,1,20,50,4,1,2,3,0
|
||||
57,1,1,17,92,0,1,3,2,0
|
||||
80,35,1,58,45,0,0,3,1,0
|
||||
30,47,1,8,47,1,0,2,1,0
|
||||
82,32,0,99,39,1,3,1,3,0
|
||||
20,84,0,0,51,2,3,2,3,0
|
||||
42,88,0,0,54,2,2,2,0,0
|
||||
66,45,0,91,10,3,2,1,0,0
|
||||
81,14,0,19,55,3,0,1,2,1
|
||||
74,37,0,88,78,4,0,3,2,1
|
||||
89,99,0,100,60,4,0,3,3,0
|
||||
15,20,0,45,11,0,0,1,3,1
|
||||
92,28,0,85,90,2,0,1,1,0
|
||||
55,4,0,13,95,2,0,2,1,1
|
||||
2,6,0,35,0,2,0,2,0,0
|
||||
61,56,0,90,0,2,0,3,0,0
|
||||
76,11,0,61,10,3,0,3,1,1
|
||||
26,80,0,57,9,3,0,1,2,1
|
||||
40,44,0,81,8,3,0,2,3,1
|
||||
50,66,0,23,7,3,0,3,0,1
|
||||
48,15,0,77,6,2,0,0,1,0
|
||||
11,54,0,65,44,3,3,1,2,0
|
||||
23,55,0,34,43,3,3,2,1,0
|
||||
51,32,0,32,62,3,3,3,3,0
|
||||
54,76,0,21,76,2,3,1,2,0
|
||||
95,88,0,43,78,2,3,2,1,0
|
||||
23,23,0,23,9,2,3,3,3,0
|
||||
44,34,0,91,72,3,3,1,0,0
|
||||
33,11,0,82,67,3,3,2,2,0
|
||||
45,9,0,44,50,2,3,3,3,0
|
||||
21,67,0,50,52,2,3,1,0,0
|
||||
92,46,0,83,63,3,3,2,1,0
|
||||
20,55,1,43,34,0,3,2,2,0
|
||||
15,23,1,23,26,0,3,3,3,0
|
||||
45,67,1,12,67,0,3,1,0,0
|
||||
59,88,1,34,87,0,3,2,1,0
|
||||
32,32,0,32,90,0,3,3,2,0
|
||||
1,60,0,55,11,0,1,0,0,1
|
||||
2,70,0,44,12,1,1,0,1,1
|
||||
3,44,0,11,13,2,1,0,2,1
|
||||
4,55,0,34,66,3,0,0,3,1
|
||||
5,66,0,90,77,0,0,1,2,1
|
||||
6,22,0,89,88,0,0,2,2,1
|
||||
7,1,0,45,9,0,1,2,3,1
|
||||
8,2,0,34,22,3,1,2,3,1
|
||||
9,3,0,56,34,3,1,0,1,1
|
||||
10,6,0,78,5,3,0,3,1,1
|
||||
11,8,0,36,67,2,0,0,0,1
|
||||
12,59,0,57,23,2,1,1,0,1
|
||||
13,67,0,29,34,1,1,0,1,1
|
||||
14,20,0,30,90,1,1,2,2,1
|
||||
15,21,0,66,89,0,1,3,3,1
|
||||
44,100,0,91,72,3,3,1,0,0
|
||||
33,100,0,82,67,3,3,2,2,0
|
||||
45,100,0,44,50,2,3,3,3,0
|
||||
21,100,0,50,52,2,3,1,0,0
|
||||
92,100,0,83,63,3,3,2,1,0
|
||||
20,100,1,43,34,0,3,2,2,0
|
||||
15,100,1,23,26,0,3,3,3,0
|
||||
45,100,1,12,67,0,3,1,0,0
|
||||
59,100,1,34,87,0,3,2,1,0
|
||||
32,100,0,32,90,0,3,3,2,0
|
||||
1,100,0,55,11,0,1,0,0,0
|
||||
2,100,0,44,12,1,1,0,1,0
|
||||
3,100,0,11,13,2,1,0,2,0
|
||||
4,100,0,34,66,3,0,0,3,0
|
||||
5,100,0,90,77,0,0,1,2,0
|
||||
6,100,0,89,88,0,0,2,2,0
|
||||
7,100,0,45,9,0,1,2,3,0
|
||||
8,100,0,34,22,3,1,2,3,0
|
||||
9,100,0,56,34,3,1,0,1,0
|
||||
10,100,0,78,5,3,0,3,1,0
|
||||
11,100,0,36,67,2,0,0,0,0
|
||||
12,100,0,57,23,2,1,1,0,0
|
||||
13,100,0,29,34,1,1,0,1,0
|
||||
14,100,0,30,90,1,1,2,2,0
|
||||
15,100,0,66,89,0,1,3,3,0
|
||||
1,6,0,5,10,4,1,1,3,1
|
||||
2,7,0,4,20,4,1,2,2,1
|
||||
3,4,0,11,30,4,1,3,1,1
|
||||
4,5,0,43,5,2,0,1,2,1
|
||||
5,6,0,9,17,2,0,2,1,1
|
||||
6,2,0,98,18,4,0,3,1,1
|
||||
7,11,0,54,19,4,1,0,2,1
|
||||
8,20,0,43,22,4,1,1,1,1
|
||||
9,30,0,65,43,4,1,2,3,1
|
||||
10,60,0,87,50,1,0,3,3,1
|
||||
11,80,0,63,76,1,0,0,2,1
|
||||
12,95,0,75,32,1,1,1,1,1
|
||||
13,76,0,30,43,2,1,2,0,1
|
||||
14,2,0,92,9,2,1,3,0,1
|
||||
1,6,0,5,10,4,3,1,3,0
|
||||
2,7,0,4,20,4,3,2,2,0
|
||||
3,4,0,11,30,4,3,3,1,0
|
||||
4,5,0,43,5,2,3,1,2,0
|
||||
5,6,0,9,17,2,3,2,1,0
|
||||
6,2,0,98,18,4,3,3,1,0
|
||||
7,11,0,54,19,4,3,0,2,0
|
||||
8,20,0,43,22,4,3,1,1,0
|
||||
9,30,0,65,43,4,3,2,3,0
|
||||
10,60,0,87,50,1,3,3,3,0
|
||||
11,80,0,63,76,1,3,0,2,0
|
||||
12,95,0,75,32,1,3,1,1,0
|
||||
13,76,0,30,43,2,3,2,0,0
|
||||
14,2,0,92,9,2,3,3,0,0
|
|
29
Drzewo.py
29
Drzewo.py
@ -1,29 +0,0 @@
|
||||
from sklearn import tree as skltree
|
||||
import pandas,os
|
||||
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
|
||||
class Drzewo:
|
||||
def __init__(self):
|
||||
self.tree=self.treeLearn()
|
||||
|
||||
def treeLearn(self):
|
||||
csvdata=pandas.read_csv('Data/dataTree2.csv')
|
||||
#csvdata = pandas.read_csv('Data/dataTree2.csv')
|
||||
x=csvdata[atributes]
|
||||
decision=csvdata['action']
|
||||
self.tree=skltree.DecisionTreeClassifier()
|
||||
self.tree=self.tree.fit(x.values,decision)
|
||||
|
||||
def plotTree(self):
|
||||
plt.figure(figsize=(20,30))
|
||||
skltree.plot_tree(self.tree,filled=True,feature_names=atributes)
|
||||
plt.title("Drzewo decyzyjne wytrenowane na przygotowanych danych: ")
|
||||
plt.savefig('tree.png')
|
||||
#plt.show()
|
||||
def makeDecision(self,values):
|
||||
action=self.tree.predict([values]) #0- nie podlewac, 1-podlewac
|
||||
if(action==[0]):
|
||||
return "Nie"
|
||||
if(action==[1]):
|
||||
return "Tak"
|
@ -1,139 +0,0 @@
|
||||
import json
|
||||
import random
|
||||
|
||||
from displayControler import NUM_Y, NUM_X
|
||||
|
||||
iterat = 2500
|
||||
population = 120
|
||||
roulette = True
|
||||
|
||||
plants = ['corn', 'potato', 'tomato', 'carrot']
|
||||
initial_yields = {'corn': 38, 'potato': 40, 'tomato': 43, 'carrot': 45}
|
||||
yield_reduction = {
|
||||
'corn': {'corn': -4.5, 'potato': -3, 'tomato': -7, 'carrot': -7},
|
||||
'potato': {'corn': -7, 'potato': -5, 'tomato': -10, 'carrot': -6},
|
||||
'tomato': {'corn': -4, 'potato': -5, 'tomato': -7, 'carrot': -7},
|
||||
'carrot': {'corn': -11, 'potato': -5, 'tomato': -4, 'carrot': -7}
|
||||
}
|
||||
yield_reduction2 = {
|
||||
'corn': {'corn': None, 'potato': -4, 'tomato': -2, 'carrot': -4},
|
||||
'potato': {'corn': None, 'potato': -5, 'tomato': -5, 'carrot': -2},
|
||||
'tomato': {'corn': -5, 'potato': -3, 'tomato': -7, 'carrot': None},
|
||||
'carrot': {'corn': -3, 'potato': -6, 'tomato': -4, 'carrot': -9}
|
||||
}
|
||||
yield_multiplier = {'corn': 1.25, 'potato': 1.17, 'tomato': 1.22, 'carrot': 1.13}
|
||||
yield_multiplier2 = {'corn': 1.25, 'potato': 1.19, 'tomato': 1.22, 'carrot': 1.15}
|
||||
|
||||
|
||||
def calculate_yields(garden):
|
||||
rows = len(garden)
|
||||
cols = len(garden[0])
|
||||
|
||||
total_yields = 0
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
plant = garden[i][j]
|
||||
yield_count = initial_yields[plant]
|
||||
|
||||
# Sprawdzanie sąsiadów
|
||||
neighbors = [
|
||||
(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)
|
||||
]
|
||||
|
||||
for ni, nj in neighbors:
|
||||
if 0 <= ni < rows and 0 <= nj < cols:
|
||||
neighbor_plant = garden[ni][nj]
|
||||
yield_count += yield_reduction[plant][neighbor_plant]
|
||||
|
||||
yield_count *= yield_multiplier[plant]
|
||||
total_yields += yield_count
|
||||
|
||||
return total_yields
|
||||
|
||||
|
||||
def calculate_yields2(garden):
|
||||
rows = len(garden)
|
||||
cols = len(garden[0])
|
||||
|
||||
total_yields = 0
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
plant = garden[i][j]
|
||||
yield_count = initial_yields[plant]
|
||||
|
||||
# Sprawdzanie sąsiadów
|
||||
neighbors = [
|
||||
(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)
|
||||
]
|
||||
neighbor_flag = False
|
||||
for ni, nj in neighbors:
|
||||
if 0 <= ni < rows and 0 <= nj < cols:
|
||||
neighbor_plant = garden[ni][nj]
|
||||
|
||||
if yield_reduction2[plant][neighbor_plant] is not None: # jeśli jest wartość None to plony dla tej rośliny będą wyzerowane
|
||||
yield_count += yield_reduction2[plant][neighbor_plant]
|
||||
else:
|
||||
neighbor_flag = True
|
||||
|
||||
if not neighbor_flag:
|
||||
yield_count *= yield_multiplier2[plant]
|
||||
total_yields += yield_count
|
||||
|
||||
return total_yields
|
||||
|
||||
|
||||
def generate_garden(rows=20, cols=12):
|
||||
return [[random.choice(plants) for _ in range(cols)] for _ in range(rows)]
|
||||
|
||||
|
||||
def generate_garden_with_yields(t, rows=NUM_Y, cols=NUM_X):
|
||||
garden = generate_garden(rows, cols)
|
||||
if t == 1:
|
||||
total_yields = calculate_yields(garden)
|
||||
else:
|
||||
total_yields = calculate_yields2(garden)
|
||||
return [garden, total_yields]
|
||||
|
||||
|
||||
def generate():
|
||||
s1 = 0
|
||||
s2 = 0
|
||||
n = 150
|
||||
for i in range(n):
|
||||
x = generate_garden_with_yields(1)
|
||||
s1 += x[1]
|
||||
y = generate_garden_with_yields(2)
|
||||
s2 += y[1]
|
||||
return [s1/n, s2/n]
|
||||
|
||||
|
||||
data = generate()
|
||||
# print(data)
|
||||
|
||||
# Odczyt z pliku
|
||||
with open(f'pole_pop{population}_iter{iterat}_{roulette}.json', 'r') as file:
|
||||
garden_data = json.load(file)
|
||||
|
||||
# print("Odczytane dane ogrodu:")
|
||||
# for row in garden_data:
|
||||
# print(row)
|
||||
|
||||
print("Wygenerowane przy pomocy GA: ", calculate_yields(garden_data))
|
||||
print(f"Przeciętny ogród wygenerowany randomowo ma {data[0]} plonów")
|
||||
print("Uśredniony przyrost plonów (ile razy więcej plonów): ", calculate_yields(garden_data)/data[0])
|
||||
|
||||
|
||||
|
||||
# Odczyt z pliku
|
||||
with open(f'pole2_pop{population}_iter{iterat}_{roulette}.json', 'r') as file:
|
||||
garden_data2 = json.load(file)
|
||||
|
||||
# print("Odczytane dane ogrodu:")
|
||||
# for row in garden_data2:
|
||||
# print(row)
|
||||
|
||||
print("Wygenerowane: przy pomocy GA2", calculate_yields2(garden_data2))
|
||||
print(f"Przeciętny ogród wygenerowany randomowo ma {data[1]} plonów")
|
||||
print("Uśredniony przyrost plonów (ile razy więcej plonów): ", calculate_yields2(garden_data2)/data[1])
|
@ -1,208 +0,0 @@
|
||||
import copy
|
||||
import json
|
||||
import random
|
||||
from displayControler import NUM_X, NUM_Y
|
||||
|
||||
# Definiowanie stałych dla roślin i plonów
|
||||
plants = ['corn', 'potato', 'tomato', 'carrot']
|
||||
initial_yields = {'corn': 38, 'potato': 40, 'tomato': 43, 'carrot': 45}
|
||||
yield_reduction = {
|
||||
'corn': {'corn': -4.5, 'potato': -3, 'tomato': -7, 'carrot': -7},
|
||||
'potato': {'corn': -7, 'potato': -5, 'tomato': -10, 'carrot': -6},
|
||||
'tomato': {'corn': -4, 'potato': -5, 'tomato': -7, 'carrot': -7},
|
||||
'carrot': {'corn': -11, 'potato': -5, 'tomato': -4, 'carrot': -7}
|
||||
}
|
||||
yield_multiplier = {'corn': 1.25, 'potato': 1.17, 'tomato': 1.22, 'carrot': 1.13}
|
||||
|
||||
|
||||
# Generowanie listy 20x12 z losowo rozmieszczonymi roślinami
|
||||
def generate_garden(rows=20, cols=12):
|
||||
return [[random.choice(plants) for _ in range(cols)] for _ in range(rows)]
|
||||
|
||||
|
||||
# Funkcja do obliczania liczby plonów
|
||||
def calculate_yields(garden):
|
||||
rows = len(garden)
|
||||
cols = len(garden[0])
|
||||
|
||||
total_yields = 0
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
plant = garden[i][j]
|
||||
yield_count = initial_yields[plant]
|
||||
|
||||
# Sprawdzanie sąsiadów
|
||||
neighbors = [
|
||||
(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)
|
||||
]
|
||||
|
||||
for ni, nj in neighbors:
|
||||
if 0 <= ni < rows and 0 <= nj < cols:
|
||||
neighbor_plant = garden[ni][nj]
|
||||
yield_count += yield_reduction[plant][neighbor_plant]
|
||||
|
||||
yield_count *= yield_multiplier[plant]
|
||||
total_yields += yield_count
|
||||
|
||||
return total_yields
|
||||
|
||||
|
||||
# Funkcja do generowania planszy/ogrodu i zapisywania go jako lista z liczbą plonów
|
||||
def generate_garden_with_yields(rows=NUM_Y, cols=NUM_X):
|
||||
garden = generate_garden(rows, cols)
|
||||
total_yields = calculate_yields(garden)
|
||||
return [garden, total_yields]
|
||||
|
||||
|
||||
# Funkcja do generowania linii cięcia i zapisywania jej jako liczba roślin w kolumnie z pierwszej planszy/ogrodu
|
||||
def line():
|
||||
path = []
|
||||
flag = False
|
||||
x = random.randint(4, 8)
|
||||
position = (0, x)
|
||||
path.append(position)
|
||||
while not flag: # wybór punktu dopóki nie wybierze się skrajnego
|
||||
# prawdopodobieństwo "ruchu" -> 0.6: w prawo, 0.2: w góre, 0.2: w dół
|
||||
p = [(position[0] + 1, position[1]), (position[0], position[1] + 1), (position[0], position[1] - 1)]
|
||||
w = [0.6, 0.2, 0.2]
|
||||
position2 = random.choices(p, w)[0]
|
||||
if position2 not in path: # sprawdzenie czy dany punkt nie był już wybrany aby nie zapętlać się
|
||||
path.append(position2)
|
||||
position = position2
|
||||
if position[0] == NUM_X or position[1] == 0 or position[1] == NUM_Y: # sprawdzenie czy osiągnięto skrajny punkt
|
||||
flag = True
|
||||
info = [] # przeformatowanie sposobu zapisu na liczbę roślin w kolumnie, które będzię się dzidziczyło z pierwszej planszy/ogrodu
|
||||
for i in range(len(path) - 1):
|
||||
if path[i + 1][0] - path[i][0] == 1:
|
||||
info.append(NUM_Y - path[i][1])
|
||||
if len(info) < NUM_X: # uzupełnienie informacji o dziedziczeniu z planszy/ogrodu
|
||||
if path[-1:][0][1] == 0:
|
||||
x = NUM_Y
|
||||
else:
|
||||
x = 0
|
||||
while len(info) < NUM_X:
|
||||
info.append(x)
|
||||
# return path, info
|
||||
return info
|
||||
|
||||
|
||||
# Funkcja do generowania potomstwa
|
||||
def divide_gardens(garden1, garden2):
|
||||
info = line()
|
||||
new_garden1 = [[] for _ in range(NUM_Y)]
|
||||
new_garden2 = [[] for _ in range(NUM_Y)]
|
||||
for i in range(NUM_X):
|
||||
for j in range(NUM_Y):
|
||||
# do utworzonych kolumn w nowych planszach/ogrodach dodajemy dziedziczone rośliny
|
||||
if j < info[i]:
|
||||
new_garden1[j].append(garden1[j][i])
|
||||
new_garden2[j].append(garden2[j][i])
|
||||
else:
|
||||
new_garden1[j].append(garden2[j][i])
|
||||
new_garden2[j].append(garden1[j][i])
|
||||
|
||||
return [new_garden1, calculate_yields(new_garden1)], [new_garden2, calculate_yields(new_garden2)]
|
||||
|
||||
|
||||
# Funkcja do mutacji danej planszy/ogrodu
|
||||
def mutation(garden, not_used):
|
||||
new_garden = copy.deepcopy(garden)
|
||||
for i in range(NUM_X):
|
||||
x = random.randint(0, 11) # wybieramy, w którym wierszu w i-tej kolumnie zmieniamy roślinę na inną
|
||||
other_plants = [plant for plant in plants if plant != new_garden[x][i]]
|
||||
new_garden[x][i] = random.choice(other_plants)
|
||||
return [new_garden, calculate_yields(new_garden)]
|
||||
|
||||
|
||||
# Funkcja do generowania pierwszego pokolenia
|
||||
def generate(n):
|
||||
generation = []
|
||||
for i in range(n * 3):
|
||||
generation.append(generate_garden_with_yields())
|
||||
generation.sort(reverse=True, key=lambda x: x[1])
|
||||
return generation[:n]
|
||||
|
||||
|
||||
# Funkcja do implementacji ruletki (sposobu wyboru) - sumuje wszystkie plony generacji
|
||||
def sum_yields(x):
|
||||
s = 0
|
||||
for i in range(len(x)):
|
||||
s += x[i][1]
|
||||
return s
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
roulette = True
|
||||
attemps = 150
|
||||
iterat = 2500
|
||||
population = 120
|
||||
best = []
|
||||
for a in range(attemps):
|
||||
generation = generate(population)
|
||||
print(generation[0][1])
|
||||
for i in range(iterat): # ile iteracji - nowych pokoleń
|
||||
print(a, i)
|
||||
new_generation = generation[:(population // 7)] # dziedziczenie x najlepszych osobników
|
||||
j = 0
|
||||
while j < (
|
||||
population - (
|
||||
population // 7)): # dobór reszty osobników do pełnej liczby populacji danego pokolenia
|
||||
if roulette: # zasada ruletki -> "2 rzuty kulką"
|
||||
s = sum_yields(generation) # suma wszystkich plnów całego pokolenia
|
||||
z = []
|
||||
if s == 0: # wtedy każdy osobnik ma takie same szanse
|
||||
z.append(random.randint(0, population - 1))
|
||||
z.append(random.randint(0, population - 1))
|
||||
else:
|
||||
weights = [] # wagi prawdopodobieństwa dla każdego osobnika generacji
|
||||
pos = [] # numery od 0 do 49 odpowiadające numerom osobnikom w generacji
|
||||
for i in range(population):
|
||||
weights.append(generation[i][1] / s)
|
||||
pos.append(i)
|
||||
z.append(random.choices(pos, weights)[0]) # wybranie osobnika według wag prawdopodobieństwa
|
||||
z.append(random.choices(pos, weights)[0]) # wybranie osobnika według wag prawdopodobieństwa
|
||||
else: # metoda rankingu
|
||||
z = random.sample(range(0, int(population // 1.7)), 2)
|
||||
|
||||
# krzyzowanie 90% szans, mutacja 10% szans
|
||||
function = [divide_gardens, mutation]
|
||||
weight = [0.9, 0.1]
|
||||
fun = random.choices(function, weight)[0]
|
||||
h = fun(generation[z[0]][0], generation[z[1]][0])
|
||||
if len(h[0]) == 2:
|
||||
new_generation.append(h[0])
|
||||
new_generation.append(h[1])
|
||||
j += 2
|
||||
else:
|
||||
new_generation.append(h)
|
||||
j += 1
|
||||
|
||||
new_generation.sort(reverse=True, key=lambda x: x[1]) # sortowanie malejąco listy według wartości plonów
|
||||
generation = new_generation[:population]
|
||||
|
||||
best.append(generation[0])
|
||||
|
||||
best.sort(reverse=True, key=lambda x: x[1])
|
||||
|
||||
# Zapis do pliku
|
||||
# for i in range(len(best)):
|
||||
# print(best[i][1], calculate_yields(best[i][0]))
|
||||
#
|
||||
#
|
||||
# with open(f'pole_pop{population}_iter{iterat}_{roulette}.json', 'w') as file: # zapis planszy/ogrodu do pliku json
|
||||
# json.dump(best[0][0], file, indent=4)
|
||||
#
|
||||
# print("Dane zapisane do pliku")
|
||||
|
||||
# Odczyt z pliku
|
||||
# with open(f'pole_pop{population}_iter{iterat}_{roulette}.json', 'r') as file:
|
||||
# garden_data = json.load(file)
|
||||
#
|
||||
# print("Odczytane dane ogrodu:")
|
||||
# for row in garden_data:
|
||||
# print(row)
|
||||
#
|
||||
# print(calculate_yields(garden_data))
|
||||
# if best[0][0] == garden_data:
|
||||
# print("POPRAWNE: ", calculate_yields(garden_data), calculate_yields(best[0][0]))
|
@ -1,213 +0,0 @@
|
||||
import copy
|
||||
import json
|
||||
import random
|
||||
from displayControler import NUM_X, NUM_Y
|
||||
|
||||
# Definiowanie stałych dla roślin i plonów
|
||||
plants = ['corn', 'potato', 'tomato', 'carrot']
|
||||
initial_yields = {'corn': 38, 'potato': 40, 'tomato': 43, 'carrot': 45}
|
||||
yield_reduction = {
|
||||
'corn': {'corn': None, 'potato': -4, 'tomato': -2, 'carrot': -4},
|
||||
'potato': {'corn': None, 'potato': -5, 'tomato': -5, 'carrot': -2},
|
||||
'tomato': {'corn': -5, 'potato': -3, 'tomato': -7, 'carrot': None},
|
||||
'carrot': {'corn': -3, 'potato': -6, 'tomato': -4, 'carrot': -9}
|
||||
}
|
||||
yield_multiplier = {'corn': 1.25, 'potato': 1.19, 'tomato': 1.22, 'carrot': 1.15}
|
||||
|
||||
|
||||
# Generowanie listy 20x12 z losowo rozmieszczonymi roślinami
|
||||
def generate_garden(rows=20, cols=12):
|
||||
return [[random.choice(plants) for _ in range(cols)] for _ in range(rows)]
|
||||
|
||||
|
||||
# Funkcja do obliczania liczby plonów
|
||||
def calculate_yields(garden):
|
||||
rows = len(garden)
|
||||
cols = len(garden[0])
|
||||
|
||||
total_yields = 0
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
plant = garden[i][j]
|
||||
yield_count = initial_yields[plant]
|
||||
|
||||
# Sprawdzanie sąsiadów
|
||||
neighbors = [
|
||||
(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)
|
||||
]
|
||||
neighbor_flag = False
|
||||
for ni, nj in neighbors:
|
||||
if 0 <= ni < rows and 0 <= nj < cols:
|
||||
neighbor_plant = garden[ni][nj]
|
||||
|
||||
if yield_reduction[plant][neighbor_plant] is not None: # jeśli jest wartość None to plony dla tej rośliny będą wyzerowane
|
||||
yield_count += yield_reduction[plant][neighbor_plant]
|
||||
else:
|
||||
neighbor_flag = True
|
||||
|
||||
if not neighbor_flag:
|
||||
yield_count *= yield_multiplier[plant]
|
||||
total_yields += yield_count
|
||||
|
||||
return total_yields
|
||||
|
||||
|
||||
# Funkcja do generowania planszy/ogrodu i zapisywania go jako lista z liczbą plonów
|
||||
def generate_garden_with_yields(rows=NUM_Y, cols=NUM_X):
|
||||
garden = generate_garden(rows, cols)
|
||||
total_yields = calculate_yields(garden)
|
||||
return [garden, total_yields]
|
||||
|
||||
|
||||
# Funkcja do generowania linii cięcia i zapisywania jej jako liczba roślin w kolumnie z pierwszej planszy/ogrodu
|
||||
def line():
|
||||
path = []
|
||||
flag = False
|
||||
x = random.randint(4, 8)
|
||||
position = (0, x)
|
||||
path.append(position)
|
||||
while not flag: # wybór punktu dopóki nie wybierze się skrajnego
|
||||
# prawdopodobieństwo "ruchu" -> 0.6: w prawo, 0.2: w góre, 0.2: w dół
|
||||
p = [(position[0] + 1, position[1]), (position[0], position[1] + 1), (position[0], position[1] - 1)]
|
||||
w = [0.6, 0.2, 0.2]
|
||||
position2 = random.choices(p, w)[0]
|
||||
if position2 not in path: # sprawdzenie czy dany punkt nie był już wybrany aby nie zapętlać się
|
||||
path.append(position2)
|
||||
position = position2
|
||||
if position[0] == NUM_X or position[1] == 0 or position[1] == NUM_Y: # sprawdzenie czy osiągnięto skrajny punkt
|
||||
flag = True
|
||||
info = [] # przeformatowanie sposobu zapisu na liczbę roślin w kolumnie, które będzię się dzidziczyło z pierwszej planszy/ogrodu
|
||||
for i in range(len(path) - 1):
|
||||
if path[i + 1][0] - path[i][0] == 1:
|
||||
info.append(NUM_Y - path[i][1])
|
||||
if len(info) < NUM_X: # uzupełnienie informacji o dziedziczeniu z planszy/ogrodu
|
||||
if path[-1:][0][1] == 0:
|
||||
x = NUM_Y
|
||||
else:
|
||||
x = 0
|
||||
while len(info) < NUM_X:
|
||||
info.append(x)
|
||||
# return path, info
|
||||
return info
|
||||
|
||||
|
||||
# Funkcja do generowania potomstwa
|
||||
def divide_gardens(garden1, garden2):
|
||||
info = line()
|
||||
new_garden1 = [[] for _ in range(NUM_Y)]
|
||||
new_garden2 = [[] for _ in range(NUM_Y)]
|
||||
for i in range(NUM_X):
|
||||
for j in range(NUM_Y):
|
||||
# do utworzonych kolumn w nowych planszach/ogrodach dodajemy dziedziczone rośliny
|
||||
if j < info[i]:
|
||||
new_garden1[j].append(garden1[j][i])
|
||||
new_garden2[j].append(garden2[j][i])
|
||||
else:
|
||||
new_garden1[j].append(garden2[j][i])
|
||||
new_garden2[j].append(garden1[j][i])
|
||||
|
||||
return [new_garden1, calculate_yields(new_garden1)], [new_garden2, calculate_yields(new_garden2)]
|
||||
|
||||
|
||||
# Funkcja do mutacji danej planszy/ogrodu
|
||||
def mutation(garden, not_used):
|
||||
new_garden = copy.deepcopy(garden)
|
||||
for i in range(NUM_X):
|
||||
x = random.randint(0, 11) # wybieramy, w którym wierszu w i-tej kolumnie zmieniamy roślinę na inną
|
||||
other_plants = [plant for plant in plants if plant != new_garden[x][i]]
|
||||
new_garden[x][i] = random.choice(other_plants)
|
||||
return [new_garden, calculate_yields(new_garden)]
|
||||
|
||||
|
||||
# Funkcja do generowania pierwszego pokolenia
|
||||
def generate(n):
|
||||
generation = []
|
||||
for i in range(n * 3):
|
||||
generation.append(generate_garden_with_yields())
|
||||
generation.sort(reverse=True, key=lambda x: x[1])
|
||||
return generation[:n]
|
||||
|
||||
|
||||
# Funkcja do implementacji ruletki (sposobu wyboru) - sumuje wszystkie plony generacji
|
||||
def sum_yields(x):
|
||||
s = 0
|
||||
for i in range(len(x)):
|
||||
s += x[i][1]
|
||||
return s
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
roulette = True
|
||||
attemps = 20
|
||||
iterat = 2500
|
||||
population = 120
|
||||
best = []
|
||||
for a in range(attemps):
|
||||
generation = generate(population)
|
||||
print(generation[0][1])
|
||||
for i in range(iterat): # ile iteracji - nowych pokoleń
|
||||
print(a, i)
|
||||
new_generation = generation[:(population // 7)] # dziedziczenie x najlepszych osobników
|
||||
j = 0
|
||||
while j < (
|
||||
population - (
|
||||
population // 7)): # dobór reszty osobników do pełnej liczby populacji danego pokolenia
|
||||
if roulette: # zasada ruletki -> "2 rzuty kulką"
|
||||
s = sum_yields(generation) # suma wszystkich plnów całego pokolenia
|
||||
z = []
|
||||
if s == 0: # wtedy każdy osobnik ma takie same szanse
|
||||
z.append(random.randint(0, population - 1))
|
||||
z.append(random.randint(0, population - 1))
|
||||
else:
|
||||
weights = [] # wagi prawdopodobieństwa dla każdego osobnika generacji
|
||||
pos = [] # numery od 0 do 49 odpowiadające numerom osobnikom w generacji
|
||||
for i in range(population):
|
||||
weights.append(generation[i][1] / s)
|
||||
pos.append(i)
|
||||
z.append(random.choices(pos, weights)[0]) # wybranie osobnika według wag prawdopodobieństwa
|
||||
z.append(random.choices(pos, weights)[0]) # wybranie osobnika według wag prawdopodobieństwa
|
||||
else: # metoda rankingu
|
||||
z = random.sample(range(0, int(population // 1.7)), 2)
|
||||
|
||||
# krzyzowanie 90% szans, mutacja 10% szans
|
||||
function = [divide_gardens, mutation]
|
||||
weight = [0.9, 0.1]
|
||||
fun = random.choices(function, weight)[0]
|
||||
h = fun(generation[z[0]][0], generation[z[1]][0])
|
||||
if len(h[0]) == 2:
|
||||
new_generation.append(h[0])
|
||||
new_generation.append(h[1])
|
||||
j += 2
|
||||
else:
|
||||
new_generation.append(h)
|
||||
j += 1
|
||||
|
||||
new_generation.sort(reverse=True, key=lambda x: x[1]) # sortowanie malejąco listy według wartości plonów
|
||||
generation = new_generation[:population]
|
||||
|
||||
best.append(generation[0])
|
||||
|
||||
best.sort(reverse=True, key=lambda x: x[1])
|
||||
|
||||
# Zapis do pliku
|
||||
# for i in range(len(best)):
|
||||
# print(best[i][1], calculate_yields(best[i][0]))
|
||||
#
|
||||
#
|
||||
# with open(f'pole2_pop{population}_iter{iterat}_{roulette}.json', 'w') as file: # zapis planszy/ogrodu do pliku json
|
||||
# json.dump(best[0][0], file, indent=4)
|
||||
#
|
||||
# print("Dane zapisane do pliku")
|
||||
#
|
||||
# Odczyt z pliku
|
||||
# with open(f'pole2_pop{population}_iter{iterat}_{roulette}.json', 'r') as file:
|
||||
# garden_data = json.load(file)
|
||||
#
|
||||
# print("Odczytane dane ogrodu:")
|
||||
# for row in garden_data:
|
||||
# print(row)
|
||||
#
|
||||
# print(calculate_yields(garden_data))
|
||||
# if best[0][0] == garden_data:
|
||||
# print("POPRAWNE: ", calculate_yields(garden_data), calculate_yields(best[0][0]))
|
@ -1,211 +0,0 @@
|
||||
import copy
|
||||
import json
|
||||
import random
|
||||
from displayControler import NUM_X, NUM_Y
|
||||
|
||||
# Definiowanie stałych dla roślin i plonów
|
||||
plants = ['corn', 'potato', 'tomato', 'carrot']
|
||||
initial_yields = {'corn': 38, 'potato': 40, 'tomato': 43, 'carrot': 45}
|
||||
yield_reduction = {
|
||||
'corn': {'corn': None, 'potato': 0, 'tomato': 0, 'carrot': 0},
|
||||
'potato': {'corn': None, 'potato': 0, 'tomato': 0, 'carrot': 0},
|
||||
'tomato': {'corn': 0, 'potato': 0, 'tomato': 0, 'carrot': None},
|
||||
'carrot': {'corn': 0, 'potato': 0, 'tomato': 0, 'carrot': 0}
|
||||
}
|
||||
yield_multiplier = {'corn': 1.25, 'potato': 1.19, 'tomato': 1.22, 'carrot': 1.13}
|
||||
|
||||
|
||||
# Generowanie listy 20x12 z losowo rozmieszczonymi roślinami
|
||||
def generate_garden(rows=20, cols=12):
|
||||
return [[random.choice(plants) for _ in range(cols)] for _ in range(rows)]
|
||||
|
||||
|
||||
# Funkcja do obliczania liczby plonów
|
||||
def calculate_yields(garden):
|
||||
rows = len(garden)
|
||||
cols = len(garden[0])
|
||||
|
||||
total_yields = 0
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
plant = garden[i][j]
|
||||
|
||||
# Sprawdzanie sąsiadów
|
||||
neighbors = [
|
||||
(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)
|
||||
]
|
||||
neighbor_flag = False
|
||||
for ni, nj in neighbors:
|
||||
if 0 <= ni < rows and 0 <= nj < cols:
|
||||
neighbor_plant = garden[ni][nj]
|
||||
|
||||
if yield_reduction[plant][neighbor_plant] is None: # jeśli jest wartość None to plony dla tej rośliny będą wyzerowane
|
||||
neighbor_flag = True
|
||||
|
||||
if not neighbor_flag:
|
||||
total_yields += 1
|
||||
|
||||
return total_yields
|
||||
|
||||
|
||||
# Funkcja do generowania planszy/ogrodu i zapisywania go jako lista z liczbą plonów
|
||||
def generate_garden_with_yields(rows=NUM_Y, cols=NUM_X):
|
||||
garden = generate_garden(rows, cols)
|
||||
total_yields = calculate_yields(garden)
|
||||
return [garden, total_yields]
|
||||
|
||||
|
||||
# Funkcja do generowania linii cięcia i zapisywania jej jako liczba roślin w kolumnie z pierwszej planszy/ogrodu
|
||||
def line():
|
||||
path = []
|
||||
flag = False
|
||||
x = random.randint(4, 8)
|
||||
position = (0, x)
|
||||
path.append(position)
|
||||
while not flag: # wybór punktu dopóki nie wybierze się skrajnego
|
||||
# prawdopodobieństwo "ruchu" -> 0.6: w prawo, 0.2: w góre, 0.2: w dół
|
||||
p = [(position[0] + 1, position[1]), (position[0], position[1] + 1), (position[0], position[1] - 1)]
|
||||
w = [0.6, 0.2, 0.2]
|
||||
position2 = random.choices(p, w)[0]
|
||||
if position2 not in path: # sprawdzenie czy dany punkt nie był już wybrany aby nie zapętlać się
|
||||
path.append(position2)
|
||||
position = position2
|
||||
if position[0] == NUM_X or position[1] == 0 or position[1] == NUM_Y: # sprawdzenie czy osiągnięto skrajny punkt
|
||||
flag = True
|
||||
info = [] # przeformatowanie sposobu zapisu na liczbę roślin w kolumnie, które będzię się dzidziczyło z pierwszej planszy/ogrodu
|
||||
for i in range(len(path) - 1):
|
||||
if path[i + 1][0] - path[i][0] == 1:
|
||||
info.append(NUM_Y - path[i][1])
|
||||
if len(info) < NUM_X: # uzupełnienie informacji o dziedziczeniu z planszy/ogrodu
|
||||
if path[-1:][0][1] == 0:
|
||||
x = NUM_Y
|
||||
else:
|
||||
x = 0
|
||||
while len(info) < NUM_X:
|
||||
info.append(x)
|
||||
# return path, info
|
||||
return info
|
||||
|
||||
|
||||
# Funkcja do generowania potomstwa
|
||||
def divide_gardens(garden1, garden2):
|
||||
info = line()
|
||||
new_garden1 = [[] for _ in range(NUM_Y)]
|
||||
new_garden2 = [[] for _ in range(NUM_Y)]
|
||||
for i in range(NUM_X):
|
||||
for j in range(NUM_Y):
|
||||
# do utworzonych kolumn w nowych planszach/ogrodach dodajemy dziedziczone rośliny
|
||||
if j < info[i]:
|
||||
new_garden1[j].append(garden1[j][i])
|
||||
new_garden2[j].append(garden2[j][i])
|
||||
else:
|
||||
new_garden1[j].append(garden2[j][i])
|
||||
new_garden2[j].append(garden1[j][i])
|
||||
|
||||
return [new_garden1, calculate_yields(new_garden1)], [new_garden2, calculate_yields(new_garden2)]
|
||||
|
||||
|
||||
# Funkcja do mutacji danej planszy/ogrodu
|
||||
def mutation(garden, not_used):
|
||||
new_garden = copy.deepcopy(garden)
|
||||
for i in range(NUM_X):
|
||||
x = random.randint(0, 11) # wybieramy, w którym wierszu w i-tej kolumnie zmieniamy roślinę na inną
|
||||
other_plants = [plant for plant in plants if plant != new_garden[x][i]]
|
||||
new_garden[x][i] = random.choice(other_plants)
|
||||
return [new_garden, calculate_yields(new_garden)]
|
||||
|
||||
|
||||
# Funkcja do generowania pierwszego pokolenia
|
||||
def generate(n):
|
||||
generation = []
|
||||
for i in range(n * 3):
|
||||
generation.append(generate_garden_with_yields())
|
||||
generation.sort(reverse=True, key=lambda x: x[1])
|
||||
return generation[:n]
|
||||
|
||||
|
||||
# Funkcja do implementacji ruletki (sposobu wyboru) - sumuje wszystkie plony generacji
|
||||
def sum_yields(x):
|
||||
s = 0
|
||||
for i in range(len(x)):
|
||||
s += x[i][1]
|
||||
return s
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
roulette = True
|
||||
attemps = 1
|
||||
population = 120
|
||||
best = []
|
||||
iter = 0
|
||||
for a in range(attemps):
|
||||
generation = generate(population)
|
||||
print(generation[0][1])
|
||||
while generation[0][1] != NUM_X*NUM_Y: # ile iteracji - nowych pokoleń
|
||||
iter += 1
|
||||
print(iter)
|
||||
print(generation[0][1])
|
||||
new_generation = generation[:(population // 7)] # dziedziczenie x najlepszych osobników
|
||||
j = 0
|
||||
while j < (
|
||||
population - (
|
||||
population // 7)): # dobór reszty osobników do pełnej liczby populacji danego pokolenia
|
||||
if roulette: # zasada ruletki -> "2 rzuty kulką"
|
||||
s = sum_yields(generation) # suma wszystkich plnów całego pokolenia
|
||||
z = []
|
||||
if s == 0: # wtedy każdy osobnik ma takie same szanse
|
||||
z.append(random.randint(0, population - 1))
|
||||
z.append(random.randint(0, population - 1))
|
||||
else:
|
||||
weights = [] # wagi prawdopodobieństwa dla każdego osobnika generacji
|
||||
pos = [] # numery od 0 do 49 odpowiadające numerom osobnikom w generacji
|
||||
for i in range(population):
|
||||
weights.append(generation[i][1] / s)
|
||||
pos.append(i)
|
||||
z.append(random.choices(pos, weights)[0]) # wybranie osobnika według wag prawdopodobieństwa
|
||||
z.append(random.choices(pos, weights)[0]) # wybranie osobnika według wag prawdopodobieństwa
|
||||
else: # metoda rankingu
|
||||
z = random.sample(range(0, int(population // 1.7)), 2)
|
||||
|
||||
# krzyzowanie 90% szans, mutacja 10% szans
|
||||
function = [divide_gardens, mutation]
|
||||
weight = [0.9, 0.1]
|
||||
fun = random.choices(function, weight)[0]
|
||||
h = fun(generation[z[0]][0], generation[z[1]][0])
|
||||
if len(h[0]) == 2:
|
||||
new_generation.append(h[0])
|
||||
new_generation.append(h[1])
|
||||
j += 2
|
||||
else:
|
||||
new_generation.append(h)
|
||||
j += 1
|
||||
|
||||
new_generation.sort(reverse=True, key=lambda x: x[1]) # sortowanie malejąco listy według wartości plonów
|
||||
generation = new_generation[:population]
|
||||
|
||||
best.append(generation[0])
|
||||
|
||||
best.sort(reverse=True, key=lambda x: x[1])
|
||||
|
||||
# Zapis do pliku
|
||||
# for i in range(len(best)):
|
||||
# print(best[i][1], calculate_yields(best[i][0]))
|
||||
#
|
||||
#
|
||||
# with open(f'pole3_pop{population}_{iter}_{roulette}.json', 'w') as file: # zapis planszy/ogrodu do pliku json
|
||||
# json.dump(best[0][0], file, indent=4)
|
||||
#
|
||||
# print("Dane zapisane do pliku")
|
||||
#
|
||||
# Odczyt z pliku
|
||||
# with open(f'pole3_pop{population}_{iter}_{roulette}.json', 'r') as file:
|
||||
# garden_data = json.load(file)
|
||||
#
|
||||
# print("Odczytane dane ogrodu:")
|
||||
# for row in garden_data:
|
||||
# print(row)
|
||||
#
|
||||
# print(calculate_yields(garden_data))
|
||||
# if best[0][0] == garden_data:
|
||||
# print("POPRAWNE: ", calculate_yields(garden_data), calculate_yields(best[0][0]))
|
87
Image.py
87
Image.py
@ -1,104 +1,29 @@
|
||||
import pygame
|
||||
import displayControler as dCon
|
||||
import random
|
||||
import neuralnetwork
|
||||
import os
|
||||
|
||||
class Image:
|
||||
def __init__(self):
|
||||
self.plants_image_dict={}
|
||||
self.tractor_image=None
|
||||
self.garage_image=None
|
||||
self.stone_image=None
|
||||
self.gasStation_image=None
|
||||
def load_images(self):
|
||||
files_plants={
|
||||
0:"borowka",
|
||||
files_plants={0:"borowka",
|
||||
1:"kukurydza",
|
||||
2:"pszenica",
|
||||
3:"slonecznik",
|
||||
4:"winogrono",
|
||||
5:"ziemniak",
|
||||
6:"dirt",
|
||||
7:"mud",
|
||||
8:"road"}
|
||||
5:"ziemniak"}
|
||||
for index in files_plants:
|
||||
if index >= 6:
|
||||
plant_image = pygame.image.load("images/" + files_plants[index] + ".jpg")
|
||||
else:
|
||||
plant_image=pygame.image.load("images/plants/"+files_plants[index]+".jpg")
|
||||
plant_image=pygame.image.load("images/plants/"+files_plants[index]+".jpg")
|
||||
plant_image=pygame.transform.scale(plant_image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||
self.plants_image_dict[files_plants[index]]=plant_image
|
||||
tractor_image=pygame.image.load("images/traktor.png")
|
||||
tractor_image=pygame.transform.scale(tractor_image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||
garage=pygame.image.load("images/garage.png")
|
||||
self.garage_image=pygame.transform.scale(garage,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||
stone=pygame.image.load("images/stone.png")
|
||||
self.stone_image=pygame.transform.scale(stone,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||
gasStation=pygame.image.load("images/gasStation.png")
|
||||
self.gasStation_image=pygame.transform.scale(gasStation,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||
|
||||
def return_random_plant(self):
|
||||
x=random.randint(0,5) #disabled dirt and mud generation
|
||||
x=random.randint(0,5)
|
||||
keys=list(self.plants_image_dict.keys())
|
||||
plant=keys[x]
|
||||
return (plant,self.plants_image_dict[plant])
|
||||
return self.plants_image_dict[plant]
|
||||
|
||||
def return_plant(self,plant_name):
|
||||
return (plant_name,self.plants_image_dict[plant_name])
|
||||
|
||||
def return_garage(self):
|
||||
return self.garage_image
|
||||
|
||||
def return_stone(self):
|
||||
return self.stone_image
|
||||
|
||||
def return_gasStation(self):
|
||||
return self.gasStation_image
|
||||
|
||||
# losowanie zdjęcia z testowego datasetu bez powtórzeń
|
||||
imagePathList = []
|
||||
def getRandomImageFromDataBase():
|
||||
label = random.choice(neuralnetwork.labels)
|
||||
folderPath = f"dataset/test/{label}"
|
||||
files = os.listdir(folderPath)
|
||||
random_image = random.choice(files)
|
||||
imgPath = os.path.join(folderPath, random_image)
|
||||
|
||||
while imgPath in imagePathList:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
label = random.choice(neuralnetwork.labels)
|
||||
folderPath = f"dataset/test/{label}"
|
||||
files = os.listdir(folderPath)
|
||||
random_image = random.choice(files)
|
||||
imgPath = os.path.join(folderPath, random_image)
|
||||
|
||||
imagePathList.append(imgPath)
|
||||
|
||||
image = pygame.image.load(imgPath)
|
||||
image=pygame.transform.scale(image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||
return image, label, imgPath
|
||||
|
||||
def getSpedifiedImageFromDatabase(label):
|
||||
folderPath = f"dataset/test/{label}"
|
||||
files = os.listdir(folderPath)
|
||||
random_image = random.choice(files)
|
||||
imgPath = os.path.join(folderPath, random_image)
|
||||
|
||||
while imgPath in imagePathList:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
label = random.choice(neuralnetwork.labels)
|
||||
folderPath = f"dataset/test/{label}"
|
||||
files = os.listdir(folderPath)
|
||||
random_image = random.choice(files)
|
||||
imgPath = os.path.join(folderPath, random_image)
|
||||
|
||||
imagePathList.append(imgPath)
|
||||
|
||||
image = pygame.image.load(imgPath)
|
||||
image=pygame.transform.scale(image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||
return image, label, imgPath
|
||||
return self.plants_image_dict[plant_name]
|
13
Node.py
13
Node.py
@ -1,13 +0,0 @@
|
||||
class Node:
|
||||
state = None #[{stan}]
|
||||
parent = None #[Node]
|
||||
action = None #[Forward/Right/Left]
|
||||
|
||||
def __init__(self, state):
|
||||
self.state = state
|
||||
|
||||
def __lt__(self, other):
|
||||
"""
|
||||
Definicja metody __lt__ (less than), która jest wymagana do porównywania obiektów typu Node.
|
||||
"""
|
||||
return self.g + self.h < other.g + other.h
|
19
Osprzet.py
19
Osprzet.py
@ -1,19 +0,0 @@
|
||||
import Akcja
|
||||
class Osprzet:
|
||||
def __init__(self, id, marka, model, akcje = None):
|
||||
self.id = id
|
||||
self.marka = marka
|
||||
self.model = model
|
||||
if akcje is None:
|
||||
self.akcje = []
|
||||
else:
|
||||
self.akcje = akcje
|
||||
|
||||
|
||||
plug = Osprzet(1,'Bomet', 'U031')
|
||||
siewnik = Osprzet(2, "Amazone", "12001-C")
|
||||
rozsiewacz = Osprzet(3, 'John Deere', 'TF 1500', [Akcja.Akcja("zyznosc")])
|
||||
opryskiwacz = Osprzet(4, 'John Deere', 'M720', [Akcja.Akcja("grzyb"), Akcja.Akcja("bakterie"), Akcja.Akcja("nawodnienie"), Akcja.Akcja("wzrost")])
|
||||
header = Osprzet(5, 'John Deere', 'X350R')
|
||||
#jak istnieją jakieś bardziej profesjonalne nazwy czy lepsze to śmiało zmieńcie
|
||||
|
61
Pole.py
61
Pole.py
@ -4,21 +4,14 @@ import Colors
|
||||
import pygame
|
||||
import time
|
||||
import Ui
|
||||
import math
|
||||
import random
|
||||
import neuralnetwork
|
||||
import Image
|
||||
|
||||
stoneList = [(3,3), (3,4), (3,5), (3,6), (4,6), (5,6), (6,6), (7,6), (8,6), (9,6), (10,6), (11,6), (12,6), (13,6), (14,6), (15,6), (16,6), (16,7), (16,8), (16,9)]
|
||||
stoneFlag = False
|
||||
|
||||
class Pole:
|
||||
def __init__(self,screen,image_loader, gasStation = (-1, -1)):
|
||||
def __init__(self,screen,image_loader):
|
||||
self.screen=screen
|
||||
self.slot_dict={} #Slot are stored in dictionary with key being a Tuple of x and y coordinates so top left slot key is (0,0) and value is slot object
|
||||
self.ui=Ui.Ui(screen)
|
||||
self.image_loader=image_loader
|
||||
self.gasStation=gasStation
|
||||
|
||||
def get_slot_from_cord(self,coordinates):
|
||||
(x_axis,y_axis)=coordinates
|
||||
@ -30,9 +23,9 @@ class Pole:
|
||||
|
||||
def get_slot_dict(self): #returns whole slot_dict
|
||||
return self.slot_dict
|
||||
|
||||
|
||||
#Draw grid and tractor (new one)
|
||||
def draw_grid(self, nn=False):
|
||||
def draw_grid(self):
|
||||
for x in range(0,dCon.NUM_X): #Draw all cubes in X axis
|
||||
for y in range(0,dCon.NUM_Y): #Draw all cubes in Y axis
|
||||
new_slot=Slot.Slot(x,y,Colors.BROWN,self.screen,self.image_loader) #Creation of empty slot
|
||||
@ -40,55 +33,13 @@ class Pole:
|
||||
slot_dict=self.get_slot_dict()
|
||||
for coordinates in slot_dict:
|
||||
slot_dict[coordinates].draw()
|
||||
garage=self.slot_dict[(0,0)]
|
||||
garage.set_garage_image()
|
||||
if stoneFlag:
|
||||
for i in stoneList:
|
||||
st=self.slot_dict[i]
|
||||
st.set_stone_image()
|
||||
if self.gasStation[0] != -1:
|
||||
st=self.slot_dict[self.gasStation]
|
||||
st.set_gasStation_image()
|
||||
|
||||
def randomize_colors(self, nn = False):
|
||||
def randomize_colors(self):
|
||||
pygame.display.update()
|
||||
time.sleep(3)
|
||||
#self.ui.render_text("Randomizing Crops")
|
||||
self.ui.render_text("Randomizing Crops")
|
||||
for coordinates in self.slot_dict:
|
||||
if(stoneFlag):
|
||||
if( coordinates in stoneList or coordinates == self.gasStation ):
|
||||
continue
|
||||
if(coordinates==(0,0)):
|
||||
continue
|
||||
else:
|
||||
self.slot_dict[coordinates].set_random_plant(nn)
|
||||
def setPlantsByList(self, plantList):
|
||||
pygame.display.update()
|
||||
time.sleep(3)
|
||||
for coordinates in self.slot_dict:
|
||||
if(coordinates==(0,0)):
|
||||
continue
|
||||
else:
|
||||
self.slot_dict[coordinates].set_specifided_plant(plantList[coordinates[1]][coordinates[0]])
|
||||
self.slot_dict[coordinates].set_random_plant()
|
||||
|
||||
def change_color_of_slot(self,coordinates,color): #Coordinates must be tuple (x,y) (left top slot has cord (0,0) ), color has to be from defined in Colors.py or custom in RGB value (R,G,B)
|
||||
self.get_slot_from_cord(coordinates).color_change(color)
|
||||
|
||||
def get_neighbor(self, slot, dx, dy):
|
||||
neighbor_x = slot.x_axis + dx
|
||||
neighbor_y = slot.y_axis + dy
|
||||
return self.get_slot_from_cord((neighbor_x, neighbor_y))
|
||||
|
||||
def is_valid_move(self, coordinates):
|
||||
return coordinates in self.slot_dict
|
||||
|
||||
def check_collision(self,mouse_x,mouse_y):
|
||||
mouse_x=math.floor(mouse_x/dCon.CUBE_SIZE)
|
||||
mouse_y=math.floor(mouse_y/dCon.CUBE_SIZE)
|
||||
if(mouse_x<dCon.NUM_X):
|
||||
if(mouse_y<dCon.NUM_Y):
|
||||
collided=self.get_slot_from_cord((mouse_x,mouse_y))
|
||||
return collided.print_status()
|
||||
return ""
|
||||
|
||||
|
||||
|
123
Roslina.py
123
Roslina.py
@ -1,123 +0,0 @@
|
||||
import Stan
|
||||
import Srodek
|
||||
import random
|
||||
|
||||
class Roslina:
|
||||
nazwa = None #[string]
|
||||
stan = None #[Stan]
|
||||
srodek = None #[List<Srodek>]
|
||||
|
||||
|
||||
"""
|
||||
Nawodnienie (update co 30s):
|
||||
- pszenica: -8
|
||||
- kukurydza: -7
|
||||
- ziemniak: -6
|
||||
- słonecznik: -5
|
||||
- borówka: -4
|
||||
- winogrono: -4
|
||||
|
||||
Żyzność (update co 30s):
|
||||
- pszenica: -7
|
||||
- kukurydza: -4
|
||||
- ziemniak: -5
|
||||
- słonecznik: -3
|
||||
- borówka: -5
|
||||
- winogrono: -4
|
||||
|
||||
Wzrost (update co 30s):
|
||||
- pszenica: +8
|
||||
- kukurydza: +4
|
||||
- ziemniak: +5
|
||||
- słonecznik: +3
|
||||
- borówka: +5
|
||||
- winogrono: +4
|
||||
|
||||
Koszt (0-15):
|
||||
- pszenica: 7
|
||||
- kukurydza: 9
|
||||
- ziemniak: 2
|
||||
- słonecznik: 5
|
||||
- borówka: 3
|
||||
- winogrono: 4
|
||||
- szuter (ścieżka): 0
|
||||
- błoto: 15
|
||||
|
||||
|
||||
def __init__(self, nazwa, stan, srodek):
|
||||
self.nazwa = nazwa
|
||||
self.stan = stan
|
||||
self.srodek = srodek
|
||||
"""
|
||||
|
||||
def __init__(self, nazwa):
|
||||
self.nazwa = nazwa
|
||||
self.stan = Stan.Stan()
|
||||
if nazwa == "dirt":
|
||||
self.stan.koszt = 0
|
||||
self.stan.nawodnienie = 100
|
||||
elif nazwa == "mud":
|
||||
self.stan.koszt = 15
|
||||
self.stan.nawodnienie = 100
|
||||
else:
|
||||
self.stan.set_random()
|
||||
if nazwa == "pszenica":
|
||||
self.stan.koszt = 7
|
||||
elif nazwa == "kukurydza":
|
||||
self.stan.koszt = 9
|
||||
elif nazwa == "ziemniak":
|
||||
self.stan.koszt = 2
|
||||
elif nazwa == "slonecznik":
|
||||
self.stan.koszt = 5
|
||||
elif nazwa == "borowka":
|
||||
self.stan.koszt = 3
|
||||
else: # winogrono
|
||||
self.stan.koszt = 4
|
||||
self.srodek = None
|
||||
|
||||
|
||||
def checkSrodek(self):
|
||||
#może wykorzystać AI do porównywania zdjęć
|
||||
|
||||
for i in self.srodek:
|
||||
for j in self.stan.akcja.srodki:
|
||||
if i == j:
|
||||
return i
|
||||
return False
|
||||
|
||||
|
||||
def doAkcja(self):
|
||||
# sprawdza jaki srodek do danej akcji i jaki z nich może być użyty przy tej roślinie
|
||||
# robi akcje
|
||||
# aktualizuje dane o stanie i zdjęcie w zależności od wykonanej czynności (benefits w klasie akcja) -> (self.stan.akcja.benefits)
|
||||
|
||||
x = self.checkSrodek()
|
||||
# robi akcje
|
||||
setattr(self.stan, self.stan.akcja.benefits[0], self.stan.akcja.benefits[1])
|
||||
return
|
||||
|
||||
|
||||
def isAkcja(self):
|
||||
# sprawdza czy jakaś akcja musi być wykonana, jeżeli tak, to ją wywołuje
|
||||
# sprawdza czy jeszcze coś trzeba zrobić
|
||||
|
||||
self.stan.checkStan()
|
||||
while self.stan.akcja != None:
|
||||
self.doAkcja()
|
||||
self.stan.checkStan()
|
||||
return
|
||||
|
||||
def return_stan(self):
|
||||
return self.stan
|
||||
|
||||
def return_stan_for_tree(self):
|
||||
return self.stan.return_stan_for_tree()
|
||||
|
||||
def get_hydrate_stats(self):
|
||||
return self.stan.return_hydrate()
|
||||
|
||||
def report_status(self):
|
||||
return f"Nazwa rosliny: {self.nazwa} "+self.stan.report_all()
|
||||
|
||||
def return_status_tree(self):
|
||||
return self.stan.return_stan_for_tree()
|
82
Slot.py
82
Slot.py
@ -3,105 +3,37 @@ import displayControler as dCon
|
||||
import Colors
|
||||
import random
|
||||
import Image
|
||||
import Roslina
|
||||
|
||||
BORDER_THICKNESS=1 #Has to be INT value
|
||||
class Slot:
|
||||
def __init__(self,x_axis,y_axis,color,screen,image_loader):
|
||||
self.x_axis=x_axis
|
||||
self.y_axis=y_axis
|
||||
self.plant_image = None
|
||||
self.plant=None
|
||||
self.plant=color #TODO CHANGE IT BY HOOKING PLANT CLASS
|
||||
self.screen=screen
|
||||
self.field=pygame.Rect(self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE,dCon.CUBE_SIZE,dCon.CUBE_SIZE)
|
||||
self.image_loader=image_loader
|
||||
self.garage_image=None
|
||||
self.label = None
|
||||
self.imagePath = None
|
||||
|
||||
def draw(self):
|
||||
pygame.draw.rect(self.screen,Colors.BROWN,self.field,0) #Draw field
|
||||
pygame.draw.rect(self.screen,Colors.BLACK,self.field,BORDER_THICKNESS) #Draw border
|
||||
pygame.display.update()
|
||||
|
||||
def redraw_image(self, destroy = True):
|
||||
if destroy:
|
||||
self.mark_visited()
|
||||
else:
|
||||
self.screen.blit(self.plant_image, (self.x_axis * dCon.CUBE_SIZE, self.y_axis * dCon.CUBE_SIZE))
|
||||
pygame.draw.rect(self.screen, Colors.BLACK, self.field, BORDER_THICKNESS)
|
||||
|
||||
def mark_visited(self):
|
||||
plant,self.plant_image=self.image_loader.return_plant('road')
|
||||
self.screen.blit(self.plant_image, (self.x_axis * dCon.CUBE_SIZE, self.y_axis * dCon.CUBE_SIZE))
|
||||
pygame.draw.rect(self.screen, Colors.BLACK, self.field, BORDER_THICKNESS)
|
||||
def redraw_image(self):
|
||||
self.set_image()
|
||||
|
||||
def color_change(self,color):
|
||||
self.plant=color
|
||||
self.draw()
|
||||
|
||||
def set_random_plant(self, nn=False):
|
||||
if not nn:
|
||||
(plant_name,self.plant_image)=self.random_plant()
|
||||
self.plant=Roslina.Roslina(plant_name)
|
||||
else:
|
||||
self.plant_image, self.label, self.imagePath = self.random_plant_dataset()
|
||||
# print(self.plant_image)
|
||||
self.plant=Roslina.Roslina(self.label)
|
||||
self.set_image()
|
||||
|
||||
def set_specifided_plant(self, plant):
|
||||
self.plant_image, self.label, self.imagePath = self.specified_plant_dataset(plant)
|
||||
self.plant=Roslina.Roslina(self.label)
|
||||
def set_random_plant(self):
|
||||
self.plant=self.random_plant()
|
||||
self.set_image()
|
||||
|
||||
def set_image(self):
|
||||
if self.plant_image is None:
|
||||
self.plant_image = self.image_loader.return_random_plant()
|
||||
self.screen.blit(self.plant_image, (self.x_axis * dCon.CUBE_SIZE, self.y_axis * dCon.CUBE_SIZE))
|
||||
pygame.draw.rect(self.screen, Colors.BLACK, self.field, BORDER_THICKNESS)
|
||||
self.screen.blit(self.plant,(self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE))
|
||||
pygame.draw.rect(self.screen,Colors.BLACK,self.field,BORDER_THICKNESS)
|
||||
|
||||
def set_garage_image(self):
|
||||
self.plant_image=self.image_loader.return_garage()
|
||||
self.screen.blit(self.plant_image, (self.x_axis * dCon.CUBE_SIZE, self.y_axis * dCon.CUBE_SIZE))
|
||||
pygame.draw.rect(self.screen, Colors.BLACK, self.field, BORDER_THICKNESS)
|
||||
|
||||
def set_stone_image(self):
|
||||
self.plant_image=self.image_loader.return_stone()
|
||||
self.screen.blit(self.plant_image, (self.x_axis * dCon.CUBE_SIZE, self.y_axis * dCon.CUBE_SIZE))
|
||||
pygame.draw.rect(self.screen, Colors.BLACK, self.field, BORDER_THICKNESS)
|
||||
|
||||
def set_gasStation_image(self):
|
||||
self.plant_image=self.image_loader.return_gasStation()
|
||||
self.screen.blit(self.plant_image, (self.x_axis * dCon.CUBE_SIZE, self.y_axis * dCon.CUBE_SIZE))
|
||||
pygame.draw.rect(self.screen, Colors.BLACK, self.field, BORDER_THICKNESS)
|
||||
|
||||
def random_plant(self): #Probably will not be used later only for demo purpouse
|
||||
return self.image_loader.return_random_plant()
|
||||
def random_plant_dataset(self):
|
||||
return Image.getRandomImageFromDataBase()
|
||||
def specified_plant_dataset(self, plant):
|
||||
return Image.getSpedifiedImageFromDatabase(plant)
|
||||
|
||||
def return_plant(self):
|
||||
return self.plant
|
||||
|
||||
def get_hydrate_stats(self):
|
||||
return self.plant.get_hydrate_stats()
|
||||
|
||||
def print_status(self):
|
||||
return f"wspolrzedne: (X:{self.x_axis} Y:{self.y_axis}) "+self.plant.report_status()
|
||||
|
||||
def irrigatePlant(self):
|
||||
self.plant.stan.nawodnienie = 100
|
||||
|
||||
def setHydrate(self,index):
|
||||
if(index==0):
|
||||
self.plant.stan.nawodnienie=random.randint(0,60)
|
||||
elif(index==1):
|
||||
self.plant.stan.nawodnienie=random.randint(61,100)
|
||||
elif(index==-1):
|
||||
pass
|
||||
|
||||
def return_stan_for_tree(self):
|
||||
return self.plant.return_stan_for_tree()
|
@ -1,5 +0,0 @@
|
||||
class Srodek:
|
||||
def __init__(self, id, nazwa, typ):
|
||||
self.id = id
|
||||
self.nazwa = nazwa
|
||||
self.typ = typ
|
66
Stan.py
66
Stan.py
@ -1,66 +0,0 @@
|
||||
import Akcja
|
||||
import random
|
||||
|
||||
class Stan:
|
||||
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"
|
||||
wzrost = None #[int] 0-100 (75-100: scinanie), wzrasta w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
||||
choroba = None #[int] brak-0,choroba-1
|
||||
akcja = None #[Akcja]
|
||||
koszt = None #[int] 0-15, im więcej tym trudniej wjechać
|
||||
|
||||
|
||||
|
||||
def __init__(self, nawodnienie, zyznosc, wzrost, choroba):
|
||||
self.nawodnienie = nawodnienie
|
||||
self.zyznosc = zyznosc
|
||||
self.wzrost = wzrost
|
||||
self.choroba = choroba
|
||||
|
||||
def __init__(self):
|
||||
self.nawodnienie=0
|
||||
|
||||
def set_random(self):
|
||||
self.nawodnienie=random.randint(0,100)
|
||||
self.zyznosc=random.randint(0,100)
|
||||
self.wzrost=random.randint(0,100)
|
||||
self.choroba=random.randint(0,1)
|
||||
|
||||
def checkStan(self):
|
||||
# sprawdza stan rośliny i podejmuje akcje jeśli potrzebna
|
||||
|
||||
if self.nawodnienie <= 60:
|
||||
self.akcja = Akcja.Akcja("nawodnienie")
|
||||
return
|
||||
elif self.zyznosc <= 60:
|
||||
self.akcja = Akcja.Akcja("zyznosc")
|
||||
return
|
||||
elif self.wzrost >= 75:
|
||||
self.akcja = Akcja.Akcja("wzrost")
|
||||
return
|
||||
elif self.choroba != "brak":
|
||||
self.akcja = Akcja.Akcja(self.choroba)
|
||||
return
|
||||
else:
|
||||
self.akcja = None
|
||||
return
|
||||
|
||||
def return_hydrate(self):
|
||||
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):
|
||||
return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.return_disease_as_string()}"
|
||||
|
304
Tractor.py
304
Tractor.py
@ -1,290 +1,42 @@
|
||||
import time
|
||||
import pygame
|
||||
import random
|
||||
|
||||
import Pole
|
||||
import displayControler as dCon
|
||||
import Slot
|
||||
import Osprzet
|
||||
import Node
|
||||
import Condition
|
||||
import Drzewo
|
||||
import neuralnetwork as nn
|
||||
|
||||
condition=Condition.Condition()
|
||||
drzewo=Drzewo.Drzewo()
|
||||
|
||||
format_string = "{:<25}{:<25}{:<25}{:<10}{:<10}{:<10}{:<25}{:<15}{:<20}{:<10}{:<15}"
|
||||
format_string_nn="{:<10}{:<20}{:<20}{:<15}{:<20}"
|
||||
|
||||
|
||||
tab = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
|
||||
0, 1, 0, 1, 0, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
|
||||
|
||||
|
||||
class Tractor:
|
||||
DIRECTION_NORTH = 'N'
|
||||
DIRECTION_SOUTH = 'S'
|
||||
DIRECTION_WEST = 'W'
|
||||
DIRECTION_EAST = 'E'
|
||||
|
||||
def __init__(self,slot,screen, osprzet,clock,bfs2_flag):
|
||||
self.tractor_images = {
|
||||
Tractor.DIRECTION_NORTH: pygame.transform.scale(pygame.image.load('images/traktorN.png'),
|
||||
(dCon.CUBE_SIZE, dCon.CUBE_SIZE)),
|
||||
Tractor.DIRECTION_SOUTH: pygame.transform.scale(pygame.image.load('images/traktorS.png'),
|
||||
(dCon.CUBE_SIZE, dCon.CUBE_SIZE)),
|
||||
Tractor.DIRECTION_WEST: pygame.transform.scale(pygame.image.load('images/traktorW.png'),
|
||||
(dCon.CUBE_SIZE, dCon.CUBE_SIZE)),
|
||||
Tractor.DIRECTION_EAST: pygame.transform.scale(pygame.image.load('images/traktor.png'),
|
||||
(dCon.CUBE_SIZE, dCon.CUBE_SIZE))
|
||||
}
|
||||
self.direction = Tractor.DIRECTION_EAST # początkowy kierunek wschód
|
||||
self.current_tractor_image = self.tractor_images[self.direction]
|
||||
def __init__(self,x_axis,y_axis,screen):
|
||||
self.x_axis=x_axis
|
||||
self.y_axis=y_axis
|
||||
self.tractor_image = pygame.image.load('images/traktor.png')
|
||||
self.tractor_image = pygame.transform.scale(self.tractor_image, (dCon.CUBE_SIZE, dCon.CUBE_SIZE))
|
||||
self.screen=screen
|
||||
self.slot=slot
|
||||
self.osprzet = osprzet
|
||||
self.clock=clock
|
||||
self.slot_hydrate_dict={}
|
||||
self.bfs2_flag=bfs2_flag
|
||||
self.waterLevel=random.randint(0,100)
|
||||
self.slot=None
|
||||
|
||||
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.tractor_image, (self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE))
|
||||
pygame.display.update()
|
||||
|
||||
def turn_left(self):
|
||||
# zmiana kierunku w lewo
|
||||
direction_map = {
|
||||
Tractor.DIRECTION_EAST: Tractor.DIRECTION_NORTH,
|
||||
Tractor.DIRECTION_NORTH: Tractor.DIRECTION_WEST,
|
||||
Tractor.DIRECTION_WEST: Tractor.DIRECTION_SOUTH,
|
||||
Tractor.DIRECTION_SOUTH: Tractor.DIRECTION_EAST
|
||||
}
|
||||
self.direction = direction_map[self.direction]
|
||||
self.current_tractor_image = self.tractor_images[self.direction]
|
||||
def move_tractor(self,x):
|
||||
if(x==0):
|
||||
if(dCon.isValidMove(self.x_axis + 1, self.y_axis)):
|
||||
print("Ruch w prawo")
|
||||
self.x_axis=self.x_axis+1
|
||||
elif(x==1):
|
||||
if(dCon.isValidMove(self.x_axis - 1, self.y_axis)):
|
||||
print("Ruch w lewo")
|
||||
self.x_axis=self.x_axis-1
|
||||
elif(x==2):
|
||||
if(dCon.isValidMove(self.x_axis, self.y_axis + 1)):
|
||||
print("Ruch w dol")
|
||||
self.y_axis=self.y_axis+1
|
||||
elif(x==3):
|
||||
if(dCon.isValidMove(self.x_axis, self.y_axis - 1)):
|
||||
print("Ruch w gore")
|
||||
self.y_axis=self.y_axis-1
|
||||
self.draw_tractor()
|
||||
|
||||
def tree_move(self, pole):
|
||||
drzewo.treeLearn()
|
||||
drzewo.plotTree()
|
||||
self.snake_move_irrigation(pole, drzewo)
|
||||
|
||||
def get_attributes(self):
|
||||
slot_attributes=self.slot.return_stan_for_tree()
|
||||
climate_attributes=condition.return_condition()
|
||||
attributes=[]
|
||||
attributes=attributes+slot_attributes+[self.waterLevel]+climate_attributes
|
||||
return attributes
|
||||
|
||||
def get_attributes_for_print(self):
|
||||
slot_attributes=self.slot.return_plant().return_status_tree()
|
||||
climate_attributes=condition.getCondition()
|
||||
slot_attributes=slot_attributes+[self.waterLevel]
|
||||
return slot_attributes+climate_attributes
|
||||
|
||||
def turn_right(self):
|
||||
# zmiana kierunku w prawo
|
||||
direction_map = {
|
||||
Tractor.DIRECTION_EAST: Tractor.DIRECTION_SOUTH,
|
||||
Tractor.DIRECTION_SOUTH: Tractor.DIRECTION_WEST,
|
||||
Tractor.DIRECTION_WEST: Tractor.DIRECTION_NORTH,
|
||||
Tractor.DIRECTION_NORTH: Tractor.DIRECTION_EAST
|
||||
}
|
||||
self.direction = direction_map[self.direction]
|
||||
self.current_tractor_image = self.tractor_images[self.direction]
|
||||
self.draw_tractor()
|
||||
|
||||
def move_forward(self, pole, destroy = True):
|
||||
next_slot_coordinates = None
|
||||
if self.direction == Tractor.DIRECTION_EAST:
|
||||
next_slot_coordinates = (self.slot.x_axis + 1, self.slot.y_axis)
|
||||
self.current_tractor_image = self.tractor_images[self.direction]
|
||||
elif self.direction == Tractor.DIRECTION_WEST:
|
||||
next_slot_coordinates = (self.slot.x_axis - 1, self.slot.y_axis)
|
||||
self.current_tractor_image = self.tractor_images[self.direction]
|
||||
elif self.direction == Tractor.DIRECTION_SOUTH:
|
||||
next_slot_coordinates = (self.slot.x_axis, self.slot.y_axis + 1)
|
||||
self.current_tractor_image = self.tractor_images[self.direction]
|
||||
elif self.direction == Tractor.DIRECTION_NORTH:
|
||||
next_slot_coordinates = (self.slot.x_axis, self.slot.y_axis - 1)
|
||||
self.current_tractor_image = self.tractor_images[self.direction]
|
||||
|
||||
# sprawdzenie czy następny slot jest dobry
|
||||
self.do_move_if_valid(pole,next_slot_coordinates, destroy)
|
||||
self.clock.tick(10)
|
||||
|
||||
def do_move_if_valid(self,pole, next_slot_coordinates, destroy = True):
|
||||
if next_slot_coordinates and pole.is_valid_move(next_slot_coordinates):
|
||||
next_slot = pole.get_slot_from_cord(next_slot_coordinates)
|
||||
self.slot.redraw_image(destroy)
|
||||
self.slot = next_slot
|
||||
self.draw_tractor()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def random_move(self, pole):
|
||||
self.clock.tick(2)
|
||||
# losowanie skrętu
|
||||
turn_direction = random.choice([self.turn_left, self.turn_right])
|
||||
turn_direction()
|
||||
self.clock.tick(5)
|
||||
# wykonanie ruchu do przodu z uwzględnieniem aktualnej orientacji
|
||||
self.move_forward(pole)
|
||||
|
||||
def reset_pos(self,pole):
|
||||
self.do_move_if_valid(pole,(0,0))
|
||||
|
||||
def initial_move(self,pole):
|
||||
if (self.bfs2_flag==True):
|
||||
index=0
|
||||
|
||||
for y in range (0,dCon.NUM_Y):
|
||||
if(y%2==0):
|
||||
for x in range(0,dCon.NUM_X):
|
||||
if(pole.is_valid_move((x,y))):
|
||||
pole.get_slot_from_cord((x,y)).setHydrate(tab[index])
|
||||
self.snake_move(pole,x,y)
|
||||
index=index+1
|
||||
else:
|
||||
for x in range(dCon.NUM_X,-1,-1):
|
||||
if(pole.is_valid_move((x,y))):
|
||||
pole.get_slot_from_cord((x,y)).setHydrate(tab[index])
|
||||
self.snake_move(pole,x,y)
|
||||
index=index+1
|
||||
else:
|
||||
for y in range (0,dCon.NUM_Y):
|
||||
if(y%2==0):
|
||||
for x in range(0,dCon.NUM_X):
|
||||
self.snake_move(pole,x,y)
|
||||
else:
|
||||
for x in range(dCon.NUM_X,-1,-1):
|
||||
self.snake_move(pole,x,y)
|
||||
|
||||
|
||||
def snake_move_irrigation(self, pole, drzewo):
|
||||
headers=['Wspolrzedne','Czy podlac','Poziom nawodnienia','Wzrost','Choroba','Zyznosc','Poziom wody w traktorze','Temperatura','Opady','Pora Roku','Aktualny czas']
|
||||
print(format_string.format(*headers))
|
||||
initPos = (self.slot.x_axis, self.slot.y_axis)
|
||||
counter = 0
|
||||
for i in range(initPos[1], dCon.NUM_Y):
|
||||
for j in range(initPos[0], dCon.NUM_X):
|
||||
attributes=self.get_attributes()
|
||||
decision = drzewo.makeDecision(attributes)
|
||||
self.pretty_print_tree([str("({:02d}, {:02d})").format(self.slot.x_axis, self.slot.y_axis),decision,*self.get_attributes_for_print()])
|
||||
if decision == "Tak":
|
||||
self.slot.irrigatePlant()
|
||||
counter += 1
|
||||
condition.cycle()
|
||||
pygame.time.delay(50)
|
||||
self.waterLevel=random.randint(0,100)
|
||||
#condition.getCondition()
|
||||
self.move_forward(pole, False)
|
||||
if i % 2 == 0 and i != dCon.NUM_Y - 1:
|
||||
self.turn_right()
|
||||
self.move_forward(pole, False)
|
||||
self.turn_right()
|
||||
elif i != dCon.NUM_Y - 1:
|
||||
self.turn_left()
|
||||
self.move_forward(pole, False)
|
||||
self.turn_left()
|
||||
print("podlanych slotów: ", str(counter))
|
||||
|
||||
def snake_move_predict_plant(self, pole, model, headers, actions = None):
|
||||
print(format_string_nn.format(*headers))
|
||||
initPos = (self.slot.x_axis, self.slot.y_axis)
|
||||
count = 0
|
||||
for i in range(initPos[1], dCon.NUM_Y):
|
||||
for j in range(initPos[0], dCon.NUM_X):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
if self.slot.imagePath != None:
|
||||
predictedLabel = nn.predictLabel(self.slot.imagePath, model)
|
||||
|
||||
#print(str("Coords: ({:02d}, {:02d})").format(self.slot.x_axis, self.slot.y_axis), "real:", self.slot.label, "predicted:", predictedLabel, "correct" if (self.slot.label == predictedLabel) else "incorrect", 'nawożę za pomocą:', nn.fertilizer[predictedLabel])
|
||||
# print(format_string_nn.format(f"{self.slot.x_axis,self.slot.y_axis}",self.slot.label,predictedLabel,"correct" if (self.slot.label == predictedLabel) else "incorrect",nn.fertilizer[predictedLabel]))
|
||||
for a in actions:
|
||||
a(predictedLabel)
|
||||
if self.slot.label != predictedLabel:
|
||||
# self.slot.mark_visited()
|
||||
count += 1
|
||||
self.move_forward(pole, False)
|
||||
if i % 2 == 0 and i != dCon.NUM_Y - 1:
|
||||
self.turn_right()
|
||||
self.move_forward(pole, False)
|
||||
self.turn_right()
|
||||
elif i != dCon.NUM_Y - 1:
|
||||
self.turn_left()
|
||||
self.move_forward(pole, False)
|
||||
self.turn_left()
|
||||
print(f"Dobrze rozpoznanych roślin: {20*12-count}, źle rozpoznanych roślin: {count}")
|
||||
|
||||
def fertilize_slot(self, predictedLabel):
|
||||
print(format_string_nn.format(f"{self.slot.x_axis,self.slot.y_axis}",self.slot.label,predictedLabel,"correct" if (self.slot.label == predictedLabel) else "incorrect",nn.fertilizer[predictedLabel]))
|
||||
if self.slot.label != predictedLabel:
|
||||
self.slot.mark_visited()
|
||||
|
||||
def irigate_slot_NN(self, predictedLabel):
|
||||
attributes=self.get_attributes()
|
||||
decision = drzewo.makeDecision(attributes)
|
||||
print(format_string_nn.format(f"{self.slot.x_axis,self.slot.y_axis}",self.slot.label,predictedLabel,"correct" if (self.slot.label == predictedLabel) else "incorrect",decision))
|
||||
condition.cycle()
|
||||
self.waterLevel = random.randint(0, 100)
|
||||
|
||||
def snake_move(self,pole,x,y):
|
||||
next_slot_coordinates=(x,y)
|
||||
if(self.do_move_if_valid(pole,next_slot_coordinates)):
|
||||
if (x,y) not in Pole.stoneList:
|
||||
if x == 0 and y == 0:
|
||||
hydrateIndex = -1
|
||||
elif pole.get_slot_from_cord((x,y)).get_hydrate_stats() < 60:
|
||||
hydrateIndex = 0
|
||||
else:
|
||||
hydrateIndex = 1
|
||||
self.slot_hydrate_dict[(x,y)]= hydrateIndex #Budowanie slownika slotow z poziomem nawodnienia dla traktorka
|
||||
self.clock.tick(10)
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
|
||||
def move_by_root(self, root, pole, actions = None):
|
||||
for move in root:
|
||||
self.slot.redraw_image()
|
||||
if move[1] == 'forward':
|
||||
self.move_forward(pole)
|
||||
if move[1] == 'right':
|
||||
self.turn_right()
|
||||
if move[1] == 'left':
|
||||
self.turn_left()
|
||||
for a in actions:
|
||||
a()
|
||||
|
||||
self.clock.tick(3)
|
||||
|
||||
#to tak zrobiłam już na później, może się przyda
|
||||
def change_osprzet(self, new_osprzet):
|
||||
self.osprzet = new_osprzet
|
||||
|
||||
def print_osprzet_info(self):
|
||||
print("ID:", self.osprzet.id)
|
||||
print("Marka:", self.osprzet.marka)
|
||||
print("Model:", self.osprzet.model)
|
||||
if self.osprzet.akcje:
|
||||
print("Akcje:")
|
||||
for akcja in self.osprzet.akcje:
|
||||
print("- Typ:", akcja.typ)
|
||||
else:
|
||||
print("Brak akcji przypisanych do tego sprzętu.")
|
||||
|
||||
def pretty_print_tree(self,attributes):
|
||||
print(format_string.format(*attributes))
|
||||
def irrigateSlot(self):
|
||||
try:
|
||||
self.slot.irrigatePlant()
|
||||
except:
|
||||
pass
|
||||
def random_move(self):
|
||||
x=random.randint(0,3)
|
||||
self.move_tractor(x)
|
||||
|
32
Ui.py
32
Ui.py
@ -7,36 +7,10 @@ class Ui:
|
||||
def __init__(self,screen):
|
||||
self.screen=screen
|
||||
self.font='freesansbold.ttf' #Feel free to change it :D
|
||||
if(dCon.NUM_Y<7):
|
||||
self.font_size=int(15)
|
||||
self.line=20
|
||||
self.first_line=20
|
||||
if(dCon.NUM_Y>=7):
|
||||
self.font_size=int(30)
|
||||
self.line=30
|
||||
self.first_line=30
|
||||
|
||||
self.font_size=int(32)
|
||||
def render_text(self,string_to_print):
|
||||
font=pygame.font.Font(self.font,self.font_size)
|
||||
text=font.render(string_to_print,True,Colors.BLACK,Colors.WHITE)
|
||||
textRect=text.get_rect()
|
||||
textRect.center=(dCon.getGameWidth() // 2,dCon.getScreenHeihgt() // 2)
|
||||
self.screen.blit(text,textRect)
|
||||
|
||||
def render_text_to_console(self,string_to_print):
|
||||
font=pygame.font.Font(self.font,self.font_size)
|
||||
string_to_print=str(string_to_print)
|
||||
self.break_string_to_console(string_to_print)
|
||||
for string in self.to_print:
|
||||
text=font.render(string,True,Colors.BLACK,Colors.WHITE)
|
||||
textRect=text.get_rect()
|
||||
textRect.center=(dCon.getGameWidth()+350/2,self.line)
|
||||
textRect.scale_by(x=350,y=100)
|
||||
self.screen.blit(text,textRect)
|
||||
self.line=self.line+self.first_line
|
||||
def clear_console(self):
|
||||
self.line=self.first_line
|
||||
pygame.draw.rect(self.screen,(0,0,0) , pygame.Rect(dCon.returnConsoleCoordinate(), 0, dCon.getConsoleWidth(), dCon.getScreenHeihgt()), 0)
|
||||
|
||||
def break_string_to_console(self,string_to_print):
|
||||
self.to_print=string_to_print.split(" ")
|
||||
textRect.center=(dCon.getScreenWidth() // 2,dCon.getScreenHeihgt() // 2)
|
||||
self.screen.blit(text,textRect)
|
@ -10,28 +10,8 @@ def isValidMove(x, y):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def getGameWidth():
|
||||
def getScreenWidth():
|
||||
return NUM_X * CUBE_SIZE
|
||||
|
||||
def returnConsoleCoordinate():
|
||||
return NUM_X * CUBE_SIZE
|
||||
|
||||
|
||||
|
||||
|
||||
def getScreenHeihgt():
|
||||
return NUM_Y * CUBE_SIZE
|
||||
|
||||
|
||||
def getScreenWidth(show_console):
|
||||
screen_width=getGameWidth()
|
||||
if(show_console):
|
||||
screen_width=screen_width+350
|
||||
return screen_width
|
||||
|
||||
def getConsoleWidth():
|
||||
return 350
|
||||
|
||||
def getConsoleWidthCenter():
|
||||
return getScreenWidth()+getConsoleWidth()/2
|
||||
return NUM_Y * CUBE_SIZE
|
BIN
images/dirt.jpg
BIN
images/dirt.jpg
Binary file not shown.
Before ![]() (image error) Size: 412 KiB |
Binary file not shown.
Before ![]() (image error) Size: 11 KiB |
Binary file not shown.
Before ![]() (image error) Size: 82 KiB |
BIN
images/mud.jpg
BIN
images/mud.jpg
Binary file not shown.
Before ![]() (image error) Size: 285 KiB |
BIN
images/road.jpg
BIN
images/road.jpg
Binary file not shown.
Before ![]() (image error) Size: 43 KiB |
BIN
images/stone.png
BIN
images/stone.png
Binary file not shown.
Before ![]() (image error) Size: 549 KiB |
Binary file not shown.
Before ![]() (image error) Size: 67 KiB |
Binary file not shown.
Before ![]() (image error) Size: 70 KiB |
Binary file not shown.
Before ![]() (image error) Size: 65 KiB |
2
main.py
2
main.py
@ -1,3 +1,3 @@
|
||||
import App
|
||||
|
||||
App.init(demo=True)#DEMO=TRUE WILL INIT DEMO MODE WITH RANDOM COLOR GEN
|
||||
App.init(demo=True)#DEMO=TRUE WILL INIT DEMO MODE WITH RANDOM COLOR GEN
|
Binary file not shown.
Binary file not shown.
114
neuralnetwork.py
114
neuralnetwork.py
@ -1,114 +0,0 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from torch.utils.data import DataLoader
|
||||
from torchvision import datasets
|
||||
from torchvision.transforms import Compose, Lambda, ToTensor
|
||||
import torchvision.transforms as transforms
|
||||
import matplotlib.pyplot as plt
|
||||
from PIL import Image
|
||||
import random
|
||||
|
||||
imageSize = (128, 128)
|
||||
labels = ['carrot','corn', 'potato', 'tomato'] # musi być w kolejności alfabetycznej
|
||||
fertilizer = {labels[0]: 'kompost', labels[1]: 'saletra amonowa', labels[2]: 'superfosfat', labels[3]:'obornik kurzy'}
|
||||
#labels = ['corn','tomato'] #uncomment this two lines for 2 crops only
|
||||
#fertilizer = {labels[0]: 'kompost', labels[1]: 'saletra amonowa'}
|
||||
torch.manual_seed(42)
|
||||
|
||||
#device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
device = torch.device("cpu")
|
||||
# device = torch.device("mps") if torch.backends.mps.is_available() else torch.device('cpu')
|
||||
# print(device)
|
||||
|
||||
def getTransformation():
|
||||
transform=transforms.Compose([
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
|
||||
transforms.Resize(imageSize),
|
||||
Lambda(lambda x: x.flatten())])
|
||||
return transform
|
||||
|
||||
def getDataset(train=True):
|
||||
transform = getTransformation()
|
||||
if (train):
|
||||
trainset = datasets.ImageFolder(root='dataset/train', transform=transform)
|
||||
return trainset
|
||||
else:
|
||||
testset = datasets.ImageFolder(root='dataset/test', transform=transform)
|
||||
return testset
|
||||
|
||||
|
||||
def train(model, dataset, n_iter=100, batch_size=256):
|
||||
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
|
||||
criterion = nn.NLLLoss()
|
||||
dl = DataLoader(dataset, batch_size=batch_size)
|
||||
model.train()
|
||||
for epoch in range(n_iter):
|
||||
for images, targets in dl:
|
||||
optimizer.zero_grad()
|
||||
out = model(images.to(device))
|
||||
loss = criterion(out, targets.to(device))
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
if epoch % 10 == 0:
|
||||
print('epoch: %3d loss: %.4f' % (epoch, loss))
|
||||
return model
|
||||
|
||||
def accuracy(model, dataset):
|
||||
model.eval()
|
||||
correct = sum([(model(images.to(device)).argmax(dim=1) == targets.to(device)).sum()
|
||||
for images, targets in DataLoader(dataset, batch_size=256)])
|
||||
return correct.float() / len(dataset)
|
||||
|
||||
def getModel():
|
||||
hidden_size = 500
|
||||
model = nn.Sequential(
|
||||
nn.Linear(imageSize[0] * imageSize[1] * 3, hidden_size),
|
||||
nn.ReLU(),
|
||||
nn.Linear(hidden_size, len(labels)),
|
||||
nn.LogSoftmax(dim=-1)
|
||||
).to(device)
|
||||
return model
|
||||
|
||||
def saveModel(model, path):
|
||||
print("Saving model")
|
||||
torch.save(model.state_dict(), path)
|
||||
|
||||
def loadModel(path):
|
||||
print("Loading model")
|
||||
model = getModel()
|
||||
model.load_state_dict(torch.load(path, map_location=torch.device('cpu'))) # musiałem tutaj dodać to ładowanie z mapowaniem na cpu bo u mnie CUDA nie działa wy pewnie możecie to usunąć
|
||||
return model
|
||||
|
||||
def trainNewModel(n_iter=100, batch_size=256):
|
||||
trainset = getDataset(True)
|
||||
model = getModel()
|
||||
model = train(model, trainset)
|
||||
return model
|
||||
|
||||
def predictLabel(imagePath, model):
|
||||
image = Image.open(imagePath).convert("RGB")
|
||||
image = preprocess_image(image)
|
||||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
model.to(device)
|
||||
with torch.no_grad():
|
||||
model.eval() # Ustawienie modelu w tryb ewaluacji
|
||||
output = model(image)
|
||||
|
||||
# Znalezienie indeksu klasy o największej wartości prawdopodobieństwa
|
||||
predicted_class = torch.argmax(output).item()
|
||||
return labels[predicted_class]
|
||||
|
||||
# Znalezienie indeksu klasy o największej wartości prawdopodobieństwa
|
||||
predicted_class = torch.argmax(output).item()
|
||||
return labels[predicted_class]
|
||||
|
||||
|
||||
def preprocess_image(image):
|
||||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
transform = getTransformation()
|
||||
image = transform(image).unsqueeze(0) # Add batch dimension
|
||||
image = image.to(device) # Move the image tensor to the same device as the model
|
||||
return image
|
||||
|
||||
|
@ -1,266 +0,0 @@
|
||||
[
|
||||
[
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn"
|
||||
],
|
||||
[
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn"
|
||||
],
|
||||
[
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn"
|
||||
],
|
||||
[
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn"
|
||||
],
|
||||
[
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato"
|
||||
],
|
||||
[
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato"
|
||||
]
|
||||
]
|
@ -1,266 +0,0 @@
|
||||
[
|
||||
[
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato"
|
||||
],
|
||||
[
|
||||
"corn",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"tomato",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"potato"
|
||||
],
|
||||
[
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"potato",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot"
|
||||
],
|
||||
[
|
||||
"potato",
|
||||
"potato",
|
||||
"tomato",
|
||||
"tomato",
|
||||
"corn",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato"
|
||||
],
|
||||
[
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"tomato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot"
|
||||
],
|
||||
[
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"tomato",
|
||||
"corn"
|
||||
],
|
||||
[
|
||||
"potato",
|
||||
"tomato",
|
||||
"tomato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"potato",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"potato",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"potato",
|
||||
"potato",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato",
|
||||
"potato"
|
||||
],
|
||||
[
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot",
|
||||
"corn",
|
||||
"carrot",
|
||||
"corn",
|
||||
"tomato"
|
||||
]
|
||||
]
|
@ -1,266 +0,0 @@
|
||||
[
|
||||
[
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"carrot",
|
||||
"potato"
|
||||
],
|
||||
[
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"potato",
|
||||
"potato"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"potato",
|
||||
"carrot"
|
||||
],
|
||||
[
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot"
|
||||
],
|
||||
[
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"potato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot"
|
||||
],
|
||||
[
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"carrot",
|
||||
"potato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot"
|
||||
],
|
||||
[
|
||||
"potato",
|
||||
"potato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato"
|
||||
],
|
||||
[
|
||||
"potato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot"
|
||||
],
|
||||
[
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"corn",
|
||||
"corn",
|
||||
"tomato",
|
||||
"corn",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato",
|
||||
"tomato",
|
||||
"carrot",
|
||||
"tomato"
|
||||
]
|
||||
]
|
24
readme.txt
24
readme.txt
@ -1,24 +0,0 @@
|
||||
Required packages:
|
||||
pygame,matplotlib,sklearn,pandas
|
||||
How to install:
|
||||
pip install pygame
|
||||
pip install matplotlib
|
||||
pip install scikit-learn
|
||||
pip install pandas
|
||||
How to run:
|
||||
For BFS3:
|
||||
-in App.py: -change bfs3_flag to True (other flags need to be disabled) -ensure that in App.py in BFS3 you give goalTreasure
|
||||
-in Image.py change range in function return_random_plant to (0,5)
|
||||
For Astar:
|
||||
in App.py change Astar to True (other flags need to be disabled)
|
||||
-in Image.py change range in function return_random_plant to (0,7)
|
||||
For Astar2:
|
||||
-in App.py change Astar2 flag to True (other flags need to be disabled)
|
||||
-in Image.py change range in function return_random_plant to (0,7)
|
||||
For Tree:
|
||||
-in App.py change TreeFlag to True (other flags need to be disabled)
|
||||
-in Image.py change range in function return_random_plant to (0,5)
|
||||
For neuralnetwork:
|
||||
-in App.py change nnFlag to True (other flags need to be disabled)
|
||||
For final_show (neuralnetwork+tree+genetic algorithm)
|
||||
-in App.py change finalFlag to True (other flags need to be disabled)
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
87
treeData.py
87
treeData.py
@ -1,87 +0,0 @@
|
||||
tab = []
|
||||
def iter(odp, i):
|
||||
if i == 0:
|
||||
j = ""
|
||||
for k in range(0, 101, 28):
|
||||
odp += f"{k},"
|
||||
odp = iter(odp, i + 1)
|
||||
j = str(k)
|
||||
odp = odp[:-(len(j) + 1)]
|
||||
return odp
|
||||
if i == 1:
|
||||
j = ""
|
||||
for k in range(0, 101, 28):
|
||||
odp += f"{k},"
|
||||
odp = iter(odp, i + 1)
|
||||
j = str(k)
|
||||
odp = odp[:-(len(j) + 1)]
|
||||
return odp
|
||||
if i == 2:
|
||||
j = ""
|
||||
for k in range(2):
|
||||
odp += f"{k},"
|
||||
odp = iter(odp, i + 1)
|
||||
j = str(k)
|
||||
odp = odp[:-(len(j) + 1)]
|
||||
return odp
|
||||
if i == 3:
|
||||
j = ""
|
||||
for k in range(0, 101, 34):
|
||||
odp += f"{k},"
|
||||
odp = iter(odp, i + 1)
|
||||
j = str(k)
|
||||
odp = odp[:-(len(j) + 1)]
|
||||
return odp
|
||||
if i == 4:
|
||||
j = ""
|
||||
for k in range(0, 101, 40):
|
||||
odp += f"{k},"
|
||||
odp = iter(odp, i + 1)
|
||||
j = str(k)
|
||||
odp = odp[:-(len(j) + 1)]
|
||||
return odp
|
||||
if i == 5:
|
||||
j = ""
|
||||
for k in range(0, 4, 2):
|
||||
odp += f"{k},"
|
||||
odp = iter(odp, i + 1)
|
||||
j = str(k)
|
||||
odp = odp[:-(len(j) + 1)]
|
||||
return odp
|
||||
if i == 6:
|
||||
j = ""
|
||||
for k in range(0, 4, 2):
|
||||
odp += f"{k},"
|
||||
odp = iter(odp, i + 1)
|
||||
j = str(k)
|
||||
odp = odp[:-(len(j) + 1)]
|
||||
return odp
|
||||
if i == 7:
|
||||
j = ""
|
||||
for k in range(0, 4, 2):
|
||||
odp += f"{k},"
|
||||
odp = iter(odp, i + 1)
|
||||
j = str(k)
|
||||
odp = odp[:-(len(j) + 1)]
|
||||
return odp
|
||||
if i == 8:
|
||||
j=""
|
||||
for k in range(4):
|
||||
odp += f"{k},"
|
||||
odp = iter(odp, i + 1)
|
||||
j = str(k)
|
||||
odp = odp[:-(len(j) + 1)]
|
||||
return odp
|
||||
if i == 9:
|
||||
global licznik
|
||||
x = odp.split(",")
|
||||
if (int(x[0]) > 60 or int(x[1]) > 90 or int(x[2]) == 1 or int(x[3]) > 70 or int(x[4]) <= 10 or int(x[5]) == 0 or int(x[5]) == 4 or int(x[6]) == 2 or int(x[6]) == 3 or int(x[7]) == 0 or int(x[8]) == 1):
|
||||
odp += "0"
|
||||
else:
|
||||
odp += "1"
|
||||
print(odp)
|
||||
tab.append(odp)
|
||||
licznik += 1
|
||||
return odp[:-1]
|
||||
|
||||
iter("", 0)
|
Loading…
Reference in New Issue
Block a user