74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
import pygame
|
|
|
|
import Board
|
|
import FindPath
|
|
import TractorAction
|
|
import WeatherConditions
|
|
import drawUI
|
|
import graph
|
|
from decisiontree import dtree
|
|
from Tractor import Tractor
|
|
from TractorLoad import TillageUnit
|
|
from constants import *
|
|
from manualSteering import manualSteeringDriver
|
|
|
|
pygame.init()
|
|
|
|
display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICAL))
|
|
pygame.display.set_caption('Tractor')
|
|
|
|
working = True
|
|
autoAction = True
|
|
|
|
animationSpeed = ANIMATION_PART
|
|
|
|
hitchCounter = 0
|
|
loadCounter = 0
|
|
toolCounter = - 1
|
|
|
|
board = Board.generate()
|
|
|
|
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()
|
|
|
|
while working:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
working = False
|
|
if event.type == pygame.KEYDOWN:
|
|
hitchCounter, loadCounter = \
|
|
manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter)
|
|
|
|
field = board[tractor.horizontal_index][tractor.vertical_index]
|
|
|
|
|
|
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
|
|
decision = dtree.predict([field.state, day_time, weather, temperature, wind, humidy])
|
|
|
|
if not move_list and decision == 'Make Action':
|
|
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)
|
|
|
|
clock.tick(FPS)
|
|
|
|
|
|
pygame.quit()
|
|
quit() |