From 285fd66d18c1c93c720bce492a7bda85d1744fea Mon Sep 17 00:00:00 2001 From: Leonid Belyaev Date: Sun, 14 Nov 2021 11:06:20 -0500 Subject: [PATCH] more skeletal --- code/bot/main.py | 59 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/code/bot/main.py b/code/bot/main.py index 0a3b3a4..2173491 100644 --- a/code/bot/main.py +++ b/code/bot/main.py @@ -4,6 +4,27 @@ import random import typing +class TetrisGame(): + """Our search-problem class""" + + def __init__(self): + pass + + def add_piece(self): + """Add a specific piece to the game""" + pass + + def next_piece(self): + pass + + def is_terminal(self, state: 'TetrisState'): + """Can be re-implemented based on subclass of game""" + # Default: there exists a block greater than the "roof" + pass + + def get_succs(self): + pass + class TetrisState(): """Tetris states are all the same really - it's a driver TetrisGame that differentiates gametypes @@ -13,10 +34,19 @@ def __init__(self, block_grid: 'BlockGrid', piece: 'Piece'): self.current_piece = piece class Piece(): - """A collection of blocks""" - pass + """A collection of blocks- limited to 5x5 + Pieces rotate about the geometric center at (2, 2) - sculpt accordingly + """ + def __init__(self, block_label: str, block_coordinates: list): + self.piece_grid = [] + for i in range(5): + self.piece_grid.append([Block("empty")] * 5) + for x, y in block_coordinates: + self.piece_grid[x][y] = Block(block_label) + def left_rotate(self): + pass class Block(): def __init__(self, label): @@ -28,22 +58,31 @@ def __repr__(self): else: return "x" + def __eq__(self, o): + return self.label == o.label + class BlockGrid(): - def __init__(self, x_dimension=10, y_dimension=20, cheese_count=0): - if cheese_count > y_dimension: - raise RuntimeError + def __init__(self, x_dimension=10, y_dimension=20): self.grid = [] + self.x_dimension = x_dimension + self.y_dimension = y_dimension for y in range(y_dimension): self.grid.append([Block("empty")] * x_dimension) - for cheese_y in range(cheese_count): - cheese_row = [Block("cheese")] * x_dimension - hole_index = random.choice(range(x_dimension)) - cheese_row[hole_index] = Block("empty") - self.grid[y_dimension - cheese_y - 1] = cheese_row + def send_garbage(self, garbage_count: int, garbage_label: str, hole_count: int): + if hole_count > self.x_dimension: + raise RuntimeError + for garbage_y in range(garbage_count): + garbage_row = [Block(garbage_label)] * self.x_dimension + while hole_count != 0: + new_hole_index = random.choice(range(self.x_dimension)) + if garbage_row[new_hole_index] != Block("empty"): + garbage_row[new_hole_index] = Block("empty") + hole_count -= 1 + self.grid[self.y_dimension - garbage_y -1] = garbage_row def __repr__(self): repr = ""