Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aeblyve committed Nov 14, 2021
1 parent 285fd66 commit 0920c04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions code/bot/main.py → code/bot/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import random
import typing
import unittest

class TetrisGame():
"""Our search-problem class"""
Expand Down Expand Up @@ -35,7 +36,7 @@ def __init__(self, block_grid: 'BlockGrid', piece: 'Piece'):

class Piece():
"""A collection of blocks- limited to 5x5
Pieces rotate about the geometric center at (2, 2) - sculpt accordingly
Pieces rotate about the center at (2, 2) - sculpt accordingly
"""

def __init__(self, block_label: str, block_coordinates: list):
Expand All @@ -46,7 +47,16 @@ def __init__(self, block_label: str, block_coordinates: list):
self.piece_grid[x][y] = Block(block_label)

def left_rotate(self):
pass
for y in range(len(self.piece_grid)):
for x in range(len(self.piece_grid[0])):
if x == 2 and y == 2:
# can't rotate the center this way- but the center never changes anyway
continue
offset_x, offset_y = (x - 2, y - 2)
new_offset_x, new_offset_y = (offset_y, -1 * offset_x)
new_x, new_y = (new_offset_x + 2, new_offset_y + 2)
self.piece_grid[new_y][new_x] = self.piece_grid[y][x]


class Block():
def __init__(self, label):
Expand Down
4 changes: 4 additions & 0 deletions code/bot/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python3

import unittest
import main

0 comments on commit 0920c04

Please sign in to comment.