2021-03-29 02:19:55 +02:00
|
|
|
import pygame
|
|
|
|
|
2021-04-13 17:52:27 +02:00
|
|
|
import Board
|
2021-05-19 04:01:26 +02:00
|
|
|
import FindPath
|
2021-03-30 00:54:29 +02:00
|
|
|
import TractorAction
|
2021-05-19 04:11:26 +02:00
|
|
|
import WeatherConditions
|
2021-04-13 17:52:27 +02:00
|
|
|
import drawUI
|
2021-05-19 04:45:37 +02:00
|
|
|
import Graphsearch as graph
|
2021-05-19 04:11:26 +02:00
|
|
|
from decisiontree import dtree
|
2021-03-29 20:51:47 +02:00
|
|
|
from Tractor import Tractor
|
|
|
|
from TractorLoad import TillageUnit
|
|
|
|
from constants import *
|
2021-04-13 17:52:27 +02:00
|
|
|
from manualSteering import manualSteeringDriver
|
|
|
|
|
2021-03-29 02:19:55 +02:00
|
|
|
pygame.init()
|
|
|
|
|
|
|
|
display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICAL))
|
|
|
|
pygame.display.set_caption('Tractor')
|
|
|
|
|
|
|
|
working = True
|
2021-03-29 17:18:14 +02:00
|
|
|
autoAction = True
|
2021-03-30 00:54:29 +02:00
|
|
|
|
|
|
|
animationSpeed = ANIMATION_PART
|
2021-03-29 14:33:16 +02:00
|
|
|
|
2021-03-29 13:46:30 +02:00
|
|
|
hitchCounter = 0
|
2021-03-29 14:33:16 +02:00
|
|
|
loadCounter = 0
|
2021-03-29 21:59:19 +02:00
|
|
|
toolCounter = - 1
|
2021-03-29 14:33:16 +02:00
|
|
|
|
2021-03-29 02:19:55 +02:00
|
|
|
board = Board.generate()
|
|
|
|
|
2021-05-19 04:01:26 +02:00
|
|
|
tractor = Tractor(horizontal_index=-0, vertical_index=0, hitch="nothing", header=False, autodrive=True,
|
|
|
|
direction="RIGHT")
|
|
|
|
|
2021-03-29 14:33:16 +02:00
|
|
|
tillageUnit = TillageUnit("Nothing")
|
|
|
|
|
2021-03-29 03:41:38 +02:00
|
|
|
tractor.turnOnEngine()
|
2021-05-19 04:01:26 +02:00
|
|
|
move_list = []
|
2021-03-29 02:19:55 +02:00
|
|
|
|
|
|
|
clock = pygame.time.Clock()
|
|
|
|
|
2021-05-19 04:45:37 +02:00
|
|
|
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
|
|
|
|
|
|
|
|
weatherTimer = 0
|
|
|
|
|
2021-03-29 02:19:55 +02:00
|
|
|
while working:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
working = False
|
|
|
|
if event.type == pygame.KEYDOWN:
|
2021-04-13 18:57:48 +02:00
|
|
|
hitchCounter, loadCounter = \
|
|
|
|
manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter)
|
2021-03-29 02:53:27 +02:00
|
|
|
|
2021-03-29 14:33:16 +02:00
|
|
|
field = board[tractor.horizontal_index][tractor.vertical_index]
|
|
|
|
|
2021-05-19 04:45:37 +02:00
|
|
|
if weatherTimer == 10:
|
|
|
|
weatherTimer = 0
|
|
|
|
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
|
2021-05-19 04:11:26 +02:00
|
|
|
|
2021-05-19 04:45:37 +02:00
|
|
|
#decision = dtree.predict([field.state, day_time, weather, temperature, wind, humidy])
|
|
|
|
decision = 'Make Action'
|
2021-04-13 18:57:48 +02:00
|
|
|
|
2021-05-19 04:01:26 +02:00
|
|
|
if not move_list and decision == 'Make Action':
|
2021-04-13 20:29:06 +02:00
|
|
|
field.state = TractorAction.changeFieldState(field, tractor)
|
2021-05-19 04:01:26 +02:00
|
|
|
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))
|
2021-05-19 04:45:37 +02:00
|
|
|
# TractorAction.changeFieldState(field, tractor)
|
2021-05-19 04:01:26 +02:00
|
|
|
|
|
|
|
if field.horizontal_index == 0 and field.vertical_index == 0 and not move_list:
|
|
|
|
tractor, tillageUnit, toolCounter = TractorAction.autoToolsChange(tractor, tillageUnit, toolCounter)
|
2021-03-29 19:15:36 +02:00
|
|
|
|
2021-05-19 04:45:37 +02:00
|
|
|
drawUI.drawUI(board, display, tractor, tractor.direction, tillageUnit, field, animationSpeed, weather, day_time, temperature, wind, humidy, decision)
|
2021-03-29 17:18:14 +02:00
|
|
|
|
2021-03-29 02:19:55 +02:00
|
|
|
clock.tick(FPS)
|
2021-05-19 04:45:37 +02:00
|
|
|
weatherTimer = weatherTimer + 1
|
2021-04-13 21:50:08 +02:00
|
|
|
|
2021-03-29 02:19:55 +02:00
|
|
|
pygame.quit()
|
2021-05-19 04:45:37 +02:00
|
|
|
quit()
|