From 18045380bb78df073834333adcb6b2cd18527b0d Mon Sep 17 00:00:00 2001 From: Sverre Nystad <89105607+SverreNystad@users.noreply.github.com> Date: Tue, 9 Apr 2024 05:05:16 +0200 Subject: [PATCH] refactor: methods to use underscore prefix in board.py to indicate privateness --- src/game/board.py | 14 +++++++------- test/game/test_board.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/game/board.py b/src/game/board.py index 9811f83..82a1bb3 100644 --- a/src/game/board.py +++ b/src/game/board.py @@ -45,7 +45,7 @@ def __init__(self): self.prevBoard = copy.deepcopy(self.board) self.block = Block(3, 0, 0) - self.placeBlock() + self._placeBlock() self.nextBlock = Block(0, 5, random.randint(0, 6)) @@ -94,7 +94,7 @@ def doAction(self, action: Action) -> None: if self.isValidBlockPosition(new_block): print("Valid move") self.block = new_block - self.placeBlock() + self._placeBlock() def isValidBlockPosition(self, block: Block) -> bool: """ @@ -156,7 +156,7 @@ def _intersects(self, block: Block) -> bool: def isGameOver(self): return self.gameOver - def placeBlock(self): + def _placeBlock(self): """Places the current block on the board""" self.board = copy.deepcopy(self.prevBoard) for i in range(4): @@ -177,7 +177,7 @@ def _shiftToNewBlock(self): j + self.block.x ] = 1 # self.block.color - def checkGameState(self) -> int: + def _checkGameState(self) -> int: amount = 0 fullRows = [] @@ -214,7 +214,7 @@ def getPossibleMoves(self) -> list["Board"]: moveBoard.block.setCoordinates(i, 0) for j in range(currentRotation): moveBoard.block.rotateRight() - moveBoard.placeBlock() + moveBoard._placeBlock() while moveBoard.isValidBlockPosition(moveBoard.block.moveDown): moveBoard.block.moveDown() @@ -232,11 +232,11 @@ def getPossibleMoves(self) -> list["Board"]: def printBoard(self): print("_______________________________________") for row in self.board: - print("|" + " ".join(self.checkCharacter(cell) for cell in row) + "|") + print("|" + " ".join(self._checkCharacter(cell) for cell in row) + "|") print("‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾") - def checkCharacter(self, character) -> str: + def _checkCharacter(self, character) -> str: if character == 1: return "■" else: diff --git a/test/game/test_board.py b/test/game/test_board.py index 5daa21e..9ceba45 100644 --- a/test/game/test_board.py +++ b/test/game/test_board.py @@ -64,7 +64,7 @@ def test_clear_row(): ] lines_to_remove = 1 board.printBoard() - rows_removed = board.checkGameState() + rows_removed = board._checkGameState() board.printBoard() for expected_row, board_row in zip(expected_board, board.board): assert expected_row == board_row @@ -120,7 +120,7 @@ def test_clear_rows(): ] lines_to_remove = 3 board.printBoard() - rows_removed = board.checkGameState() + rows_removed = board._checkGameState() board.printBoard() for expected_row, board_row in zip(expected_board, board.board): assert expected_row == board_row @@ -154,7 +154,7 @@ def test_do_not_clear_not_full_row(): ] lines_to_remove = 0 board.printBoard() - rows_removed = board.checkGameState() + rows_removed = board._checkGameState() board.printBoard() assert rows_removed == lines_to_remove