new veggies changes
This commit is contained in:
parent
4564030f27
commit
1a0e89c1e7
BIN
agent/.DS_Store
vendored
Normal file
BIN
agent/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
agent/methods/__pycache__/genetic_algorithm.cpython-310.pyc
Normal file
BIN
agent/methods/__pycache__/genetic_algorithm.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
agent/neural_network/.DS_Store
vendored
BIN
agent/neural_network/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
BIN
agent/neural_network/images/.DS_Store
vendored
BIN
agent/neural_network/images/.DS_Store
vendored
Binary file not shown.
BIN
agent/neural_network/images/test/.DS_Store
vendored
BIN
agent/neural_network/images/test/.DS_Store
vendored
Binary file not shown.
@ -41,7 +41,8 @@ def main(path):
|
||||
# read and preprocess the image
|
||||
image = cv2.imread(path)
|
||||
# get the ground truth class
|
||||
gt_class = path.split('/')[-2]
|
||||
#gt_class = path.split('/')[-2]
|
||||
gt_class = path.split('/')
|
||||
orig_image = image.copy()
|
||||
# convert to RGB format
|
||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
|
BIN
core/.DS_Store
vendored
Normal file
BIN
core/.DS_Store
vendored
Normal file
Binary file not shown.
Binary file not shown.
@ -27,7 +27,6 @@ class Chicken:
|
||||
self.step = 0
|
||||
|
||||
def move(self, direction):
|
||||
print('MOVE')
|
||||
if direction == 'move':
|
||||
if self.angle == 0 and self.y != 0:
|
||||
self.y -= 1
|
||||
@ -56,9 +55,7 @@ class Chicken:
|
||||
self.image = self.left
|
||||
|
||||
self.step = self.step + 1
|
||||
print(self.x, self.y)
|
||||
print('step: ', self.step)
|
||||
|
||||
print('The chicken is on: ', self.x, self.y)
|
||||
def water(self, xy , plant_list):
|
||||
for obj in plant_list:
|
||||
if obj.xy == xy:
|
||||
|
BIN
core/constants/__pycache__/strings.cpython-310.pyc
Normal file
BIN
core/constants/__pycache__/strings.cpython-310.pyc
Normal file
Binary file not shown.
24
core/constants/strings.py
Normal file
24
core/constants/strings.py
Normal file
@ -0,0 +1,24 @@
|
||||
#image path
|
||||
#plants
|
||||
class ConStrings:
|
||||
flower = r'resources/plants/flower.png'
|
||||
bush = r'resources/plants/bush.png'
|
||||
ivy = r'resources/plants/ivy.png'
|
||||
wheat_dead = r'resources/plants/wheat_dead.png'
|
||||
wheat= r'resources/plants/wheat.png'
|
||||
|
||||
strawberry = r'resources/fruits/6.png'
|
||||
grapes = r'resources/fruits/8.png'
|
||||
apple = r'resources/fruits/9.png'
|
||||
banana = r'resources/fruits/10.png'
|
||||
|
||||
eggplant = r'resources/vegies/1.png'
|
||||
carrot = r'resources/vegies/12.png'
|
||||
pumpkin = r'resources/vegies/11.png'
|
||||
tomato = r'resources/vegies/7.png'
|
||||
pepper = r'resources/vegies/14.png'
|
||||
papaya = r'resources/vegies/2.png'
|
||||
|
||||
|
||||
stone = r'resources/stones/stone.png'
|
||||
aim = r'resources/aim.png'
|
Binary file not shown.
Binary file not shown.
@ -1,10 +1,10 @@
|
||||
class Plant:
|
||||
def __init__(self, id, name, state, image_zero, image_one, x, y, empty):
|
||||
def __init__(self, id, name, state, image_zero, image_one, image_path, x, y, empty):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.state = state
|
||||
self.image_state_zero = image_zero
|
||||
self.image_state_one = image_one
|
||||
self.image_path = image_path
|
||||
self.xy = [x, y]
|
||||
self.empty = empty
|
||||
|
@ -1,7 +1,9 @@
|
||||
import pygame
|
||||
import random
|
||||
from core.plants import plant
|
||||
from core.constants import strings
|
||||
|
||||
constant = strings.ConStrings
|
||||
|
||||
|
||||
class PlantsSettings:
|
||||
@ -12,33 +14,43 @@ class PlantsSettings:
|
||||
self.all_plants = []
|
||||
self.all_fruits = []
|
||||
#plants
|
||||
self.flower_image = pygame.image.load(r'resources/plants/flower.png').convert_alpha()
|
||||
self.flower_image = pygame.image.load(constant.flower).convert_alpha()
|
||||
self.flower_image = pygame.transform.scale(self.flower_image, (self.cell_size, self.cell_size))
|
||||
self.bush_image = pygame.image.load(r'resources/plants/bush.png').convert_alpha()
|
||||
self.bush_image = pygame.image.load(constant.bush).convert_alpha()
|
||||
self.bush_image = pygame.transform.scale(self.bush_image, (self.cell_size, self.cell_size))
|
||||
self.ivy_image = pygame.image.load(r'resources/plants/ivy.png').convert_alpha()
|
||||
self.ivy_image = pygame.image.load(constant.ivy).convert_alpha()
|
||||
self.ivy_image = pygame.transform.scale(self.ivy_image, (self.cell_size, self.cell_size))
|
||||
self.wheat_dead_image = pygame.image.load(r'resources/plants/wheat_dead.png').convert_alpha()
|
||||
self.wheat_dead_image = pygame.image.load(constant.wheat_dead).convert_alpha()
|
||||
self.wheat_dead_image = pygame.transform.scale(self.wheat_dead_image, (self.cell_size, self.cell_size))
|
||||
self.wheat_image = pygame.image.load(r'resources/plants/wheat.png').convert_alpha()
|
||||
self.wheat_image = pygame.image.load(constant.wheat).convert_alpha()
|
||||
self.wheat_image = pygame.transform.scale(self.wheat_image, (self.cell_size, self.cell_size))
|
||||
#vegies
|
||||
self.eggplant_image = pygame.image.load(r'resources/vegies/1.png').convert_alpha()
|
||||
self.eggplant_image = pygame.image.load(constant.eggplant).convert_alpha()
|
||||
self.eggplant_image = pygame.transform.scale(self.eggplant_image, (self.cell_size, self.cell_size))
|
||||
self.tomato_image = pygame.image.load(constant.tomato).convert_alpha()
|
||||
self.tomato_image = pygame.transform.scale(self.tomato_image, (self.cell_size, self.cell_size))
|
||||
self.carrot_image = pygame.image.load(constant.carrot).convert_alpha()
|
||||
self.carrot_image = pygame.transform.scale(self.carrot_image, (self.cell_size, self.cell_size))
|
||||
self.pumpkin_image = pygame.image.load(constant.pumpkin).convert_alpha()
|
||||
self.pumpkin_image = pygame.transform.scale(self.pumpkin_image, (self.cell_size, self.cell_size))
|
||||
self.papaya_image = pygame.image.load(constant.papaya).convert_alpha()
|
||||
self.papaya_image = pygame.transform.scale(self.papaya_image, (self.cell_size, self.cell_size))
|
||||
self.pepper_image = pygame.image.load(constant.pepper).convert_alpha()
|
||||
self.pepper_image = pygame.transform.scale(self.pepper_image, (self.cell_size, self.cell_size))
|
||||
#fruits
|
||||
self.strawberrie_image = pygame.image.load(r'resources/fruits/6.png').convert_alpha()
|
||||
self.strawberrie_image = pygame.transform.scale(self.strawberrie_image, (self.cell_size, self.cell_size))
|
||||
self.grapes_image = pygame.image.load(r'resources/fruits/8.png').convert_alpha()
|
||||
self.strawberry_image = pygame.image.load(constant.strawberry).convert_alpha()
|
||||
self.strawberry_image = pygame.transform.scale(self.strawberry_image, (self.cell_size, self.cell_size))
|
||||
self.grapes_image = pygame.image.load(constant.grapes).convert_alpha()
|
||||
self.grapes_image = pygame.transform.scale(self.grapes_image, (self.cell_size-12, self.cell_size))
|
||||
self.apple_image = pygame.image.load(r'resources/fruits/9.png').convert_alpha()
|
||||
self.apple_image = pygame.image.load(constant.apple).convert_alpha()
|
||||
self.apple_image = pygame.transform.scale(self.apple_image, (self.cell_size, self.cell_size))
|
||||
self.banana_image = pygame.image.load(r'resources/fruits/10.png').convert_alpha()
|
||||
self.banana_image = pygame.image.load(constant.banana).convert_alpha()
|
||||
self.banana_image = pygame.transform.scale(self.banana_image, (self.cell_size, self.cell_size))
|
||||
|
||||
self.stone_image = pygame.image.load(r'resources/stones/stone.png').convert_alpha()
|
||||
self.stone_image = pygame.image.load(constant.stone).convert_alpha()
|
||||
self.stone_image = pygame.transform.scale(self.stone_image, (self.cell_size, self.cell_size))
|
||||
|
||||
self.aim_image = pygame.image.load(r'resources/aim.png').convert_alpha()
|
||||
self.aim_image = pygame.image.load(constant.aim).convert_alpha()
|
||||
self.aim_image = pygame.transform.scale(self.aim_image, (self.cell_size, self.cell_size))
|
||||
|
||||
def locate_plant(self, field_list, name, num_of_blocks): # finds open space (coordinates)
|
||||
@ -50,7 +62,7 @@ class PlantsSettings:
|
||||
self.all_plants.append([rand_x, rand_y])
|
||||
if name == 'wheat':
|
||||
self.block = plant.Plant(
|
||||
i, name, 0, self.wheat_dead_image, self.wheat_image, rand_x, rand_y, False
|
||||
i, name, 0, self.wheat_dead_image, self.wheat_image, constant.wheat_dead, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'eggplant':
|
||||
self.block = plant.Plant(
|
||||
@ -88,34 +100,75 @@ class PlantsSettings:
|
||||
self.all_fruits.append([rand_x, rand_y])
|
||||
if name == 'wheat':
|
||||
self.block = plant.Plant(
|
||||
i, name, 0, self.wheat_dead_image, self.wheat_image, rand_x, rand_y, False
|
||||
i, name, 0, self.wheat_dead_image, self.wheat_image, constant.wheat_dead, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'strawberry':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.strawberrie_image, self.strawberrie_image, rand_x, rand_y, False
|
||||
i, name, 1, self.strawberry_image, self.strawberry_image, constant.strawberry, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'grapes':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.grapes_image, self.grapes_image, rand_x, rand_y, False
|
||||
i, name, 1, self.grapes_image, self.grapes_image,constant.grapes, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'apple':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.apple_image, self.apple_image, rand_x, rand_y, False
|
||||
i, name, 1, self.apple_image, self.apple_image,constant.apple, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'banana':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.banana_image, self.banana_image, rand_x, rand_y, False
|
||||
i, name, 1, self.banana_image, self.banana_image,constant.banana, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'stone':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.stone_image, self.stone_image, rand_x, rand_y, False
|
||||
i, name, 1, self.stone_image, self.stone_image, constant.stone, rand_x, rand_y, False
|
||||
)
|
||||
field_list.append(self.block)
|
||||
break
|
||||
|
||||
def locate_veggies(self, field_list, name, num_of_blocks): # finds open space (coordinates)
|
||||
for i in range(num_of_blocks):
|
||||
while True:
|
||||
rand_x = random.randint(0, self.cell_number - 1) # to check
|
||||
rand_y = random.randint(0, self.cell_number - 1)
|
||||
if [rand_x, rand_y] not in self.all_fruits:
|
||||
self.all_fruits.append([rand_x, rand_y])
|
||||
if name == 'wheat':
|
||||
self.block = plant.Plant(
|
||||
i, name, 0, self.wheat_dead_image, self.wheat_image, constant.wheat_dead, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'pumpkin':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.pumpkin_image, self.pumpkin_image, constant.pumpkin, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'pepper':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.pepper_image, self.pepper_image, constant.pepper, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'papaya':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.papaya_image, self.papaya_image, constant.papaya, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'carrot':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.carrot_image, self.carrot_image, constant.carrot, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'tomato':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.tomato_image, self.tomato_image, constant.tomato, rand_x, rand_y, False
|
||||
)
|
||||
if name == 'stone':
|
||||
self.block = plant.Plant(
|
||||
i, name, 1, self.stone_image, self.stone_image, constant.stone, rand_x, rand_y, False
|
||||
)
|
||||
field_list.append(self.block)
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
def locate_aim(self, field_list, x, y):
|
||||
self.block = plant.Plant(
|
||||
999, 'aim', 1, self.aim_image, self.aim_image, x, y, False
|
||||
999, 'aim', 1, self.aim_image, self.aim_image, constant.aim, x, y, False
|
||||
)
|
||||
field_list.append(self.block)
|
||||
|
||||
|
76
main.py
76
main.py
@ -32,7 +32,8 @@ class Game:
|
||||
self.surface = pygame.display.set_mode((self.cell_size*self.cell_number, self.cell_size*self.cell_number))
|
||||
|
||||
self.grass_list = [] # 1-level
|
||||
self.plant_list = [] # 2-level
|
||||
self.plant_list = [] # 2-level - test
|
||||
self.veggies_list = [] # 2-level - first model agent
|
||||
self.fruits_list = [] # 2-level - second model agent
|
||||
self.stone_list = [] # 3-level
|
||||
self.aim_list = [] # 4-level
|
||||
@ -48,18 +49,23 @@ class Game:
|
||||
# self.Plants.locate_plant(self.plant_list, 'flower', self.blocks_number)
|
||||
# self.Plants.locate_plant(self.plant_list, 'bush', self.blocks_number)
|
||||
|
||||
#fruits_list
|
||||
self.Plants.locate_fruit(self.fruits_list, 'apple', self.blocks_number-5)
|
||||
self.Plants.locate_fruit(self.fruits_list, 'banana', self.blocks_number-5)
|
||||
self.Plants.locate_fruit(self.fruits_list, 'strawberry', self.blocks_number-5)
|
||||
self.Plants.locate_fruit(self.fruits_list, 'grapes', self.blocks_number-5)
|
||||
self.Plants.locate_fruit(self.plant_list, 'wheat', self.blocks_number)
|
||||
# #fruits_list
|
||||
# self.Plants.locate_fruit(self.fruits_list, 'apple', self.blocks_number-5)
|
||||
# self.Plants.locate_fruit(self.fruits_list, 'banana', self.blocks_number-5)
|
||||
# self.Plants.locate_fruit(self.fruits_list, 'strawberry', self.blocks_number-5)
|
||||
# self.Plants.locate_fruit(self.fruits_list, 'grapes', self.blocks_number-5)
|
||||
# self.Plants.locate_fruit(self.fruits_list, 'wheat', self.blocks_number)
|
||||
|
||||
#vegies_list
|
||||
self.Plants.locate_veggies(self.veggies_list, 'pepper', self.blocks_number-5)
|
||||
self.Plants.locate_veggies(self.veggies_list, 'carrot', self.blocks_number-5)
|
||||
self.Plants.locate_veggies(self.veggies_list, 'pumpkin', self.blocks_number-5)
|
||||
self.Plants.locate_veggies(self.veggies_list, 'wheat', self.blocks_number)
|
||||
|
||||
|
||||
self.Plants.locate_aim(self.aim_list, 0, 0)
|
||||
|
||||
self.Plants.locate_fruit(self.stone_list, 'stone', self.blocks_number)
|
||||
self.Plants.locate_veggies(self.stone_list, 'stone', self.blocks_number)
|
||||
|
||||
#self.image_wheat = self.Plants.wheat_watered()
|
||||
self.chicken = chick.Chicken(self.surface, self.cell_size, self.cell_number)
|
||||
@ -69,14 +75,14 @@ class Game:
|
||||
running = True
|
||||
clock = pygame.time.Clock()
|
||||
move_chicken_event = pygame.USEREVENT + 1
|
||||
pygame.time.set_timer(move_chicken_event, 500) # chicken moves every 1000 ms
|
||||
pygame.time.set_timer(move_chicken_event, 1000) # chicken moves every 1000 ms
|
||||
self.search_object = graph_search.Search(self.cell_size, self.cell_number)
|
||||
chicken_next_moves = []
|
||||
|
||||
veggies = dict()
|
||||
veggies_debug = dict()
|
||||
|
||||
wheat_list = [obj for obj in self.plant_list if obj.name == "wheat" and obj.state == 0]
|
||||
wheat_list = [obj for obj in self.veggies_list if obj.name == "wheat" and obj.state == 0]
|
||||
|
||||
new_list = [()]
|
||||
a = 1
|
||||
@ -107,7 +113,7 @@ class Game:
|
||||
if event.type == move_chicken_event:
|
||||
if len(chicken_next_moves) == 0:
|
||||
angles = {0: 'UP', 90: 'RIGHT', 270: 'LEFT', 180: 'DOWN'}
|
||||
closest_wheat = self.search_object.closest_point(self.chicken.x, self.chicken.y, 'wheat', self.plant_list)
|
||||
closest_wheat = self.search_object.closest_point(self.chicken.x, self.chicken.y, 'wheat', self.veggies_list)
|
||||
# self.aim_list[0].xy[0] = closest_wheat[0]
|
||||
# self.aim_list[0].xy[1] = closest_wheat[1]
|
||||
self.aim_list[0].xy[0] = best_path[a][0]
|
||||
@ -115,40 +121,50 @@ class Game:
|
||||
# a += 1
|
||||
# target = wheat_list[a]
|
||||
# chicken_next_moves = self.search_object.astarsearch(
|
||||
# [self.chicken.x, self.chicken.y, angles[self.chicken.angle]], [closest_wheat[0], closest_wheat[1]], self.stone_list, self.plant_list)
|
||||
# [self.chicken.x, self.chicken.y, angles[self.chicken.angle]], [closest_wheat[0], closest_wheat[1]], self.stone_list, self.veggies_list)
|
||||
|
||||
chicken_next_moves = self.search_object.astarsearch(
|
||||
[self.chicken.x, self.chicken.y, angles[self.chicken.angle]], [best_path[a][0], best_path[a][1]], self.stone_list, self.plant_list)
|
||||
[self.chicken.x, self.chicken.y, angles[self.chicken.angle]], [best_path[a][0], best_path[a][1]], self.stone_list, self.veggies_list)
|
||||
|
||||
a += 1
|
||||
#neural_network
|
||||
current_veggie = next(os.walk('./agent/neural_network/images/test'))[1][random.randint(0, len(next(os.walk('./agent/neural_network/images/test'))[1])-1)]
|
||||
if(current_veggie in veggies_debug):
|
||||
veggies_debug[current_veggie]+=1
|
||||
else:
|
||||
veggies_debug[current_veggie] = 1
|
||||
# #neural_network
|
||||
# current_veggie = next(os.walk('./agent/neural_network/images/test'))[1][random.randint(0, len(next(os.walk('./agent/neural_network/images/test'))[1])-1)]
|
||||
# if(current_veggie in veggies_debug):
|
||||
# veggies_debug[current_veggie]+=1
|
||||
# else:
|
||||
# veggies_debug[current_veggie] = 1
|
||||
|
||||
current_veggie_example = next(os.walk(f'./agent/neural_network/images/test/{current_veggie}'))[2][random.randint(0, len(next(os.walk(f'./agent/neural_network/images/test/{current_veggie}'))[2])-1)]
|
||||
predicted_veggie = inference.main(f"./agent/neural_network/images/test/{current_veggie}/{current_veggie_example}")
|
||||
if predicted_veggie in veggies:
|
||||
veggies[predicted_veggie]+=1
|
||||
else:
|
||||
veggies[predicted_veggie] = 1
|
||||
print("Debug veggies: ", veggies_debug, "Predicted veggies: ", veggies)
|
||||
# current_veggie_example = next(os.walk(f'./agent/neural_network/images/test/{current_veggie}'))[2][random.randint(0, len(next(os.walk(f'./agent/neural_network/images/test/{current_veggie}'))[2])-1)]
|
||||
# predicted_veggie = inference.main(f"./agent/neural_network/images/test/{current_veggie}/{current_veggie_example}")
|
||||
# if predicted_veggie in veggies:
|
||||
# veggies[predicted_veggie]+=1
|
||||
# else:
|
||||
# veggies[predicted_veggie] = 1
|
||||
# print("Debug veggies: ", veggies_debug, "Predicted veggies: ", veggies)
|
||||
else:
|
||||
self.chicken.move(chicken_next_moves.pop(0)[0])
|
||||
if len(chicken_next_moves) == 0:
|
||||
self.chicken.water([self.aim_list[0].xy[0], self.aim_list[0].xy[1]], self.plant_list)
|
||||
self.chicken.water([self.aim_list[0].xy[0], self.aim_list[0].xy[1]], self.veggies_list)
|
||||
print(self.chicken.x, self.chicken.y)
|
||||
|
||||
current_block = ''
|
||||
for obj in self.veggies_list:
|
||||
if obj.xy == [self.chicken.x, self.chicken.y]:
|
||||
if obj.name != 'wheat':
|
||||
current_block = obj.image_path
|
||||
if current_block == '':
|
||||
print('the block is empty')
|
||||
else:
|
||||
veggies_images = inference.main(current_block)
|
||||
print('Current veggie: ',veggies_images)
|
||||
elif event.type == QUIT:
|
||||
running = False
|
||||
|
||||
self.surface.fill((123, 56, 51)) # background color
|
||||
self.Field.draw_grass(self.grass_list)
|
||||
self.Plants.draw_plant(self.plant_list)
|
||||
self.Plants.draw_plant(self.fruits_list)
|
||||
#self.Plants.draw_plant(self.plant_list)
|
||||
#self.Plants.draw_plant(self.fruits_list)
|
||||
self.Plants.draw_plant(self.stone_list)
|
||||
self.Plants.draw_plant(self.veggies_list)
|
||||
|
||||
self.Plants.draw_aim(self.aim_list)
|
||||
|
||||
|
BIN
resources/.DS_Store
vendored
BIN
resources/.DS_Store
vendored
Binary file not shown.
BIN
resources/vegies/.DS_Store
vendored
BIN
resources/vegies/.DS_Store
vendored
Binary file not shown.
BIN
resources/vegies/11.png
Normal file
BIN
resources/vegies/11.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
BIN
resources/vegies/12.png
Normal file
BIN
resources/vegies/12.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
BIN
resources/vegies/14.png
Normal file
BIN
resources/vegies/14.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
BIN
resources/vegies/2.png
Normal file
BIN
resources/vegies/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Loading…
Reference in New Issue
Block a user