bug fix v2

This commit is contained in:
Nikodem145 2024-05-27 14:59:44 +02:00
parent 2b829714ac
commit 2ff85f9abb
2 changed files with 7 additions and 3 deletions

View File

@ -44,7 +44,7 @@ class Board:
} }
def generate_board(self): def generate_board(self):
self.board = [[random.choice([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) 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 = [ self.vegetables = [
[None for _ in range(cols)] for _ in range(rows) [None for _ in range(cols)] for _ in range(rows)
] ]
@ -53,7 +53,7 @@ class Board:
] ]
for row in range(rows): for row in range(rows):
for col in range(cols): for col in range(cols):
if self.board[row][col] in (6, 7, 8, 9, 10, 11): if self.board[row][col] in (6, 7, 8, 9):
vegetable_type = random.choice(list(self.warzywa_images.keys())) vegetable_type = random.choice(list(self.warzywa_images.keys()))
vegetable_image = random.choice(self.warzywa_images[vegetable_type]) vegetable_image = random.choice(self.warzywa_images[vegetable_type])
self.vegetables[row][col] = vegetable_image self.vegetables[row][col] = vegetable_image

View File

@ -56,6 +56,10 @@ class Tractor:
else: else:
return # Nie możemy się ruszyć poza planszę return # Nie możemy się ruszyć poza planszę
if next_row >= len(board.vegetable_names) or next_col >= len(board.vegetable_names[0]):
print(f"Next position ({next_row}, {next_col}) is out of range")
return
vegetable_name = None vegetable_name = None
if board.vegetables[next_row][next_col]: if board.vegetables[next_row][next_col]:
@ -86,7 +90,7 @@ class Tractor:
} }
should_water = predict(self.model, self.feature_columns, sample) should_water = predict(self.model, self.feature_columns, sample)
print(f"Predykcja dla pola ({next_row}, {next_col}) z cechami {sample}: {should_water}") print(f"Predykcja dla pola ({next_row}, {next_col}): {should_water}")
if should_water[0].strip() == 'tak': if should_water[0].strip() == 'tak':
board.set_soil(next_row, next_col) board.set_soil(next_row, next_col)
else: else: