Compare commits

...

92 Commits

Author SHA1 Message Date
secret_dude
9007ea7ae2 FINAL2 2021-06-22 23:27:36 +02:00
secret_dude
bed9656adf Merge remote-tracking branch 'origin/master'
# Conflicts:
#	createNeuralNetworkDatabase.py
2021-06-22 23:12:42 +02:00
secret_dude
809ab043b7 FINAL 2021-06-22 23:12:13 +02:00
076472cfd1 Neural Network 2021-06-22 22:56:01 +02:00
secret_dude
e8db800831 minor changes 2021-06-02 01:33:24 +02:00
secret_dude
c6df15c609 minor changes 2021-06-02 01:32:48 +02:00
secret_dude
4acea19558 minor changes 2021-06-01 22:47:53 +02:00
ccce3c9362 Neural Network - images 2021-06-01 22:31:49 +02:00
secret_dude
e75de81fbd minor changes 2021-05-31 21:09:45 +02:00
01dae9185b DecisionTree save and load from file 2021-05-31 21:05:42 +02:00
b3197dccd2 decision tree update v.2 2021-05-31 20:48:38 +02:00
secret_dude
66fe537f7a minor changes 2021-05-31 20:34:09 +02:00
e10fbe4e48 decision tree update 2021-05-19 15:04:10 +02:00
secret_dude
3b44694641 upadate ui 2021-05-19 05:12:42 +02:00
secret_dude
f3b42cef6a tree graph 2021-05-19 05:04:00 +02:00
d91b9141fc decision tree update 2021-05-19 04:53:19 +02:00
secret_dude
422d7adaac main update 2021-05-19 04:45:37 +02:00
secret_dude
b571318359 createTreeData 2021-05-19 04:11:26 +02:00
secret_dude
449f88eb5b Merge remote-tracking branch 'origin/master' 2021-05-19 04:02:28 +02:00
34599b9bfc decision tree 2021-05-19 04:02:14 +02:00
secret_dude
d457eda72d Merge remote-tracking branch 'origin/master'
# Conflicts:
#	Field.py
#	constants.py
#	main.py
2021-05-19 04:02:03 +02:00
secret_dude
bf9fbb1235 createTreeData 2021-05-19 04:01:26 +02:00
b12ed9bcda A* and corrected graphsearch 2021-04-28 15:31:40 +02:00
5109d10d8c A* and corrected graphsearch 2021-04-28 15:31:17 +02:00
secret_dude
8098a258f2 field cost final 2021-04-27 21:35:58 +02:00
secret_dude
5e4af5773b field cost 2021-04-27 19:36:48 +02:00
1bdef8cc56 graphserach v0.6.4 2021-04-14 14:34:57 +02:00
d45ec38792 graphserach v0.6.3 2021-04-14 01:42:42 +02:00
d9597d3e26 graphserach v0.6.2 2021-04-14 00:05:16 +02:00
5bfca831f2 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	FindPath.py
2021-04-13 21:51:20 +02:00
430ca8dc05 graphserach v0.6 2021-04-13 21:50:08 +02:00
secret_dude
2b6a15a95b minor updates 2 2021-04-13 21:49:31 +02:00
bb5eb51b1c graphserach v0.6 2021-04-13 21:39:04 +02:00
7b59525adc graphserach v0.5 2021-04-13 21:34:48 +02:00
secret_dude
84857e357c minor updates 2021-04-13 20:29:06 +02:00
secret_dude
b3da1c6654 animations update 2021-04-13 18:57:48 +02:00
secret_dude
55171b73f9 SterowanieManualnePrzeniesione 2021-04-13 18:48:24 +02:00
secret_dude
ac55e5bf57 SterowanieManualnePrzeniesione 2021-04-13 18:40:58 +02:00
secret_dude
e121af6630 SterowanieManualnePrzeniesione 2021-04-13 18:09:27 +02:00
secret_dude
7dc8362f1d SterowanieManualnePrzeniesione 2021-04-13 17:52:27 +02:00
6ec20924d1 updated graphics 2021-03-31 15:24:40 +02:00
secret_dude
09eb0bbc2f V1.34 2021-03-30 00:54:29 +02:00
secret_dude
bad695ca49 V1.34 2021-03-29 21:59:19 +02:00
e2c69cd3b9 updated graphics 2021-03-29 21:46:40 +02:00
41272aea6e Merge remote-tracking branch 'origin/master' 2021-03-29 21:45:08 +02:00
9af7e0d421 updated graphics 2021-03-29 21:40:55 +02:00
secret_dude
736af08577 V. 12 2021-03-29 21:18:55 +02:00
secret_dude
6524408bc9 V. 12 2021-03-29 21:18:14 +02:00
secret_dude
19e42bbdf9 V. 12 2021-03-29 21:14:07 +02:00
John Doe
b32d77fe3f V. 12 2021-03-29 20:51:47 +02:00
v7eZ3t
4960362fb5 v 1.23 2021-03-29 20:36:34 +02:00
v7eZ3t
0eb57f3839 v 1.23 2021-03-29 20:36:34 +02:00
v7eZ3t
6f547d2e56 v. 1.12 2021-03-29 20:36:34 +02:00
v7eZ3t
f4f0114664 v. 1.10 2021-03-29 20:36:34 +02:00
v7eZ3t
01cb7d0ada v. 1.10 2021-03-29 20:36:34 +02:00
v7eZ3t
6aff48d4e2 v. 1.06 2021-03-29 20:36:34 +02:00
v7eZ3t
ea27502bc6 v. 1.06 2021-03-29 20:36:34 +02:00
v7eZ3t
1476926694 v. 1.06 2021-03-29 20:36:34 +02:00
v7eZ3t
f81317a298 v. 1.06 2021-03-29 20:36:34 +02:00
v7eZ3t
eb1ff813eb v. 1.06 2021-03-29 20:36:34 +02:00
v7eZ3t
d8b82b541a v. 1.06 2021-03-29 20:36:34 +02:00
v7eZ3t
2a50f9d41d v. 1.06 2021-03-29 20:36:34 +02:00
v7eZ3t
cffc1dbca8 basic_agent 2021-03-29 20:36:34 +02:00
v7eZ3t
d66c54bece basic_agent 2021-03-29 20:36:34 +02:00
v7eZ3t
78f3d1ba7f basic_agent 2021-03-29 20:36:34 +02:00
v7eZ3t
3f277d22ff basic_agent 2021-03-29 20:36:34 +02:00
v7eZ3t
3fe181efa0 v 1.23 2021-03-29 20:30:21 +02:00
v7eZ3t
a5d9403a07 v 1.23 2021-03-29 19:15:36 +02:00
v7eZ3t
11b1d1834c v 1.23 2021-03-29 17:18:14 +02:00
v7eZ3t
5c8d3aabbd v 1.23 2021-03-29 14:36:28 +02:00
v7eZ3t
f1b61a0889 wszystko działa 2021-03-29 14:33:16 +02:00
v7eZ3t
087cb6031d v 1.23 2021-03-29 13:46:30 +02:00
v7eZ3t
9b75da63ac v. 1.10 2021-03-29 13:32:51 +02:00
v7eZ3t
91106af2a8 v. 1.10 2021-03-29 13:06:57 +02:00
v7eZ3t
aa9e61f921 v. 1.20 2021-03-29 04:17:31 +02:00
v7eZ3t
f748251d10 v. 1.10 2021-03-29 03:41:38 +02:00
v7eZ3t
968013d375 v. 1.12 2021-03-29 02:53:27 +02:00
v7eZ3t
00b2790c8c v. 1.10 2021-03-29 02:19:55 +02:00
v7eZ3t
4165c16818 v. 1.10 2021-03-29 01:40:51 +02:00
v7eZ3t
f0c13cb6ea Merge remote-tracking branch 'origin/master' 2021-03-29 01:24:47 +02:00
v7eZ3t
162c051b09 v. 1.06 2021-03-29 01:24:28 +02:00
f7b29335f5 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	drawUI.py
2021-03-29 01:16:09 +02:00
a9fb64841b dodane grafiki 2021-03-29 01:15:48 +02:00
v7eZ3t
d778014e92 v. 1.06 2021-03-29 00:40:43 +02:00
v7eZ3t
b705cb2b1c v. 1.06 2021-03-28 23:43:21 +02:00
v7eZ3t
cd8686fa46 v. 1.06 2021-03-28 23:33:46 +02:00
v7eZ3t
c981921fbd v. 1.06 2021-03-28 23:18:29 +02:00
v7eZ3t
ba1f2d96b6 v. 1.06 2021-03-28 22:55:01 +02:00
v7eZ3t
f72df6eac1 v. 1.06 2021-03-28 22:51:41 +02:00
v7eZ3t
ba447abfb9 basic_agent 2021-03-28 22:42:36 +02:00
v7eZ3t
803757806a basic_agent 2021-03-28 17:29:08 +02:00
v7eZ3t
bf51b1b511 basic_agent 2021-03-17 14:48:50 +01:00
2103 changed files with 1511 additions and 73 deletions

2
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

8
.idea/AI_PRO2.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/AI_PRO2.iml" filepath="$PROJECT_DIR$/.idea/AI_PRO2.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,12 +1,18 @@
import random
from Main.constants import *
board = []
from Field import Field
from constants import *
states = ['toPlow', 'toSeed', 'toFertilize', 'toWater', 'toCut']
def generate():
for i in range(int(HORIZONTAL_TILES_NUMBER)):
board.append([random.randint(0, 3)])
for j in range(int(VERTICAL_TILES_NUMBER)):
board[i].append(random.randint(0, 3))
board = []
for i in range(0, int(HORIZONTAL_TILES_NUMBER)):
board.append([])
for j in range(0, int(VERTICAL_TILES_NUMBER)):
board[i].append(Field(int(i * TILE_SIZE), int(j * TILE_SIZE), random.choice(states)))
board[0][0] = Field(int(0 * TILE_SIZE), int(0 * TILE_SIZE), "TOOLS_FIELD")
board[1][0] = Field(int(1 * TILE_SIZE), int(0 * TILE_SIZE), "FUEL_FIELD")
return board

38
Field.py Normal file
View File

@ -0,0 +1,38 @@
class Field:
def __init__(self, horizontal_index, vertical_index, state):
self.__horizontal_index = horizontal_index
self.__vertical_index = vertical_index
self.__state = state
@property
def state(self):
return self.__state
@property
def horizontal_index(self):
return self.__horizontal_index
@property
def vertical_index(self):
return self.__vertical_index
@property
def cost(self):
if self.state == 'toPlow':
return 1
elif self.state == 'toSeed':
return 2
elif self.state == 'toFertilize':
return 3
elif self.state == 'toWater':
return 4
elif self.state == 'toCut':
return 100
else:
return 0
@state.setter
def state(self, state):
if state == "toPlow" or state == "toWater" or state == "toSeed" or \
state == "toFertilize" or state == "toCut" or state == "TOOLS_FIELD" or state == "FUEL_FIELD":
self.__state = state

30
FindPath.py Normal file
View File

@ -0,0 +1,30 @@
from constants import *
def whichStateLookingFor(tractor, TillageUnit):
searching_field = "none"
if tractor.header and tractor.hitch == "Crop Trailer":
searching_field = "toCut"
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Nothing":
searching_field = "toPlow"
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Water":
searching_field = "toWater"
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Seeds":
searching_field = "toSeed"
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Fertilizer":
searching_field = "toFertilize"
return searching_field
def nearestLookingField(board, tractor, TillageUnit):
end_horizontal_index = 0
end_vertical_index = 0
searching_field = whichStateLookingFor(tractor, TillageUnit)
for i in range(0, int(HORIZONTAL_TILES_NUMBER)):
for j in range(0, int(VERTICAL_TILES_NUMBER)):
field = board[i][j]
if searching_field == field.state:
end_horizontal_index = field.horizontal_index / TILE_SIZE
end_vertical_index = field.vertical_index / TILE_SIZE
return end_horizontal_index, end_vertical_index
return end_horizontal_index, end_vertical_index

174
Graphsearch.py Normal file
View File

@ -0,0 +1,174 @@
from operator import itemgetter
import constants
class Istate:
def __init__(self, direction, horizontal_index, vertical_index):
self.__direction = direction
self.__horizontal_index = horizontal_index
self.__vertical_index = vertical_index
@property
def direction(self):
return self.__direction
@property
def horizontal_index(self):
return self.__horizontal_index
@property
def vertical_index(self):
return self.__vertical_index
class Node:
def __init__(self, action, direction, parent, horizontal_index, vertical_index):
self.__action = action
self.__direction = direction
self.__parent = parent
self.__horizontal_index = horizontal_index
self.__vertical_index = vertical_index
@property
def action(self):
return self.__action
@property
def direction(self):
return self.__direction
@property
def parent(self):
return self.__parent
@property
def horizontal_index(self):
return self.__horizontal_index
@property
def vertical_index(self):
return self.__vertical_index
def goal_test(elem, goaltest):
if elem.horizontal_index == goaltest[0] and elem.vertical_index == goaltest[1]:
return True
else:
# print("Traktor wartosc horizontal_index: ", elem.horizontal_index)
# print("Traktor wartosc vertical_index: ", elem.vertical_index)
return False
def print_moves(elem):
moves_list = []
while elem.parent is not None:
moves_list.append(elem.action)
elem = elem.parent
moves_list.reverse()
return moves_list
def cost(board, node):
cost_value = 0
while node.parent is not None:
field = board[node.horizontal_index][node.vertical_index]
cost_value = cost_value + field.cost + 1
node = node.parent
return cost_value
def heuristic(node, goaltest):
return abs(node.horizontal_index - goaltest[0]) + abs(node.vertical_index - goaltest[1])
def f(board, node, goaltest):
cost_value = cost(board, node)
return cost_value + heuristic(node, goaltest)
def succ(elem):
actions_list = []
direction = elem.direction
if direction == "UP":
direction = "RIGHT"
elif direction == "RIGHT":
direction = "DOWN"
elif direction == "DOWN":
direction = "LEFT"
elif direction == "LEFT":
direction = "UP"
actions_list.append(("Right_Rotation", (direction, elem.horizontal_index, elem.vertical_index)))
direction = elem.direction
if direction == "UP":
direction = "LEFT"
elif direction == "LEFT":
direction = "DOWN"
elif direction == "DOWN":
direction = "RIGHT"
elif direction == "RIGHT":
direction = "UP"
actions_list.append(("Left_Rotation", (direction, elem.horizontal_index, elem.vertical_index)))
horizontal_change = 0
vertical_change = 0
if elem.direction == "RIGHT" and elem.horizontal_index < constants.HORIZONTAL_TILES_NUMBER - 1:
horizontal_change = 1
elif elem.direction == "LEFT" and elem.horizontal_index > 0:
horizontal_change = -1
elif elem.direction == "UP" and elem.vertical_index > 0:
vertical_change = -1
elif elem.direction == "DOWN" and elem.vertical_index < constants.VERTICAL_TILES_NUMBER - 1:
vertical_change = 1
actions_list.append(("Move", (elem.direction, elem.horizontal_index + horizontal_change,
elem.vertical_index + vertical_change)))
return actions_list
def graphsearch(fringe, explored, istate, goaltest, board):
node = Node(None, istate.direction, None, istate.horizontal_index, istate.vertical_index)
fringe.append((node, 0))
while True:
if not fringe:
return False
elem = fringe.pop(0)
temp = elem[0]
if goal_test(elem[0], goaltest) is True:
return print_moves(elem[0])
explored.append(elem)
for (action, state) in succ(temp):
fringe_list = []
fringe_list_priority = []
explored_list = []
for (x, y) in fringe:
fringe_list.append((x.direction, x.horizontal_index, x.vertical_index))
fringe_list_priority.append(((x.direction, x.horizontal_index, x.vertical_index), y))
for (x, y) in explored:
explored_list.append((x.direction, x.horizontal_index, x.vertical_index))
x = Node(action, state[0], elem[0], state[1], state[2])
p = f(board, x, goaltest)
if state not in fringe_list and state not in explored_list:
fringe.append((x, p))
fringe = sorted(fringe, key=itemgetter(1))
elif state in fringe_list:
index = 0
for (state_priority, r) in fringe_list_priority:
if state_priority == state:
if r > p:
fringe.insert(index, (x, p))
fringe.pop(index + 1)
fringe = sorted(fringe, key=itemgetter(1))
break
index = index + 1

142
Tractor.py Normal file
View File

@ -0,0 +1,142 @@
from TractorLoad import TillageUnit
from constants import HORIZONTAL_TILES_NUMBER, VERTICAL_TILES_NUMBER
class Tractor:
def __init__(self, horizontal_index, vertical_index, hitch, header, autodrive, direction):
self.__horizontal_index = horizontal_index
self.__vertical_index = vertical_index
self.__hitch = hitch
self.__header = header
self.__autodrive = autodrive
self.__fuel_tank = 100
self.__engineWorking = False
self.__direction = direction
@property
def horizontal_index(self):
return self.__horizontal_index
def __horizontal_index(self, horizontal_index):
if 1 <= horizontal_index < HORIZONTAL_TILES_NUMBER:
if self.__engineWorking:
self.__horizontal_index = horizontal_index
@property
def vertical_index(self):
return self.__vertical_index
def __vertical_index(self, vertical_index):
if 1 <= self.__vertical_index < VERTICAL_TILES_NUMBER-1:
if self.__engineWorking:
self.__vertical_index = vertical_index
@property
def hitch(self):
return self.__hitch
@hitch.setter
def hitch(self, hitch):
if hitch == "Crop Trailer" or isinstance(hitch, TillageUnit) or hitch == "Nothing":
self.__hitch = hitch
@property
def fuel_tank(self):
return self.__fuel_tank
def __fuel_tank(self, fuel_tank):
if 0 < fuel_tank < 100:
self.__fuel_tank = fuel_tank
def fill_tank(self):
self.__fuel_tank = 100
def reduce_fuel(self):
if 0 < self.fuel_tank <= 100:
self.__fuel_tank = self.__fuel_tank - 0.1
if self.__fuel_tank <= 0:
self.__engineWorking = False
@property
def header(self):
return self.__header
@header.setter
def header(self, header):
if header is True or header is False:
self.__header = header
@property
def engineWorking(self):
return self.__engineWorking
def turnOnEngine(self):
if self.__fuel_tank > 0:
self.__engineWorking = True
else:
print("noFuel")
def turnOffEngine(self):
self.__engineWorking = False
@property
def autodrive(self):
return self.__autodrive
@autodrive.setter
def autodrive(self, autodrive):
if isinstance(autodrive, bool):
self.__autodrive = autodrive
@property
def direction(self):
return self.__direction
@direction.setter
def direction(self, direction):
self.__direction = direction
def drive(self):
mRange = 1
if not self.__engineWorking:
return
if self.__direction == "UP" and self.vertical_index > 0:
self.__vertical_index += - mRange
elif self.__direction == "DOWN" and self.vertical_index < VERTICAL_TILES_NUMBER-1:
self.__vertical_index += mRange
elif self.__direction == "RIGHT" and self.horizontal_index < HORIZONTAL_TILES_NUMBER-1:
self.__horizontal_index += mRange
elif self.__direction == "LEFT" and self.horizontal_index > 0:
self.__horizontal_index += -mRange
self.reduce_fuel()
def left_rotation(self):
if self.__direction == "UP":
self.__direction = "LEFT"
elif self.__direction == "LEFT":
self.__direction = "DOWN"
elif self.__direction == "DOWN":
self.__direction = "RIGHT"
elif self.__direction == "RIGHT":
self.__direction = "UP"
def right_rotation(self):
if self.__direction == "UP":
self.__direction = "RIGHT"
elif self.__direction == "RIGHT":
self.__direction = "DOWN"
elif self.__direction == "DOWN":
self.__direction = "LEFT"
elif self.__direction == "LEFT":
self.__direction = "UP"
def auto_movement(self, move):
if move == "Move":
self.drive()
elif move == "Left_Rotation":
self.left_rotation()
elif move == "Right_Rotation":
self.right_rotation()

45
TractorAction.py Normal file
View File

@ -0,0 +1,45 @@
from TractorLoad import TillageUnit
def changeFieldState(field, tractor):
if tractor.header and tractor.hitch == "Crop Trailer" and field.state == "toCut":
return "toPlow"
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Nothing" and field.state == "toPlow":
return "toWater"
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Water" and field.state == "toWater":
return "toSeed"
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Seeds" and field.state == "toSeed":
return "toFertilize"
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Fertilizer" and field.state == "toFertilize":
return "toCut"
def autoToolsChange(tractor, tillageUnit, toolCounter):
if tractor.horizontal_index == 0 and tractor.vertical_index == 0:
toolCounter = (toolCounter + 1) % 5
tractor, tillageUnit = chooseToolset(tractor, tillageUnit, toolCounter)
tractor.fill_tank()
return tractor, tillageUnit, toolCounter
def chooseToolset(tractor, tillageUnit, set):
if set == 0:
tractor.hitch = tillageUnit
tractor.hitch.load = "Nothing"
if set == 1:
tractor.hitch = tillageUnit
tractor.hitch.load = "Water"
if set == 2:
tractor.hitch = tillageUnit
tractor.hitch.load = "Seeds"
if set == 3:
tractor.hitch = tillageUnit
tractor.hitch.load = "Fertilizer"
if set == 4:
tractor.header = True
tractor.hitch = "Crop Trailer"
return tractor, tillageUnit

12
TractorLoad.py Normal file
View File

@ -0,0 +1,12 @@
class TillageUnit:
def __init__(self, __load):
self.__load = __load
@property
def load(self):
return self.__load
@load.setter
def load(self, load):
if load == "Fertilizer" or load == "Seeds" or load == "Water" or load == "Nothing":
self.__load = load

10
WeatherConditions.py Normal file
View File

@ -0,0 +1,10 @@
import random
def checkConditions():
weather = random.choice(['Clear Sky', 'Cloudy', 'Rainy', 'Hail'])
day_time = random.choice(['Day', 'Night'])
temperature = random.choice(['Freezing', 'Cold', 'Mild', 'Hot'])
wind = random.choice(['Windless', 'Strong Wind', 'Gale'])
humidy = random.choice(['Low', 'High'])
return weather, day_time, temperature, wind, humidy

7
animations.py Normal file
View File

@ -0,0 +1,7 @@
from constants import ANIMATION_PART
def animationsOn():
ANIMATION_PART = 11
def animationsOff():
ANIMATION_PART = 1

23
changeFilenames.py Normal file
View File

@ -0,0 +1,23 @@
# Pythono3 code to rename multiple
# files in a directory or folder
# importing os module
import os
path = 'neural_network\\images\\potatoes\\'
def main():
for count, filename in enumerate(os.listdir(path)):
dst = 'potato' + str(count) + ".jpg"
src = path + filename
dst = path + dst
# rename() function will
# rename all the files
os.rename(src, dst)
# Driver Code
if __name__ == '__main__':
# Calling main() function
main()

View File

@ -1,18 +1,19 @@
#constants
# display size in pixels
DISPLAY_SIZE_HORIZONTAL = 600
DISPLAY_SIZE_VERTICAL = 600
from math import ceil, floor
#TILE DIVIDER
TILE_DIVIDER = 100
DISPLAY_SIZE_HORIZONTAL = 1600
DISPLAY_SIZE_VERTICAL = 800
#TILE DIVIDER = TILE SIZE
TILE_SIZE = 100
# number of tiles
HORIZONTAL_TILES_NUMBER = DISPLAY_SIZE_HORIZONTAL/TILE_DIVIDER
VERTICAL_TILES_NUMBER = DISPLAY_SIZE_VERTICAL/TILE_DIVIDER
HORIZONTAL_TILES_NUMBER = floor((DISPLAY_SIZE_HORIZONTAL)/TILE_SIZE)
VERTICAL_TILES_NUMBER = floor((DISPLAY_SIZE_VERTICAL-200)/TILE_SIZE)
#TILE_SIZE
TILE_SIZE = DISPLAY_SIZE_HORIZONTAL/HORIZONTAL_TILES_NUMBER
#colors
WHITE = (255, 255, 255) #SUPER UPRAWA
@ -23,15 +24,19 @@ GREEN = (0, 255, 0) #DO SCIECIA
#tractor const
TRACTOR_HORIZONTAL_LOCATION = DISPLAY_SIZE_HORIZONTAL/2
TRACTOR_VERTICAL_LOCATION = DISPLAY_SIZE_VERTICAL/2
TRACTOR_WIDTH = TILE_SIZE
TRACTOR_HEIGHT = TILE_SIZE
#FRAMES PER SECOND
FPS = 144
FPS = 5
#ANIMATION_PART
ANIMATION_PART = 1
TRACTOR_DIRECTION_RIGHT = 2
TRACTOR_DIRECTION_UP = 1
TRACTOR_DIRECTION_DOWN = 3
TRACTOR_DIRECTION_LEFT = 4

55
convertToPrediction.py Normal file
View File

@ -0,0 +1,55 @@
def convert(field_state, weather, day_time, temperature, wind, humidy):
field_value = 0
weather_value = 0
day_time_value = 0
temperature_value = 0
wind_value = 0
humidy_value = 0
if field_state == "toPlow":
field_value = 0
elif field_state == "toWater":
field_value = 1
elif field_state == "toSeed":
field_value = 2
elif field_state == "toFertilize":
field_value = 3
elif field_state == "toCut":
field_value = 4
if weather == "Clear Sky":
weather_value = 0
elif weather == "Cloudy":
weather_value = 1
elif weather == "Rainy":
weather_value = 2
elif weather == "Hail":
weather_value = 3
if day_time == "Night":
day_time_value = 0
elif day_time == "Day":
day_time_value = 1
if temperature == "Freezing":
temperature_value = 0
elif temperature == "Cold":
temperature_value = 1
elif temperature == "Mild":
temperature_value = 2
elif temperature == "Hot":
temperature_value = 3
if wind == "Windless":
wind_value = 0
elif wind == "Strong Wind":
wind_value = 1
elif wind == "Gale":
wind_value = 2
if humidy == "Low":
humidy_value = 0
elif humidy == "High":
humidy_value = 1
return field_value, weather_value, day_time_value, temperature_value, wind_value, humidy_value

55
createDecisionTree.py Normal file
View File

@ -0,0 +1,55 @@
import pandas
from sklearn import tree
import pydotplus
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
import matplotlib.image as pltimg
import joblib
df = pandas.read_csv("treedata\\data.csv")
#Map text values to number values
d = {'toPlow' : 0, 'toWater' : 1, 'toSeed' : 2, 'toFertilize' : 3, 'toCut' : 4}
df['Field'] = df['Field'].map(d)
d = {'Night' : 0, 'Day' : 1}
df['Day Time'] = df['Day Time'].map(d)
d = {'Clear Sky' : 0, 'Cloudy' : 1, 'Rainy' : 2, 'Hail': 3}
df['Weather'] = df['Weather'].map(d)
d = {'Freezing' : 0, 'Cold' : 1, 'Mild': 2, 'Hot': 3}
df['Temperature'] = df['Temperature'].map(d)
d = {'Windless' : 0, 'Strong Wind' : 1, 'Gale': 2}
df['Wind'] = df['Wind'].map(d)
d = {'Low': 0, 'High': 1}
df['Humidy'] = df['Humidy'].map(d)
d = {'Wait' : 0, 'Make Action' : 1}
df['Decision'] = df['Decision'].map(d)
#Separate the feature columns from targert columns
features = ['Field', 'Day Time', 'Weather', 'Temperature', 'Wind', 'Humidy']
X = df[features]
y = df['Decision']
dtree = DecisionTreeClassifier()
dtree = dtree.fit(X, y)
joblib.dump(dtree, 'treedata\\DecisionTree.pkl')
data = tree.export_graphviz(dtree, out_file=None, feature_names=features)
graph = pydotplus.graph_from_dot_data(data)
graph.write_png('treedata\\mydecisiontree.png')
img = pltimg.imread('treedata\\mydecisiontree.png')
imgplot = plt.imshow(img)
plt.show()
#print(dtree.predict([[0, 1, 0, 0, 0, 1]]))

View File

@ -0,0 +1,48 @@
import os
import cv2
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.pyplot import imshow
path_potatoes = 'neural_network\\images\\potatoes'
path_beetroot = 'neural_network\\images\\beetroot'
size = 100
#POTATOES
image_data = []
label_data = []
for img in os.listdir(path_potatoes):
pic = cv2.imread(os.path.join(path_potatoes,img))
pic = cv2.cvtColor(pic,cv2.COLOR_BGR2RGB)
pic = cv2.resize(pic,(size,size))
image_data.append([pic])
label_data.append(1)
#np.save(os.path.join('neural_network','potatoes-dataset'),np.array(training_data_potatoes))
#saved_potatoes = np.load(os.path.join('neural_network','potatoes-dataset.npy'))
#BEETROOT
for img in os.listdir(path_beetroot):
pic = cv2.imread(os.path.join(path_beetroot,img))
pic = cv2.cvtColor(pic,cv2.COLOR_BGR2RGB)
pic = cv2.resize(pic,(size,size))
image_data.append([pic])
label_data.append(0)
#np.save(os.path.join('neural_network','beetroot-dataset'),np.array(training_data_beetroot))
#saved_potatoes = np.load(os.path.join('neural_network','beetroot-dataset.npy'))
np.save(os.path.join('neural_network','image-dataset'),np.array(image_data))
np.save(os.path.join('neural_network','label-dataset'),np.array(label_data))
saved_images = np.load(os.path.join('neural_network','image-dataset.npy'))
print(saved_images.shape)
plt.imshow(saved_images[0].reshape(size,size,3))
plt.imshow(np.array(image_data[0]).reshape(size,size,3))
plt.show()

122
createTreeData.py Normal file
View File

@ -0,0 +1,122 @@
from itertools import product
import csv
# stan pola: toCut, toPlow, toWater, toSeed, toFertilize
# pora dnia: dzień, noc
# pogoda: sunny, cloudy, rainy, hail
# temperatura: freezing, cold, mild, hot
# wiatr: windless, strong wind, gale
# humidy: low, high
field_states = ['toPlow', 'toWater', 'toSeed', 'toFertilize', 'toCut']
day_time = ['Day', 'Night']
weather = ['Clear Sky', 'Cloudy', 'Rainy', 'Hail']
temperature = ['Freezing', 'Cold', 'Mild', 'Hot']
wind = ['Windless', 'Strong Wind', 'Gale']
humidy = ['Low', 'High']
output = list(product(field_states, day_time, weather, temperature, wind, humidy))
dict = []
for x in range(len(output)):
if x % 3 == 0:
while True:
mField = output[x][0]
mDay_time = output[x][1]
mWeather = output[x][2]
mTemperature = output[x][3]
mWind = output[x][4]
mHumidy = output[x][5]
mDecision = 'null'
# pora dnia: dzień 2, noc -2
# pogoda: sunny+3, cloudy+3, rainy-2, hail-5
# temperatura: freezing -3, cold-1, mild+4, hot+2
# wiatr: windless +2, strong wind-1, gale-3
# humidy: low+2, high-3
if mDay_time == 'Day':
valDay_time = 2
else:
valDay_time = -3
if mWeather == 'Clear Sky' or 'Cloudy':
valWeather = 3
elif mWeather == 'Rainy':
valWeather = -2
else:
valWeather = -5
if mTemperature == 'Freezing':
valTemperature = -3
elif mTemperature == 'Cold':
valTemperature = -1
elif mTemperature == 'Mild':
valTemperature = 4
else:
valTemperature = 2
if mWind == 'Windless':
valWind = +2
elif mWind == 'Strong Wind':
valWind = -1
else:
valWind = -3
if humidy == 'Low':
valHumidy = 2
else:
valHumidy = -2
result = valDay_time + valWeather + valTemperature + valWind + valHumidy
if result >= 0:
mDecision = "Make Action"
else:
mDecision = "Wait"
#Special conditions
if mDay_time == 'Night' and (mField == 'toWater' or mField == 'toCut'):
mDecision = "Make Action"
break
else:
mDecision = "Wait"
if mWeather == 'Rainy' and (mField == 'toPlow' or mField == 'toSeed'):
mDecision = "Make Action"
break
else:
mDecision = 'Wait'
if mWeather == 'Hail':
mDecision = 'Wait'
break
if mTemperature == 'Freezing':
mDecision = 'Wait'
break
if mWind == 'Gale':
mDecision = 'Wait'
break
if mHumidy == 'High' and mField == 'toCut':
mDecision = "Wait"
break
else:
mDecision = "Make Action"
break
dict.append({'Field': mField, 'Day Time': mDay_time, 'Weather': mWeather,
'Temperature': mTemperature, 'Wind': mWind, 'Humidy': mHumidy, 'Decision': mDecision})
fields = ['Field', 'Day Time', 'Weather', 'Temperature', 'Wind', 'Humidy', 'Decision']
filename = "treedata\\data.csv"
with open(filename, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fields)
writer.writeheader()
writer.writerows(dict)

102
drawUI.py Normal file
View File

@ -0,0 +1,102 @@
from TractorLoad import TillageUnit
from constants import *
from images import *
import pygame
def drawUI(board, display, tractor, direction, tillageUnit, field, animationSpeed, weather, day_time, temperature, wind, humidy, decision):
if animationSpeed == 1:
display.fill(WHITE)
makeField(board, display)
drawTractor(display, tractor.horizontal_index, tractor.vertical_index, direction, 0)
drawInfo(display, tractor, tillageUnit, field, direction, weather, day_time, temperature, wind, humidy, decision)
pygame.display.update()
for i in range(1, animationSpeed):
display.fill(WHITE)
makeField(board, display)
drawTractor(display, tractor.horizontal_index, tractor.vertical_index, direction, i)
drawInfo(display, tractor, tillageUnit, field, direction)
pygame.display.update()
def drawInfo(display, tractor, tillageUnit, field, direction, weather, day_time, temperature, wind, humidy, decision):
myfont = pygame.font.SysFont('Comic Sans MS', 30)
hitches = tractor.hitch
if isinstance(tractor.hitch, TillageUnit):
hitches = "Tillage Unit"
if decision == [0]:
decision = "Wait"
else:
decision = "Make Action"
text = f"(Q)Hitches: {hitches} (W)Header: {tractor.header} (R)Engine working: {tractor.engineWorking} (T)Autodrive: {tractor.autodrive} Fuel: {round(tractor.fuel_tank,1)}"
textsurface = myfont.render(text, False, (0, 0, 0))
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 200)))
text = f"(E)Tillage Unit Load: {tillageUnit.load} (^) Direction: {direction}"
textsurface = myfont.render(text, False, (0, 0, 0))
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 150)))
text = f"Current field: {field.horizontal_index/100, field.vertical_index/100, field.state} Action: {decision}"
textsurface = myfont.render(text, False, (0, 0, 0))
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 100)))
text = f"Weather: {weather} Day Time: {day_time} Temperature: {temperature} Wind: {wind} Humidy: {humidy}"
textsurface = myfont.render(text, False, (0, 0, 0))
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 50)))
def makeField(board, screen: pygame.Surface):
for i in range(int(HORIZONTAL_TILES_NUMBER)):
for j in range(int(VERTICAL_TILES_NUMBER)):
field = board[i][j]
pos_x = i * TILE_SIZE + TILE_SIZE // 2
pos_y = j * TILE_SIZE + TILE_SIZE // 2
if field.state == "toWater":
to_water_rect.center = (pos_x, pos_y)
screen.blit(to_water, to_water_rect)
elif field.state == "toPlow":
to_plow_rect.center = (pos_x, pos_y)
screen.blit(to_plow, to_plow_rect)
elif field.state == "toSeed":
to_seed_rect.center = (pos_x, pos_y)
screen.blit(to_seed, to_seed_rect)
elif field.state == "toCut":
to_cut_rect.center = (pos_x, pos_y)
screen.blit(to_cut, to_cut_rect)
elif field.state == "toFertilize":
to_fertilizer_rect.center = (pos_x, pos_y)
screen.blit(to_fertilizer, to_fertilizer_rect)
elif field.state == "TOOLS_FIELD":
tools_rect.center = (pos_x, pos_y)
screen.blit(tools, tools_rect)
elif field.state == "FUEL_FIELD":
fuel_rect.center = (pos_x, pos_y)
screen.blit(fuel, fuel_rect)
def drawTractor(screen: pygame.Surface, tractor_horizontal_index, tractor_vertical_index, direction, i):
tractor_pic = tractor_up
horizontal = tractor_horizontal_index * TILE_SIZE
vertical = tractor_vertical_index * TILE_SIZE
i = i/ANIMATION_PART
if direction == "UP":
tractor_pic = tractor_up
vertical = vertical - (TILE_SIZE * i)
if direction == "DOWN":
tractor_pic = tractor_down
vertical = vertical + (TILE_SIZE * i)
if direction == "LEFT":
tractor_pic = tractor_left
horizontal = horizontal - (TILE_SIZE * i)
if direction == "RIGHT":
tractor_pic = tractor_right
horizontal = horizontal + (TILE_SIZE * i)
screen.blit(tractor_pic, (horizontal, vertical))

30
driving.py Normal file
View File

@ -0,0 +1,30 @@
from drawUI import *
import pygame
# def autodrive(tractor, direction, comeback):
# if tractor.autodrive:
# if not comeback:
# if direction == "RIGHT" and tractor.horizontal_index == HORIZONTAL_TILES_NUMBER - 1:
# direction = "DOWN"
# elif direction == "DOWN" and tractor.horizontal_index == HORIZONTAL_TILES_NUMBER - 1:
# direction = "LEFT"
# elif direction == "LEFT" and tractor.horizontal_index == 0:
# direction = "DOWN"
# elif direction == "DOWN" and tractor.horizontal_index == 0:
# direction = "RIGHT"
# else:
# direction = "UP"
# return direction
#
# def isComebackTime(tractor, direction, comeback):
# if tractor.vertical_index == 5 and tractor.horizontal_index == 0:
# comeback = True
# print(comeback)
# direction = "UP"
# if tractor.vertical_index == 0 and tractor.horizontal_index == 0:
# comeback = False
# print(comeback)
# direction = "RIGHT"
# return comeback, direction

48
images.py Normal file
View File

@ -0,0 +1,48 @@
import pygame
from constants import TILE_SIZE
tractor_up_image = pygame.image.load("resources/tractor_up.png")
tractor_up = pygame.transform.scale(tractor_up_image, (TILE_SIZE, TILE_SIZE))
tractor_right_image = pygame.image.load("resources/tractor_right.png")
tractor_right = pygame.transform.scale(tractor_right_image, (TILE_SIZE, TILE_SIZE))
tractor_down_image = pygame.image.load("resources/tractor_down.png")
tractor_down = pygame.transform.scale(tractor_down_image, (TILE_SIZE, TILE_SIZE))
tractor_left_image = pygame.image.load("resources/tractor_left.png")
tractor_left = pygame.transform.scale(tractor_left_image, (TILE_SIZE, TILE_SIZE))
to_water_image = pygame.image.load("resources/to_water.png")
to_water = pygame.transform.scale(to_water_image, (TILE_SIZE, TILE_SIZE))
to_plow_image = pygame.image.load("resources/to_plow.png")
to_plow = pygame.transform.scale(to_plow_image, (TILE_SIZE, TILE_SIZE))
to_seed_image = pygame.image.load("resources/to_seed.png")
to_seed = pygame.transform.scale(to_seed_image, (TILE_SIZE, TILE_SIZE))
to_cut_image = pygame.image.load("resources/to_cut.png")
to_cut = pygame.transform.scale(to_cut_image, (TILE_SIZE, TILE_SIZE))
to_fertilizer_image = pygame.image.load("resources/to_fertilizer.png")
to_fertilizer = pygame.transform.scale(to_fertilizer_image, (TILE_SIZE, TILE_SIZE))
fuel_image = pygame.image.load("resources/fuel.png")
fuel = pygame.transform.scale(fuel_image, (TILE_SIZE, TILE_SIZE))
tools_image = pygame.image.load("resources/tools.png")
tools = pygame.transform.scale(tools_image, (TILE_SIZE, TILE_SIZE))
tractor_up_rect = tractor_up.get_rect()
tractor_right_rect = tractor_right.get_rect()
tractor_down_rect = tractor_down.get_rect()
tractor_left_rect = tractor_left.get_rect()
to_water_rect = to_water.get_rect()
to_plow_rect = to_plow.get_rect()
to_seed_rect = to_seed.get_rect()
to_cut_rect = to_cut.get_rect()
to_fertilizer_rect = to_fertilizer.get_rect()
fuel_rect = fuel.get_rect()
tools_rect = tools.get_rect()

122
main.py
View File

@ -1,81 +1,93 @@
import pygame
# wersja 1.05
import Board
import FindPath
import TractorAction
import WeatherConditions
import convertToPrediction
import drawUI
import Graphsearch as graph
from Tractor import Tractor
from TractorLoad import TillageUnit
from constants import *
from Main import Board
from Main.constants import *
from manualSteering import manualSteeringDriver
import joblib
import pygame
pygame.init()
# display size in pixels
display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICAL))
# program name
pygame.display.set_caption('Tryryryry')
pygame.display.set_caption('Tractor')
working = True
autoAction = True
tractor_horizontal_location = TRACTOR_HORIZONTAL_LOCATION
tractor_vertical_location = TRACTOR_VERTICAL_LOCATION
animationSpeed = ANIMATION_PART
horizontal_change = 0
vertical_change = 0
hitchCounter = 0
loadCounter = 0
toolCounter = - 1
change_tile = False
#środowisko
board = Board.generate()
color = BLACK
#agent
tractor = Tractor(horizontal_index=-0, vertical_index=0, hitch="nothing", header=False, autodrive=True,
direction="RIGHT")
tillageUnit = TillageUnit("Nothing")
tractor.turnOnEngine()
move_list = []
clock = pygame.time.Clock()
#zjawiska pogodowe
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
weatherTimer = 0
#pętla główna działania programu
while working:
for event in pygame.event.get():
if event.type == pygame.QUIT:
working = False
if event.type == pygame.KEYDOWN:
print(tractor_horizontal_location, " ", tractor_vertical_location)
if event.key == pygame.K_LEFT and tractor_horizontal_location > 0:
horizontal_change = -TRACTOR_WIDTH
vertical_change = 0
elif event.key == pygame.K_RIGHT and tractor_horizontal_location < DISPLAY_SIZE_HORIZONTAL - TRACTOR_WIDTH:
horizontal_change = TRACTOR_WIDTH
vertical_change = 0
elif event.key == pygame.K_UP and tractor_vertical_location > 0:
vertical_change = -TRACTOR_HEIGHT
horizontal_change = 0
elif event.key == pygame.K_DOWN and tractor_vertical_location < DISPLAY_SIZE_VERTICAL - TRACTOR_HEIGHT:
vertical_change = TRACTOR_HEIGHT
horizontal_change = 0
elif event.key == pygame.K_SPACE:
change_tile = True
hitchCounter, loadCounter = \
manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter)
tractor_horizontal_location += horizontal_change
tractor_vertical_location += vertical_change
display.fill(WHITE)
for i in range(int(HORIZONTAL_TILES_NUMBER)):
for j in range(int(VERTICAL_TILES_NUMBER)):
if change_tile and i * TILE_SIZE == tractor_horizontal_location and j * TILE_SIZE == tractor_vertical_location:
board[i][j] = 4
change_tile = False
if board[i][j] == 0:
color = WHITE
elif board[i][j] == 1:
color = RED
elif board[i][j] == 2:
color = YELLOW
elif board[i][j] == 3:
color = GREEN
elif board[i][j] == 4:
color = BLACK
field = board[tractor.horizontal_index][tractor.vertical_index]
pygame.draw.rect(display, color,
[i * TILE_SIZE, j * TILE_SIZE, TILE_SIZE, TILE_SIZE])
if weatherTimer == 5:
weatherTimer = 0
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
pygame.draw.rect(display, BLACK,
[tractor_horizontal_location, tractor_vertical_location, TRACTOR_WIDTH, TRACTOR_HEIGHT])
#sformulowanie informacji dla drzewa decyzyjnego / lista informacji o aktualnej pogodzie i polu
question = [convertToPrediction.convert(field.state, weather, day_time, temperature, wind, humidy)]
dtree = joblib.load('treedata\\DecisionTree.pkl')
#przekazanie informacji do drzewa
decision = dtree.predict(question)
if tractor.autodrive:
# A*************
if not move_list and decision == 1:
field.state = TractorAction.changeFieldState(field, tractor)
istate = graph.Istate(tractor.direction, tractor.horizontal_index, tractor.vertical_index)
move_list = graph.graphsearch([], [], istate, FindPath.nearestLookingField(board, tractor, TillageUnit), board)
print(move_list)
elif move_list:
tractor.auto_movement(move_list.pop(0))
# TractorAction.changeFieldState(field, tractor)
if field.horizontal_index == 0 and field.vertical_index == 0 and not move_list:
tractor, tillageUnit, toolCounter = TractorAction.autoToolsChange(tractor, tillageUnit, toolCounter)
drawUI.drawUI(board, display, tractor, tractor.direction, tillageUnit, field, animationSpeed, weather, day_time,
temperature, wind, humidy, decision)
pygame.display.update()
clock.tick(FPS)
horizontal_change = 0
vertical_change = 0
# commit test 2
weatherTimer = weatherTimer + 1
pygame.quit()
quit()

62
manualSteering.py Normal file
View File

@ -0,0 +1,62 @@
from TractorAction import changeFieldState
from constants import *
import pygame
def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter):
if event.key == pygame.K_SPACE:
field = board[tractor.horizontal_index][tractor.vertical_index]
field.state = changeFieldState(field, tractor)
if event.key == pygame.K_q:
hitchCounter = (hitchCounter + 1) % 3
if hitchCounter == 0:
tractor.hitch = "Crop Trailer"
if hitchCounter == 1:
tractor.hitch = tillageUnit
if hitchCounter == 2:
tractor.hitch = "Nothing"
if event.key == pygame.K_w:
if tractor.header:
tractor.header = False
else:
tractor.header = True
if event.key == pygame.K_e:
loadCounter = (loadCounter + 1) % 4
if loadCounter == 0:
tillageUnit.load = "Nothing"
elif loadCounter == 1:
tillageUnit.load = "Seeds"
elif loadCounter == 2:
tillageUnit.load = "Water"
elif loadCounter == 3:
tillageUnit.load = "Fertilizer"
if event.key == pygame.K_m:
tractor.drive()
if event.key == pygame.K_r:
if tractor.engineWorking:
tractor.turnOffEngine()
else:
tractor.turnOnEngine()
if event.key == pygame.K_t:
if tractor.autodrive:
tractor.autodrive = False
else:
tractor.autodrive = True
manualTurning(event, tractor)
return hitchCounter, loadCounter
def manualTurning(event, tractor):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT and tractor.horizontal_index > 0:
tractor.direction = "LEFT"
elif event.key == pygame.K_RIGHT and tractor.horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
tractor.direction = "RIGHT"
elif event.key == pygame.K_UP and tractor.vertical_index > 0:
tractor.direction = "UP"
elif event.key == pygame.K_DOWN and tractor.vertical_index < VERTICAL_TILES_NUMBER - 1:
tractor.direction = "DOWN"

54
neuralNetwork.py Normal file
View File

@ -0,0 +1,54 @@
import numpy as np
import torch
import torch.nn as nn
import torch.optim as optim
from matplotlib.pyplot import imshow
import numpy as np
from matplotlib.pyplot import imshow
import matplotlib.pyplot as ppl
def plotdigit(image):
img = np.reshape(image, (-250, 250))
imshow(img, cmap='Greys', vmin=0, vmax=255)
ppl.show()
train_images = np.load('neural_network\\image-dataset.npy')
print(train_images.shape)
train_labels = np.load('neural_network\\label-dataset.npy')
train_images = train_images / 255
train_labels = train_labels / 255
train_images = [torch.tensor(image, dtype=torch.float32) for image in train_images]
print(train_images[0].shape)
train_labels = [torch.tensor(label, dtype=torch.long) for label in train_labels]
input_dim = 100*100*3
output_dim = 2
model = nn.Sequential(
nn.Linear(input_dim, output_dim),
nn.LogSoftmax()
)
def train(model, n_iter):
criterion = nn.NLLLoss()
optimizer = optim.SGD(model.parameters(), lr=0.001)
for epoch in range(n_iter):
for image, label in zip(train_images, train_labels):
optimizer.zero_grad()
output = model(image)
loss = criterion(output.unsqueeze(0), label.unsqueeze(0))
loss.backward()
optimizer.step()
print(f'epoch: {epoch:03}')
train(model, 100)

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Some files were not shown because too many files have changed in this diff Show More