add usage of decision tree
This commit is contained in:
parent
13ccc6c184
commit
fda1579a87
23
src/main.py
23
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')
|
||||
|
Loading…
Reference in New Issue
Block a user