From 66fe537f7a5013ddd53be51604735238ce6409d0 Mon Sep 17 00:00:00 2001 From: secret_dude Date: Mon, 31 May 2021 20:34:09 +0200 Subject: [PATCH] minor changes --- createTreeData.py | 101 ---------------------------------------------- main.py | 26 ++++++------ manualSteering.py | 8 ++-- 3 files changed, 18 insertions(+), 117 deletions(-) delete mode 100644 createTreeData.py diff --git a/createTreeData.py b/createTreeData.py deleted file mode 100644 index bf61d13..0000000 --- a/createTreeData.py +++ /dev/null @@ -1,101 +0,0 @@ -from itertools import product -import numpy as np -import pandas as pd -import csv -import id3test -import pprint -import sys -import pandas -from sklearn import tree -import pydotplus -from sklearn.tree import DecisionTreeClassifier -import matplotlib.pyplot as plt -import matplotlib.image as pltimg - -# stan pola: toCut, toPlow, toWater, toSeed, toFertilize -# pora dnia: dzień, noc -# pogoda: sunny, cloudy, rainy, hail -# temperatura: freezing, cold, mild, hot -# wiatr: windless, strong wind, gale -# humidy: low, high - - -field_states = ['toPlow', 'toWater', 'toSeed', 'toFertilize', 'toCut'] -day_time = ['Day', 'Night'] -weather = ['Clear Sky', 'Cloudy', 'Rainy', 'Hail'] -temperature = ['Freezing', 'Cold', 'Mild', 'Hot'] -wind = ['Windless', 'Strong Wind', 'Gale'] -humidy = ['Low', 'High'] - -output = list(product(field_states, day_time, weather, temperature, wind, humidy)) - -dict = [] - -for x in range(len(output)): - while True: - mField = output[x][0] - mDay_time = output[x][1] - mWeather = output[x][2] - mTemperature = output[x][3] - mWind = output[x][4] - mHumidy = output[x][5] - mDecision = 'null' - - # pora dnia: dzień 2, noc -2 - # pogoda: sunny+3, cloudy+3, rainy-2, hail-5 - # temperatura: freezing -3, cold-1, mild+4, hot+2 - # wiatr: windless +2, strong wind-1, gale-3 - # humidy: low+2, high-3 - - if mDay_time == 'Day': - valDay_time = 2 - else: - valDay_time = -3 - - if mWeather == 'Sunny' or 'Cloudy': - valWeather = 3 - elif mWeather == 'Rainy': - valWeather = -2 - else: - valWeather = -5 - - if mTemperature == 'Freezing': - valTemperature = -3 - elif mTemperature == 'Cold': - valTemperature = -1 - elif mTemperature == 'Mild': - valTemperature = 4 - else: - valTemperature = 2 - - if mWind == 'Windless': - valWind = +2 - elif mWind == 'Strong Wind': - valWind = -1 - else: - valWind = -3 - - if humidy == 'Low': - valHumidy = 2 - else: - valHumidy = -2 - - result = valDay_time + valWeather + valTemperature + valWind + valHumidy - if result >= 0: - mDecision = "Make Action" - else: - mDecision = "Wait" - - break - - dict.append({'Field': mField, 'Day Time': mDay_time, 'Weather': mWeather, - 'Temperature': mTemperature, 'Wind': mWind, 'Humidy': mHumidy, 'Decision': mDecision}) - -fields = ['Field', 'Day Time', 'Weather', 'Temperature', 'Wind', 'Humidy', 'Decision'] - -filename = "treedata\\data.csv" - -with open(filename, 'w') as csvfile: - writer = csv.DictWriter(csvfile, fieldnames=fields) - writer.writeheader() - writer.writerows(dict) diff --git a/main.py b/main.py index 7a3d45c..bb67d7d 100644 --- a/main.py +++ b/main.py @@ -53,27 +53,29 @@ while working: field = board[tractor.horizontal_index][tractor.vertical_index] - if weatherTimer == 30: + if weatherTimer == 2: weatherTimer = 0 weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions() question = [convertToPrediction.convert(field.state, weather, day_time, temperature, wind, humidy)] decision = dtree.predict(question) - if not move_list and decision == 1: - 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) + if tractor.autodrive: + if not move_list and decision == 1: + 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) + 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) + 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, weather, day_time, temperature, wind, humidy, decision) + drawUI.drawUI(board, display, tractor, tractor.direction, tillageUnit, field, animationSpeed, weather, day_time, + temperature, wind, humidy, decision) clock.tick(FPS) weatherTimer = weatherTimer + 1 diff --git a/manualSteering.py b/manualSteering.py index e5942ca..fd59e54 100644 --- a/manualSteering.py +++ b/manualSteering.py @@ -53,10 +53,10 @@ def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadC def manualTurning(event, tractor): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT and tractor.horizontal_index > 0: - tractor.direction = TRACTOR_DIRECTION_LEFT + tractor.direction = "LEFT" elif event.key == pygame.K_RIGHT and tractor.horizontal_index < HORIZONTAL_TILES_NUMBER - 1: - tractor.direction = TRACTOR_DIRECTION_RIGHT + tractor.direction = "RIGHT" elif event.key == pygame.K_UP and tractor.vertical_index > 0: - tractor.direction = TRACTOR_DIRECTION_UP + tractor.direction = "UP" elif event.key == pygame.K_DOWN and tractor.vertical_index < VERTICAL_TILES_NUMBER - 1: - tractor.direction = TRACTOR_DIRECTION_DOWN + tractor.direction = "DOWN"