Skip to content

Commit

Permalink
feat: added backbone for multiple corols
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard-Prokhorikhin committed Apr 23, 2024
1 parent 9641f41 commit 6704d2d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/agents/heuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ def max_height(gameState: Tetris) -> int:
return max(checkedList)


# Does this work? row cleared in get_possible_boards??
def lines_cleaned(gameState: Tetris) -> int:
"""Retrurns the number of lines cleared."""
sum = 0
for row in gameState.board:
if all(cell == 1 for cell in row):
if all(cell >= 1 for cell in row):
sum += 1
return sum

Expand All @@ -70,7 +71,7 @@ def bumpiness(gameState: Tetris) -> int:
total_bumpiness += abs(columnHeightMap[key] - columnHeightMap[key + 1])
return total_bumpiness


# Henrik exluse ???
def aggregate_height(gameState: Tetris) -> int:
"Returns the sum of all column-heights"
max_height = gameState.ROWS
Expand Down Expand Up @@ -100,7 +101,7 @@ def find_holes(gameState: Tetris) -> int:
for column in range(gameState.COLUMNS):
top_block = gameState.ROWS
for row in range(gameState.ROWS):
if (gameState.prevBoard[row][column] == 1) and (row < top_block):
if (gameState.prevBoard[row][column] >= 1) and (row < top_block):
top_block = row
if (gameState.prevBoard[row][column] == 0) and (row > top_block):
holes += 1
Expand Down
11 changes: 6 additions & 5 deletions src/game/TetrisGameManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SCREEN_WIDTH = WIDTH * BLOCK_SIZE
SCREEN_HEIGHT = (HEIGHT - START_HEIGHT) * BLOCK_SIZE

# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
Expand Down Expand Up @@ -47,7 +48,7 @@ def startGame(self):
clock = pygame.time.Clock()

while not self.board.gameOver:
self.draw_board(self.board.board)
self.draw_board(self.board)
self.inputHandling()
if self.board.blockHasLanded:
self.board.updateBoard() # Update the board after a block has landed and spawn a new block
Expand Down Expand Up @@ -81,13 +82,13 @@ def checkTimer(self):
self.currentTime = newTime
self.movePiece(Action.SOFT_DROP)

def draw_board(self, board):
def draw_board(self, gameState: Tetris):
self.screen.fill(BLACK)
temp = deepcopy(board)
temp = temp[START_HEIGHT:]
temp = deepcopy(gameState)
temp_board = temp.board[START_HEIGHT:]
for y in range(HEIGHT-START_HEIGHT):
for x in range(WIDTH):
if temp[y][x] == 1:
if temp_board[y][x] == 1:
pygame.draw.rect(self.screen, BLUE, (x * BLOCK_SIZE, y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE))
pygame.draw.rect(self.screen, WHITE, (x * BLOCK_SIZE, y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE), 1)

Expand Down
6 changes: 3 additions & 3 deletions src/game/tetris.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _placeBlock(self):
if i * 4 + j in self.block.image():
self.board[i + self.block.y][
j + self.block.x
] = 1 # self.block.color
] = self.block.type + 1 # implicit color 1 to 7


def _shiftToNewBlock(self):
Expand All @@ -215,7 +215,7 @@ def _shiftToNewBlock(self):
if i * 4 + j in self.block.image():
self.board[i + self.block.y][
j + self.block.x
] = 1 # self.block.color
] = self.block.type + 1 # implicit color 1 to 7

def _checkGameOver(self):
"""Checks if the game is over"""
Expand Down Expand Up @@ -304,7 +304,7 @@ def printBoard(self):
print("‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾")

def _checkCharacter(self, character) -> str:
if character == 1:
if character >= 1:
return "■"
else:
return "▧"
Expand Down

0 comments on commit 6704d2d

Please sign in to comment.