From 2ff85f9abbfe81b3edb6b5bc492a428b93b9bd3d Mon Sep 17 00:00:00 2001 From: Nikodem145 Date: Mon, 27 May 2024 14:59:44 +0200 Subject: [PATCH] bug fix v2 --- board.py | 4 ++-- tractor.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/board.py b/board.py index f32eee7ef..96bee4887 100644 --- a/board.py +++ b/board.py @@ -44,7 +44,7 @@ class Board: } 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 = [ [None for _ in range(cols)] for _ in range(rows) ] @@ -53,7 +53,7 @@ class Board: ] for row in range(rows): 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_image = random.choice(self.warzywa_images[vegetable_type]) self.vegetables[row][col] = vegetable_image diff --git a/tractor.py b/tractor.py index a55e41612..a1c33f9b2 100644 --- a/tractor.py +++ b/tractor.py @@ -56,6 +56,10 @@ class Tractor: else: 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 if board.vegetables[next_row][next_col]: @@ -86,7 +90,7 @@ class Tractor: } 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': board.set_soil(next_row, next_col) else: