From d91b9141fc1d09419e0a2d3736eac2e191f4edd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz?= Date: Wed, 19 May 2021 04:53:19 +0200 Subject: [PATCH] decision tree update --- convertToPrediction.py | 55 ++++++++++++++++++++++++++++++++++++++++++ main.py | 7 +++--- 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 convertToPrediction.py diff --git a/convertToPrediction.py b/convertToPrediction.py new file mode 100644 index 0000000..c2d0770 --- /dev/null +++ b/convertToPrediction.py @@ -0,0 +1,55 @@ +def convert(field_state, weather, day_time, temperature, wind, humidy): + field_value = 0 + weather_value = 0 + day_time_value = 0 + temperature_value = 0 + wind_value = 0 + humidy_value = 0 + + if field_state == "toPlow": + field_value = 0 + elif field_state == "toWater": + field_value = 1 + elif field_state == "toSeed": + field_value = 2 + elif field_state == "toFertilize": + field_value = 3 + elif field_state == "toCut": + field_value = 4 + + if weather == "Clear Sky": + weather_value = 0 + elif weather == "Cloudy": + weather_value = 1 + elif weather == "Rainy": + weather_value = 2 + elif weather == "Hail": + weather_value = 3 + + if day_time == "Night": + day_time_value = 0 + elif day_time == "Day": + day_time_value = 1 + + if temperature == "Freezing": + temperature_value = 0 + elif temperature == "Cold": + temperature_value = 1 + elif temperature == "Mild": + temperature_value = 2 + elif temperature == "Hot": + temperature_value = 3 + + if wind == "Windless": + wind_value = 0 + elif wind == "Strong Wind": + wind_value = 1 + elif wind == "Gale": + wind_value = 2 + + if humidy == "Low": + humidy_value = 0 + elif humidy == "High": + humidy_value = 1 + + return field_value, weather_value, day_time_value, temperature_value, wind_value, humidy_value \ No newline at end of file diff --git a/main.py b/main.py index 23f5f00..65870ac 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import Board import FindPath import TractorAction import WeatherConditions +import convertToPrediction import drawUI import Graphsearch as graph from decisiontree import dtree @@ -56,10 +57,10 @@ while working: weatherTimer = 0 weather, day_time, temperature, wind, humidy = WeatherConditions.checkConditions() - #decision = dtree.predict([field.state, day_time, weather, temperature, wind, humidy]) - decision = 'Make Action' + question = [convertToPrediction.convert(field.state, weather, day_time, temperature, wind, humidy)] + decision = dtree.predict(question) - if not move_list and decision == 'Make Action': + 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)