diff --git a/decisionTree/data.csv b/decisionTree/data.csv new file mode 100644 index 0000000..0563613 --- /dev/null +++ b/decisionTree/data.csv @@ -0,0 +1,22 @@ +1-2-3-4-5;1-green 2-yellow 3-orange 4-black 5-while 6-blue;in dB 0-100;0-24;0/1;in cm;in C;0/1 +Size;Color;Sound;Time;Smell;Height;Temperature;ToRemove +1;2;0;16;1;10;25;1 +2;1;0;12;0;50;24;0 +2;3;30;13;1;38;38;0 +1;4;0;7;1;5;27;1 +1;2;0;16;1;10;25;1 +2;1;0;12;0;50;24;0 +2;3;30;13;1;38;38;0 +1;4;0;7;1;5;27;1 +1;2;0;16;1;10;25;1 +2;1;0;12;0;50;24;0 +2;3;30;13;1;38;38;0 +1;4;0;7;1;5;27;1 +1;2;0;16;1;10;25;1 +2;1;0;12;0;50;24;0 +2;3;30;13;1;38;38;0 +1;4;0;7;1;5;27;1 +1;2;0;16;1;10;25;1 +2;1;0;12;0;50;24;0 +2;3;30;13;1;38;38;0 +1;4;0;7;1;5;27;1 \ No newline at end of file diff --git a/decisionTree/decision_tree_model.pkl b/decisionTree/decision_tree_model.pkl new file mode 100644 index 0000000..58f7d19 Binary files /dev/null and b/decisionTree/decision_tree_model.pkl differ diff --git a/decisionTree/evaluate.py b/decisionTree/evaluate.py new file mode 100644 index 0000000..5c27f94 --- /dev/null +++ b/decisionTree/evaluate.py @@ -0,0 +1,9 @@ +import joblib + +def evaluate(data): + # Load the model + clf = joblib.load('decisionTree/decision_tree_model.pkl') + + # Make a prediction + prediction = clf.predict(data) + return prediction \ No newline at end of file diff --git a/decisionTree/prepare.py b/decisionTree/prepare.py new file mode 100644 index 0000000..93968c9 --- /dev/null +++ b/decisionTree/prepare.py @@ -0,0 +1,21 @@ +import pandas as pd +from sklearn.tree import DecisionTreeClassifier +from sklearn.model_selection import train_test_split +from sklearn import metrics +import joblib + +pima = pd.read_csv("data.csv", header=1, delimiter=';') + +feature_cols = ['Size', 'Color', 'Sound', 'Time','Smell', 'Height','Temperature'] +X = pima[feature_cols] +y = pima.ToRemove + +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1) +clf = DecisionTreeClassifier() +clf = clf.fit(X_train,y_train) + +joblib.dump(clf, 'decision_tree_model.pkl') + +y_pred = clf.predict(X_test) + +print("Accuracy:",metrics.accuracy_score(y_test, y_pred)) \ No newline at end of file diff --git a/domain/entities/cat.py b/domain/entities/cat.py index a0acd5b..14e44b3 100644 --- a/domain/entities/cat.py +++ b/domain/entities/cat.py @@ -13,3 +13,5 @@ class Cat(Entity): self.busy = False self.sleeping = False self.direction = 0 + + self.props = [1,2,0,16,1,10,25] \ No newline at end of file diff --git a/domain/entities/earring.py b/domain/entities/earring.py new file mode 100644 index 0000000..f9498ec --- /dev/null +++ b/domain/entities/earring.py @@ -0,0 +1,8 @@ +from domain.entities.entity import Entity +from domain.world import World + + +class Earring(Entity): + def __init__(self, x: int, y: int): + super().__init__(x, y, "EARRING") + self.props = [2,1,0,12,0,50,24] \ No newline at end of file diff --git a/domain/entities/garbage.py b/domain/entities/garbage.py index c93501d..cda5b91 100644 --- a/domain/entities/garbage.py +++ b/domain/entities/garbage.py @@ -1,11 +1,11 @@ from domain.entities.entity import Entity -from domain.world import World class Garbage(Entity): def __init__(self, x: int, y: int): - super().__init__(x, y, "GARBAGE") + super().__init__(x, y, "PEEL") self.wet = False self.size = 0 + self.props = [1,2,0,16,1,10,25] # TODO GARBAGE: add more properties diff --git a/domain/world.py b/domain/world.py index def2082..dac7580 100644 --- a/domain/world.py +++ b/domain/world.py @@ -1,3 +1,4 @@ +from decisionTree.evaluate import evaluate from domain.entities.entity import Entity @@ -15,6 +16,8 @@ class World: def add_entity(self, entity: Entity): if entity.type == "PEEL": self.dust[entity.x][entity.y].append(entity) + elif entity.type == "EARRING": + self.dust[entity.x][entity.y].append(entity) elif entity.type == "VACUUM": self.vacuum = entity elif entity.type == "DOC_STATION": @@ -29,7 +32,10 @@ class World: return bool(self.obstacles[x][y]) def is_garbage_at(self, x: int, y: int) -> bool: - return bool(self.dust[x][y]) + if len(self.dust[x][y]) == 0: + return False + tmp = evaluate([self.dust[x][y][0].props]) + return bool(tmp[0]) def is_docking_station_at(self, x: int, y: int) -> bool: return bool(self.doc_station.x == x and self.doc_station.y == y) diff --git a/main.py b/main.py index 0bdd36a..c2999f6 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,8 @@ from domain.commands.vacuum_move_command import VacuumMoveCommand from domain.entities.cat import Cat from domain.entities.entity import Entity from domain.entities.vacuum import Vacuum +from domain.entities.garbage import Garbage +from domain.entities.earring import Earring from domain.entities.docking_station import Doc_Station from domain.world import World from view.renderer import Renderer @@ -135,7 +137,7 @@ def generate_world(tiles_x: int, tiles_y: int) -> World: for _ in range(10): temp_x = randint(0, tiles_x - 1) temp_y = randint(0, tiles_y - 1) - world.add_entity(Entity(temp_x, temp_y, "PEEL")) + world.add_entity(Garbage(temp_x, temp_y)) world.vacuum = Vacuum(1, 1) world.doc_station = Doc_Station(9, 8) if config.getboolean("APP", "cat"): @@ -146,6 +148,7 @@ def generate_world(tiles_x: int, tiles_y: int) -> World: world.add_entity(Entity(3, 4, "PLANT2")) world.add_entity(Entity(8, 8, "PLANT2")) world.add_entity(Entity(9, 3, "PLANT3")) + world.add_entity(Earring(5, 5)) return world diff --git a/media/sprites/earrings.webp b/media/sprites/earrings.webp new file mode 100644 index 0000000..9c84a7e Binary files /dev/null and b/media/sprites/earrings.webp differ diff --git a/requirements.txt b/requirements.txt index edcb635..98bd1d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,6 @@ pygame configparser -formaFormatting: Provider - black \ No newline at end of file +pandas +scikit-learn +joblib +# formaFormatting: Provider - black \ No newline at end of file diff --git a/view/renderer.py b/view/renderer.py index e8294cb..e21d270 100644 --- a/view/renderer.py +++ b/view/renderer.py @@ -94,6 +94,13 @@ class Renderer: self.tile_height + self.tile_height / 4, ), ), + "EARRING": pygame.transform.scale( + pygame.image.load("media/sprites/earrings.webp"), + ( + self.tile_width + self.tile_width / 4, + self.tile_height + self.tile_height / 4, + ), + ), } self.cat_direction_sprite = {