Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge master into hm7 #29

Merged
merged 68 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
d3b216f
please
lldckv Mar 31, 2023
c8a69ca
what is up with isort
lldckv Mar 31, 2023
227c12f
after branch renaming 2
lldckv Mar 31, 2023
b2947dd
after branch renaming 3
lldckv Mar 31, 2023
6e4ae6f
after branch renaming 5
lldckv Mar 31, 2023
2a6d8fb
after branch renaming 6
lldckv Mar 31, 2023
7d3ec82
after branch renaming 7
lldckv Mar 31, 2023
1503bf9
it will fail with isort
lldckv Mar 31, 2023
e376ca9
fixed
lldckv Mar 31, 2023
1ca4dc5
fixed 2
lldckv Mar 31, 2023
a741b59
please
May 16, 2023
201bf1d
please fix
May 16, 2023
742dbd2
please fix 2
May 16, 2023
3ea841d
please fix 3
May 16, 2023
f3b9ce3
please fix im crying
May 16, 2023
e963673
please fix im crying
May 16, 2023
6d758c7
please fix im crying
May 16, 2023
2bf1b5f
please fix im crying
May 16, 2023
2cb2aa9
please fix im crying
May 16, 2023
2b15e7f
please fix im crying
May 16, 2023
d83bdf8
please fix im crying
May 16, 2023
01e86d6
please fix im crying
May 16, 2023
2d4e932
please fix im crying
May 16, 2023
27efca1
please fix im crying
May 16, 2023
8186937
please fix im crying
May 16, 2023
a04e0af
please fix im crying
May 16, 2023
61fb766
please fix im crying
May 16, 2023
fdf020c
please fix im crying
May 16, 2023
848c63b
please fix im crying
May 16, 2023
9949131
Update cs102.yml
lldckv May 23, 2023
6a4c907
:)
May 23, 2023
b2fc3d2
Update cs102.yml
lldckv May 23, 2023
dd0a003
:))
May 23, 2023
a27bf57
will it work
Jun 6, 2023
dec2d30
will it work 2
Jun 6, 2023
9c6e109
check
Jun 8, 2023
8ecd579
Update requirements.txt
lldckv Jun 10, 2023
25dcd70
Update requirements.txt
lldckv Jun 10, 2023
f5c0032
check
Jun 10, 2023
7246b37
check
Jun 10, 2023
7b5828c
Create cr
lldckv Jun 10, 2023
e9982c1
Create cr
lldckv Jun 10, 2023
9c3848f
Create cr
lldckv Jun 10, 2023
4ccbddb
Create cr
lldckv Jun 10, 2023
af81266
Create cr
lldckv Jun 10, 2023
1c9ee0f
added tests1
lldckv Jun 10, 2023
8aa648c
Delete cr
lldckv Jun 10, 2023
18f5fce
tokewn
lldckv Jun 10, 2023
40b1dd4
3
lldckv Jun 10, 2023
3221130
Delete cr
lldckv Jun 10, 2023
cfbc609
Delete cr
lldckv Jun 10, 2023
af1e784
Add files via upload
lldckv Jun 10, 2023
5451378
Delete cr
lldckv Jun 10, 2023
43a2fcf
Add files via upload
lldckv Jun 10, 2023
30dc6be
Delete cr
lldckv Jun 10, 2023
58c7c2c
Update cs102.yml
lldckv Jun 10, 2023
dde48f5
Update cs102.yml
lldckv Jun 10, 2023
385b842
check3
Jun 14, 2023
1f0280a
Create fake
lldckv Jun 20, 2023
357e604
Created using Colaboratory
lldckv Jun 20, 2023
452d671
Created using Colaboratory
lldckv Jun 20, 2023
495384a
Merge pull request #25 from lldckv/master
lldckv Nov 7, 2023
783eba7
Merge pull request #18 from lldckv/homework06
lldckv Nov 7, 2023
fb3a94b
Merge pull request #26 from lldckv/master
lldckv Nov 7, 2023
5a12011
Merge pull request #27 from lldckv/homework05
lldckv Nov 7, 2023
7d5a23f
Merge pull request #28 from lldckv/master
lldckv Nov 7, 2023
8490271
Merge pull request #9 from lldckv/homework04
lldckv Nov 7, 2023
49ec65a
Merge branch 'homework07' into master
lldckv Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cs102.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black mypy pylint pygame pyfakefs pandas boddle sqlalchemy requests bs4
pip install black mypy pylint pygame pyfakefs pandas boddle sqlalchemy requests bs4 gspread telebot responses httpretty community vk_api
- name: Install project dependencies
run: |
if [ -f ${{ github.head_ref }}/requirements.txt ];
Expand Down
45 changes: 34 additions & 11 deletions homework04/life.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,69 @@ def __init__(
self.generations = 1

def create_grid(self, randomize: bool = False) -> Grid:
# Copy from previous assignment
pass
if randomize:
grid = [[random.randint(0, 1) for _ in range(self.cols)] for _ in range(self.rows)]
else:
grid = [[0 for _ in range(self.cols)] for _ in range(self.rows)]
return grid

def get_neighbours(self, cell: Cell) -> Cells:
# Copy from previous assignment
pass
ind = [
x
for x in [(cell[0] + i, cell[1] + j) for i in range(-1, 2) for j in range(-1, 2)]
if (-1 < x[0] < self.rows and -1 < x[1] < self.cols)
]
ind.remove(cell)
cells = [self.curr_generation[x[0]][x[1]] for x in ind]
return cells

def get_next_generation(self) -> Grid:
# Copy from previous assignment
pass
new_grid = [[0 for _ in range(self.cols)] for _ in range(self.rows)]
for i in range(self.rows):
for j in range(self.cols):
c = sum(self.get_neighbours((i, j)))
if (c == 2 and self.curr_generation[i][j] == 1) or c == 3:
new_grid[i][j] = 1
return new_grid

def step(self) -> None:
"""
Выполнить один шаг игры.
"""
pass
if not self.is_max_generations_exceeded:
self.prev_generation = self.curr_generation.copy()
self.curr_generation = self.get_next_generation()
self.generations += 1

@property
def is_max_generations_exceeded(self) -> bool:
"""
Не превысило ли текущее число поколений максимально допустимое.
"""
pass
return self.generations + 1 > self.max_generations # type: ignore

@property
def is_changing(self) -> bool:
"""
Изменилось ли состояние клеток с предыдущего шага.
"""
pass
return not self.prev_generation == self.curr_generation

@staticmethod
def from_file(filename: pathlib.Path) -> "GameOfLife":
"""
Прочитать состояние клеток из указанного файла.
"""
pass
with open(filename, "r", encoding="utf-8") as f1:
grid = [list(map(int, t.strip())) for t in f1.readlines() if len(t.strip()) != 0]
game = GameOfLife((len(grid), len(grid[0])))
game.curr_generation = grid
return game

def save(self, filename: pathlib.Path) -> None:
"""
Сохранить текущее состояние клеток в указанный файл.
"""
pass
with open(filename, "w", encoding="utf-8") as f2:
for row in self.curr_generation:
f2.write(" ".join(map(str, row)) + "\n")
29 changes: 25 additions & 4 deletions homework04/life_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,37 @@
class Console(UI):
def __init__(self, life: GameOfLife) -> None:
super().__init__(life)
self.life = life

def draw_borders(self, screen) -> None:
""" Отобразить рамку. """
pass
"""Отобразить рамку."""
# y, x = screen.getmaxyx()
# y-=3
# x-=2
# border_line = '+' + (x * '-') + '+'
# screen.addstr(0, 0, border_line)
# screen.addstr(y + 1, 0, border_line)
# for i in range(0,y):
# screen.addstr(1 + i, 0, '|')
# screen.addstr(1 + i, x + 1, '|')
# screen.refresh()"
screen.border("|", "|", "-", "-", "+", "+", "+", "+")

def draw_grid(self, screen) -> None:
""" Отобразить состояние клеток. """
pass
"""Отобразить состояние клеток."""
grid = self.life.curr_generation
for i in range(len(grid)):
screen.addstr(i + 1, 1, "".join(map(str, grid[i])).replace("1", "*").replace("0", " "))

def run(self) -> None:
screen = curses.initscr()
# PUT YOUR CODE HERE
screen.nodelay(True)
screen.resize(self.life.rows + 3, self.life.cols + 3)

self.draw_borders(screen)
while screen.getch() != ord("e"):
self.draw_grid(screen)
self.life.step()
screen.refresh()
curses.endwin()
76 changes: 70 additions & 6 deletions homework04/life_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,79 @@
class GUI(UI):
def __init__(self, life: GameOfLife, cell_size: int = 10, speed: int = 10) -> None:
super().__init__(life)
self.game = life
self.cell_size = cell_size
self.width = cell_size * life.cols
self.height = cell_size * life.rows
self.cell_height = life.rows
self.cell_width = life.cols
self.screen_size = cell_size * life.cols, cell_size * life.rows
self.max_generations = life.max_generations
self.screen = pygame.display.set_mode(self.screen_size)
self.speed = speed

def draw_lines(self) -> None:
# Copy from previous assignment
pass
for x in range(0, self.width, self.cell_size):
pygame.draw.line(self.screen, pygame.Color("black"), (x, 0), (x, self.height))
for y in range(0, self.height, self.cell_size):
pygame.draw.line(self.screen, pygame.Color("black"), (0, y), (self.width, y))

def draw_grid(self) -> None:
# Copy from previous assignment
pass
for _ in range(self.cell_height):
for y in range(self.cell_height):
for x in range(self.cell_width):
if self.game.curr_generation[y][x] == 1:
pygame.draw.rect(
self.screen,
pygame.Color("green"),
(x * self.cell_size, y * self.cell_size, self.cell_size, self.cell_size),
)
else:
pygame.draw.rect(
self.screen,
pygame.Color("white"),
(x * self.cell_size, y * self.cell_size, self.cell_size, self.cell_size),
)

def run(self) -> None:
# Copy from previous assignment
pass
pygame.init()
clock = pygame.time.Clock()
pygame.display.set_caption("Game of Life")
self.screen.fill(pygame.Color("white"))
running = True
paused = False
self.game.step()
self.draw_grid()
self.draw_lines()
pygame.display.flip()
clock.tick(self.speed)
while self.game.is_changing and not self.game.is_max_generations_exceeded and running:
if not paused:
self.game.step()
self.draw_grid()
self.draw_lines()
pygame.display.flip()
clock.tick(self.speed)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
paused = not paused
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
pos = pygame.mouse.get_pos()
col = pos[0] // self.cell_size
row = pos[1] // self.cell_size
self.game.curr_generation[row][col] = 1
pygame.display.update()
self.draw_grid()
self.draw_lines()
pygame.display.flip()
clock.tick(self.speed)
pygame.quit()


if __name__ == "__main__":
game = GUI(GameOfLife((50, 50), randomize=True), cell_size=10, speed=1)
game.run()
75 changes: 54 additions & 21 deletions homework04/life_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@


class GameOfLife:
def __init__(
self, width: int = 640, height: int = 480, cell_size: int = 10, speed: int = 10
) -> None:
def __init__(self, width: int = 640, height: int = 480, cell_size: int = 10, speed: int = 10) -> None:
self.width = width
self.height = height
self.cell_size = cell_size
Expand All @@ -30,41 +28,41 @@ def __init__(
self.speed = speed

def draw_lines(self) -> None:
""" Отрисовать сетку """
"""Отрисовать сетку"""
for x in range(0, self.width, self.cell_size):
pygame.draw.line(self.screen, pygame.Color("black"), (x, 0), (x, self.height))
for y in range(0, self.height, self.cell_size):
pygame.draw.line(self.screen, pygame.Color("black"), (0, y), (self.width, y))

def run(self) -> None:
""" Запустить игру """
"""Запустить игру"""
pygame.init()
clock = pygame.time.Clock()
pygame.display.set_caption("Game of Life")
self.screen.fill(pygame.Color("white"))

# Создание списка клеток
# PUT YOUR CODE HERE
self.grid = self.create_grid(True)

running = True
while running:
self.draw_grid()
self.draw_lines()
for event in pygame.event.get():
if event.type == QUIT:
running = False
self.draw_lines()

# Отрисовка списка клеток
# Выполнение одного шага игры (обновление состояния ячеек)
# PUT YOUR CODE HERE
# Отрисовка списка клеток
# Выполнение одного шага игры (обновление состояния ячеек)

pygame.display.flip()
clock.tick(self.speed)
self.grid = self.get_next_generation()
pygame.display.flip()
clock.tick(self.speed)
pygame.quit()

def create_grid(self, randomize: bool = False) -> Grid:
"""
Создание списка клеток.

Клетка считается живой, если ее значение равно 1, в противном случае клетка
считается мертвой, то есть, ее значение равно 0.

Expand All @@ -79,15 +77,32 @@ def create_grid(self, randomize: bool = False) -> Grid:
out : Grid
Матрица клеток размером `cell_height` х `cell_width`.
"""
pass
if randomize:
grid = [[random.randint(0, 1) for _ in range(self.cell_width)] for _ in range(self.cell_height)]
else:
grid = [[0 for _ in range(self.cell_width)] for _ in range(self.cell_height)]
return grid

def draw_grid(self) -> None:
"""
Отрисовка списка клеток с закрашиванием их в соответствующе цвета.
"""
pass

def get_neighbours(self, cell: Cell) -> Cells:
for i in range(self.cell_height):
for j in range(self.cell_width):
if self.grid[i][j] == 0:
pygame.draw.rect(
self.screen,
pygame.Color("white"),
(j * self.cell_size, i * self.cell_size, self.cell_size, self.cell_size),
)
else:
pygame.draw.rect(
self.screen,
pygame.Color("green"),
(j * self.cell_size, i * self.cell_size, self.cell_size, self.cell_size),
)

def get_neighbours(self, cell: Cell) -> Cells: # Type : Ignore
"""
Вернуть список соседних клеток для клетки `cell`.

Expand All @@ -105,9 +120,16 @@ def get_neighbours(self, cell: Cell) -> Cells:
out : Cells
Список соседних клеток.
"""
pass

def get_next_generation(self) -> Grid:
arr = [
x
for x in [(cell[0] + i, cell[1] + j) for i in range(-1, 2) for j in range(-1, 2)]
if (-1 < x[0] < self.cell_height and -1 < x[1] < self.cell_width)
]
arr.remove(cell)
cells = [self.grid[x[0]][x[1]] for x in arr]
return cells

def get_next_generation(self) -> tp.List[Cells]: # Type : Ignore
"""
Получить следующее поколение клеток.

Expand All @@ -116,4 +138,15 @@ def get_next_generation(self) -> Grid:
out : Grid
Новое поколение клеток.
"""
pass
new_grid = [[0 for _ in range(self.cell_width)] for _ in range(self.cell_height)]
for i in range(self.cell_height):
for j in range(self.cell_width):
c = sum(self.get_neighbours((i, j)))
if (c == 2 and self.grid[i][j] == 1) or c == 3:
new_grid[i][j] = 1
return new_grid


if __name__ == "__main__":
game = GameOfLife(speed=100)
game.run()
Loading
Loading