Compare commits
No commits in common. "abee4a4a6ccc0c4affde1e650e927386f9145127" and "6ff8fdbe59e4a5ea8f19004112949200751cc3c7" have entirely different histories.
abee4a4a6c
...
6ff8fdbe59
@ -1,7 +1,8 @@
|
||||
{
|
||||
"ExpandedNodes": [
|
||||
""
|
||||
"",
|
||||
"\\decisionTree"
|
||||
],
|
||||
"SelectedNode": "\\C:\\Users\\zmysz\\Desktop\\nowy-inteligentny-traktor",
|
||||
"SelectedNode": "\\decisionTree\\decisionTree.sav",
|
||||
"PreviewInSolutionExplorer": false
|
||||
}
|
Binary file not shown.
Binary file not shown.
BIN
.vs/slnx.sqlite
BIN
.vs/slnx.sqlite
Binary file not shown.
13
classes.py
13
classes.py
@ -8,7 +8,6 @@ class Field:
|
||||
self.fertilizedTime = fertilizedTime # number
|
||||
|
||||
|
||||
|
||||
class Plant:
|
||||
def __init__(self, plantType, growthState):
|
||||
self.plantType = plantType # wheat/carrot/cabbage
|
||||
@ -24,15 +23,3 @@ class Player:
|
||||
x = 0
|
||||
y = 0
|
||||
rotation = 0
|
||||
|
||||
|
||||
class Watering:
|
||||
def __init__(self, rain, planted, temperature, sunny, snowy, moist, rotten, dayTime ):
|
||||
self.rain = rain # yes/no
|
||||
self.planted = planted # yes/no
|
||||
self.temperature = temperature # good/bad
|
||||
self.sunny = sunny
|
||||
self.snowy = snowy # yes/no
|
||||
self.moist = moist # yes/no
|
||||
self.rotten = rotten # yes/no
|
||||
self.dayTime = dayTime # 1 2 3 4
|
||||
|
@ -1,6 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
# from sklearn.datasets import load_iris
|
||||
from sklearn.tree import export_text
|
||||
|
||||
@ -9,7 +6,7 @@ import joblib
|
||||
|
||||
X1 = []
|
||||
view = []
|
||||
with open("database.txt", 'r') as f:
|
||||
with open("decisionTree/database.txt", 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
test_list = [int(i) for i in line]
|
||||
@ -53,14 +50,14 @@ with open("database.txt", 'r') as f:
|
||||
view.append(x)
|
||||
X1.append(test_list)
|
||||
|
||||
f = open("learning_set.txt", "w") # zapisuje atrybuty s³ownie
|
||||
f = open("decisionTree/learning_set.txt", "w") # zapisuje atrybuty s³ownie
|
||||
for i in view:
|
||||
f.write(str(i)+"\n")
|
||||
f.close()
|
||||
|
||||
|
||||
Y1 = []
|
||||
with open("decissions.txt", 'r') as f: # czyta decyzje
|
||||
with open("decisionTree/decissions.txt", 'r') as f: # czyta decyzje
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
test = int(line)
|
||||
@ -70,7 +67,7 @@ dataset = X1
|
||||
decision = Y1
|
||||
labels = ['Rain', 'Plant', 'Temperature', 'Sun', 'Snow', 'Moisture', 'Rotten', 'Time']
|
||||
model = DecisionTreeClassifier(random_state=0, max_depth=20).fit(dataset, decision)
|
||||
filename = 'decisionTree.sav'
|
||||
filename = 'decisionTree/decisionTree.sav'
|
||||
print("Model trained")
|
||||
print("Decision tree:")
|
||||
print(export_text(model, feature_names=labels))
|
||||
|
31
main.py
31
main.py
@ -1,5 +1,3 @@
|
||||
import joblib
|
||||
import numpy as np
|
||||
import pygame
|
||||
import random
|
||||
|
||||
@ -12,7 +10,7 @@ from torchvision.transforms import Lambda
|
||||
from PIL import Image
|
||||
|
||||
import astar
|
||||
from classes import Field, Player, Watering
|
||||
from classes import Field, Player
|
||||
from bfs import Istate, succ
|
||||
from bfs import graphsearch
|
||||
from board import Grid, Box, Obstacle, getGridBoxes, gridObjects
|
||||
@ -408,26 +406,6 @@ def eventHandler(kbdObj, mouseObj):
|
||||
|
||||
goalNode = [int(posX/50), int(posY/50)]
|
||||
|
||||
# drzewo decyzyjne:
|
||||
W = np.random.randint(2, size=(10, 10, 8))
|
||||
|
||||
# Wczytywanie modelu z pliku
|
||||
labels = ['Rain', 'Planted', 'Temperature', 'Sun', 'Snow', 'Moisture', 'Rotten', 'Time']
|
||||
loaded_model = joblib.load('decisionTree/decisionTree.sav')
|
||||
sample = W[goalNode[0]-1][goalNode[1]-1]
|
||||
|
||||
# Klasyfikacja przy użyciu wczytanego modelu
|
||||
predicted_class = loaded_model.predict([sample])
|
||||
print(labels)
|
||||
print(sample)
|
||||
print('Predicted class:', predicted_class)
|
||||
|
||||
# Decyzja dotycząca podlania grządek na podstawie przewidzianej etykiety
|
||||
if predicted_class == [1]:
|
||||
print('Podlej grządkę')
|
||||
else:
|
||||
print('Nie podlewaj grządki')
|
||||
|
||||
print('goalNode x = ', goalNode[0], 'goalNode y = ', goalNode[1])
|
||||
|
||||
# Delay to avoid multiple spawning of objects
|
||||
@ -716,7 +694,6 @@ T = [[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,2,1,0,0,0),Field(1,3,0,0,0,0
|
||||
[Field(1,0,0,0,0,0),Field(0,2,0,0,0,0),Field(1,1,0,0,0,0),Field(1,0,1,0,0,0),Field(0,2,1,0,0,0),Field(0,3,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)],
|
||||
[Field(1,0,1,0,0,0),Field(0,0,0,0,0,0),Field(1,1,1,0,0,0),Field(1,0,0,0,0,0),Field(0,1,1,0,0,0),Field(0,0,1,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,2,1,0,0,0)]]
|
||||
|
||||
|
||||
# =========================================================================================
|
||||
# no i tutaj mamy główna pętlę programu
|
||||
|
||||
@ -776,10 +753,6 @@ while running:
|
||||
j = j + 1
|
||||
i = i + 1
|
||||
|
||||
font = pygame.font.SysFont('comicsans', 22)
|
||||
labelx = font.render('temp:22 |rain:none |snow:none |sun:cloudy |time:evening', True, (0, 0, 0))
|
||||
SCREEN.blit(labelx, (10, 10))
|
||||
|
||||
i = 0
|
||||
while i < len(T)+1:
|
||||
pygame.draw.line(SCREEN, (0, 0, 0), (50 + i * 50, 50), (50 + i * 50, 50 + len(T) * 50), 1)
|
||||
@ -802,7 +775,7 @@ while running:
|
||||
# player seen at the beginning
|
||||
SCREEN.blit(tmpImg, (55 + 50 * player.x, 55 + 50 * player.y))
|
||||
|
||||
|
||||
font = pygame.font.SysFont('comicsans', 22)
|
||||
label = font.render('F - cel | X - drzewo', True, (0, 0, 0))
|
||||
label1 = font.render('ARROWS - ręczne poruszanie', True, (0, 0, 0))
|
||||
label2 = font.render('A - lewo | D - prawo | W - ruch', True, (0, 0, 0))
|
||||
|
Loading…
Reference in New Issue
Block a user