From fda1579a87677d54064079fb1d218804d3ce049c Mon Sep 17 00:00:00 2001 From: matixezor Date: Mon, 17 May 2021 17:53:21 +0200 Subject: [PATCH] add usage of decision tree --- src/main.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index ceaab63..8198a85 100644 --- a/src/main.py +++ b/src/main.py @@ -2,11 +2,12 @@ import pygame as pg from agent import Agent from game_ui import GameUi -from const import ICON, IMAGES, DEBUG_FIELD from environment import Environment -from search_algoritms.BFS import breadth_first_search, breadth_first_search_for_a_star -from src.search_algoritms.a_star import a_star from tilesFactory import TilesFactory +from const import ICON, IMAGES, DEBUG_FIELD +from src.search_algoritms.a_star import a_star +from search_algoritms.BFS import breadth_first_search_for_a_star +from machine_learning.decision_tree import get_decision, tree_root def handle_keys(env, agent, game_ui, factory): @@ -65,9 +66,8 @@ def main(): while env.mine_count: print('-' * 20) # path, actions = breadth_first_search(env.field, agent.x, agent.y, agent.direction) - path, actions = a_star(env.field, agent.x, agent.y, agent.direction, - breadth_first_search_for_a_star(env.field, agent.x, agent.y, - agent.direction)) + goal = breadth_first_search_for_a_star(env.field, agent.x, agent.y, agent.direction) + path, actions = a_star(env.field, agent.x, agent.y, agent.direction, goal) if not path and not env.field[agent.y][agent.x].mine: print('Unable to find path, rocks are in the way') break @@ -75,6 +75,17 @@ def main(): print(f'Actions:{actions}') for action in actions: pg.fastevent.post(pg.event.Event(pg.KEYDOWN, {'key': action})) + goal_tile = env.field[goal[1]][goal[0]] + data = { + 'visibility': goal_tile.visibility, + 'stability': goal_tile.stability, + 'armed': goal_tile.mine.armed, + 'ground': goal_tile.ground, + 'mine_type': goal_tile.mine.mine_type, + 'pressure_gt_two': True if goal_tile.mine.pressure > 2 else False + } + decision = get_decision(data, tree_root) + print(f'Decision: {decision}') pg.fastevent.post(pg.event.Event(pg.KEYDOWN, {'key': pg.K_SPACE})) handle_keys(env, agent, game_ui, factory) print('Sector clear')