From 8704aacde8c0a868d4055ebd20f228064ba96866 Mon Sep 17 00:00:00 2001 From: Milosz Rolewski Date: Thu, 25 May 2023 18:11:06 +0200 Subject: [PATCH] WORLD_MATRIX evaluation --- __pycache__/settings.cpython-310.pyc | Bin 555 -> 606 bytes main.py | 13 +++++++-- settings.py | 7 +++-- src/Field.py | 10 ++++++- src/ID3.py | 39 +++++++++++++++++++++----- src/Plant.py | 23 ++++++++++++--- src/__pycache__/Field.cpython-310.pyc | Bin 802 -> 1132 bytes src/__pycache__/Plant.cpython-310.pyc | Bin 1340 -> 1656 bytes src/__pycache__/map.cpython-310.pyc | Bin 2932 -> 3164 bytes src/map.py | 30 ++++++++++++-------- src/trained_tree.txt | 7 ----- 11 files changed, 95 insertions(+), 34 deletions(-) delete mode 100644 src/trained_tree.txt diff --git a/__pycache__/settings.cpython-310.pyc b/__pycache__/settings.cpython-310.pyc index 952eafd768579a41ca219d3bd12f9052649526d2..0af80cb05eeb962a636735d62d8559a31d3f8fff 100644 GIT binary patch delta 231 zcmZ3@a*u^KpO=@50SJm4@>5<-&OB7#a= zFl4TnI8R-dMhpt%*2wSTdc)-nW^cw*iur9tCFiUnO>>@H5PG$iHVmq z83iW(F=FJOtj}o4!5;4F7~q0 J5Q0b{CIHXVHTnPm delta 181 zcmcb|vYLfApO=@50SFG{=A|r{$ScbjHBnpLCxtbNErl(LJ)I$ieGy|6M+!$2ClGU` za;9>LFhp^ua7OW@aHVjk@TBmj@XcX~;!WWXX3!LP2{KBP@fJ&QVNpru1{MZ}%oh`v zsq-?uQ~^p9v4e?;zcd+nCaW+SG4f3gXSAF=lQEf15hSBHnTg3pP7286VPIiqVdMZp O7A6qQ0)!w^hzS70)+4b1 diff --git a/main.py b/main.py index 99686d4..af5e54f 100644 --- a/main.py +++ b/main.py @@ -2,10 +2,12 @@ import pygame import sys import random 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.Plant import Plant from src.bfs import Astar +from src.Field import Field + # pygame initialization pygame.init() @@ -40,8 +42,15 @@ tractor_move = pygame.USEREVENT + 1 pygame.time.set_timer(tractor_move, 800) moves = [] 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) +mx=int((mx+18)/36) +my=int((my+18)/36) +print("Destination: ", mx,my) +tmp = WORLD_MATRIX[mx][my] + moves = goal_astar.search( [tractor.rect.x, tractor.rect.y, directions[tractor.rotation]], destination) diff --git a/settings.py b/settings.py index ed0d402..53f1734 100644 --- a/settings.py +++ b/settings.py @@ -1,10 +1,13 @@ from cmath import sqrt -screen_width=1200#936 -screen_height=1000#936 +screen_width=1200 +#screen_width=936 +# screen_height=1000 +screen_height=936 SIZE = (screen_width, screen_height) SPECIES=["carrot","potato","beetroot","wheat"] +WEATHER=['slonce','wiatr','snieg','deszcz'] # size in pixels of one tile = 36px/36px tile = (36, 36) block_size = 36 diff --git a/src/Field.py b/src/Field.py index fedc537..6d6b599 100644 --- a/src/Field.py +++ b/src/Field.py @@ -1,8 +1,9 @@ from pygame.sprite import Sprite +from src.Plant import Plant class Field(Sprite): 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__() self.type = type self.x = x @@ -18,4 +19,11 @@ class Field(Sprite): self.plant_type = plant_type self.fertilizer_type = fertilizer_type self.to_water = to_water + self.plantObj = plantObj + + def getPlantObj(self): + return self.plantObj + + def setPlantObj(self,newPlant): + self.plantObj=newPlant diff --git a/src/ID3.py b/src/ID3.py index 7b488e6..d0357a5 100644 --- a/src/ID3.py +++ b/src/ID3.py @@ -1,11 +1,36 @@ import pandas as pd -from sklearn.tree import DecisionTreeClassifier, export_text -from sklearn.preprocessing import LabelEncoder -from sklearn.model_selection import train_test_split -from sklearn import metrics +from sklearn.tree import DecisionTreeClassifier +import pickle +import os +from sklearn import tree +import pydotplus +import matplotlib.image as pltimg +import matplotlib.pyplot as plt # 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() -y.head() \ No newline at end of file +x_train = train.drop('czy_zebrac',axis=1) +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() \ No newline at end of file diff --git a/src/Plant.py b/src/Plant.py index 11e8cc4..b0ee9e1 100644 --- a/src/Plant.py +++ b/src/Plant.py @@ -2,11 +2,24 @@ import pygame from settings import block_size 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__() 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": self.growth_time=100 self.weight=50 @@ -47,4 +60,6 @@ class Plant(pygame.sprite.Sprite): self.image = pygame.transform.scale(self.image,(block_size, block_size)) self.rect = self.image.get_rect() self.rect.center = [pos_x,pos_y] - \ No newline at end of file + +def getParameters(self): + return [self.species, self.wzrost, self.wilgotnosc, self.dni_od_nawiezienia,self.aktualna_pogoda,self.czy_robaczywa,self.cena_sprzedarzy] \ No newline at end of file diff --git a/src/__pycache__/Field.cpython-310.pyc b/src/__pycache__/Field.cpython-310.pyc index 350b21c3770344292ff5d6033f151161f1777666..7300160e4f4417f2fa847552b8ea741f69c85054 100644 GIT binary patch literal 1132 zcmZXTOK;RL5XbGjHk69Uf}N%8$`XfG^eb?L z<9;PyIq?-ZG2`u)NI06G#^ZSY$#`53hY5l4{aeky`h@(#Np}P=c>$)M0yyDRl8R=O zqVGws@-v^3H-!5bVai8ngk?^K%-~F*QJoW7-8X?3);vm_BgFB*1~$0S?UoI5I=vn3EH-rpM{7 z4fUcC%EpY9^Ri{k2JNyDmVU8xY2&8WWn0#B8>_XRi`;AP&OW3g$S>qn z#ZVg6M_>!60b+>20;(}$7qN%fM;ssy5qAJBm4H@C7^`Z&kmwH>`?SdA zX2sQ0J%&sQ3u=cq$5IF>8SALu!&mVC72az!ja?9v0gVrKeHT4WLpyAiGtfNJ?&d1| kW7~%lJlgyY-YoZSC$+1uD{cI2^Oeu>WZbC?ApfEF7d6)ZE&u=k delta 382 zcmYjMu};G<5Ix&T8Uij15nTde0Vxvd4^T0}Ruy&2Vyf7n2!~d78DK#OBt{fvV(oA6 zCmGq0_y~L!LoD6XJ^S7ByWe;d4VRoJ;LhIFo&2KBFq<7YCP5MnH7N*zOORBuH;_z` zS5{CN%pnhda408TG+&u&txBZ*!~TiQnvc=xI|NYR9P7f1N@-d0o)~-T3TNzf^DVX{ zI4zmxyX}m89_G9YtkO3oaso3zh!HTj*=`5)q@B>SBy==zWwZ8$9;69*8v4J+LR9zF zT8KPsH|+QsbsZO?)C+4%rL_=dAFVv3*o_b{j*o<?U zlml?$fFhr`CC|W>C+H(s;*P`%aOA({t0&f)-_Gp*XJ^;DU(6qt6Wg}Q&_2A6>8r7D zc6fiWciXN|^&NXzCH|E4^u?t#8Mn(%E}107li-Ka$y=xfvhe`ycv)J9-Y z2efGubZ857(?-}_A~|$d^3+Yl>r14E&9s%aj+B)wh!Rk>R}6k9GqTzUqhZI}{QRA_ zIN!>-x^p<4i8x6Mb2^@k;xvkrVX;Qh*o(=F{OLHDje}_H7p{Mtp81o=_fF$cOnzYx zXXl=XU;F5%m>&k1OHRcsAYaVR^Bd}?n`WUU!Q@En;L5~RiE9$O5?zVw65IKO`mFsN zu4z{J<xp7ybEU#d#3ClJpr?y%DF45?9v63|=-(Fh5f=8S8>CNs;hzL)Ad-g|OBA5X#Q+_a?&aUKTlZve cDYsmuT)-Hd#B??Z9>|?124FCYZz$H_C-5k+0{{R3 delta 527 zcmYL`%SyvQ6ozM#nMs8GyKTwO*^V63<&)H# zKSOIBHX>c)jAiVZP5F#*mh+s2R&IfI&WYb!$rkBMkPS)_pdtx6q(GM(utYBC4bI>x z!E-_$a$zW`oU^AtlW$BFV+xF^1JfK#S3iw(J4sbgnRX7m3z?3FQBt^J7!Tqs3=1b6MmKSk7Aj7|xZj_=*{^{tL>l#PlV$wcWMy(K zF8nT}#}%e)O+LlT-oD;5=xBAIp`St^QVo|ixvA`^WOK5rw%h*}qqL=Pj~*Ur)Q^tw MfGkzU=krDD8yz}tz5oCK diff --git a/src/__pycache__/map.cpython-310.pyc b/src/__pycache__/map.cpython-310.pyc index ea4355d1a3c0ff1da6ef1a50e0e1c8f03ed6f811..85981300e298bc92b0920c3ce500f51b058586d4 100644 GIT binary patch delta 1044 zcmZvb&rcIU6vt;~e|Bk0#R??`5JaFx5Tge}j6X>Pqxb_*LnO`8+2A7XmbYV&W*ba2 zo+O%#7jM*?i3j~Byz14Be}KKJi5@)orbRBgoBhoD@tw(=d9yz{zZ9}zCgTu%UOWl; z+uZx?H%1$hYOAzg2HNMt1DJxYT@;jc2r-CX#1I25ABN;jOzSA`( zEMbe(W6D_&v!WtT?#za@aH#D&;t8O5!F0II)#&tR@r_J8c zeiXnyrP5r^A*ZbLt*bXKPnNEno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