IDE3 #12
Binary file not shown.
13
main.py
13
main.py
@ -2,10 +2,12 @@ import pygame
|
|||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
from settings import screen_height, screen_width, SIZE, SPECIES, block_size, tile, road_coords, directions
|
from settings import screen_height, screen_width, SIZE, SPECIES, block_size, tile, road_coords, directions
|
||||||
from src.map import drawRoads, seedForFirstTime, return_fields_list
|
from src.map import drawRoads, seedForFirstTime, return_fields_list, WORLD_MATRIX
|
||||||
from src.Tractor import Tractor
|
from src.Tractor import Tractor
|
||||||
from src.Plant import Plant
|
from src.Plant import Plant
|
||||||
from src.bfs import Astar
|
from src.bfs import Astar
|
||||||
|
from src.Field import Field
|
||||||
|
|
||||||
|
|
||||||
# pygame initialization
|
# pygame initialization
|
||||||
pygame.init()
|
pygame.init()
|
||||||
@ -40,8 +42,15 @@ tractor_move = pygame.USEREVENT + 1
|
|||||||
pygame.time.set_timer(tractor_move, 800)
|
pygame.time.set_timer(tractor_move, 800)
|
||||||
moves = []
|
moves = []
|
||||||
goal_astar = Astar()
|
goal_astar = Astar()
|
||||||
destination = (random.randrange(0, 936, 36), random.randrange(0, 900, 36))
|
mx=random.randrange(0, 936, 36)
|
||||||
|
my=random.randrange(0, 936, 36)
|
||||||
|
destination = (mx, my)
|
||||||
print("Destination: ", destination)
|
print("Destination: ", destination)
|
||||||
|
mx=int((mx+18)/36)
|
||||||
|
my=int((my+18)/36)
|
||||||
|
print("Destination: ", mx,my)
|
||||||
|
tmp = WORLD_MATRIX[mx][my]
|
||||||
|
|
||||||
moves = goal_astar.search(
|
moves = goal_astar.search(
|
||||||
[tractor.rect.x, tractor.rect.y, directions[tractor.rotation]], destination)
|
[tractor.rect.x, tractor.rect.y, directions[tractor.rotation]], destination)
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
from cmath import sqrt
|
from cmath import sqrt
|
||||||
|
|
||||||
|
|
||||||
screen_width=1200#936
|
screen_width=1200
|
||||||
screen_height=1000#936
|
#screen_width=936
|
||||||
|
# screen_height=1000
|
||||||
|
screen_height=936
|
||||||
SIZE = (screen_width, screen_height)
|
SIZE = (screen_width, screen_height)
|
||||||
SPECIES=["carrot","potato","beetroot","wheat"]
|
SPECIES=["carrot","potato","beetroot","wheat"]
|
||||||
|
WEATHER=['slonce','wiatr','snieg','deszcz']
|
||||||
# size in pixels of one tile = 36px/36px
|
# size in pixels of one tile = 36px/36px
|
||||||
tile = (36, 36)
|
tile = (36, 36)
|
||||||
block_size = 36
|
block_size = 36
|
||||||
|
10
src/Field.py
10
src/Field.py
@ -1,8 +1,9 @@
|
|||||||
from pygame.sprite import Sprite
|
from pygame.sprite import Sprite
|
||||||
|
from src.Plant import Plant
|
||||||
|
|
||||||
class Field(Sprite):
|
class Field(Sprite):
|
||||||
def __init__(self, type, x, y, image, cost, hydration_level , soil,
|
def __init__(self, type, x, y, image, cost, hydration_level , soil,
|
||||||
fertilizer_degree, development_degree, plant_type, fertilizer_type, to_water):
|
fertilizer_degree, development_degree, plant_type, fertilizer_type, to_water, plantObj):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.type = type
|
self.type = type
|
||||||
self.x = x
|
self.x = x
|
||||||
@ -18,4 +19,11 @@ class Field(Sprite):
|
|||||||
self.plant_type = plant_type
|
self.plant_type = plant_type
|
||||||
self.fertilizer_type = fertilizer_type
|
self.fertilizer_type = fertilizer_type
|
||||||
self.to_water = to_water
|
self.to_water = to_water
|
||||||
|
self.plantObj = plantObj
|
||||||
|
|
||||||
|
def getPlantObj(self):
|
||||||
|
return self.plantObj
|
||||||
|
|
||||||
|
def setPlantObj(self,newPlant):
|
||||||
|
self.plantObj=newPlant
|
||||||
|
|
||||||
|
39
src/ID3.py
39
src/ID3.py
@ -1,11 +1,36 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sklearn.tree import DecisionTreeClassifier, export_text
|
from sklearn.tree import DecisionTreeClassifier
|
||||||
from sklearn.preprocessing import LabelEncoder
|
import pickle
|
||||||
from sklearn.model_selection import train_test_split
|
import os
|
||||||
from sklearn import metrics
|
from sklearn import tree
|
||||||
|
import pydotplus
|
||||||
|
import matplotlib.image as pltimg
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
# Read the CSV file
|
# Read the CSV file
|
||||||
data = pd.read_csv("train_2.csv", delimiter=";")
|
train = pd.read_csv("train_2.csv", delimiter=";")
|
||||||
|
|
||||||
y = data[['czy_zebrac']].copy()
|
x_train = train.drop('czy_zebrac',axis=1)
|
||||||
y.head()
|
y_train = train['czy_zebrac']
|
||||||
|
|
||||||
|
d_tree = DecisionTreeClassifier()
|
||||||
|
d_tree = d_tree.fit(x_train,y_train)
|
||||||
|
|
||||||
|
# Save the decision tree model as a pickle file in the script's folder
|
||||||
|
pickle.dump(d_tree, open('tree.plk', 'wb'))
|
||||||
|
|
||||||
|
# Export the decision tree as DOT data
|
||||||
|
data = tree.export_graphviz(d_tree, out_file=None)
|
||||||
|
|
||||||
|
# Create a graph from the DOT data
|
||||||
|
graph = pydotplus.graph_from_dot_data(data)
|
||||||
|
|
||||||
|
# Save the graph as a PNG image in the script's folder
|
||||||
|
graph.write_png(os.path.join('.', 'mytree.png'))
|
||||||
|
|
||||||
|
# Read the PNG image
|
||||||
|
img = pltimg.imread(os.path.join('.', 'mytree.png'))
|
||||||
|
|
||||||
|
# Display the image
|
||||||
|
imgplot = plt.imshow(img)
|
||||||
|
plt.show()
|
21
src/Plant.py
21
src/Plant.py
@ -2,11 +2,24 @@ import pygame
|
|||||||
from settings import block_size
|
from settings import block_size
|
||||||
|
|
||||||
class Plant(pygame.sprite.Sprite):
|
class Plant(pygame.sprite.Sprite):
|
||||||
def __init__(self,species,is_ill,pos_x,pos_y):
|
def __init__(self,wzrost,
|
||||||
|
wilgotnosc,
|
||||||
|
dni_od_nawiezienia,
|
||||||
|
aktualna_pogoda,
|
||||||
|
czy_robaczywa,
|
||||||
|
cena_sprzedarzy,
|
||||||
|
species,
|
||||||
|
pos_x,
|
||||||
|
pos_y):
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.species=species
|
self.species=species
|
||||||
self.is_ill=is_ill
|
self.wzrost=wzrost
|
||||||
|
self.wilgotnosc=wilgotnosc
|
||||||
|
self.dni_od_nawiezienia=dni_od_nawiezienia
|
||||||
|
self.aktualna_pogoda=aktualna_pogoda
|
||||||
|
self.czy_robaczywa=czy_robaczywa
|
||||||
|
self.cena_sprzedarzy=cena_sprzedarzy
|
||||||
if species=="carrot":
|
if species=="carrot":
|
||||||
self.growth_time=100
|
self.growth_time=100
|
||||||
self.weight=50
|
self.weight=50
|
||||||
@ -48,3 +61,5 @@ class Plant(pygame.sprite.Sprite):
|
|||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.center = [pos_x,pos_y]
|
self.rect.center = [pos_x,pos_y]
|
||||||
|
|
||||||
|
def getParameters(self):
|
||||||
|
return [self.species, self.wzrost, self.wilgotnosc, self.dni_od_nawiezienia,self.aktualna_pogoda,self.czy_robaczywa,self.cena_sprzedarzy]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
30
src/map.py
30
src/map.py
@ -33,7 +33,7 @@ def get_cost_by_type(plant_type):
|
|||||||
fields = pygame.sprite.Group()
|
fields = pygame.sprite.Group()
|
||||||
|
|
||||||
|
|
||||||
world_matrix = [[0 for _ in range(fields_amount+1)] for _ in range(fields_amount+1)]
|
WORLD_MATRIX = [[0 for _ in range(fields_amount+1)] for _ in range(fields_amount+1)]
|
||||||
|
|
||||||
def drawRoads(screen):
|
def drawRoads(screen):
|
||||||
#drawing roads:
|
#drawing roads:
|
||||||
@ -42,15 +42,15 @@ def drawRoads(screen):
|
|||||||
for x in road_coords:
|
for x in road_coords:
|
||||||
for block in range(int(fields_amount)+1):
|
for block in range(int(fields_amount)+1):
|
||||||
screen.blit(road, (x*block_size, block * 36))
|
screen.blit(road, (x*block_size, block * 36))
|
||||||
tmp_field=Field('road', x*block_size, block * 36, None, get_cost_by_type('road'), None, None, None, None, 'road', None, None)
|
tmp_field=Field('road', x*block_size, block * 36, None, get_cost_by_type('road'), None, None, None, None, 'road', None, None,plantObj=None)
|
||||||
fields.add(tmp_field)
|
fields.add(tmp_field)
|
||||||
world_matrix[x][block]=Road(x,block)
|
WORLD_MATRIX[x][block]=Road(x,block)
|
||||||
for y in road_coords:
|
for y in road_coords:
|
||||||
for block in range(int(fields_amount)+1):
|
for block in range(int(fields_amount)+1):
|
||||||
screen.blit(road, (block * block_size, y*block_size))
|
screen.blit(road, (block * block_size, y*block_size))
|
||||||
tmp_field=Field('road', block * block_size, y*block_size, None, get_cost_by_type('road'), None, None, None, None, 'road', None, None)
|
tmp_field=Field('road', block * block_size, y*block_size, None, get_cost_by_type('road'), None, None, None, None, 'road', None, None,plantObj=None)
|
||||||
fields.add(tmp_field)
|
fields.add(tmp_field)
|
||||||
world_matrix[block][y]=Road(block,y)
|
WORLD_MATRIX[block][y]=Road(block,y)
|
||||||
|
|
||||||
|
|
||||||
barn_img = pygame.image.load('assets/barn.png')
|
barn_img = pygame.image.load('assets/barn.png')
|
||||||
@ -68,21 +68,29 @@ def seedForFirstTime():
|
|||||||
|
|
||||||
x = (((field%5)*((block_size*(field_width+1)))) + ((blocks_seeded_in_field % field_width)*block_size) + ((3/2)*block_size))
|
x = (((field%5)*((block_size*(field_width+1)))) + ((blocks_seeded_in_field % field_width)*block_size) + ((3/2)*block_size))
|
||||||
y = ((int(field/5)*((block_size*(field_width+1)))) + ((int(blocks_seeded_in_field/field_height))*block_size) + ((3/2)*block_size))
|
y = ((int(field/5)*((block_size*(field_width+1)))) + ((int(blocks_seeded_in_field/field_height))*block_size) + ((3/2)*block_size))
|
||||||
|
# wzrost;wilgotnosc;dni_od_nawiezienia;aktualna_pogoda;czy_roslina_robaczywa;typ_rosliny;pojemnosc_ekwipunku;cena_sprzedarzy;czy_zebrac
|
||||||
|
|
||||||
new_plant = Plant(plant_name,0, x, y)
|
new_plant = Plant(
|
||||||
|
wzrost=random.randint(0, 100),
|
||||||
|
wilgotnosc=random.randint(0, 100),
|
||||||
|
dni_od_nawiezienia=random.randint(0, 31),
|
||||||
|
aktualna_pogoda='_',
|
||||||
|
czy_robaczywa=random.randint(0, 1),
|
||||||
|
cena_sprzedarzy=random.randint(500, 2000),
|
||||||
|
species=plant_name,
|
||||||
|
pos_x=x,
|
||||||
|
pos_y=y)
|
||||||
blocks_seeded_in_field = blocks_seeded_in_field + 1
|
blocks_seeded_in_field = blocks_seeded_in_field + 1
|
||||||
plant_group.add(new_plant)
|
plant_group.add(new_plant)
|
||||||
tmp_field_plant = Field('field', x-18, y-18, None, get_cost_by_type(plant_name), None, None, None, None, plant_name, None, None)
|
tmp_field_plant = Field('field', x-18, y-18, None, get_cost_by_type(plant_name), None, None, None, None, plant_name, None, None, plantObj=new_plant)
|
||||||
fields.add(tmp_field_plant)
|
fields.add(tmp_field_plant)
|
||||||
|
|
||||||
mx = int((x-18)/36)
|
mx = int((x-18)/36)
|
||||||
my = int((y-18)/36)
|
my = int((y-18)/36)
|
||||||
world_matrix[mx][my]=tmp_field_plant
|
WORLD_MATRIX[mx][my]=tmp_field_plant
|
||||||
|
|
||||||
# for i in range(1,4):
|
|
||||||
# world_matrix[mx][my+i]=tmp_field_plant
|
|
||||||
#debug
|
#debug
|
||||||
print(world_matrix)
|
# print(WORLD_MATRIX)
|
||||||
#end of debug
|
#end of debug
|
||||||
|
|
||||||
return plant_group
|
return plant_group
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
|--- czy_roslina_robaczywa <= 0.50
|
|
||||||
| |--- class: 0
|
|
||||||
|--- czy_roslina_robaczywa > 0.50
|
|
||||||
| |--- dni_od_nawiezienia <= 9.50
|
|
||||||
| | |--- class: 0
|
|
||||||
| |--- dni_od_nawiezienia > 9.50
|
|
||||||
| | |--- class: 1
|
|
Loading…
Reference in New Issue
Block a user