Update tractor.py
This commit is contained in:
parent
bb6bc0ffa2
commit
268a39aa2d
15
tractor.py
15
tractor.py
@ -1,10 +1,11 @@
|
||||
import pygame
|
||||
from constant import size, rows, cols
|
||||
from decisiontree import predict
|
||||
from neuralnetwork import predict_image
|
||||
|
||||
|
||||
class Tractor:
|
||||
def __init__(self, row, col, model, feature_columns):
|
||||
def __init__(self, row, col, model, feature_columns, neuralnetwork):
|
||||
self.row = row
|
||||
self.col = col
|
||||
self.images = {
|
||||
@ -16,6 +17,7 @@ class Tractor:
|
||||
self.direction = "down"
|
||||
self.model = model
|
||||
self.feature_columns = feature_columns
|
||||
self.neuralnetwork = neuralnetwork
|
||||
|
||||
def draw(self, win):
|
||||
tractor_image = self.images[self.direction]
|
||||
@ -40,6 +42,7 @@ class Tractor:
|
||||
self.direction = "left"
|
||||
elif self.direction == "left":
|
||||
self.direction = "up"
|
||||
|
||||
|
||||
def move_forward(self, board):
|
||||
if self.direction == "up" and self.row > 0:
|
||||
@ -53,6 +56,14 @@ class Tractor:
|
||||
else:
|
||||
return # Nie możemy się ruszyć poza planszę
|
||||
|
||||
image_path = board.vegetables[next_row][next_col] # Ścieżka do obrazu warzywa
|
||||
|
||||
# Predykcja warzywa po obrazie
|
||||
if image_path is not None:
|
||||
print(image_path, "mialo byc")
|
||||
vegetable_name = predict_image(image_path, self.neuralnetwork)
|
||||
print(vegetable_name, "jest")
|
||||
|
||||
if board.is_dirt(next_row, next_col) and board.board[next_row][next_col] != 10:
|
||||
soil_features = board.soil_features
|
||||
sample = {
|
||||
@ -63,7 +74,7 @@ class Tractor:
|
||||
"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]]
|
||||
"roslina": "warzywa/" + str(vegetable_name) + ".png"
|
||||
}
|
||||
|
||||
should_water = predict(self.model, self.feature_columns, sample)
|
||||
|
Loading…
Reference in New Issue
Block a user