From 89bef876b42b0bff51dc74b69fb719fc7d14d120 Mon Sep 17 00:00:00 2001 From: egotd Date: Thu, 19 May 2022 11:45:35 +0200 Subject: [PATCH] Add console info about decisions --- classes/decisionTrees.py | 23 +++++++++++++++++------ classes/minesweeper.py | 2 +- main.py | 4 ++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/classes/decisionTrees.py b/classes/decisionTrees.py index 1e14735..bb95422 100644 --- a/classes/decisionTrees.py +++ b/classes/decisionTrees.py @@ -3,18 +3,21 @@ from multiprocessing import freeze_support import pandas as pd from numpy import random +# decision tree create + +############### class DecisionTrees: - def return_predict(self): - # Header looks like: - # header = ['Size(bigger_more_difficult)', 'Year(older_more_difficult)', 'Protection_from_defuse', - # 'Meters_under_the_ground', 'Random_detonation_chance', 'Detonation_power_in_m', - # 'Decision'] # read data df = pd.read_csv("D:\\1 Python projects\Saper\data\db.txt") + # Header of df looks like: + header = ['Size(bigger_more_difficult)', 'Year(older_more_difficult)', 'Protection_from_defuse', + 'Meters_under_the_ground', 'Random_detonation_chance', 'Detonation_power_in_m', + 'Decision'] + # print data # print(df.head()) @@ -26,6 +29,7 @@ class DecisionTrees: # print predict # print(chef.predict(model, [1, 2022, 0, 0, 0, 10])) + # random generate characteristics for mine size = random.randint(1, 10) year = random.randint(1941, 2022) protection = 0 @@ -40,5 +44,12 @@ class DecisionTrees: mine_characteristics = [size, year, protection, m_under_the_ground, detonation_chance, detonation_power_in_m] - print(mine_characteristics) + # print data about mine + print("Mine characteristics : ") + cnt = 0 + for i in mine_characteristics: + print(header[cnt], " = ", i) + cnt += 1 + + # return prediction return chef.predict(model, mine_characteristics) diff --git a/classes/minesweeper.py b/classes/minesweeper.py index 724a926..64197b9 100644 --- a/classes/minesweeper.py +++ b/classes/minesweeper.py @@ -397,7 +397,7 @@ class Minesweeper: tree = decisionTrees.DecisionTrees() decision = tree.return_predict() - print(decision) + print("Decision : ", decision) self.current_map.mines.remove(mine) pygame.mixer.Channel(3).set_volume(0.7) diff --git a/main.py b/main.py index 58fb09f..028adbd 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,8 @@ import os os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide" import pygame +from chefboost import Chefboost as chef +import pandas as pd # system - klasy związane z pygame # minesweeper - klasy związane z samym saperem # ai - klasa wykonująca ruchy sapera @@ -25,6 +27,8 @@ pygame.font.init() def main(): + + if MUSIC: pygame.mixer.init() pygame.mixer.Channel(0).play(pygame.mixer.Sound("assets/music.ogg"), -1)