main update

This commit is contained in:
secret_dude 2021-05-19 04:45:37 +02:00
parent b571318359
commit 422d7adaac
3 changed files with 23 additions and 12 deletions

View File

@ -14,7 +14,7 @@ df['Field'] = df['Field'].map(d)
d = {'Night' : 0, 'Day' : 1}
df['Day Time'] = df['Day Time'].map(d)
d = {'Sunny' : 0, 'Cloudy' : 1, 'Rainy' : 2, 'Hail': 3}
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}

View File

@ -4,12 +4,12 @@ from images import *
import pygame
def drawUI(board, display, tractor, direction, tillageUnit, field, animationSpeed):
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)
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)
@ -19,7 +19,7 @@ def drawUI(board, display, tractor, direction, tillageUnit, field, animationSpee
pygame.display.update()
def drawInfo(display, tractor, tillageUnit, field, direction):
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):
@ -33,10 +33,14 @@ def drawInfo(display, tractor, tillageUnit, field, 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} "
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)):

21
main.py
View File

@ -5,7 +5,7 @@ import FindPath
import TractorAction
import WeatherConditions
import drawUI
import graph
import Graphsearch as graph
from decisiontree import dtree
from Tractor import Tractor
from TractorLoad import TillageUnit
@ -38,6 +38,10 @@ move_list = []
clock = pygame.time.Clock()
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
weatherTimer = 0
while working:
for event in pygame.event.get():
if event.type == pygame.QUIT:
@ -48,9 +52,12 @@ while working:
field = board[tractor.horizontal_index][tractor.vertical_index]
if weatherTimer == 10:
weatherTimer = 0
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions()
decision = dtree.predict([field.state, day_time, weather, temperature, wind, humidy])
#decision = dtree.predict([field.state, day_time, weather, temperature, wind, humidy])
decision = 'Make Action'
if not move_list and decision == 'Make Action':
field.state = TractorAction.changeFieldState(field, tractor)
@ -60,15 +67,15 @@ while working:
elif move_list:
tractor.auto_movement(move_list.pop(0))
#TractorAction.changeFieldState(field, tractor)
# 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)
drawUI.drawUI(board, display, tractor, tractor.direction, tillageUnit, field, animationSpeed, weather, day_time, temperature, wind, humidy, decision)
clock.tick(FPS)
weatherTimer = weatherTimer + 1
pygame.quit()
quit()
quit()