Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
bb6bc0ffa2 | |||
8fcf4fad2b | |||
fb4cd44b61 |
@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.9 (traktor)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (traktor)" project-jdk-type="Python SDK" />
|
||||
</project>
|
89
board.py
@ -2,59 +2,116 @@ import pygame
|
||||
from constant import size, rows, cols
|
||||
import random
|
||||
|
||||
|
||||
class Board:
|
||||
def __init__(self):
|
||||
self.board = []
|
||||
self.vegetables = []
|
||||
self.soil_features = None
|
||||
self.load_images()
|
||||
self.generate_board()
|
||||
|
||||
|
||||
def load_images(self):
|
||||
self.grass = pygame.image.load("board/grass.png")
|
||||
self.dirt = pygame.image.load("board/dirt.png")
|
||||
self.rock= pygame.image.load("board/rock.png")
|
||||
self.rock = pygame.image.load("board/rock.png")
|
||||
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(rows)] for _ in range(cols)]
|
||||
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):
|
||||
for col in range(cols):
|
||||
cube_rect = pygame.Rect(row * size, col * size, size, size)
|
||||
cube=self.board[row][col]
|
||||
|
||||
if row==4 and col==4:
|
||||
cube_rect = pygame.Rect(col * size, row * size, size, size)
|
||||
cube = self.board[row][col]
|
||||
if row == 4 and col == 4:
|
||||
win.blit(self.grass, cube_rect)
|
||||
elif cube == 0:
|
||||
rock_scale = pygame.transform.scale(self.rock, (size, size))
|
||||
win.blit(self.dirt, cube_rect)
|
||||
win.blit(rock_scale, cube_rect)
|
||||
elif cube == 1:
|
||||
weed_scale = pygame.transform.scale(self.weeds, (size,size))
|
||||
weed_scale = pygame.transform.scale(self.weeds, (size, size))
|
||||
win.blit(self.grass, cube_rect)
|
||||
win.blit(weed_scale, cube_rect)
|
||||
elif cube in(2,3,4,5):
|
||||
elif cube in (2, 3, 4, 5):
|
||||
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
|
||||
|
||||
def is_weed(self,row,col):
|
||||
def is_weed(self, row, col):
|
||||
return self.board[row][col] == 1
|
||||
|
||||
def set_grass(self,row,col):
|
||||
self.board[row][col]=2
|
||||
def set_grass(self, row, col):
|
||||
self.board[row][col] = 2
|
||||
|
||||
def is_dirt(self,row,col):
|
||||
return self.board[row][col] in (6,7,8,9)
|
||||
def is_dirt(self, row, col):
|
||||
return self.board[row][col] in (6, 7, 8, 9)
|
||||
|
||||
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
|
83
kolejka.py
@ -1,80 +1,39 @@
|
||||
from constant import width, height, rows, cols
|
||||
from constant import rows, cols
|
||||
|
||||
class Stan:
|
||||
def __init__(self, row, col, dir):
|
||||
def __init__(self, row, col, direction):
|
||||
self.p = []
|
||||
self.a = ""
|
||||
self.row = row
|
||||
self.col = col
|
||||
self.direction = dir
|
||||
self.direction = direction
|
||||
def __str__(self):
|
||||
return f"row: {self.row}, col: {self.col}, direction: {self.direction}"
|
||||
|
||||
def parrent(self, stan, action):
|
||||
if(len(self.p) == 0):
|
||||
if len(self.p) == 0:
|
||||
self.p.append(stan)
|
||||
self.a = action
|
||||
|
||||
def succ(self, action, board):
|
||||
if(action == "up"):
|
||||
if(self.direction == "left"):
|
||||
if not board.is_rock(max(self.col - 1, 0), self.row):
|
||||
return Stan( self.row , max(self.col - 1, 0), self.direction)
|
||||
return Stan(self.row, self.col, self.direction)
|
||||
if(self.direction == "up"):
|
||||
if not board.is_rock(self.col, max(self.row - 1, 0)):
|
||||
return Stan(max(self.row - 1,0) , self.col, self.direction)
|
||||
return Stan(self.row, self.col, self.direction)
|
||||
if(self.direction == "right"):
|
||||
if not board.is_rock(min(self.col + 1, cols - 1), self.row):
|
||||
return Stan(self.row, min(self.col + 1, cols - 1) , self.direction)
|
||||
return Stan(self.row, self.col, self.direction)
|
||||
if(self.direction == "down"):
|
||||
if not board.is_rock(self.col, min(self.row + 1,rows - 1 )):
|
||||
return Stan(min(self.row + 1,rows - 1 ) , self.col, self.direction)
|
||||
return Stan(self.row, self.col, self.direction)
|
||||
if(action == "left"):
|
||||
if(self.direction == "left"):
|
||||
return Stan(self.row , self.col, "down")
|
||||
if(self.direction == "up"):
|
||||
return Stan(self.row, self.col, "left")
|
||||
if(self.direction == "right"):
|
||||
return Stan(self.row, self.col, "up")
|
||||
if(self.direction == "down"):
|
||||
return Stan(self.row, self.col , "right")
|
||||
if(action == "right"):
|
||||
if(self.direction == "left"):
|
||||
return Stan(self.row, self.col, "up")
|
||||
if(self.direction == "up"):
|
||||
return Stan(self.row, self.col, "right")
|
||||
if(self.direction == "right"):
|
||||
return Stan(self.row, self.col, "down")
|
||||
if(self.direction == "down"):
|
||||
return Stan(self.row, self.col,"left")
|
||||
move_offsets = {
|
||||
"up": {"up": (-1, 0), "left": (0, -1), "down": (1, 0), "right": (0, 1)},
|
||||
"left": {"up": "left", "left": "down", "down": "right", "right": "up"},
|
||||
"right": {"up": "right", "right": "down", "down": "left", "left": "up"}
|
||||
}
|
||||
|
||||
class Kolejka:
|
||||
def __init__(self):
|
||||
self.id = 0
|
||||
self.len = 0
|
||||
self.stany = []
|
||||
if action == "up":
|
||||
row_offset, col_offset = move_offsets[action][self.direction]
|
||||
new_row = self.row + row_offset
|
||||
new_col = self.col + col_offset
|
||||
if 0 <= new_row < rows and 0 <= new_col < cols and not board.is_rock(new_row, new_col):
|
||||
return Stan(new_row, new_col, self.direction)
|
||||
|
||||
def dodaj_stan(self, stan):
|
||||
self.stany.append(stan)
|
||||
self.len += 1
|
||||
def usun_stan(self):
|
||||
if not self.czy_pusta():
|
||||
self.id += 1
|
||||
return self.stany[self.id - 1]
|
||||
else:
|
||||
raise IndexError("Kolejka stanów jest pusta")
|
||||
elif action in ["left", "right"]:
|
||||
new_direction = move_offsets[action][self.direction]
|
||||
return Stan(self.row, self.col, new_direction)
|
||||
|
||||
def czy_pusta(self):
|
||||
return self.len <= self.id
|
||||
|
||||
def check(self, stan):
|
||||
indeks = 0
|
||||
for i in self.stany:
|
||||
if(stan.direction == i.direction and stan.col == i.col and stan.row == i.row):
|
||||
return True
|
||||
return False
|
||||
return None
|
||||
|
||||
class Odwiedzone:
|
||||
def __init__(self):
|
||||
|
152
main.py
@ -2,123 +2,113 @@ import pygame
|
||||
from board import Board
|
||||
from constant import width, height, rows, cols
|
||||
from tractor import Tractor
|
||||
from kolejka import Stan, Kolejka, Odwiedzone
|
||||
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.col, goaltest.row):
|
||||
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]
|
||||
|
||||
return akcje
|
||||
def graphsearch(istate, goaltest, board):
|
||||
def graphsearch(istate, board):
|
||||
explored = Odwiedzone()
|
||||
fringe = Kolejka()
|
||||
fringe.dodaj_stan(istate)
|
||||
fringe = Queue()
|
||||
fringe.put(istate)
|
||||
moves = ["up", "left", "right"]
|
||||
while not fringe.czy_pusta():
|
||||
elem = fringe.usun_stan()
|
||||
if goal_test(elem, goaltest, board):
|
||||
return actions(elem, istate)
|
||||
while not fringe.empty():
|
||||
elem = fringe.get()
|
||||
if goal_test(elem, board):
|
||||
return actions(elem, istate), elem
|
||||
explored.dodaj_stan(elem)
|
||||
for action in moves:
|
||||
stan = elem.succ(action, board)
|
||||
if((not fringe.check(stan)) and (not explored.check(stan))):
|
||||
if stan is not None:
|
||||
if not fringe_check(fringe, stan) and not explored.check(stan):
|
||||
stan.parrent(elem, action)
|
||||
fringe.dodaj_stan(stan)
|
||||
return "Brak sciezki"
|
||||
fringe.put(stan)
|
||||
return [], None
|
||||
|
||||
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():
|
||||
rotation = ["left", "up", "right", "down"]
|
||||
istate = 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()
|
||||
actions = graphsearch(istate, goaltest, board)
|
||||
print("akcje: >",actions )
|
||||
tractor = Tractor(4, 4)
|
||||
tractor = Tractor(4, 4, model, feature_columns)
|
||||
|
||||
while run:
|
||||
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():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
if keys[pygame.K_UP]:
|
||||
if(tractor.direction == "up" and tractor.row > 0 ):
|
||||
if board.is_weed(tractor.col, tractor.row - 1):
|
||||
board.set_grass(tractor.col, tractor.row - 1)
|
||||
tractor.row -= 1
|
||||
elif board.is_dirt(tractor.col, tractor.row - 1):
|
||||
board.set_soil(tractor.col, tractor.row - 1)
|
||||
tractor.row -= 1
|
||||
elif not board.is_rock(tractor.col, tractor.row - 1):
|
||||
tractor.row -= 1
|
||||
if(tractor.direction == "left" and tractor.col > 0):
|
||||
if board.is_weed(tractor.col - 1, tractor.row):
|
||||
board.set_grass(tractor.col - 1, tractor.row)
|
||||
tractor.col -= 1
|
||||
elif board.is_dirt(tractor.col - 1, tractor.row):
|
||||
board.set_soil(tractor.col - 1, tractor.row)
|
||||
tractor.col -= 1
|
||||
elif not board.is_rock(tractor.col - 1, tractor.row):
|
||||
tractor.col -= 1
|
||||
if(tractor.direction == "down" and tractor.row < rows - 1):
|
||||
if board.is_weed(tractor.col, tractor.row + 1):
|
||||
board.set_grass(tractor.col, tractor.row + 1)
|
||||
tractor.row += 1
|
||||
elif board.is_dirt(tractor.col, tractor.row + 1):
|
||||
board.set_soil(tractor.col, tractor.row + 1)
|
||||
tractor.row += 1
|
||||
elif not board.is_rock(tractor.col, tractor.row + 1):
|
||||
tractor.row += 1
|
||||
if(tractor.direction == "right" and tractor.col < cols - 1):
|
||||
if board.is_weed(tractor.col + 1, tractor.row):
|
||||
board.set_grass(tractor.col + 1, tractor.row)
|
||||
tractor.col += 1
|
||||
elif board.is_dirt(tractor.col + 1, tractor.row):
|
||||
board.set_soil(tractor.col + 1, tractor.row)
|
||||
tractor.col += 1
|
||||
elif not board.is_rock(tractor.col + 1, tractor.row):
|
||||
tractor.col += 1
|
||||
if keys[pygame.K_LEFT]:
|
||||
for i in range(0, 4):
|
||||
if(tractor.direction == rotation[i]):
|
||||
if(i == 0):
|
||||
i = 4
|
||||
tractor.direction = rotation[i-1]
|
||||
break
|
||||
if keys[pygame.K_RIGHT]:
|
||||
for i in range(0, 4):
|
||||
if(tractor.direction == rotation[i]):
|
||||
if(i == 3):
|
||||
i = -1
|
||||
tractor.direction = rotation[i+1]
|
||||
break
|
||||
akcja = akcje.pop(0)
|
||||
if akcja == "left":
|
||||
tractor.turn_left()
|
||||
elif akcja == "right":
|
||||
tractor.turn_right()
|
||||
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
|
||||
|
||||
pygame.quit()
|
||||
|
||||
main()
|
||||
|
||||
|
66
tractor.py
@ -1,17 +1,75 @@
|
||||
import pygame
|
||||
from constant import size
|
||||
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 = {
|
||||
"up": pygame.image.load("tractor/up.png"),
|
||||
"down": pygame.image.load("tractor/down.png"),
|
||||
"left": pygame.image.load("tractor/left.png"),
|
||||
"right":pygame.image.load("tractor/right.png")
|
||||
"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]
|
||||
win.blit(tractor_image, (self.col*size, self.row*size))
|
||||
win.blit(tractor_image, (self.col * size, self.row * size))
|
||||
|
||||
def turn_left(self):
|
||||
if self.direction == "up":
|
||||
self.direction = "left"
|
||||
elif self.direction == "left":
|
||||
self.direction = "down"
|
||||
elif self.direction == "down":
|
||||
self.direction = "right"
|
||||
elif self.direction == "right":
|
||||
self.direction = "up"
|
||||
|
||||
def turn_right(self):
|
||||
if self.direction == "up":
|
||||
self.direction = "right"
|
||||
elif self.direction == "right":
|
||||
self.direction = "down"
|
||||
elif self.direction == "down":
|
||||
self.direction = "left"
|
||||
elif self.direction == "left":
|
||||
self.direction = "up"
|
||||
|
||||
def move_forward(self, board):
|
||||
if self.direction == "up" and self.row > 0:
|
||||
next_row, next_col = self.row - 1, self.col
|
||||
elif self.direction == "left" and self.col > 0:
|
||||
next_row, next_col = self.row, self.col - 1
|
||||
elif self.direction == "down" and self.row < rows - 1:
|
||||
next_row, next_col = self.row + 1, self.col
|
||||
elif self.direction == "right" and self.col < cols - 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 |