Skip to content

Commit

Permalink
refactor: methods to use underscore prefix in board.py to indicate pr…
Browse files Browse the repository at this point in the history
…ivateness
  • Loading branch information
SverreNystad committed Apr 9, 2024
1 parent 7f4931d commit 1804538
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/game/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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):
Expand All @@ -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 = []

Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions test/game/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1804538

Please sign in to comment.