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} d = {'Night' : 0, 'Day' : 1}
df['Day Time'] = df['Day Time'].map(d) 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) df['Weather'] = df['Weather'].map(d)
d = {'Freezing' : 0, 'Cold' : 1, 'Mild': 2, 'Hot': 3} d = {'Freezing' : 0, 'Cold' : 1, 'Mild': 2, 'Hot': 3}

View File

@ -4,12 +4,12 @@ from images import *
import pygame 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: if animationSpeed == 1:
display.fill(WHITE) display.fill(WHITE)
makeField(board, display) makeField(board, display)
drawTractor(display, tractor.horizontal_index, tractor.vertical_index, direction, 0) 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() pygame.display.update()
for i in range(1, animationSpeed): for i in range(1, animationSpeed):
display.fill(WHITE) display.fill(WHITE)
@ -19,7 +19,7 @@ def drawUI(board, display, tractor, direction, tillageUnit, field, animationSpee
pygame.display.update() 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) myfont = pygame.font.SysFont('Comic Sans MS', 30)
hitches = tractor.hitch hitches = tractor.hitch
if isinstance(tractor.hitch, TillageUnit): if isinstance(tractor.hitch, TillageUnit):
@ -33,10 +33,14 @@ def drawInfo(display, tractor, tillageUnit, field, direction):
textsurface = myfont.render(text, False, (0, 0, 0)) textsurface = myfont.render(text, False, (0, 0, 0))
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 150))) 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)) textsurface = myfont.render(text, False, (0, 0, 0))
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 100))) 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): def makeField(board, screen: pygame.Surface):
for i in range(int(HORIZONTAL_TILES_NUMBER)): for i in range(int(HORIZONTAL_TILES_NUMBER)):

21
main.py
View File

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