add days of week
This commit is contained in:
parent
37aca9f70e
commit
ae1cb2900b
24
UI/grid.py
24
UI/grid.py
@ -39,6 +39,9 @@ class Grid:
|
||||
if node.field_type == trash and node.house.empty == False:
|
||||
trash_possition.append((node.row,node.col))
|
||||
return trash_possition
|
||||
|
||||
def day_of_week(self, d: int):
|
||||
return self.table[0][0].house.get_day_of_week(d)
|
||||
|
||||
|
||||
|
||||
@ -62,13 +65,14 @@ class House:
|
||||
plastic = (8,ORANGE,"plastic")
|
||||
|
||||
#define days of the week
|
||||
MONDAY = (paper)
|
||||
TUESDAY = (glass)
|
||||
WEDNESDAY=(plastic,metal)
|
||||
THURSDAY = (glass)
|
||||
FRIDAY = (paper,metal)
|
||||
SATURDAY = (plastic)
|
||||
SUNDAY = (metal)
|
||||
MONDAY = (1, "Monday", paper, metal)
|
||||
TUESDAY = (2, "Tuesday", glass)
|
||||
WEDNESDAY=(3, "Wednesday", plastic, metal)
|
||||
THURSDAY = (4, "Thursday", glass)
|
||||
FRIDAY = (5, "Friday", paper, metal)
|
||||
SATURDAY = (6, "Saturday", plastic)
|
||||
SUNDAY = (7, "Sunday", metal)
|
||||
DAYS = [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]
|
||||
|
||||
|
||||
def __init__(self):
|
||||
@ -104,6 +108,12 @@ class House:
|
||||
self.trash = self.plastic
|
||||
self.trash_file = self.find_trash_file(self.trash)
|
||||
|
||||
def get_day_of_week(self, d: int):
|
||||
for day in self.DAYS:
|
||||
if day[0] == d:
|
||||
return day
|
||||
|
||||
|
||||
|
||||
class Node:
|
||||
# define rectangles dimensions
|
||||
|
72
UI/window.py
72
UI/window.py
@ -1,22 +1,13 @@
|
||||
import pygame as pg
|
||||
import numpy as np
|
||||
import random
|
||||
import itertools as it
|
||||
import math
|
||||
from UI.grid import Grid, Node
|
||||
from Logic.Apath import a_path
|
||||
|
||||
|
||||
class Window():
|
||||
def __init__(self, grid: Grid,start: (int,int),end: (int,int),mode: int):
|
||||
def __init__(self, grid: Grid,start: (int,int),end: (int,int)):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
self.start = start
|
||||
self.end = end
|
||||
self.grid = grid
|
||||
@ -33,38 +24,56 @@ class Window():
|
||||
screen_height = rows * (height + margin) + 2 * margin
|
||||
|
||||
self.screen = pg.display.set_mode([screen_width, screen_height])
|
||||
|
||||
self.end = False
|
||||
|
||||
self.clock = pg.time.Clock()
|
||||
|
||||
|
||||
def obstacles(self, grid: Grid,option: int):
|
||||
if option == 1:
|
||||
for x in range(len(grid.table)*2):
|
||||
grid.generate_trash(random.randint(1,len(grid.table)-1),random.randint(1,len(grid.table)-1))
|
||||
elif option == 2:
|
||||
for x in range (13):
|
||||
grid.change_field(x,14,3)
|
||||
for x in range (8):
|
||||
grid.change_field(12,x+6,3)
|
||||
def random_trash(grid: Grid):
|
||||
for x in range(len(grid.table)*2):
|
||||
grid.generate_trash(random.randint(1,len(grid.table)-1),random.randint(1,len(grid.table)-1))
|
||||
|
||||
|
||||
|
||||
obstacles(self,grid,mode)
|
||||
#generate trash
|
||||
random_trash(grid)
|
||||
grid.change_field(start[0], start[1], 1)
|
||||
grid.change_field(end[0], end[1], 2)
|
||||
|
||||
|
||||
#day of week (random)
|
||||
def garbage_to_collect():
|
||||
garbage = []
|
||||
field_types = []
|
||||
d = random.randint(1,7)
|
||||
day = grid.day_of_week(d)
|
||||
for index, x in enumerate(day):
|
||||
if index != 0 and index != 1:
|
||||
garbage.append(x)
|
||||
print(garbage)
|
||||
print("Today is:", day[1], ", garbage to collect: ",end = '')
|
||||
for x in garbage:
|
||||
print(x[2],", ",end='')
|
||||
field_types.append(x[0])
|
||||
return field_types
|
||||
|
||||
#list of trash to collect
|
||||
to_collect = grid.get_trash_possition(5)
|
||||
print("to collect len: ",len(to_collect))
|
||||
garbage = garbage_to_collect()
|
||||
|
||||
#all obstacles, remove from list objects to collect
|
||||
obs = [3,5,6,7,8]
|
||||
for x in garbage:
|
||||
obs.remove(x)
|
||||
|
||||
#list of garbage to collect
|
||||
to_collect = []
|
||||
for x in garbage:
|
||||
to_collect.extend(grid.get_trash_possition(x))
|
||||
print("\n",len(to_collect)," garbage to collect.")
|
||||
print(to_collect)
|
||||
|
||||
#sort list of tuples to get minimum distance betwen all of them
|
||||
|
||||
#fajnie jakby sie udalo to zrobic wydajniej ale narazie niech bedzie tak
|
||||
sorted(to_collect)
|
||||
to_collect = sorted(to_collect)
|
||||
|
||||
#window init
|
||||
pg.init() # pylint: disable=no-member
|
||||
# setup window
|
||||
pg.display.set_caption('Inteligentna śmieciarka')
|
||||
@ -86,11 +95,10 @@ class Window():
|
||||
print("collected:",grid.table[x][y].house.trash[2],"on possition: (",x,",",y,") ", grid.table[x][y].house.trash_file)
|
||||
|
||||
|
||||
#visit all points from from to_collect
|
||||
|
||||
#visit all points from to_collect
|
||||
|
||||
for ind, x in enumerate(to_collect):
|
||||
#copy table
|
||||
obs = [3,8,6,7]
|
||||
|
||||
if ind == 0:
|
||||
array = [[self.grid.table[col][row] for row in range(cols)] for col in range(rows)]
|
||||
path = a_path(array,(start[0],start[1]),(x[0],x[1]),obs)
|
||||
|
Loading…
Reference in New Issue
Block a user