vege, precition,every dirt

This commit is contained in:
s464923 2024-05-18 22:51:09 +02:00
parent 8fcf4fad2b
commit bb6bc0ffa2
15 changed files with 390 additions and 60 deletions

View File

@ -5,6 +5,8 @@ import random
class Board: class Board:
def __init__(self): def __init__(self):
self.board = [] self.board = []
self.vegetables = []
self.soil_features = None
self.load_images() self.load_images()
self.generate_board() self.generate_board()
@ -15,8 +17,52 @@ class Board:
self.weeds = pygame.image.load("board/weeds.png") self.weeds = pygame.image.load("board/weeds.png")
self.soil = pygame.image.load("board/zyzna.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): 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.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): def draw_cubes(self, win):
for row in range(rows): for row in range(rows):
@ -37,8 +83,20 @@ class Board:
win.blit(self.grass, cube_rect) win.blit(self.grass, cube_rect)
elif cube == 10: elif cube == 10:
win.blit(self.soil, cube_rect) 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: else:
win.blit(self.dirt, cube_rect) 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): def is_rock(self, row, col):
return self.board[row][col] == 0 return self.board[row][col] == 0
@ -54,3 +112,6 @@ class Board:
def set_soil(self, row, col): def set_soil(self, row, col):
self.board[row][col] = 10 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
View 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
1 wilgotnosc_gleby temperatura_gleby opady_deszczu wiek_rosliny proc_ekspo_na_swiatlo pora_dnia pora_roku roslina podlac
2 40 20 5 3 70 10 2 1 nie
3 60 25 0 2 50 15 3 2 tak
4 30 18 10 1 80 12 4 3 nie
5 50 22 3 4 60 18 1 4 tak
6 45 23 2 5 75 8 2 5 tak
7 55 26 8 3 70 14 3 6 nie
8 35 21 1 2 55 16 4 7 tak
9 65 24 6 4 80 11 1 8 nie
10 42 20 4 3 65 13 2 9 tak
11 48 22 7 5 75 9 3 10 tak
12 30 25 0 1 70 14 2 1 tak
13 60 18 10 2 60 8 3 2 nie
14 35 20 2 3 50 12 4 3 tak
15 50 23 1 4 65 17 1 4 tak
16 45 24 5 5 80 10 2 5 tak
17 55 22 3 3 75 13 3 6 nie
18 40 26 8 6 70 16 1 7 nie
19 62 21 1 4 85 9 2 8 tak
20 47 25 6 5 60 11 3 9 nie
21 58 20 4 3 75 14 4 10 tak
22 38 24 7 3 65 11 1 1 tak
23 59 20 3 2 55 16 2 2 nie
24 33 22 5 1 70 9 3 3 nie
25 52 25 2 4 80 14 4 4 tak
26 46 21 1 5 75 10 1 5 tak
27 56 26 8 3 70 15 2 6 nie
28 34 23 0 2 60 8 3 7 nie
29 63 18 4 4 85 12 4 8 nie
30 41 20 1 3 65 13 1 9 tak
31 49 22 9 5 75 17 2 10 tak
32 29 25 0 2 70 14 3 1 tak
33 61 18 11 3 60 8 1 2 nie
34 37 20 2 4 50 12 2 3 tak
35 51 23 0 5 65 16 4 4 tak
36 44 24 4 6 80 10 3 5 tak
37 54 22 3 3 75 13 1 6 nie
38 39 26 7 1 70 15 2 7 nie
39 64 21 0 4 85 9 3 8 tak
40 48 25 5 5 60 11 4 9 nie
41 57 20 2 3 75 14 1 10 tak
42 32 24 8 3 65 10 2 1 tak
43 62 19 2 2 55 15 3 2 nie
44 36 21 1 1 70 12 4 3 nie
45 53 22 4 4 80 16 1 4 tak
46 42 23 2 5 75 8 2 5 tak
47 58 26 6 3 70 14 3 6 nie
48 35 21 0 2 60 17 4 7 nie
49 65 18 3 4 85 11 1 8 nie
50 45 20 1 3 65 13 2 9 tak
51 50 22 7 5 75 9 3 10 tak
52 31 25 0 2 70 14 1 1 tak
53 60 18 9 3 60 8 2 2 nie
54 34 20 3 4 50 12 3 3 tak
55 52 23 1 5 65 16 4 4 tak
56 47 24 6 6 80 10 1 5 tak
57 55 22 2 3 75 13 2 6 nie
58 38 26 8 1 70 15 3 7 nie
59 64 21 0 4 85 9 4 8 tak
60 41 20 2 3 65 13 1 9 tak
61 49 22 8 5 75 17 2 10 tak
62 30 24 1 2 70 14 3 1 tak
63 61 18 10 3 60 8 1 2 nie
64 37 20 4 4 50 12 2 3 tak
65 51 23 2 5 65 16 4 4 tak
66 44 24 5 6 80 10 3 5 tak
67 53 22 3 3 75 13 1 6 nie
68 39 26 7 1 70 15 2 7 nie
69 65 21 0 4 85 9 3 8 tak
70 48 25 6 5 60 11 4 9 nie
71 57 20 3 3 75 14 1 10 tak
72 32 24 9 2 65 10 2 1 tak
73 62 19 1 2 55 15 3 2 nie
74 36 21 2 1 70 12 4 3 nie
75 55 23 3 4 80 16 1 4 tak
76 42 23 1 5 75 8 2 5 tak
77 58 26 5 3 70 14 3 6 nie
78 35 21 0 2 60 17 4 7 nie
79 46 20 2 3 65 13 2 9 tak
80 50 22 6 5 75 9 3 10 tak
81 31 25 1 2 70 14 1 1 tak
82 60 18 8 3 60 8 2 2 nie
83 33 20 4 4 50 12 3 3 tak
84 52 23 1 5 65 16 4 4 tak
85 47 24 7 6 80 10 1 5 tak
86 38 25 2 3 65 10 1 1 tak
87 59 21 1 2 55 15 2 2 nie
88 33 23 3 1 70 9 3 3 nie
89 47 22 7 4 75 11 2 1 tak
90 58 20 4 3 60 16 1 2 nie
91 32 24 6 2 70 8 3 3 nie
92 53 23 3 5 80 15 4 4 tak
93 45 21 8 6 75 12 1 5 tak
94 55 26 11 4 70 17 2 6 nie
95 36 24 5 3 60 9 3 7 nie
96 67 19 10 4 85 13 4 8 nie
97 43 22 1 3 65 14 1 9 tak
98 51 24 9 5 75 10 2 10 tak
99 31 27 2 2 70 15 3 1 tak
100 62 18 12 3 60 8 1 2 nie
101 38 21 6 4 50 11 2 3 tak
102 49 24 4 5 65 16 4 4 tak
103 42 25 7 3 80 9 3 5 tak
104 57 23 4 3 75 12 1 6 nie
105 35 28 9 1 70 16 2 7 nie
106 76 20 11 4 85 10 3 8 nie
107 46 22 0 3 65 13 1 9 tak
108 10 25 10 5 95 9 2 10 tak
109 38 19 3 6 80 11 2 1 tak
110 57 24 2 7 90 15 1 2 tak
111 81 18 9 8 70 12 4 3 nie
112 49 22 2 9 85 18 3 4 tak
113 44 23 1 3 60 8 2 5 nie
114 24 26 5 2 75 14 3 6 tak
115 76 13 0 4 25 19 4 7 nie
116 67 15 5 2 80 11 1 8 nie
117 43 20 1 1 65 13 2 9 tak
118 50 22 8 1 20 19 3 10 nie
119 62 25 0 2 75 14 2 1 tak
120 58 18 11 3 30 8 3 2 nie
121 37 20 2 2 50 12 4 3 tak
122 21 23 0 1 65 20 1 4 tak
123 46 24 2 2 75 12 2 5 tak
124 76 22 6 2 70 13 3 6 nie
125 39 26 9 2 15 16 1 7 nie
126 53 21 2 3 80 12 2 8 tak
127 48 25 7 4 10 11 3 9 nie
128 88 19 3 6 30 11 2 1 nie
129 57 24 4 7 10 15 1 2 nie
130 11 18 9 8 90 12 4 3 tak
131 49 22 2 9 85 18 3 4 tak
132 44 23 1 1 60 8 2 5 tak
133 54 26 7 2 75 14 3 6 nie
134 36 21 0 2 55 16 4 7 tak
135 27 24 2 3 80 11 1 8 tak
136 13 20 6 4 95 10 2 9 tak
137 50 22 8 5 20 17 3 10 nie
138 32 25 1 6 95 14 2 1 tak
139 58 18 11 3 80 8 3 2 nie
140 37 20 2 1 50 12 4 3 tak
141 51 23 5 2 25 22 1 4 nie
142 46 24 0 2 75 10 2 5 tak
143 56 22 1 3 70 13 3 6 tak
144 39 26 9 4 35 20 1 7 nie
145 63 21 2 3 90 9 2 8 tak
146 48 25 7 1 70 11 3 9 nie
147 42 24 1 5 75 14 2 1 tak
148 55 20 1 8 65 13 1 2 tak
149 58 22 6 4 10 12 3 3 nie
150 47 21 2 2 70 9 4 4 tak
151 50 25 1 1 85 15 1 5 nie
152 60 23 7 7 70 11 2 6 nie
153 83 19 4 3 60 13 3 7 nie
154 68 26 8 5 90 16 4 8 nie
155 41 18 9 1 75 14 2 9 nie
156 48 20 0 8 70 8 1 10 tak
157 89 23 2 6 55 12 3 1 nie
158 59 21 2 7 80 10 4 2 tak
159 97 24 3 5 65 9 1 3 nie
160 49 22 2 9 75 15 2 4 tak
161 92 26 1 1 85 11 3 5 nie
162 21 18 4 8 70 13 4 6 tak
163 34 25 9 4 60 16 1 7 nie
164 70 19 8 5 90 14 2 8 nie
165 45 20 2 2 80 12 3 9 tak
166 53 24 7 7 75 10 1 10 nie
167 43 21 3 6 70 11 2 1 tak
168 56 22 8 8 80 13 3 2 nie
169 39 19 5 7 65 9 4 3 nie
170 48 23 1 9 75 14 1 4 tak
171 51 25 6 1 85 12 2 5 nie
172 62 24 4 2 90 15 3 6 nie
173 35 20 2 2 60 10 4 7 tak
174 69 26 7 3 85 16 1 8 nie
175 40 18 9 1 70 12 2 9 nie
176 49 22 0 5 75 11 3 10 tak
177 54 21 3 7 80 14 4 1 tak
178 63 23 8 8 90 12 1 2 nie
179 36 20 2 9 65 10 2 3 tak
180 47 24 1 1 75 13 3 4 tak
181 50 26 5 2 85 15 4 5 nie
182 34 25 2 2 90 9 1 6 tak
183 47 19 6 3 60 11 2 7 nie
184 70 25 9 2 85 17 3 8 nie
185 41 21 7 1 70 13 4 9 nie
186 52 20 1 1 75 10 1 10 tak
187 38 22 3 6 70 12 2 1 tak
188 87 23 9 7 80 14 3 2 nie
189 61 20 5 2 65 10 4 3 nie
190 49 21 0 9 75 11 1 4 tak
191 44 25 6 1 80 15 2 5 nie
192 54 19 2 1 90 13 3 6 tak
193 36 24 8 1 60 9 4 7 nie
194 67 20 3 2 85 16 1 8 nie
195 43 22 7 4 75 12 2 9 nie
196 50 23 1 5 80 10 3 10 tak
197 55 21 4 7 70 13 4 1 nie
198 63 25 9 8 90 14 1 2 nie
199 57 19 5 9 65 11 2 3 nie
200 49 24 0 1 75 16 3 4 tak
201 51 20 6 1 85 12 4 5 nie
202 64 22 4 2 90 9 1 6 nie
203 39 23 8 3 60 14 2 7 tak
204 70 21 2 1 85 13 3 8 nie
205 41 25 7 5 70 15 4 9 nie
206 52 19 1 2 75 10 1 10 tak

30
decisiontree.py Normal file
View 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

84
main.py
View File

@ -4,85 +4,111 @@ from constant import width, height, rows, cols
from tractor import Tractor from tractor import Tractor
from kolejka import Stan, Odwiedzone from kolejka import Stan, Odwiedzone
from queue import Queue 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 fps = 5
WIN = pygame.display.set_mode((width, height)) 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): def actions(elem, istate):
akcje = [] 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) akcje.append(elem.a)
elem = elem.p[0] elem = elem.p[0]
return akcje[::-1] # Odwracamy kolejność, aby akcje były w poprawnej sekwencji return akcje[::-1]
def graphsearch(istate, board):
def graphsearch(istate, goaltest, board):
explored = Odwiedzone() explored = Odwiedzone()
fringe = Queue() fringe = Queue()
fringe.put(istate) fringe.put(istate)
moves = ["up", "left", "right"] moves = ["up", "left", "right"]
while not fringe.empty(): while not fringe.empty():
elem = fringe.get() elem = fringe.get()
if goal_test(elem, goaltest, board): if goal_test(elem, board):
return actions(elem, istate) return actions(elem, istate), elem
explored.dodaj_stan(elem) explored.dodaj_stan(elem)
for action in moves: for action in moves:
stan = elem.succ(action, board) stan = elem.succ(action, board)
if stan is not None: 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) stan.parrent(elem, action)
fringe.put(stan) 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: with fringe.mutex:
for item in fringe.queue: for item in fringe.queue:
if stan.direction == item.direction and stan.col == item.col and stan.row == item.row: if stan.direction == item.direction and stan.col == item.col and stan.row == item.row:
return True return True
return False return False
def main(): def main():
initial_state = Stan(4, 4, "down") initial_state = Stan(4, 4, "down")
goaltest = Stan(1,1, "up")
run = True run = True
clock = pygame.time.Clock() clock = pygame.time.Clock()
board = Board() board = Board()
board.load_images() board.load_images()
akcje = graphsearch(initial_state, goaltest, board) tractor = Tractor(4, 4, model, feature_columns)
print("akcje: >",akcje )
tractor = Tractor(4, 4)
while run: while run:
clock.tick(fps) clock.tick(fps)
if all(not board.is_dirt(row, col) for row in range(rows) for col in range(cols)):
print("Traktor odwiedził wszystkie pola.")
break
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(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
run = False run = False
if akcje: akcja = akcje.pop(0)
action = akcje.pop(0) # Pobierz kolejną akcję z listy if akcja == "left":
if action == "left":
tractor.turn_left() tractor.turn_left()
elif action == "right": elif akcja == "right":
tractor.turn_right() tractor.turn_right()
elif action == "up": elif akcja == "up":
tractor.move_forward(board) tractor.move_forward(board)
board.draw_cubes(WIN) board.draw_cubes(WIN)
tractor.draw(WIN) tractor.draw(WIN)
pygame.display.update() 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
pygame.quit() pygame.quit()
main() main()

View File

@ -1,8 +1,10 @@
import pygame import pygame
from constant import size, rows, cols from constant import size, rows, cols
from decisiontree import predict
class Tractor: class Tractor:
def __init__(self, row, col): def __init__(self, row, col, model, feature_columns):
self.row = row self.row = row
self.col = col self.col = col
self.images = { self.images = {
@ -12,6 +14,8 @@ class Tractor:
"right": pygame.image.load("tractor/right.png") "right": pygame.image.load("tractor/right.png")
} }
self.direction = "down" self.direction = "down"
self.model = model
self.feature_columns = feature_columns
def draw(self, win): def draw(self, win):
tractor_image = self.images[self.direction] tractor_image = self.images[self.direction]
@ -39,30 +43,33 @@ class Tractor:
def move_forward(self, board): def move_forward(self, board):
if self.direction == "up" and self.row > 0: if self.direction == "up" and self.row > 0:
if not board.is_rock(self.row - 1, self.col): next_row, next_col = 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
elif self.direction == "left" and self.col > 0: elif self.direction == "left" and self.col > 0:
if not board.is_rock(self.row, self.col - 1): next_row, next_col = 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
elif self.direction == "down" and self.row < rows - 1: elif self.direction == "down" and self.row < rows - 1:
if not board.is_rock(self.row + 1, self.col): next_row, next_col = 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
elif self.direction == "right" and self.col < cols - 1: elif self.direction == "right" and self.col < cols - 1:
if not board.is_rock(self.row, self.col + 1): next_row, next_col = self.row, self.col + 1
if board.is_weed(self.row, self.col + 1): else:
board.set_grass(self.row, self.col + 1) return # Nie możemy się ruszyć poza planszę
elif board.is_dirt(self.row, self.col + 1):
board.set_soil(self.row, self.col + 1) if board.is_dirt(next_row, next_col) and board.board[next_row][next_col] != 10:
self.col += 1 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 KiB

BIN
warzywa/burak.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

BIN
warzywa/cebula.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

BIN
warzywa/marchewka.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

BIN
warzywa/papryka.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

BIN
warzywa/pomidor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

BIN
warzywa/rzepak.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

BIN
warzywa/salata.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

BIN
warzywa/szpinak.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

BIN
warzywa/ziemniak.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB