vege, precition,every dirt
61
board.py
@ -5,6 +5,8 @@ import random
|
||||
class Board:
|
||||
def __init__(self):
|
||||
self.board = []
|
||||
self.vegetables = []
|
||||
self.soil_features = None
|
||||
self.load_images()
|
||||
self.generate_board()
|
||||
|
||||
@ -15,8 +17,52 @@ class Board:
|
||||
self.weeds = pygame.image.load("board/weeds.png")
|
||||
self.soil = pygame.image.load("board/zyzna.png")
|
||||
|
||||
self.warzywa_images = {
|
||||
"pomidor": pygame.image.load("warzywa/pomidor.png"),
|
||||
"salata": pygame.image.load("warzywa/salata.png"),
|
||||
"cebula": pygame.image.load("warzywa/cebula.png"),
|
||||
"marchewka": pygame.image.load("warzywa/marchewka.png"),
|
||||
"ziemniak": pygame.image.load("warzywa/ziemniak.png"),
|
||||
"papryka": pygame.image.load("warzywa/papryka.png"),
|
||||
"burak": pygame.image.load("warzywa/burak.png"),
|
||||
"brukselka": pygame.image.load("warzywa/brukselka.png"),
|
||||
"szpinak": pygame.image.load("warzywa/szpinak.png"),
|
||||
"rzepak": pygame.image.load("warzywa/rzepak.png")
|
||||
}
|
||||
self.vegetable_types = {
|
||||
"marchewka": 1,
|
||||
"ziemniak": 2,
|
||||
"pomidor": 3,
|
||||
"salata": 4,
|
||||
"cebula": 5,
|
||||
"papryka": 6,
|
||||
"burak": 7,
|
||||
"brukselka": 8,
|
||||
"szpinak": 9,
|
||||
"rzepak": 10
|
||||
}
|
||||
|
||||
def generate_board(self):
|
||||
self.board = [[random.choice([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) for _ in range(cols)] for _ in range(rows)]
|
||||
self.vegetables = [
|
||||
[random.choice(list(self.warzywa_images.keys())) if self.board[row][col] in (6, 7, 8, 9) else None for col in range(cols)]
|
||||
for row in range(rows)
|
||||
]
|
||||
self.soil_features = self.generate_soil_features()
|
||||
|
||||
|
||||
print(f"Shared soil features: {self.soil_features}")
|
||||
|
||||
def generate_soil_features(self):
|
||||
return {
|
||||
"wilgotnosc_gleby": random.randint(30, 70),
|
||||
"temperatura_gleby": random.randint(13, 26),
|
||||
"opady_deszczu": random.randint(0, 11),
|
||||
"wiek_rosliny": random.randint(1, 9),
|
||||
"proc_ekspo_na_swiatlo": random.randint(10, 90),
|
||||
"pora_dnia": random.randint(8, 20),
|
||||
"pora_roku": random.randint(1, 4)
|
||||
}
|
||||
|
||||
def draw_cubes(self, win):
|
||||
for row in range(rows):
|
||||
@ -37,8 +83,20 @@ class Board:
|
||||
win.blit(self.grass, cube_rect)
|
||||
elif cube == 10:
|
||||
win.blit(self.soil, cube_rect)
|
||||
if self.vegetables[row][col]:
|
||||
vegetable_image = pygame.transform.scale(self.warzywa_images[self.vegetables[row][col]], (size, size))
|
||||
win.blit(vegetable_image, cube_rect)
|
||||
elif cube == 11:
|
||||
win.blit(self.dirt, cube_rect)
|
||||
if self.vegetables[row][col]:
|
||||
vegetable_image = pygame.transform.scale(self.warzywa_images[self.vegetables[row][col]],
|
||||
(size, size))
|
||||
win.blit(vegetable_image, cube_rect)
|
||||
else:
|
||||
win.blit(self.dirt, cube_rect)
|
||||
if self.vegetables[row][col]:
|
||||
vegetable_image = pygame.transform.scale(self.warzywa_images[self.vegetables[row][col]], (size, size))
|
||||
win.blit(vegetable_image, cube_rect)
|
||||
|
||||
def is_rock(self, row, col):
|
||||
return self.board[row][col] == 0
|
||||
@ -54,3 +112,6 @@ class Board:
|
||||
|
||||
def set_soil(self, row, col):
|
||||
self.board[row][col] = 10
|
||||
self.vegetables[row][col] = self.vegetables[row][col]
|
||||
def set_fakedirt(self,row,col):
|
||||
self.board[row][col] = 11
|
||||
|
206
dane.csv
Normal file
@ -0,0 +1,206 @@
|
||||
wilgotnosc_gleby,temperatura_gleby,opady_deszczu,wiek_rosliny,proc_ekspo_na_swiatlo,pora_dnia,pora_roku,roslina,podlac
|
||||
40, 20, 5, 3, 70, 10, 2, 1, nie
|
||||
60, 25, 0, 2, 50, 15, 3, 2, tak
|
||||
30, 18, 10, 1, 80, 12, 4, 3, nie
|
||||
50, 22, 3, 4, 60, 18, 1, 4, tak
|
||||
45, 23, 2, 5, 75, 8, 2, 5, tak
|
||||
55, 26, 8, 3, 70, 14, 3, 6, nie
|
||||
35, 21, 1, 2, 55, 16, 4, 7, tak
|
||||
65, 24, 6, 4, 80, 11, 1, 8, nie
|
||||
42, 20, 4, 3, 65, 13, 2, 9, tak
|
||||
48, 22, 7, 5, 75, 9, 3, 10, tak
|
||||
30, 25, 0, 1, 70, 14, 2, 1, tak
|
||||
60, 18, 10, 2, 60, 8, 3, 2, nie
|
||||
35, 20, 2, 3, 50, 12, 4, 3, tak
|
||||
50, 23, 1, 4, 65, 17, 1, 4, tak
|
||||
45, 24, 5, 5, 80, 10, 2, 5, tak
|
||||
55, 22, 3, 3, 75, 13, 3, 6, nie
|
||||
40, 26, 8, 6, 70, 16, 1, 7, nie
|
||||
62, 21, 1, 4, 85, 9, 2, 8, tak
|
||||
47, 25, 6, 5, 60, 11, 3, 9, nie
|
||||
58, 20, 4, 3, 75, 14, 4, 10, tak
|
||||
38, 24, 7, 3, 65, 11, 1, 1, tak
|
||||
59, 20, 3, 2, 55, 16, 2, 2, nie
|
||||
33, 22, 5, 1, 70, 9, 3, 3, nie
|
||||
52, 25, 2, 4, 80, 14, 4, 4, tak
|
||||
46, 21, 1, 5, 75, 10, 1, 5, tak
|
||||
56, 26, 8, 3, 70, 15, 2, 6, nie
|
||||
34, 23, 0, 2, 60, 8, 3, 7, nie
|
||||
63, 18, 4, 4, 85, 12, 4, 8, nie
|
||||
41, 20, 1, 3, 65, 13, 1, 9, tak
|
||||
49, 22, 9, 5, 75, 17, 2, 10, tak
|
||||
29, 25, 0, 2, 70, 14, 3, 1, tak
|
||||
61, 18, 11, 3, 60, 8, 1, 2, nie
|
||||
37, 20, 2, 4, 50, 12, 2, 3, tak
|
||||
51, 23, 0, 5, 65, 16, 4, 4, tak
|
||||
44, 24, 4, 6, 80, 10, 3, 5, tak
|
||||
54, 22, 3, 3, 75, 13, 1, 6, nie
|
||||
39, 26, 7, 1, 70, 15, 2, 7, nie
|
||||
64, 21, 0, 4, 85, 9, 3, 8, tak
|
||||
48, 25, 5, 5, 60, 11, 4, 9, nie
|
||||
57, 20, 2, 3, 75, 14, 1, 10, tak
|
||||
32, 24, 8, 3, 65, 10, 2, 1, tak
|
||||
62, 19, 2, 2, 55, 15, 3, 2, nie
|
||||
36, 21, 1, 1, 70, 12, 4, 3, nie
|
||||
53, 22, 4, 4, 80, 16, 1, 4, tak
|
||||
42, 23, 2, 5, 75, 8, 2, 5, tak
|
||||
58, 26, 6, 3, 70, 14, 3, 6, nie
|
||||
35, 21, 0, 2, 60, 17, 4, 7, nie
|
||||
65, 18, 3, 4, 85, 11, 1, 8, nie
|
||||
45, 20, 1, 3, 65, 13, 2, 9, tak
|
||||
50, 22, 7, 5, 75, 9, 3, 10, tak
|
||||
31, 25, 0, 2, 70, 14, 1, 1, tak
|
||||
60, 18, 9, 3, 60, 8, 2, 2, nie
|
||||
34, 20, 3, 4, 50, 12, 3, 3, tak
|
||||
52, 23, 1, 5, 65, 16, 4, 4, tak
|
||||
47, 24, 6, 6, 80, 10, 1, 5, tak
|
||||
55, 22, 2, 3, 75, 13, 2, 6, nie
|
||||
38, 26, 8, 1, 70, 15, 3, 7, nie
|
||||
64, 21, 0, 4, 85, 9, 4, 8, tak
|
||||
41, 20, 2, 3, 65, 13, 1, 9, tak
|
||||
49, 22, 8, 5, 75, 17, 2, 10, tak
|
||||
30, 24, 1, 2, 70, 14, 3, 1, tak
|
||||
61, 18, 10, 3, 60, 8, 1, 2, nie
|
||||
37, 20, 4, 4, 50, 12, 2, 3, tak
|
||||
51, 23, 2, 5, 65, 16, 4, 4, tak
|
||||
44, 24, 5, 6, 80, 10, 3, 5, tak
|
||||
53, 22, 3, 3, 75, 13, 1, 6, nie
|
||||
39, 26, 7, 1, 70, 15, 2, 7, nie
|
||||
65, 21, 0, 4, 85, 9, 3, 8, tak
|
||||
48, 25, 6, 5, 60, 11, 4, 9, nie
|
||||
57, 20, 3, 3, 75, 14, 1, 10, tak
|
||||
32, 24, 9, 2, 65, 10, 2, 1, tak
|
||||
62, 19, 1, 2, 55, 15, 3, 2, nie
|
||||
36, 21, 2, 1, 70, 12, 4, 3, nie
|
||||
55, 23, 3, 4, 80, 16, 1, 4, tak
|
||||
42, 23, 1, 5, 75, 8, 2, 5, tak
|
||||
58, 26, 5, 3, 70, 14, 3, 6, nie
|
||||
35, 21, 0, 2, 60, 17, 4, 7, nie
|
||||
46, 20, 2, 3, 65, 13, 2, 9, tak
|
||||
50, 22, 6, 5, 75, 9, 3, 10, tak
|
||||
31, 25, 1, 2, 70, 14, 1, 1, tak
|
||||
60, 18, 8, 3, 60, 8, 2, 2, nie
|
||||
33, 20, 4, 4, 50, 12, 3, 3, tak
|
||||
52, 23, 1, 5, 65, 16, 4, 4, tak
|
||||
47, 24, 7, 6, 80, 10, 1, 5, tak
|
||||
38, 25, 2, 3, 65, 10, 1, 1, tak
|
||||
59, 21, 1, 2, 55, 15, 2, 2, nie
|
||||
33, 23, 3, 1, 70, 9, 3, 3, nie
|
||||
47, 22, 7, 4, 75, 11, 2, 1, tak
|
||||
58, 20, 4, 3, 60, 16, 1, 2, nie
|
||||
32, 24, 6, 2, 70, 8, 3, 3, nie
|
||||
53, 23, 3, 5, 80, 15, 4, 4, tak
|
||||
45, 21, 8, 6, 75, 12, 1, 5, tak
|
||||
55, 26, 11, 4, 70, 17, 2, 6, nie
|
||||
36, 24, 5, 3, 60, 9, 3, 7, nie
|
||||
67, 19, 10, 4, 85, 13, 4, 8, nie
|
||||
43, 22, 1, 3, 65, 14, 1, 9, tak
|
||||
51, 24, 9, 5, 75, 10, 2, 10, tak
|
||||
31, 27, 2, 2, 70, 15, 3, 1, tak
|
||||
62, 18, 12, 3, 60, 8, 1, 2, nie
|
||||
38, 21, 6, 4, 50, 11, 2, 3, tak
|
||||
49, 24, 4, 5, 65, 16, 4, 4, tak
|
||||
42, 25, 7, 3, 80, 9, 3, 5, tak
|
||||
57, 23, 4, 3, 75, 12, 1, 6, nie
|
||||
35, 28, 9, 1, 70, 16, 2, 7, nie
|
||||
76, 20, 11, 4, 85, 10, 3, 8, nie
|
||||
46, 22, 0, 3, 65, 13, 1, 9, tak
|
||||
10, 25, 10, 5, 95, 9, 2, 10, tak
|
||||
38, 19, 3, 6, 80, 11, 2, 1, tak
|
||||
57, 24, 2, 7, 90, 15, 1, 2, tak
|
||||
81, 18, 9, 8, 70, 12, 4, 3, nie
|
||||
49, 22, 2, 9, 85, 18, 3, 4, tak
|
||||
44, 23, 1, 3, 60, 8, 2, 5, nie
|
||||
24, 26, 5, 2, 75, 14, 3, 6, tak
|
||||
76, 13, 0, 4, 25, 19, 4, 7, nie
|
||||
67, 15, 5, 2, 80, 11, 1, 8, nie
|
||||
43, 20, 1, 1, 65, 13, 2, 9, tak
|
||||
50, 22, 8, 1, 20, 19, 3, 10, nie
|
||||
62, 25, 0, 2, 75, 14, 2, 1, tak
|
||||
58, 18, 11, 3, 30, 8, 3, 2, nie
|
||||
37, 20, 2, 2, 50, 12, 4, 3, tak
|
||||
21, 23, 0, 1, 65, 20, 1, 4, tak
|
||||
46, 24, 2, 2, 75, 12, 2, 5, tak
|
||||
76, 22, 6, 2, 70, 13, 3, 6, nie
|
||||
39, 26, 9, 2, 15, 16, 1, 7, nie
|
||||
53, 21, 2, 3, 80, 12, 2, 8, tak
|
||||
48, 25, 7, 4, 10, 11, 3, 9, nie
|
||||
88, 19, 3, 6, 30, 11, 2, 1, nie
|
||||
57, 24, 4, 7, 10, 15, 1, 2, nie
|
||||
11, 18, 9, 8, 90, 12, 4, 3, tak
|
||||
49, 22, 2, 9, 85, 18, 3, 4, tak
|
||||
44, 23, 1, 1, 60, 8, 2, 5, tak
|
||||
54, 26, 7, 2, 75, 14, 3, 6, nie
|
||||
36, 21, 0, 2, 55, 16, 4, 7, tak
|
||||
27, 24, 2, 3, 80, 11, 1, 8, tak
|
||||
13, 20, 6, 4, 95, 10, 2, 9, tak
|
||||
50, 22, 8, 5, 20, 17, 3, 10, nie
|
||||
32, 25, 1, 6, 95, 14, 2, 1, tak
|
||||
58, 18, 11, 3, 80, 8, 3, 2, nie
|
||||
37, 20, 2, 1, 50, 12, 4, 3, tak
|
||||
51, 23, 5, 2, 25, 22, 1, 4, nie
|
||||
46, 24, 0, 2, 75, 10, 2, 5, tak
|
||||
56, 22, 1, 3, 70, 13, 3, 6, tak
|
||||
39, 26, 9, 4, 35, 20, 1, 7, nie
|
||||
63, 21, 2, 3, 90, 9, 2, 8, tak
|
||||
48, 25, 7, 1, 70, 11, 3, 9, nie
|
||||
42, 24, 1, 5, 75, 14, 2, 1, tak
|
||||
55, 20, 1, 8, 65, 13, 1, 2, tak
|
||||
58, 22, 6, 4, 10, 12, 3, 3, nie
|
||||
47, 21, 2, 2, 70, 9, 4, 4, tak
|
||||
50, 25, 1, 1, 85, 15, 1, 5, nie
|
||||
60, 23, 7, 7, 70, 11, 2, 6, nie
|
||||
83, 19, 4, 3, 60, 13, 3, 7, nie
|
||||
68, 26, 8, 5, 90, 16, 4, 8, nie
|
||||
41, 18, 9, 1, 75, 14, 2, 9, nie
|
||||
48, 20, 0, 8, 70, 8, 1, 10, tak
|
||||
89, 23, 2, 6, 55, 12, 3, 1, nie
|
||||
59, 21, 2, 7, 80, 10, 4, 2, tak
|
||||
97, 24, 3, 5, 65, 9, 1, 3, nie
|
||||
49, 22, 2, 9, 75, 15, 2, 4, tak
|
||||
92, 26, 1, 1, 85, 11, 3, 5, nie
|
||||
21, 18, 4, 8, 70, 13, 4, 6, tak
|
||||
34, 25, 9, 4, 60, 16, 1, 7, nie
|
||||
70, 19, 8, 5, 90, 14, 2, 8, nie
|
||||
45, 20, 2, 2, 80, 12, 3, 9, tak
|
||||
53, 24, 7, 7, 75, 10, 1, 10, nie
|
||||
43, 21, 3, 6, 70, 11, 2, 1, tak
|
||||
56, 22, 8, 8, 80, 13, 3, 2, nie
|
||||
39, 19, 5, 7, 65, 9, 4, 3, nie
|
||||
48, 23, 1, 9, 75, 14, 1, 4, tak
|
||||
51, 25, 6, 1, 85, 12, 2, 5, nie
|
||||
62, 24, 4, 2, 90, 15, 3, 6, nie
|
||||
35, 20, 2, 2, 60, 10, 4, 7, tak
|
||||
69, 26, 7, 3, 85, 16, 1, 8, nie
|
||||
40, 18, 9, 1, 70, 12, 2, 9, nie
|
||||
49, 22, 0, 5, 75, 11, 3, 10, tak
|
||||
54, 21, 3, 7, 80, 14, 4, 1, tak
|
||||
63, 23, 8, 8, 90, 12, 1, 2, nie
|
||||
36, 20, 2, 9, 65, 10, 2, 3, tak
|
||||
47, 24, 1, 1, 75, 13, 3, 4, tak
|
||||
50, 26, 5, 2, 85, 15, 4, 5, nie
|
||||
34, 25, 2, 2, 90, 9, 1, 6, tak
|
||||
47, 19, 6, 3, 60, 11, 2, 7, nie
|
||||
70, 25, 9, 2, 85, 17, 3, 8, nie
|
||||
41, 21, 7, 1, 70, 13, 4, 9, nie
|
||||
52, 20, 1, 1, 75, 10, 1, 10, tak
|
||||
38, 22, 3, 6, 70, 12, 2, 1, tak
|
||||
87, 23, 9, 7, 80, 14, 3, 2, nie
|
||||
61, 20, 5, 2, 65, 10, 4, 3, nie
|
||||
49, 21, 0, 9, 75, 11, 1, 4, tak
|
||||
44, 25, 6, 1, 80, 15, 2, 5, nie
|
||||
54, 19, 2, 1, 90, 13, 3, 6, tak
|
||||
36, 24, 8, 1, 60, 9, 4, 7, nie
|
||||
67, 20, 3, 2, 85, 16, 1, 8, nie
|
||||
43, 22, 7, 4, 75, 12, 2, 9, nie
|
||||
50, 23, 1, 5, 80, 10, 3, 10, tak
|
||||
55, 21, 4, 7, 70, 13, 4, 1, nie
|
||||
63, 25, 9, 8, 90, 14, 1, 2, nie
|
||||
57, 19, 5, 9, 65, 11, 2, 3, nie
|
||||
49, 24, 0, 1, 75, 16, 3, 4, tak
|
||||
51, 20, 6, 1, 85, 12, 4, 5, nie
|
||||
64, 22, 4, 2, 90, 9, 1, 6, nie
|
||||
39, 23, 8, 3, 60, 14, 2, 7, tak
|
||||
70, 21, 2, 1, 85, 13, 3, 8, nie
|
||||
41, 25, 7, 5, 70, 15, 4, 9, nie
|
||||
52, 19, 1, 2, 75, 10, 1, 10, tak
|
|
30
decisiontree.py
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def train_decision_tree(data):
|
||||
X = data.drop(columns=["podlac"])
|
||||
y = data["podlac"]
|
||||
model = DecisionTreeClassifier()
|
||||
model.fit(X, y)
|
||||
return model, X.columns
|
||||
|
||||
|
||||
def predict(model, feature_columns, sample):
|
||||
sample_df = pd.DataFrame([sample])
|
||||
sample_df = pd.get_dummies(sample_df)
|
||||
sample_df = sample_df.reindex(columns=feature_columns, fill_value=0)
|
||||
return model.predict(sample_df)
|
||||
|
||||
|
||||
#Marchew = 1
|
||||
#zmiemniaki = 2
|
||||
#pomidor = 3
|
||||
#salata = 4
|
||||
#cebula = 5
|
||||
#Papryka = 6
|
||||
#Buraki = 7
|
||||
#Bruksela = 8
|
||||
#Rzepak = 9
|
||||
#Szpinak = 10
|
96
main.py
@ -4,85 +4,111 @@ from constant import width, height, rows, cols
|
||||
from tractor import Tractor
|
||||
from kolejka import Stan, Odwiedzone
|
||||
from queue import Queue
|
||||
import pandas as pd
|
||||
|
||||
|
||||
data = pd.read_csv('dane.csv')
|
||||
|
||||
|
||||
from decisiontree import train_decision_tree
|
||||
|
||||
|
||||
model, feature_columns = train_decision_tree(data)
|
||||
|
||||
fps = 5
|
||||
WIN = pygame.display.set_mode((width, height))
|
||||
pygame.display.set_caption('Inteligentny Traktor')
|
||||
|
||||
pygame.display.set_caption('Inteligenty Traktor')
|
||||
def goal_test(elem, board):
|
||||
return board.is_dirt(elem.row, elem.col)
|
||||
|
||||
def goal_test(elem, goaltest, board):
|
||||
if board.is_rock(goaltest.row, goaltest.col):
|
||||
return True
|
||||
if((elem.row == goaltest.row) and (elem.col == goaltest.col)):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
def actions(elem, istate):
|
||||
akcje = []
|
||||
while (elem.row != istate.row) or (elem.col != istate.col) or (elem.direction != istate.direction):
|
||||
while elem.row != istate.row or elem.col != istate.col or elem.direction != istate.direction:
|
||||
akcje.append(elem.a)
|
||||
elem = elem.p[0]
|
||||
return akcje[::-1] # Odwracamy kolejność, aby akcje były w poprawnej sekwencji
|
||||
return akcje[::-1]
|
||||
|
||||
|
||||
|
||||
def graphsearch(istate, goaltest, board):
|
||||
def graphsearch(istate, board):
|
||||
explored = Odwiedzone()
|
||||
fringe = Queue()
|
||||
fringe.put(istate)
|
||||
moves = ["up", "left", "right"]
|
||||
while not fringe.empty():
|
||||
elem = fringe.get()
|
||||
if goal_test(elem, goaltest, board):
|
||||
return actions(elem, istate)
|
||||
if goal_test(elem, board):
|
||||
return actions(elem, istate), elem
|
||||
explored.dodaj_stan(elem)
|
||||
for action in moves:
|
||||
stan = elem.succ(action, board)
|
||||
if stan is not None:
|
||||
if((not fringe_check(fringe,stan)) and (not explored.check(stan))):
|
||||
if not fringe_check(fringe, stan) and not explored.check(stan):
|
||||
stan.parrent(elem, action)
|
||||
fringe.put(stan)
|
||||
return "Brak sciezki"
|
||||
return [], None
|
||||
|
||||
def fringe_check(fringe, stan): # Funkcja pomocnicza do sprawdzania stanu w kolejce
|
||||
def fringe_check(fringe, stan):
|
||||
with fringe.mutex:
|
||||
for item in fringe.queue:
|
||||
if stan.direction == item.direction and stan.col == item.col and stan.row == item.row:
|
||||
return True
|
||||
return False
|
||||
|
||||
def main():
|
||||
initial_state = Stan(4,4, "down")
|
||||
goaltest = Stan(1,1, "up")
|
||||
initial_state = Stan(4, 4, "down")
|
||||
run = True
|
||||
clock = pygame.time.Clock()
|
||||
board = Board()
|
||||
board.load_images()
|
||||
akcje = graphsearch(initial_state, goaltest, board)
|
||||
print("akcje: >",akcje )
|
||||
tractor = Tractor(4, 4)
|
||||
tractor = Tractor(4, 4, model, feature_columns)
|
||||
|
||||
while run:
|
||||
clock.tick(fps)
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
if all(not board.is_dirt(row, col) for row in range(rows) for col in range(cols)):
|
||||
print("Traktor odwiedził wszystkie pola.")
|
||||
break
|
||||
|
||||
if akcje:
|
||||
action = akcje.pop(0) # Pobierz kolejną akcję z listy
|
||||
if action == "left":
|
||||
akcje, nowy_stan = graphsearch(initial_state, board)
|
||||
|
||||
if not akcje:
|
||||
print("Nie znaleziono ścieżki do najbliższego pola dirt.")
|
||||
board.generate_board()
|
||||
initial_state = Stan(4, 4, "down")
|
||||
tractor = Tractor(4, 4, model, feature_columns)
|
||||
while board.is_rock(initial_state.row, initial_state.col):
|
||||
board.generate_board()
|
||||
continue
|
||||
|
||||
print("akcje: >", akcje)
|
||||
|
||||
while akcje:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
akcja = akcje.pop(0)
|
||||
if akcja == "left":
|
||||
tractor.turn_left()
|
||||
elif action == "right":
|
||||
elif akcja == "right":
|
||||
tractor.turn_right()
|
||||
elif action == "up":
|
||||
elif akcja == "up":
|
||||
tractor.move_forward(board)
|
||||
|
||||
board.draw_cubes(WIN)
|
||||
tractor.draw(WIN)
|
||||
pygame.display.update()
|
||||
pygame.time.delay(500)
|
||||
|
||||
initial_state = nowy_stan
|
||||
initial_state.direction = tractor.direction
|
||||
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
return
|
||||
|
||||
board.draw_cubes(WIN)
|
||||
tractor.draw(WIN)
|
||||
pygame.display.update()
|
||||
pygame.quit()
|
||||
|
||||
main()
|
||||
|
||||
|
57
tractor.py
@ -1,8 +1,10 @@
|
||||
import pygame
|
||||
from constant import size, rows, cols
|
||||
from decisiontree import predict
|
||||
|
||||
|
||||
class Tractor:
|
||||
def __init__(self, row, col):
|
||||
def __init__(self, row, col, model, feature_columns):
|
||||
self.row = row
|
||||
self.col = col
|
||||
self.images = {
|
||||
@ -12,6 +14,8 @@ class Tractor:
|
||||
"right": pygame.image.load("tractor/right.png")
|
||||
}
|
||||
self.direction = "down"
|
||||
self.model = model
|
||||
self.feature_columns = feature_columns
|
||||
|
||||
def draw(self, win):
|
||||
tractor_image = self.images[self.direction]
|
||||
@ -39,30 +43,33 @@ class Tractor:
|
||||
|
||||
def move_forward(self, board):
|
||||
if self.direction == "up" and self.row > 0:
|
||||
if not board.is_rock(self.row - 1, self.col):
|
||||
if board.is_weed(self.row - 1, self.col):
|
||||
board.set_grass(self.row - 1, self.col)
|
||||
elif board.is_dirt(self.row - 1, self.col):
|
||||
board.set_soil(self.row - 1, self.col)
|
||||
self.row -= 1
|
||||
next_row, next_col = self.row - 1, self.col
|
||||
elif self.direction == "left" and self.col > 0:
|
||||
if not board.is_rock(self.row, self.col - 1):
|
||||
if board.is_weed(self.row, self.col - 1):
|
||||
board.set_grass(self.row, self.col - 1)
|
||||
elif board.is_dirt(self.row, self.col - 1):
|
||||
board.set_soil(self.row, self.col - 1)
|
||||
self.col -= 1
|
||||
next_row, next_col = self.row, self.col - 1
|
||||
elif self.direction == "down" and self.row < rows - 1:
|
||||
if not board.is_rock(self.row + 1, self.col):
|
||||
if board.is_weed(self.row + 1, self.col):
|
||||
board.set_grass(self.row + 1, self.col)
|
||||
elif board.is_dirt(self.row + 1, self.col):
|
||||
board.set_soil(self.row + 1, self.col)
|
||||
self.row += 1
|
||||
next_row, next_col = self.row + 1, self.col
|
||||
elif self.direction == "right" and self.col < cols - 1:
|
||||
if not board.is_rock(self.row, self.col + 1):
|
||||
if board.is_weed(self.row, self.col + 1):
|
||||
board.set_grass(self.row, self.col + 1)
|
||||
elif board.is_dirt(self.row, self.col + 1):
|
||||
board.set_soil(self.row, self.col + 1)
|
||||
self.col += 1
|
||||
next_row, next_col = self.row, self.col + 1
|
||||
else:
|
||||
return # Nie możemy się ruszyć poza planszę
|
||||
|
||||
if board.is_dirt(next_row, next_col) and board.board[next_row][next_col] != 10:
|
||||
soil_features = board.soil_features
|
||||
sample = {
|
||||
"wilgotnosc_gleby": soil_features["wilgotnosc_gleby"],
|
||||
"temperatura_gleby": soil_features["temperatura_gleby"],
|
||||
"opady_deszczu": soil_features["opady_deszczu"],
|
||||
"wiek_rosliny": soil_features["wiek_rosliny"],
|
||||
"proc_ekspo_na_swiatlo": soil_features["proc_ekspo_na_swiatlo"],
|
||||
"pora_dnia": soil_features["pora_dnia"],
|
||||
"pora_roku": soil_features["pora_roku"],
|
||||
"roslina": board.vegetable_types[board.vegetables[next_row][next_col]]
|
||||
}
|
||||
|
||||
should_water = predict(self.model, self.feature_columns, sample)
|
||||
print(f"Predykcja dla pola ({next_row}, {next_col}) z cechami {sample}: {should_water}")
|
||||
if should_water[0].strip() == 'tak':
|
||||
board.set_soil(next_row, next_col)
|
||||
else:
|
||||
board.set_fakedirt(next_row, next_col)
|
||||
self.row, self.col = next_row, next_col # Przemieszczamy traktor niezależnie od predykcji
|
||||
|
BIN
warzywa/brukselka.png
Normal file
After Width: | Height: | Size: 294 KiB |
BIN
warzywa/burak.png
Normal file
After Width: | Height: | Size: 240 KiB |
BIN
warzywa/cebula.png
Normal file
After Width: | Height: | Size: 83 KiB |
BIN
warzywa/marchewka.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
warzywa/papryka.png
Normal file
After Width: | Height: | Size: 210 KiB |
BIN
warzywa/pomidor.png
Normal file
After Width: | Height: | Size: 240 KiB |
BIN
warzywa/rzepak.png
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
warzywa/salata.png
Normal file
After Width: | Height: | Size: 230 KiB |
BIN
warzywa/szpinak.png
Normal file
After Width: | Height: | Size: 200 KiB |
BIN
warzywa/ziemniak.png
Normal file
After Width: | Height: | Size: 184 KiB |