final version
This commit is contained in:
parent
a139a5376b
commit
e2803dff2a
@ -5,7 +5,10 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (Inteligentny_Traktor_Grupa_16)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (ai-project)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="renderExternalDocumentation" value="true" />
|
||||
</component>
|
||||
</module>
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (Inteligentny_Traktor_Grupa_16)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (ai-project)" project-jdk-type="Python SDK" />
|
||||
</project>
|
7
.idea/other.xml
Normal file
7
.idea/other.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PySciProjectComponent">
|
||||
<option name="PY_SCI_VIEW" value="true" />
|
||||
<option name="PY_SCI_VIEW_SUGGESTED" value="true" />
|
||||
</component>
|
||||
</project>
|
BIN
assets/images/chest.png
Normal file
BIN
assets/images/chest.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
assets/images/chest_potato.png
Normal file
BIN
assets/images/chest_potato.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
BIN
assets/images/chest_wheat.png
Normal file
BIN
assets/images/chest_wheat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
BIN
assets/images/the_end.png
Normal file
BIN
assets/images/the_end.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
BIN
assets/sounds/Volume Alpha 18. Sweden.wav
Normal file
BIN
assets/sounds/Volume Alpha 18. Sweden.wav
Normal file
Binary file not shown.
178
assets/train.csv
178
assets/train.csv
@ -1,178 +0,0 @@
|
||||
stan_nawodnienia, rodzaj_gleby, stan_nawiezienia, stopien_ rozwoju, rodzaj_rosliny, rodzaj_nawozu, to_water
|
||||
0.32, brunatne, 0.01, 0.45, kaktus, mineralny, 0
|
||||
0.38, brunatne, 0.15, 0.25, pszenica, organiczny, 1
|
||||
0.17, piaszczyste, 0.22, 0.13, brak, organiczny, 1
|
||||
0.67, czarnoziemy, 0.64, 0.55, pszenica, sztuczny, 0
|
||||
0.45, brunatne, 0.16, 0.16, brak, organiczny, 1
|
||||
0.25, czarnoziemy, 0,16, 0.23, pszenica, organiczny, 1
|
||||
0.10, brunatne, 0.02, 0.17, brak, mineralny, 1
|
||||
0.25, brunatne, 0.39, 0.17, kaktus, organiczny, 0
|
||||
0.92, brunatne, 0.68, 0.77, ziemniak, sztuczny, 0
|
||||
0.70, piaszczyste, 0.72, 0.79, kaktus, sztuczny, 0
|
||||
0.54, czarnoziemy, 0.95, 0.59, ziemniak, organiczny, 0
|
||||
0.21, piaszczyste, 0.05, 0.03, brak, mineralny, 1
|
||||
0.23, brunatne, 0.11, 0.26, ziemniak, organiczny, 1
|
||||
0.61, czarnoziemy, 0.76, 0.76, ziemniak, sztuczny, 0
|
||||
0.87, brunatne, 0.53, 0.85, pszenica, organiczny, 0
|
||||
0.21, brunatne, 0.01, 0.26, kaktus, mineralny, 0
|
||||
0.32, piaszczyste, 0.06, 0.40, ziemniak, mineralny, 1
|
||||
0.76, czarnoziemy, 0.79, 0.67, kaktus, mineralny, 0
|
||||
0.30, brunatne, 0.21, 0.10, brak, mineralny, 1
|
||||
0.66, piaszczyste, 0.93, 0.95, kaktus, sztuczny, 0
|
||||
0.71, brunatne, 0.52, 0.62, ziemniak, mineralny, 0
|
||||
0.43, piaszczyste, 0.38, 0.35, pszenica, sztuczny, 1
|
||||
0.66, brunatne, 0.72, 0.63, pszenica, organiczny, 0
|
||||
0.21, piaszczyste, 0.47, 0.36, brak, sztuczny, 1
|
||||
0.78, brunatne, 0.59, 0.68, pszenica, organiczny, 0
|
||||
0.85, piaszczyste, 0.77, 0.64, pszenica, organiczny, 0
|
||||
0.84, piaszczyste, 0.75, 0.86, ziemniak, sztuczny, 0
|
||||
0.71, czarnoziemy, 0.72, 0.74, kaktus, mineralny, 0
|
||||
0.75, piaszczyste, 0.77, 0.74, ziemniak, sztuczny, 0
|
||||
0.76, piaszczyste, 0.75, 0.81, kaktus, mineralny, 0
|
||||
0.72, brunatne, 0.74, 0.84, kaktus, sztuczny, 0
|
||||
0.59, brunatne, 0.82, 0.88, pszenica, organiczny, 0
|
||||
0.48, czarnoziemy, 0.15, 0.27, kaktus, organiczny, 0
|
||||
0.04, piaszczyste, 0.12, 0.17, kaktus, organiczny, 0
|
||||
0.23, brunatne, 0.12, 0.26, brak, organiczny, 1
|
||||
0.02, piaszczyste, 0.20, 0.18, brak, organiczny, 1
|
||||
0.02, piaszczyste, 0.35, 0.24, ziemniak, mineralny, 1
|
||||
0.76, piaszczyste, 0.78, 0.85, ziemniak, mineralny, 0
|
||||
0.72, czarnoziemy, 0.67, 0.76, brak, mineralny, 0
|
||||
0.06, brunatne, 0.02, 0.31, ziemniak, mineralny, 1
|
||||
0.96, czarnoziemy, 0.66, 0.80, ziemniak, sztuczny, 0
|
||||
0.34, brunatne, 0.22, 0.15, kaktus, mineralny, 0
|
||||
0.78, piaszczyste, 0.62, 0.68, pszenica, mineralny, 0
|
||||
0.01, czarnoziemy, 0.22, 0.05, pszenica, sztuczny, 1
|
||||
0.02, czarnoziemy, 0.31, 0.30, pszenica, sztuczny, 1
|
||||
0.11, piaszczyste, 0,14, 0.14, pszenica, organiczny, 1
|
||||
0.95, piaszczyste, 0.61, 0.94, brak, sztuczny, 0
|
||||
0.78, brunatne, 0.86, 0.63, pszenica, organiczny, 0
|
||||
0.03, brunatne, 0.27, 0.25, pszenica, sztuczny, 1
|
||||
0.62, czarnoziemy, 0.75, 0.75, ziemniak, sztuczny, 0
|
||||
0.24, piaszczyste, 0.02, 0.23, kaktus, organiczny, 0
|
||||
0.16, czarnoziemy, 0.29, 0.27, kaktus, sztuczny, 0
|
||||
0.24, piaszczyste, 0.14, 0.03, kaktus, mineralny, 0
|
||||
0.82, czarnoziemy, 0.77, 0.86, ziemniak, mineralny, 0
|
||||
0.25, brunatne, 0.18, 0.23, pszenica, sztuczny, 1
|
||||
0.73, czarnoziemy, 0.94, 0.54, brak, organiczny, 0
|
||||
0.63, piaszczyste, 0.84, 0.92, kaktus, sztuczny, 0
|
||||
0.78, czarnoziemy, 0.75, 0.94, brak, sztuczny, 0
|
||||
0.84, piaszczyste, 0.79, 0.80, pszenica, sztuczny, 0
|
||||
0.78, czarnoziemy, 0.95, 0.63, pszenica, mineralny, 0
|
||||
0.43, brunatne, 0.38, 0.02, pszenica, organiczny, 1
|
||||
0.88, piaszczyste, 0.84, 0.78, ziemniak, sztuczny, 0
|
||||
0.69, brunatne, 0.86, 0.55, ziemniak, organiczny, 0
|
||||
0.77, piaszczyste, 0.78, 0.55, ziemniak, organiczny, 0
|
||||
0.26, brunatne, 0.24, 0.12, ziemniak, mineralny, 1
|
||||
0.75, czarnoziemy, 0.64, 0.73, brak, mineralny, 0
|
||||
0.14, piaszczyste, 0.38, 0.44, kaktus, sztuczny, 0
|
||||
0.84, czarnoziemy, 0.85, 0.67, kaktus, organiczny, 0
|
||||
0.33, brunatne, 0.11, 0.12, brak, organiczny, 1
|
||||
0.89, brunatne, 0.67, 0.88, kaktus, organiczny, 0
|
||||
0.15, brunatne, 0.21, 0.23, pszenica, mineralny, 1
|
||||
0.07, piaszczyste, 0.24, 0.07, brak, sztuczny, 1
|
||||
0.29, czarnoziemy, 0.10, 0.14, ziemniak, sztuczny, 1
|
||||
0.99, piaszczyste, 0.99, 0.75, kaktus, mineralny, 0
|
||||
0.62, piaszczyste, 0.65, 0.75, brak, organiczny, 0
|
||||
0.33, czarnoziemy, 0.23, 0.23, brak, sztuczny, 1
|
||||
0.16, brunatne, 0.28, 0.38, brak, organiczny, 1
|
||||
0.35, piaszczyste, 0.18, 0.13, kaktus, mineralny, 0
|
||||
0.85, czarnoziemy, 0.64, 0.74, kaktus, sztuczny, 0
|
||||
0.78, czarnoziemy, 0.59, 0.72, kaktus, organiczny, 0
|
||||
0.24, czarnoziemy, 0.14, 0.18, brak, organiczny, 1
|
||||
0.25, czarnoziemy, 0.13, 0.16, pszenica, sztuczny, 1
|
||||
0.87, czarnoziemy, 0.87, 0.76, pszenica, mineralny, 0
|
||||
0.28, brunatne, 0.44, 0.27, brak, mineralny, 1
|
||||
0.47, brunatne, 0.09, 0.05, ziemniak, mineralny, 1
|
||||
0.68, piaszczyste, 0.72, 0.67, brak, sztuczny, 0
|
||||
0.23, czarnoziemy, 0.27, 0.25, pszenica, sztuczny, 1
|
||||
0.05, piaszczyste, 0.11, 0.16, kaktus, organiczny, 0
|
||||
0.12, piaszczyste, 0.21, 0.22, brak, mineralny, 1
|
||||
0.86, brunatne, 0.55, 0.67, ziemniak, organiczny, 0
|
||||
0.68, brunatne, 0.76, 0.87, pszenica, organiczny, 0
|
||||
0.04, brunatne, 0.32, 0.26, kaktus, sztuczny, 0
|
||||
0.73, piaszczyste, 0.73, 0.73, pszenica, sztuczny, 0
|
||||
0.01, czarnoziemy, 0.42, 0.34, ziemniak, mineralny, 1
|
||||
0.96, piaszczyste, 0.70, 0.71, ziemniak, organiczny, 0
|
||||
0.74, piaszczyste, 0.66, 0.79, kaktus, mineralny, 0
|
||||
0.75, brunatne, 0.66, 0.82, pszenica, mineralny, 0
|
||||
0.70, brunatne, 0.69, 0.63, pszenica, organiczny, 0
|
||||
0.66, brunatne, 0.85, 0.72, brak, sztuczny, 0
|
||||
0.73, piaszczyste, 0.58, 0.95, ziemniak, mineralny, 0
|
||||
0.36, brunatne, 0.14, 0.02, kaktus, mineralny, 0
|
||||
0.61, piaszczyste, 0.70, 0.66, kaktus, mineralny, 0
|
||||
0.83, piaszczyste, 0.68, 0.75, kaktus, sztuczny, 0
|
||||
0.55, brunatne, 0.68, 0.79, ziemniak, sztuczny, 0
|
||||
0.75, czarnoziemy, 0.64, 0.78, kaktus, organiczny, 0
|
||||
0.99, brunatne, 0.57, 0.82, pszenica, organiczny, 0
|
||||
0.88, czarnoziemy, 0.68, 0.65, kaktus, sztuczny, 0
|
||||
0.78, czarnoziemy, 0.68, 0.71, kaktus, organiczny, 0
|
||||
0.14, piaszczyste, 0.46, 0.17, brak, sztuczny, 1
|
||||
0.06, czarnoziemy, 0.23, 0.25, kaktus, sztuczny, 0
|
||||
0.56, brunatne, 0.88, 0.65, ziemniak, organiczny, 0
|
||||
0.32, brunatne, 0.39, 0.23, pszenica, organiczny, 1
|
||||
0.64, piaszczyste, 0.85, 0.99, kaktus, mineralny, 0
|
||||
0.25, czarnoziemy, 0.26, 0.45, kaktus, organiczny, 0
|
||||
0.78, piaszczyste, 0.85, 0.92, brak, mineralny, 0
|
||||
0.14, brunatne, 0.09, 0.13, pszenica, organiczny, 1
|
||||
0.82, brunatne, 0.81, 0.80, kaktus, mineralny, 0
|
||||
0.65, piaszczyste, 0.58, 0.68, pszenica, mineralny, 0
|
||||
0.32, piaszczyste, 0.25, 0.04, ziemniak, organiczny, 1
|
||||
0.33, czarnoziemy, 0.12, 0.46, kaktus, sztuczny, 0
|
||||
0.58, czarnoziemy, 0.76, 0.66, pszenica, mineralny, 0
|
||||
0.01, czarnoziemy, 0.32, 0.33, ziemniak, mineralny, 1
|
||||
0.65, brunatne, 0.88, 0.66, kaktus, organiczny, 0
|
||||
0.12, czarnoziemy, 0.16, 0.13, brak, mineralny, 1
|
||||
0.86, brunatne, 0.98, 0.88, brak, sztuczny, 0
|
||||
0.23, brunatne, 0.15, 0.15, ziemniak, mineralny, 1
|
||||
0.24, piaszczyste, 0.37, 0.34, kaktus, mineralny, 0
|
||||
0.05, brunatne, 0.18, 0.39, ziemniak, mineralny, 1
|
||||
0.23, czarnoziemy, 0.26, 0.35, ziemniak, organiczny, 1
|
||||
0.55, czarnoziemy, 0.78, 0.89, brak, organiczny, 0
|
||||
0.25, czarnoziemy, 0.13, 0.17, brak, mineralny, 1
|
||||
0.62, czarnoziemy, 0.82, 0.68, brak, sztuczny, 0
|
||||
0.85, czarnoziemy, 0.64, 0.56, brak, mineralny, 0
|
||||
0.58, piaszczyste, 0.94, 0.74, brak, sztuczny, 0
|
||||
0.17, piaszczyste, 0.34, 0.15, ziemniak, mineralny, 1
|
||||
0.26, czarnoziemy, 0.21, 0.15, pszenica, mineralny, 1
|
||||
0.22, czarnoziemy, 0.35, 0.45, pszenica, mineralny, 1
|
||||
0.21, piaszczyste, 0.26, 0.26, pszenica, organiczny, 1
|
||||
0.38, piaszczyste, 0.36, 0.14, pszenica, mineralny, 1
|
||||
0.17, piaszczyste, 0.38, 0.27, pszenica, organiczny, 1
|
||||
0.11, piaszczyste, 0.21, 0.23, pszenica, sztuczny, 1
|
||||
0.48, czarnoziemy, 0.29, 0.28, kaktus, organiczny, 0
|
||||
0.16, czarnoziemy, 0.21, 0.06, ziemniak, organiczny, 1
|
||||
0.22, piaszczyste, 0.22, 0.19, ziemniak, sztuczny, 1
|
||||
0.63, czarnoziemy, 0.87, 0.77, pszenica, mineralny, 0
|
||||
0.69, piaszczyste, 0.85, 0.78, brak, mineralny, 0
|
||||
0.55, brunatne, 0.50, 0.79, brak, organiczny, 0
|
||||
0.14, piaszczyste, 0.14, 0.35, ziemniak, mineralny, 1
|
||||
0.95, czarnoziemy, 0.82, 0.92, pszenica, organiczny, 0
|
||||
0.68, piaszczyste, 0.57, 0.62, pszenica, mineralny, 0
|
||||
0.60, brunatne, 0.66, 0.85, ziemniak, mineralny, 0
|
||||
0.50, brunatne, 0.91, 0.83, ziemniak, organiczny, 0
|
||||
0.36, piaszczyste, 0.08, 0.28, kaktus, mineralny, 0
|
||||
0.33, brunatne, 0.26, 0.38, kaktus, sztuczny, 0
|
||||
0.32, piaszczyste, 0.25, 0.24, ziemniak, sztuczny, 1
|
||||
0.84, brunatne, 0.54, 0.50, brak, mineralny, 0
|
||||
0.21, czarnoziemy, 0.49, 0.04, pszenica, organiczny, 1
|
||||
0.62, piaszczyste, 0.74, 0.85, kaktus, sztuczny, 0
|
||||
0.85, czarnoziemy, 0.67, 0.74, brak, organiczny, 0
|
||||
0.74, piaszczyste, 0.69, 0.98, ziemniak, organiczny, 0
|
||||
0.16, piaszczyste, 0.16, 0.36, pszenica, mineralny, 1
|
||||
0.01, czarnoziemy, 0.12, 0.29, ziemniak, organiczny, 1
|
||||
0.55, brunatne, 0.67, 0.74, brak, sztuczny, 0
|
||||
0.75, czarnoziemy, 0.86, 0.90, ziemniak, sztuczny, 0
|
||||
0.42, czarnoziemy, 0.25, 0.39, kaktus, sztuczny, 0
|
||||
0.25, brunatne, 0.30, 0.24, ziemniak, organiczny, 1
|
||||
0.12, czarnoziemy, 0,20, 0.09, ziemniak, mineralny, 1
|
||||
0.75, brunatne, 0.75, 0.54, pszenica, organiczny, 0
|
||||
0.65, czarnoziemy, 0.82, 0.76, pszenica, mineralny, 0
|
||||
0.79, czarnoziemy, 0.66, 0.77, pszenica, sztuczny, 0
|
||||
0.62, brunatne, 0.78, 0.84, brak, mineralny, 0
|
||||
0.05, czarnoziemy, 0.19, 0.17, brak, organiczny, 1
|
||||
0.22, czarnoziemy, 0.24, 0.25, kaktus, organiczny, 0
|
||||
0.17, brunatne, 0.31, 0.35, ziemniak, mineralny, 1
|
||||
0.91, brunatne, 0.58, 0.89, ziemniak, sztuczny, 0
|
||||
0.07, brunatne, 0.27, 0.27, ziemniak, organiczny, 1
|
||||
0.32, piaszczyste, 0.12, 0.18, brak, organiczny, 1
|
|
89
main.py
89
main.py
@ -6,10 +6,11 @@ from src.utils.cnn_model import CnnModel
|
||||
from src.world import World
|
||||
from src.tractor import Tractor
|
||||
from src.settings import Settings
|
||||
from src.utils.bfs import BFSSearcher
|
||||
from src.utils.astar import a_star_search
|
||||
from src.constants import Constants as C
|
||||
from utils.display_info import display_tile_info
|
||||
from src.utils.water_all_plants import WaterAllPlants
|
||||
from src.utils.collect_crops import CollectCrops
|
||||
from src.utils.end_crops import EndCrops
|
||||
|
||||
|
||||
def main():
|
||||
@ -22,19 +23,25 @@ def main():
|
||||
cnn_model = CnnModel(world)
|
||||
cnn_model.init_model()
|
||||
tractor = Tractor("Spalinowy", "Nawóz 1", settings, 0 * settings.tile_size, 0 * settings.tile_size, C.RIGHT)
|
||||
plants_to_water = [tile for tile in world.tiles if tile.to_water == 1]
|
||||
clock = pygame.time.Clock() # FPS purpose
|
||||
|
||||
pygame.mixer.init()
|
||||
pygame.mixer.music.load('assets/sounds/Volume Alpha 18. Sweden.wav')
|
||||
pygame.mixer.music.play(-1)
|
||||
|
||||
clock = pygame.time.Clock() # FPS purpose
|
||||
screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
|
||||
pygame.display.set_caption('TRAKTOHOLIK')
|
||||
screen.blit(pygame.image.load('assets/images/display_info/img_frame.jpg'), (700, 0))
|
||||
|
||||
start_cords = tractor.curr_position
|
||||
goals = [plant.position for plant in plants_to_water]
|
||||
cords_idx = tractor.find_nearest_cords(tractor.curr_position, goals)
|
||||
end_cords = goals[cords_idx]
|
||||
start_dir = tractor.curr_direction
|
||||
path = a_star_search(start_cords, end_cords, start_dir, world)
|
||||
plants_to_water = [tile for tile in world.tiles if tile.to_water == 1]
|
||||
plants_wheat = [tile for tile in world.tiles if tile.rodzaj_rosliny == 'pszenica']
|
||||
plants_potato = [tile for tile in world.tiles if tile.rodzaj_rosliny == 'ziemniak']
|
||||
|
||||
water_all_plants = WaterAllPlants(tractor, world, plants_to_water)
|
||||
collect_wheat = CollectCrops(tractor, plants_wheat, (0, 0))
|
||||
end_wheat = EndCrops(tractor, (0, 0), (0, 0))
|
||||
collect_potatoes = CollectCrops(tractor, plants_potato, (0, 0))
|
||||
end_potatoes = EndCrops(tractor, (0, 0), (9, 0))
|
||||
|
||||
run = True
|
||||
while run:
|
||||
@ -50,17 +57,35 @@ def main():
|
||||
if event.button == 1:
|
||||
display_tile_info(world, screen)
|
||||
|
||||
if path:
|
||||
action = path.pop(0)
|
||||
tractor.update(action)
|
||||
else:
|
||||
tractor.water_plant(world, end_cords)
|
||||
if len(goals) > 1:
|
||||
start_cord = goals.pop(cords_idx)
|
||||
cords_idx = tractor.find_nearest_cords(tractor.curr_position, goals)
|
||||
end_cords = goals[cords_idx]
|
||||
start_dir = tractor.curr_direction
|
||||
path = a_star_search(start_cord, end_cords, start_dir, world)
|
||||
water_all_plants.update(tractor, world)
|
||||
|
||||
if not C.COLLECT_WHEAT and tractor.curr_position == water_all_plants.last_cords:
|
||||
collect_wheat = CollectCrops(tractor, plants_wheat, water_all_plants.last_cords)
|
||||
C.COLLECT_WHEAT = 1
|
||||
if C.COLLECT_WHEAT:
|
||||
collect_wheat.update(tractor, world)
|
||||
|
||||
if not C.END_WHEAT and tractor.curr_position == collect_wheat.last_cords:
|
||||
end_wheat = EndCrops(tractor, collect_wheat.last_cords, (0, 0))
|
||||
C.END_WHEAT = 1
|
||||
if C.END_WHEAT:
|
||||
end_wheat.update(tractor)
|
||||
|
||||
if not C.COLLECT_POTATOES and tractor.curr_position == end_wheat.last_cords:
|
||||
collect_potatoes = CollectCrops(tractor, plants_potato, end_wheat.last_cords)
|
||||
C.COLLECT_POTATOES = 1
|
||||
if C.COLLECT_POTATOES:
|
||||
collect_potatoes.update(tractor, world)
|
||||
|
||||
if not C.END_POTATOES and tractor.curr_position == collect_potatoes.last_cords:
|
||||
end_potatoes = EndCrops(tractor, collect_potatoes.last_cords, (9, 0))
|
||||
C.END_POTATOES = 1
|
||||
if C.END_POTATOES:
|
||||
end_potatoes.update(tractor)
|
||||
|
||||
# if C.END_POTATOES:
|
||||
# if tractor.curr_position == end_potatoes.last_cords:
|
||||
# screen.blit(pygame.image.load('assets/images/the_end.png'), (190, 310))
|
||||
|
||||
pygame.time.wait(settings.freeze_time)
|
||||
pygame.display.update()
|
||||
@ -69,25 +94,3 @@ def main():
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
# # inicjalizacja array z zerami
|
||||
# rows = 10
|
||||
# cols = 10
|
||||
# field = np.zeros((rows, cols), dtype=int)
|
||||
#
|
||||
# # tworzenie ścian w array
|
||||
# for i in range(0, 9):
|
||||
# field[1, i] = 1
|
||||
#
|
||||
# field[2, 8] = 1
|
||||
# field[3, 8] = 1
|
||||
# field[3, 7] = 1
|
||||
# field[3, 6] = 1
|
||||
#
|
||||
# print(field)
|
||||
#
|
||||
# start = (0, 0)
|
||||
# goals = [(2, 7)]
|
||||
# while goals:
|
||||
# goal = goals.pop(0)
|
||||
# path = a_star(field, start, goal)
|
||||
# print(path)
|
||||
|
@ -30,3 +30,9 @@ class Constants:
|
||||
# Genetic algorithm points average
|
||||
|
||||
POINTS_AVERAGE = 6.33
|
||||
|
||||
# MOVING FLAGS
|
||||
COLLECT_WHEAT = 0
|
||||
END_WHEAT = 0
|
||||
COLLECT_POTATOES = 0
|
||||
END_POTATOES = 0
|
||||
|
@ -4,7 +4,7 @@ class Settings:
|
||||
def __init__(self):
|
||||
# Game settings
|
||||
self.fps = 60
|
||||
self.freeze_time = 250
|
||||
self.freeze_time = 100
|
||||
|
||||
# Screen settings
|
||||
self.screen_width = 910
|
||||
|
@ -71,28 +71,8 @@ class Tractor(Sprite):
|
||||
pygame.time.wait(self.settings.freeze_time) # bez tego sie kreci jak hot-wheels
|
||||
|
||||
def turn_around(self):
|
||||
if self.curr_direction == C.UP:
|
||||
self.curr_direction = C.DOWN
|
||||
self.image = pygame.transform.scale(
|
||||
pygame.image.load('assets/images/tractor/tractor-transparent-down.png'),
|
||||
(self.settings.tile_size, self.settings.tile_size))
|
||||
elif self.curr_direction == C.LEFT:
|
||||
self.curr_direction = C.RIGHT
|
||||
self.image = pygame.transform.scale(
|
||||
pygame.image.load('assets/images/tractor/tractor-transparent-right.png'),
|
||||
(self.settings.tile_size, self.settings.tile_size))
|
||||
elif self.curr_direction == C.DOWN:
|
||||
self.curr_direction = C.UP
|
||||
self.image = pygame.transform.scale(
|
||||
pygame.image.load('assets/images/tractor/tractor-transparent-up.png'),
|
||||
(self.settings.tile_size, self.settings.tile_size))
|
||||
elif self.curr_direction == C.RIGHT:
|
||||
self.curr_direction = C.LEFT
|
||||
self.image = pygame.transform.scale(
|
||||
pygame.image.load('assets/images/tractor/tractor-transparent-left.png'),
|
||||
(self.settings.tile_size, self.settings.tile_size))
|
||||
|
||||
pygame.time.wait(self.settings.freeze_time) # bez tego sie kreci jak hot-wheels
|
||||
self.turn_right()
|
||||
self.turn_right()
|
||||
|
||||
def move(self):
|
||||
self.rect.x += self.curr_direction[0] * self.settings.tractor_speed
|
||||
@ -111,6 +91,7 @@ class Tractor(Sprite):
|
||||
|
||||
def water_plant(self, world, position):
|
||||
plant = world.get_tile(position[0], position[1])
|
||||
plant.to_water = 0
|
||||
|
||||
if plant.rodzaj_rosliny == 'brak':
|
||||
plant.image = pygame.transform.scale(world.farmland_empty,
|
||||
@ -125,8 +106,13 @@ class Tractor(Sprite):
|
||||
plant.image = pygame.transform.scale(world.farmland_potato,
|
||||
(self.settings.tile_size, self.settings.tile_size))
|
||||
|
||||
def collect_crop(self, world, position):
|
||||
plant = world.get_tile(position[0], position[1])
|
||||
plant.image = pygame.transform.scale(world.farmland_empty,
|
||||
(self.settings.tile_size, self.settings.tile_size))
|
||||
|
||||
def find_nearest_cords(self, curr_cords, cords_lst):
|
||||
# source https://stackoverflow.com/questions/39107896/efficiently-finding-the-closest-coordinate-pair-from-a-set-in-python
|
||||
# https://stackoverflow.com/questions/39107896/efficiently-finding-the-closest-coordinate-pair-from-a-set-in-python
|
||||
tree = spatial.KDTree(cords_lst)
|
||||
return tree.query(curr_cords)[1]
|
||||
|
||||
@ -156,9 +142,13 @@ class Tractor(Sprite):
|
||||
# self.rect.y += self.curr_direction[1] * self.settings.tile_size # jak wejdzie na kolizje to cofamy ruch
|
||||
# w przyszlosci mozna zmienic
|
||||
|
||||
def update(self, action):
|
||||
def update_position(self):
|
||||
self.curr_position = (round(self.rect.x / self.settings.tile_size),
|
||||
self.settings.world_size - round(self.rect.y / self.settings.tile_size) - 1)
|
||||
|
||||
def update(self, action):
|
||||
self.update_position()
|
||||
|
||||
if action == C.ROTATE_RIGHT and self.rect.x:
|
||||
self.turn_right()
|
||||
elif action == C.ROTATE_LEFT:
|
||||
|
30
src/utils/collect_crops.py
Normal file
30
src/utils/collect_crops.py
Normal file
@ -0,0 +1,30 @@
|
||||
from src.tractor import Tractor
|
||||
from src.utils.bfs import BFSSearcher
|
||||
|
||||
|
||||
class CollectCrops:
|
||||
def __init__(self, tractor: Tractor, plants, start_cords):
|
||||
self.start_cords = start_cords
|
||||
self.goals = [plant.position for plant in plants]
|
||||
self.cords_idx = tractor.find_nearest_cords(tractor.curr_position, self.goals)
|
||||
self.end_cords = self.goals[self.cords_idx]
|
||||
self.start_dir = tractor.curr_direction
|
||||
self.path = BFSSearcher().search(self.start_cords, self.end_cords, self.start_dir) # a_star_search(self.start_cords, self.end_cords, self.start_dir, world)
|
||||
self.last_cords = None
|
||||
|
||||
def update(self, tractor: Tractor, world):
|
||||
if self.path:
|
||||
action = self.path.pop(0)
|
||||
tractor.update(action)
|
||||
else:
|
||||
tractor.collect_crop(world, self.end_cords)
|
||||
if len(self.goals) > 1:
|
||||
self.start_cords = self.goals.pop(self.cords_idx)
|
||||
self.cords_idx = tractor.find_nearest_cords(tractor.curr_position, self.goals)
|
||||
self.end_cords = self.goals[self.cords_idx]
|
||||
self.start_dir = tractor.curr_direction
|
||||
self.path = BFSSearcher().search(self.start_cords, self.end_cords, self.start_dir) # a_star_search(self.start_cords, self.end_cords, self.start_dir, world)
|
||||
elif len(self.goals) == 1:
|
||||
self.last_cords = self.goals.pop()
|
||||
tractor.update_position()
|
||||
|
@ -526,17 +526,6 @@
|
||||
" print(\"Actual label: \" + str(np.argmax(label, axis=1)))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c7e6f668",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"filename = '../../assets/cnn_model/xgboost_model.pkl'\n",
|
||||
"pickle.dump(xgb, open(filename, 'wb'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
@ -604,4 +593,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
}
|
30
src/utils/end_crops.py
Normal file
30
src/utils/end_crops.py
Normal file
@ -0,0 +1,30 @@
|
||||
from src.tractor import Tractor
|
||||
from src.utils.bfs import BFSSearcher
|
||||
|
||||
|
||||
class EndCrops:
|
||||
def __init__(self, tractor: Tractor, start_cords, goal):
|
||||
self.start_cords = start_cords
|
||||
self.goals = [goal]
|
||||
self.cords_idx = tractor.find_nearest_cords(tractor.curr_position, self.goals)
|
||||
self.end_cords = self.goals[self.cords_idx]
|
||||
self.start_dir = tractor.curr_direction
|
||||
self.path = BFSSearcher().search(self.start_cords, self.end_cords, self.start_dir) # a_star_search(self.start_cords, self.end_cords, self.start_dir, world)
|
||||
self.last_cords = None
|
||||
|
||||
def update(self, tractor: Tractor):
|
||||
if self.path:
|
||||
action = self.path.pop(0)
|
||||
tractor.update(action)
|
||||
else:
|
||||
# tractor.collect_crop(world, self.end_cords)
|
||||
if len(self.goals) > 1:
|
||||
self.start_cords = self.goals.pop(self.cords_idx)
|
||||
self.cords_idx = tractor.find_nearest_cords(tractor.curr_position, self.goals)
|
||||
self.end_cords = self.goals[self.cords_idx]
|
||||
self.start_dir = tractor.curr_direction
|
||||
self.path = BFSSearcher().search(self.start_cords, self.end_cords, self.start_dir) # a_star_search(self.start_cords, self.end_cords, self.start_dir, world)
|
||||
elif len(self.goals) == 1:
|
||||
self.last_cords = self.goals.pop()
|
||||
tractor.update_position()
|
||||
|
30
src/utils/water_all_plants.py
Normal file
30
src/utils/water_all_plants.py
Normal file
@ -0,0 +1,30 @@
|
||||
from src.utils.astar import a_star_search
|
||||
from src.tractor import Tractor
|
||||
|
||||
|
||||
class WaterAllPlants:
|
||||
def __init__(self, tractor: Tractor, world, plants_to_water):
|
||||
self.start_cords = tractor.curr_position
|
||||
self.goals = [plant.position for plant in plants_to_water]
|
||||
self.cords_idx = tractor.find_nearest_cords(tractor.curr_position, self.goals)
|
||||
self.end_cords = self.goals[self.cords_idx]
|
||||
self.start_dir = tractor.curr_direction
|
||||
self.path = a_star_search(self.start_cords, self.end_cords, self.start_dir, world)
|
||||
self.last_cords = None
|
||||
|
||||
def update(self, tractor: Tractor, world):
|
||||
if self.path:
|
||||
action = self.path.pop(0)
|
||||
tractor.update(action)
|
||||
else:
|
||||
if self.goals:
|
||||
tractor.water_plant(world, self.end_cords)
|
||||
if len(self.goals) > 1:
|
||||
self.start_cords = self.goals.pop(self.cords_idx)
|
||||
self.cords_idx = tractor.find_nearest_cords(tractor.curr_position, self.goals)
|
||||
self.end_cords = self.goals[self.cords_idx]
|
||||
self.start_dir = tractor.curr_direction
|
||||
self.path = a_star_search(self.start_cords, self.end_cords, self.start_dir, world)
|
||||
elif len(self.goals) == 1:
|
||||
self.last_cords = self.goals.pop()
|
||||
tractor.update_position()
|
@ -17,6 +17,7 @@ class XgbModel:
|
||||
|
||||
def parse_input(self):
|
||||
self.y_test = self.df['to_water']
|
||||
self.df = self.df.sample(frac=1) # shuffle dataframe so as to randomize tiles
|
||||
self.df = self.df.drop('to_water', axis=1)
|
||||
self.X_test = pd.get_dummies(self.df)
|
||||
|
||||
|
10
src/world.py
10
src/world.py
@ -21,6 +21,8 @@ class World:
|
||||
[0, 1, 1, 1, 0, 0, 1, 1, 1, 0],
|
||||
[0, 1, 1, 1, 0, 0, 1, 1, 1, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
|
||||
self.wheat_chest = pygame.image.load('assets/images/chest_wheat.png')
|
||||
self.potatoes_chest = pygame.image.load('assets/images/chest_potato.png')
|
||||
self.rock = pygame.image.load('assets/images/cobblestone.jpg')
|
||||
self.dirt_empty = pygame.image.load('assets/images/dirt_empty.jpeg')
|
||||
self.dirt_cactus = pygame.image.load('assets/images/dirt_cactus.jpg')
|
||||
@ -34,6 +36,14 @@ class World:
|
||||
self.plants = GeneticAlgorithm().get_plants()
|
||||
self.create_tiles()
|
||||
|
||||
wheat_chest_tile = self.get_tile(0, 0)
|
||||
wheat_chest_tile.image = pygame.transform.scale(self.wheat_chest, (settings.tile_size, settings.tile_size))
|
||||
wheat_chest_tile.cnn_image = wheat_chest_tile.image
|
||||
|
||||
potato_chest_tile = self.get_tile(9, 0)
|
||||
potato_chest_tile.image = pygame.transform.scale(self.potatoes_chest, (settings.tile_size, settings.tile_size))
|
||||
potato_chest_tile.cnn_image = potato_chest_tile.image
|
||||
|
||||
def create_tiles(self):
|
||||
row_count = 0
|
||||
df_idx = 0
|
||||
|
Loading…
Reference in New Issue
Block a user