From 63b1d36c3683bbe18b0b0ad2f7777f816d11e391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 25 May 2020 02:21:18 +0200 Subject: [PATCH] Add function testing decision tree and game mode to use it --- DecisionTree.md | 1 + src/game/Game.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 DecisionTree.md diff --git a/DecisionTree.md b/DecisionTree.md new file mode 100644 index 0000000..c51d414 --- /dev/null +++ b/DecisionTree.md @@ -0,0 +1 @@ +# DSZI_Survival - Drzewa Decyzyjne \ No newline at end of file diff --git a/src/game/Game.py b/src/game/Game.py index 5c5bd41..712e8e4 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -8,6 +8,7 @@ import pygame from src.AI.Affinities import Affinities from src.AI.DecisionTrees.DecisionTree import DecisionTree from src.AI.DecisionTrees.ExamplesManager import ExamplesManager +from src.AI.DecisionTrees.TestDecisionTree import testDecisionTree from src.AI.DecisionTrees.projectSpecificClasses.SurvivalClassification import SurvivalClassification from src.AI.GA import geneticAlgorithm from src.entities.Player import Player @@ -67,6 +68,9 @@ class Game: if argv[2] == "-p": print("Running Decision Tree in pause mode.") self.dtRun(filesPath, True) + elif argv[2] == "-test": + print("Testing Decision Tree.") + self.dtTestRun(filesPath, int(argv[3])) else: print("Running Decision Tree.") self.dtRun(filesPath) @@ -360,3 +364,14 @@ class Game: geneticAlgorithmWithDecisionTree(self.map, iter, 10, dtExamples, 0.1) print("Time elapsed: ", self.pgTimer.tick() // 1000) + def dtTestRun(self, filesPath, iterations): + # Read examples for decision tree testing + examplesFilePath = str( + filesPath) + os.sep + "data" + os.sep + "AI_data" + os.sep + "dt_exmpls" + os.sep + "dt_examples" + examplesManager = ExamplesManager(examplesFilePath) + examples = examplesManager.readExamples() + scores = testDecisionTree(examples, iterations) + + avg = sum(scores) / iterations + print("Average: {}".format(str(avg))) +