kosmetyczne zmiany

This commit is contained in:
Tomasz Adamczyk 2021-05-31 18:16:14 +02:00
parent bbb2fdefb9
commit a43f35d179
15 changed files with 43 additions and 78 deletions

View File

@ -2,49 +2,13 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/SmartTractor.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/SmartCart.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/astar.py" beforeDir="false" afterPath="$PROJECT_DIR$/astar.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/definitions.py" beforeDir="false" afterPath="$PROJECT_DIR$/definitions.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cart.py" beforeDir="false" afterPath="$PROJECT_DIR$/cart.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph.py" beforeDir="false" afterPath="$PROJECT_DIR$/graph.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/map.py" beforeDir="false" afterPath="$PROJECT_DIR$/map.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/neuralnetwork.py" beforeDir="false" afterPath="$PROJECT_DIR$/neuralnetwork.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/beetroots_stage_0.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/beetroots_stage_0.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/beetroots_stage_1.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/beetroots_stage_1.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/beetroots_stage_2.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/beetroots_stage_2.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/beetroots_stage_3.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/beetroots_stage_3.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/carrots_stage_0.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/carrots_stage_0.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/carrots_stage_1.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/carrots_stage_1.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/carrots_stage_2.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/carrots_stage_2.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/carrots_stage_3.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/carrots_stage_3.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/data.csv" beforeDir="false" afterPath="$PROJECT_DIR$/resources/decision_tree/data.csv" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/dirt.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/dirt.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/farmland_dry.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/farmland_dry.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/farmland_wet.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/farmland_wet.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/flower_dandelion.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/flower_dandelion.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/minecart_command_block_east.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/minecart_command_block_east.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/minecart_command_block_north.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/minecart_command_block_north.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/minecart_command_block_south.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/minecart_command_block_south.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/minecart_command_block_west.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/minecart_command_block_west.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/mytree.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/decision_tree/mytree.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/potatoes_stage_0.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/potatoes_stage_0.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/potatoes_stage_1.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/potatoes_stage_1.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/potatoes_stage_2.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/potatoes_stage_2.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/potatoes_stage_3.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/potatoes_stage_3.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/rail_normal.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/rail_normal.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/sponge.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/sponge.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/tree.pkl" beforeDir="false" afterPath="$PROJECT_DIR$/resources/decision_tree/tree.pkl" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/wheat_stage_0.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/wheat_stage_0.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/wheat_stage_1.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/wheat_stage_1.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/wheat_stage_2.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/wheat_stage_2.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/wheat_stage_3.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/wheat_stage_3.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/wheat_stage_4.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/wheat_stage_4.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/wheat_stage_5.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/wheat_stage_5.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/wheat_stage_6.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/wheat_stage_6.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/wheat_stage_7.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/images/wheat_stage_7.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tractor.py" beforeDir="false" afterPath="$PROJECT_DIR$/cart.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/treelearn.py" beforeDir="false" afterPath="$PROJECT_DIR$/treelearn.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -196,6 +160,7 @@
<workItem from="1622469549245" duration="1392000" />
<workItem from="1622471028909" duration="34000" />
<workItem from="1622471098158" duration="2320000" />
<workItem from="1622474297862" duration="2475000" />
</task>
<servers />
</component>
@ -207,34 +172,35 @@
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="414" y="195" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622365181713" />
<state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1621109431051">
<state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1622475063488">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622475063488" />
<state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080@0.0.1920.1080" timestamp="1621109431051" />
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1622413487618">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622413487618" />
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621429221570" />
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1622473751037">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1622477545943">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622473751037" />
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622477545943" />
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1622473751037">
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1622477545943">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622473751037" />
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622477545943" />
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1622473751037">
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1622477545943">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622473751037" />
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622477545943" />
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389326" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1622473751037">
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1622477545943">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622473751037" />
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622477545943" />
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1619289752045">
<screen x="0" y="0" width="1920" height="1080" />
@ -252,15 +218,15 @@
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1622471098618">
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1622474297784">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622471098618" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622474297784" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621439087317" />
<state x="623" y="235" width="672" height="678" key="search.everywhere.popup" timestamp="1622472745109">
<state x="623" y="235" width="672" height="678" key="search.everywhere.popup" timestamp="1622475419309">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="623" y="235" width="672" height="678" key="search.everywhere.popup/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622472745109" />
<state x="623" y="235" width="672" height="678" key="search.everywhere.popup/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622475419309" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
@ -275,6 +241,6 @@
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1622469837941" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartCart$py.coverage" NAME="py Coverage Results" MODIFIED="1622472631604" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartCart$py.coverage" NAME="py Coverage Results" MODIFIED="1622475876802" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -51,14 +51,14 @@ def cost(map, node): #funkcja kosztu : ile kosztuje przejechanie przez dane pole
cost = cost + map.get_field_cost(int(node.get_x()), int(node.get_y())) + 1
node = node.get_parent()
return cost
def f(map, node, goaltest): #funkcja zwracająca sumę funkcji kosztu oraz heurestyki
return cost(map, node) + heuristic(node, goaltest)
def f(goaltest, map, node): #funkcja zwracająca sumę funkcji kosztu oraz heurestyki
return cost(map, node) + heuristic(goaltest, node)
def goal_test(elem, goaltest): #funkcja sprawdzająca czy położenie wózka równa się położeniu punktu docelowego, jeśli tak zwraca prawdę, w przeciwnym wypadku fałsz
if elem.get_x() == goaltest[0] and elem.get_y() == goaltest[1]:
return True
else:
return False
def graphsearch(fringe, explored, istate, succ, goaltest, f, map): #przeszukiwanie grafu wszerz
def graphsearch(explored, f, fringe, goaltest, istate, map, succ): #przeszukiwanie grafu wszerz
node = Node(None, istate.get_direction(), None, istate.get_x(), istate.get_y()) #wierzchołek początkowy, stworzony ze stanu początkowego wózka
fringe.append((node, 0)) #wierzchołki do odwiedzenia z priorytetem
while True:
@ -79,7 +79,7 @@ def graphsearch(fringe, explored, istate, succ, goaltest, f, map): #przeszukiwan
for (x, y) in explored:
explored_tuple.append((x.get_direction(), x.get_x(), x.get_y()))
x = Node(action, state[0], elem[0], state[1], state[2]) #stworzenie nowego wierzchołka, którego rodzicem jest elem
p = f(map, x, goaltest) #liczy priorytet
p = f(goaltest, map, x) #liczy priorytet
if state not in fringe_tuple and state not in explored_tuple: #jeżeli stan nie znajduje się na fringe oraz nie znajduje się w liście wierzchołków odwiedzonych
fringe.append((x, p)) #dodanie wierzchołka na fringe
fringe = sorted(fringe, key=itemgetter(1)) #sortowanie fringe'a według priorytetu
@ -93,7 +93,7 @@ def graphsearch(fringe, explored, istate, succ, goaltest, f, map): #przeszukiwan
fringe = sorted(fringe, key=itemgetter(1)) #sortowanie fringe'a według priorytetu
break
i = i + 1
def heuristic(node, goaltest): #funkcja heurestyki : oszacowuje koszt osiągnięcia stanu końcowego (droga)
def heuristic(goaltest, node): #funkcja heurestyki : oszacowuje koszt osiągnięcia stanu końcowego (droga)
return abs(node.get_x() - goaltest[0]) + abs(node.get_y() - goaltest[1])
def print_moves(elem): #zwraca listę ruchów jakie należy wykonać by dotrzeć do punktu docelowego
moves_list = []

View File

@ -48,7 +48,7 @@ class Cart:
return self.y
def set_y(self, y):
self.y = y
def do_work(self, map1, station1, cart_rect): #jaką pracę wózek ma wykonać na danym polu, na którym aktualnie przebywa (zmienia stan logiczny danego pola)
def do_work(self, cart_rect, map1, station1): #jaką pracę wózek ma wykonać na danym polu, na którym aktualnie przebywa (zmienia stan logiczny danego pola)
loop = True
if self.get_all_amount_of_seeds() == 0:
loop = False
@ -125,7 +125,7 @@ class Cart:
field.get_soil().set_water_level(False)
field.get_soil().set_state(False)
self.set_collected_plants("wheat", self.get_collected_plants("wheat") + 1)
def handle_movement(self, move, cart_rect): #odpowiada za poruszanie się wózka po mapie
def handle_movement(self, cart_rect, move): #odpowiada za poruszanie się wózka po mapie
if self.get_fuel() > 0:
if move == "move":
self.move()

View File

@ -44,12 +44,12 @@ class Node: #wierzchołek grafu
return self.y
def set_y(self, y):
self.y = y
def goal_test(elem, goaltest): #funkcja sprawdzająca czy położenie wózka równa się położeniu punktu docelowego, jeśli tak zwraca prawdę, w przeciwnym wypadku fałsz
def goal_test(goaltest, elem): #funkcja sprawdzająca czy położenie wózka równa się położeniu punktu docelowego, jeśli tak zwraca prawdę, w przeciwnym wypadku fałsz
if elem.get_x() == goaltest[0] and elem.get_y() == goaltest[1]:
return True
else:
return False
def graphsearch(fringe, explored, istate, succ, goaltest): #przeszukiwanie grafu wszerz
def graphsearch(explored, fringe, goaltest, istate, succ): #przeszukiwanie grafu wszerz
node = Node(None, istate.get_direction(), None, istate.get_x(), istate.get_y()) #wierzchołek początkowy, stworzony ze stanu początkowego wózka
fringe.append(node) #wierzchołki do odwiedzenia
while True:
@ -57,7 +57,7 @@ def graphsearch(fringe, explored, istate, succ, goaltest): #przeszukiwanie grafu
return False
elem = fringe.pop(0) #zdejmujemy wierzchołek z kolejki fringe i rozpatrujemy go
temp = copy.copy(elem)
if goal_test(elem, goaltest) is True: #jeżeli osiągniemy cel w trakcie przeszukiwania grafu wszerz (wjedziemy na pole docelowe) : zwracamy listę ruchów, po których wykonaniu dotrzemy na miejsce
if goal_test(goaltest, elem) is True: #jeżeli osiągniemy cel w trakcie przeszukiwania grafu wszerz (wjedziemy na pole docelowe) : zwracamy listę ruchów, po których wykonaniu dotrzemy na miejsce
return print_moves(elem)
explored.append(elem) #dodajemy wierzchołek do listy wierzchołków odwiedzonych
for (action, state) in succ(temp): #iterujemy po wszystkich możliwych akcjach i stanach otrzymanych dla danego wierzchołka grafu

View File

@ -55,7 +55,7 @@ def create_neural_network():
images_path = glob.glob(pred_path+'/*.jpg')
pred_dict = {}
for i in images_path:
pred_dict[i[i.rfind('/') + 1:]] = prediction1(i, transformer1, model, classes)
pred_dict[i[i.rfind('/') + 1:]] = prediction1(classes, i, model, transformer1)
print(pred_dict)
else:
model = ConvNet(num_classes=6).to(device)
@ -93,11 +93,11 @@ def create_neural_network():
_, prediction = torch.max(outputs.data, 1)
test_accuracy += int(torch.sum(prediction == labels.data))
test_accuracy = test_accuracy / test_count
print('Epoch: ' + str(epoch) + ' Train Loss: ' + str(train_loss) + ' Train Accuracy: ' + str(train_accuracy) + ' Test Accuracy: ' + str(test_accuracy))
print('Epoch: ' + str(epoch + 1) + ' Train Loss: ' + str(train_loss) + ' Train Accuracy: ' + str(train_accuracy) + ' Test Accuracy: ' + str(test_accuracy))
if test_accuracy > best_accuracy:
torch.save(model.state_dict(), 'resources/neural_network/checkpoint.model')
best_accuracy = test_accuracy
def prediction1(img_path, transformer, model, classes):
def prediction1(classes, img_path, model, transformer):
image = Image.open(img_path)
image_tensor = transformer(image).float()
image_tensor = image_tensor.unsqueeze_(0)

View File

@ -12,12 +12,12 @@ class Plant:
def set_state(self, state):
self.state = state
@staticmethod
def get_mature_plant(map1, cart): #pobiera współrzędne jakiejś dojrzałej rośliny
def get_mature_plant(map): #pobiera współrzędne jakiejś dojrzałej rośliny
x = -1
y = -1
for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT):
field = map1.get_fields()[i][j]
field = map.get_fields()[i][j]
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE:
x = i
y = j
@ -36,11 +36,10 @@ class Plant:
else:
return x, y
@staticmethod
def grow_plants(
map1): #metoda statyczna, która zwiększa pole state (etap rozwoju rośliny) dla danej rośliny na danym polu o 1
def grow_plants(map): #metoda statyczna, która zwiększa pole state (etap rozwoju rośliny) dla danej rośliny na danym polu o 1
for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT):
field = map1.get_fields()[i][j]
field = map.get_fields()[i][j]
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.BEETROOTS_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_state() + 1)
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.CARROTS_MAXIMUM_STATE:
@ -50,10 +49,10 @@ class Plant:
elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 0 and field.get_plant().get_state() < definitions.WHEAT_MAXIMUM_STATE:
field.get_plant().set_state(field.get_plant().get_state() + 1)
@staticmethod
def if_any_mature_plant(map1): #sprawdza czy na polu występuje choć jedna dojrzała roślina, jeśli tak zwraca prawdę, w przeciwnym razie zwraca fałsz
def if_any_mature_plant(map): #sprawdza czy na polu występuje choć jedna dojrzała roślina, jeśli tak zwraca prawdę, w przeciwnym razie zwraca fałsz
for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT):
field = map1.get_fields()[i][j]
field = map.get_fields()[i][j]
if field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE:
return True
elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE:

10
py.py
View File

@ -34,15 +34,15 @@ def main():
if not move_list and plant.Plant.if_any_mature_plant(map1) is True: #jeżeli są jakieś ruchy do wykonania w move_list oraz istnieje jakaś dojrzała roślina
istate = graph.Istate(cart1.get_direction(), cart1.get_x() / definitions.BLOCK_SIZE, cart1.get_y() / definitions.BLOCK_SIZE) #stan początkowy wózka (jego orientacja oraz jego aktualne współrzędne)
if decision == [0]: #jeżeli decyzja jest 0 (brak powrotu do stacji) to uprawiaj pole
move_list = (astar.graphsearch([], [], istate, graph.succ, plant.Plant.get_mature_plant(map1, istate), astar.f, map1)) #lista z ruchami, które należy po kolei wykonać, astar
move_list = (astar.graphsearch([], astar.f, [], plant.Plant.get_mature_plant(map1), istate, map1, graph.succ)) #lista z ruchami, które należy po kolei wykonać, astar
else: #jeżeli decyzja jest 1 (powrót do stacji) to wróć do stacji uzupełnić zapasy
move_list = (graph.graphsearch([], [], istate, graph.succ, (0, 0))) #lista z ruchami, które należy po kolei wykonać, graphsearch
move_list = (graph.graphsearch([], [], (0, 0), istate, graph.succ)) #lista z ruchami, które należy po kolei wykonać, graphsearch
elif move_list: #jeżeli move_list nie jest pusta
cart1.handle_movement(move_list.pop(0), cart1_rect) #wykonaj kolejny ruch oraz zdejmij ten ruch z początku listy
cart1.handle_movement(cart1_rect, move_list.pop(0)) #wykonaj kolejny ruch oraz zdejmij ten ruch z początku listy
else:
cart1.handle_movement_random(cart1_rect) #wykonuj losowe ruchy
cart1.do_work(map1, station1, cart1_rect) #wykonaj pracę na danym polu
decision = treelearn.make_decision(tree, cart1.get_all_amount_of_seeds(), cart1.get_all_collected_plants(), cart1.get_all_fertilizer(), cart1.get_fuel(), cart1.get_water_level()) #podejmij decyzję czy wracać do stacji (0 : NIE, 1 : TAK)
cart1.do_work(cart1_rect, map1, station1) #wykonaj pracę na danym polu
decision = treelearn.make_decision(cart1.get_all_amount_of_seeds(), cart1.get_all_collected_plants(), cart1.get_all_fertilizer(), cart1.get_fuel(), tree, cart1.get_water_level()) #podejmij decyzję czy wracać do stacji (0 : NIE, 1 : TAK)
plant.Plant.grow_plants(map1) #zwiększ poziom dojrzałości roślin
pygame.quit()
if __name__ == "__main__":

View File

@ -6,7 +6,7 @@ import pickle
import pydotplus
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
def make_decision(tree, amount_of_seeds, collected_plants, fertilizer, fuel, water_level): #zwraca decyzję o powrocie do stacji (0 : NIE, 1 : TAK)
def make_decision(amount_of_seeds, collected_plants, fertilizer, fuel, tree, water_level): #zwraca decyzję o powrocie do stacji (0 : NIE, 1 : TAK)
decision = tree.predict([[amount_of_seeds, collected_plants, fertilizer, fuel, water_level]]) #podejmij decyzję na podstawie aktualnych parametrów wózka o powrocie do stacji lub nie
return decision
def treelearn(): #zwraca utworzone drzewo decyzyjne