From 01764a4d63f1aab5128a902c3a2f10580749d49d Mon Sep 17 00:00:00 2001 From: Michal Kijowski Date: Tue, 28 Apr 2020 10:19:34 +0000 Subject: [PATCH] Upload files to '' --- shelf.py | 73 +++++++++++++++++++++++++++++ unboxOnTheFloor.py | 10 ++++ wall.py | 12 +++++ wheel.py | 114 +++++++++++++++++++++++++++++++++++++++++++++ whereDecision.py | 60 ++++++++++++++++++++++++ 5 files changed, 269 insertions(+) create mode 100644 shelf.py create mode 100644 unboxOnTheFloor.py create mode 100644 wall.py create mode 100644 wheel.py create mode 100644 whereDecision.py diff --git a/shelf.py b/shelf.py new file mode 100644 index 0000000..a400c44 --- /dev/null +++ b/shelf.py @@ -0,0 +1,73 @@ +import pygame + +class Shelf: + def __init__(self, screen, cell, we, ns, kierunek, rodzaj): + self.kierunek = kierunek + self.rodzaj = rodzaj + self.cell = cell + self.ns = ns + self.we = we + self.screen = screen + self.occupied = False + self.box = False + if (rodzaj==1): + self.image = pygame.image.load(r'images/kr.png') + elif (rodzaj==2): + self.image = pygame.image.load(r'images/la.png') + elif (rodzaj==3): + self.image = pygame.image.load(r'images/ra.png') + elif (rodzaj==4): + self.image = pygame.image.load(r'images/ni.png') + else: + self.image = pygame.image.load(r'images/in.png') + self.image = pygame.transform.scale(self.image, (cell, cell)) + if (kierunek==1): + self.image = pygame.transform.rotate(self.image, 180) + elif (kierunek==2): + self.image = pygame.transform.rotate(self.image, 270) + elif (kierunek==3): + self.image = pygame.transform.rotate(self.image, 90) + def isOccupied(self): + return self.occupied + def put(self, boxik): + self.occupied = True + self.box = boxik + if (self.rodzaj==1): + self.image = pygame.image.load(r'images/krp.png') + elif (self.rodzaj==2): + self.image = pygame.image.load(r'images/lap.png') + elif (self.rodzaj==3): + self.image = pygame.image.load(r'images/rap.png') + elif (self.rodzaj==4): + self.image = pygame.image.load(r'images/nip.png') + else: + self.image = pygame.image.load(r'images/inp.png') + self.image = pygame.transform.scale(self.image, (self.cell, self.cell)) + if (self.kierunek==1): + self.image = pygame.transform.rotate(self.image, 180) + elif (self.kierunek==2): + self.image = pygame.transform.rotate(self.image, 270) + elif (self.kierunek==3): + self.image = pygame.transform.rotate(self.image, 90) + def get(self): + self.occupied = False + if (self.rodzaj==1): + self.image = pygame.image.load(r'images/kr.png') + elif (self.rodzaj==2): + self.image = pygame.image.load(r'images/la.png') + elif (self.rodzaj==3): + self.image = pygame.image.load(r'images/ra.png') + elif (self.rodzaj==4): + self.image = pygame.image.load(r'images/ni.png') + else: + self.image = pygame.image.load(r'images/in.png') + self.image = pygame.transform.scale(self.image, (self.cell, self.cell)) + if (self.kierunek==1): + self.image = pygame.transform.rotate(self.image, 180) + elif (self.kierunek==2): + self.image = pygame.transform.rotate(self.image, 270) + elif (self.kierunek==3): + self.image = pygame.transform.rotate(self.image, 90) + return self.box + def draw(self): + self.screen.blit(self.image, (self.cell*self.ns, self.cell*self.we)) \ No newline at end of file diff --git a/unboxOnTheFloor.py b/unboxOnTheFloor.py new file mode 100644 index 0000000..8e2ab0e --- /dev/null +++ b/unboxOnTheFloor.py @@ -0,0 +1,10 @@ +import pygame + +class UnboxOnTheFloor: + def __init__(self, screen, cell, we, ns): + self.cell = cell + self.ns = ns + self.we = we + self.screen = screen + def draw(self): + pass \ No newline at end of file diff --git a/wall.py b/wall.py new file mode 100644 index 0000000..269419b --- /dev/null +++ b/wall.py @@ -0,0 +1,12 @@ +import pygame + +class Wall: + def __init__(self, screen, cell, we, ns): + self.cell = cell + self.ns = ns + self.we = we + self.screen = screen + self.image = pygame.image.load(r'images/sc.png') + self.image = pygame.transform.scale(self.image, (cell, cell)) + def draw(self): + self.screen.blit(self.image, (self.cell*self.ns, self.cell*self.we)) \ No newline at end of file diff --git a/wheel.py b/wheel.py new file mode 100644 index 0000000..32fe8b1 --- /dev/null +++ b/wheel.py @@ -0,0 +1,114 @@ +import pygame +from floor import Floor +from boxOnTheFloor import BoxOnTheFloor +from unboxOnTheFloor import UnboxOnTheFloor +from shelf import Shelf + +class Wheel: + def __init__(self, screen, cell): + self.cell = cell + self.ns = 1 + self.we = 2 + self.direction = 3 + self.m_ns = 0 + self.m_we = 0 + self.occupied = False + self.box = False + # 1 - w gore + # 2 - w prawo + # 3 - w dol + # 4 - w lewo + self.screen = screen + self.imageorg = pygame.image.load(r'images/wo.png') + self.imageorg = pygame.transform.scale(self.imageorg, (cell, cell)) + self.image = pygame.transform.scale(self.imageorg, (cell, cell)) + def draw(self): + self.screen.blit(self.image, ((self.cell*self.we)+self.m_we, (self.cell*self.ns)+self.m_ns)) + self.m_ns = self.m_ns*(0.9) + self.m_we = self.m_we*(0.9) + def isOccupied(self): + return self.occupied + def putBox(self, boxik): + self.box = boxik + self.occupied = True + self.imageorg = pygame.image.load(r'images/wop.png') + self.imageorg = pygame.transform.scale(self.imageorg, (self.cell, self.cell)) + self.image = pygame.transform.scale(self.imageorg, (self.cell, self.cell)) + def getBox(self): + self.occupied = False + self.imageorg = pygame.image.load(r'images/wo.png') + self.imageorg = pygame.transform.scale(self.imageorg, (self.cell, self.cell)) + self.image = pygame.transform.scale(self.imageorg, (self.cell, self.cell)) + return self.box + def move(self, move, krata): + if(move.key==pygame.K_DOWN): + if(type(krata[self.ns][self.we])==UnboxOnTheFloor): + pass + elif(type(krata[self.ns+1][self.we])==Floor): + self.ns+=1 + self.m_ns=self.cell*(-1) + self.direction = 3 + elif(type(krata[self.ns+1][self.we])==Shelf): + if(self.occupied==True and krata[self.ns+1][self.we].isOccupied()==False and krata[self.ns+1][self.we].kierunek==1): + krata[self.ns+1][self.we].put(self.getBox()) + self.direction = 3 + elif(self.occupied==False and krata[self.ns+1][self.we].isOccupied()==True and krata[self.ns+1][self.we].kierunek==1): + self.putBox(krata[self.ns+1][self.we].get()) + self.direction = 3 + elif(type(krata[self.ns+1][self.we])==UnboxOnTheFloor): + if(self.ns+1==len(krata)-1): + self.ns+=1 + self.m_ns=self.cell*(-1) + self.direction = 1 + self.getBox() + elif(move.key==pygame.K_UP): + if(type(krata[self.ns-1][self.we])==Floor): + self.ns-=1 + self.m_ns=self.cell + self.direction = 1 + elif(type(krata[self.ns-1][self.we])==BoxOnTheFloor): + if(self.occupied==False): + self.putBox(krata[self.ns - 1][self.we].get()) + krata[self.ns - 1][self.we] = Floor(self.screen, self.cell, self.ns - 1, self.we) + self.ns -= 1 + self.m_ns = self.cell + self.direction = 1 + elif(type(krata[self.ns-1][self.we])==Shelf): + if(self.occupied==True and krata[self.ns-1][self.we].isOccupied()==False and krata[self.ns-1][self.we].kierunek==0): + krata[self.ns-1][self.we].put(self.getBox()) + self.direction = 1 + elif(self.occupied==False and krata[self.ns-1][self.we].isOccupied()==True and krata[self.ns-1][self.we].kierunek==0): + self.putBox(krata[self.ns-1][self.we].get()) + self.direction = 1 + elif(move.key==pygame.K_LEFT): + if(type(krata[self.ns][self.we-1])==Floor): + self.we-=1 + self.m_we=self.cell + self.direction = 4 + elif(type(krata[self.ns][self.we-1])==Shelf): + if(self.occupied==True and krata[self.ns][self.we-1].isOccupied()==False and krata[self.ns][self.we-1].kierunek==3): + krata[self.ns][self.we-1].put(self.getBox()) + self.direction = 4 + elif(self.occupied==False and krata[self.ns][self.we-1].isOccupied()==True and krata[self.ns][self.we-1].kierunek==3): + self.putBox(krata[self.ns][self.we-1].get()) + self.direction = 4 + elif(move.key==pygame.K_RIGHT): + if(type(krata[self.ns][self.we+1])==Floor): + self.we+=1 + self.m_we=self.cell*(-1) + self.direction = 2 + elif(type(krata[self.ns][self.we+1])==Shelf): + if(self.occupied==True and krata[self.ns][self.we+1].isOccupied()==False and krata[self.ns][self.we+1].kierunek==2): + krata[self.ns][self.we+1].put(self.getBox()) + self.direction = 2 + elif(self.occupied==False and krata[self.ns][self.we+1].isOccupied()==True and krata[self.ns][self.we+1].kierunek==2): + self.putBox(krata[self.ns][self.we+1].get()) + self.direction = 2 + if (self.direction==1): + self.image = pygame.transform.rotate(self.imageorg, 180) + elif (self.direction==2): + self.image = pygame.transform.rotate(self.imageorg, 90) + elif (self.direction==3): + self.image = pygame.transform.rotate(self.imageorg, 0) + elif (self.direction==4): + self.image = pygame.transform.rotate(self.imageorg, 270) diff --git a/whereDecision.py b/whereDecision.py new file mode 100644 index 0000000..786ecd2 --- /dev/null +++ b/whereDecision.py @@ -0,0 +1,60 @@ +import pandas as pd +import graphviz +import sklearn +from sklearn.tree import DecisionTreeClassifier +from ast import literal_eval as make_tuple + +class WhereDecision: + def __init__(self): + pass + + def recognize(self, recognize, regals): + zwykle = [] + kruche = [] + latwopalne = [] + radioaktywne = [] + niebezpieczne = [] + lokacja = [] + for regal in regals: + if (regal[2] == 1): + zwykle.append(0) + kruche.append(1) + latwopalne.append(0) + radioaktywne.append(0) + niebezpieczne.append(0) + lokacja.append(str("("+str(regal[0])+", "+str(regal[1])+")")) + elif (regal[2] == 2): + zwykle.append(0) + kruche.append(0) + latwopalne.append(1) + radioaktywne.append(0) + niebezpieczne.append(0) + lokacja.append(str("("+str(regal[0])+", "+str(regal[1])+")")) + elif (regal[2] == 3): + zwykle.append(0) + kruche.append(0) + latwopalne.append(0) + radioaktywne.append(1) + niebezpieczne.append(0) + lokacja.append(str("("+str(regal[0])+", "+str(regal[1])+")")) + elif (regal[2] == 4): + zwykle.append(0) + kruche.append(0) + latwopalne.append(0) + radioaktywne.append(0) + niebezpieczne.append(1) + lokacja.append(str("("+str(regal[0])+", "+str(regal[1])+")")) + else: + zwykle.append(1) + kruche.append(0) + latwopalne.append(0) + radioaktywne.append(0) + niebezpieczne.append(0) + lokacja.append(str("("+str(regal[0])+", "+str(regal[1])+")")) + z = list(zip(zwykle, kruche, latwopalne, radioaktywne, niebezpieczne)) + prenumeratorzy = pd.DataFrame({"lokacja": lokacja}) + prenumeratorzy["lokacja"], lokacja_kody = pd.factorize(prenumeratorzy["lokacja"]) + y = prenumeratorzy["lokacja"] + drzewko = DecisionTreeClassifier(criterion="entropy") + drzewko.fit(X=z, y=y) + return list(make_tuple(lokacja_kody[drzewko.predict(recognize)][0])) \ No newline at end of file