From 2cd64b39ad1bd7f300b72c38a625ccb75a44e9a5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 10 Aug 2023 02:59:27 +0000 Subject: [PATCH] style: format code with autopep8 Format code with autopep8 This commit fixes the style issues introduced in 27f24a8 according to the output from Autopep8. Details: None --- Game of Fifteen/Game_of_Fifteen.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Game of Fifteen/Game_of_Fifteen.py b/Game of Fifteen/Game_of_Fifteen.py index 2adc67ef58..8a8660c3e4 100644 --- a/Game of Fifteen/Game_of_Fifteen.py +++ b/Game of Fifteen/Game_of_Fifteen.py @@ -1,5 +1,6 @@ import random + def create_board(): numbers = list(range(1, 16)) random.shuffle(numbers) @@ -8,31 +9,38 @@ def create_board(): board = [numbers[i:i+4] for i in range(0, 16, 4)] return board + def display_board(board): for row in board: - print(' | '.join(str(num).rjust(2) if num is not None else ' ' for num in row)) + print(' | '.join(str(num).rjust(2) + if num is not None else ' ' for num in row)) print('-' * 23) + def get_empty_position(board): for i in range(4): for j in range(4): if board[i][j] is None: return i, j + def is_valid_move(move, empty_row, empty_col): row, col = move return (0 <= row < 4 and 0 <= col < 4 and (row == empty_row and abs(col - empty_col) == 1 or - col == empty_col and abs(row - empty_row) == 1)) + col == empty_col and abs(row - empty_row) == 1)) + def make_move(board, move): empty_row, empty_col = get_empty_position(board) row, col = move board[empty_row][empty_col], board[row][col] = board[row][col], board[empty_row][empty_col] + def check_win(board): return all(board[i][j] == i*4 + j + 1 for i in range(4) for j in range(4)) and board[3][3] is None + def game_of_fifteen(): board = create_board() @@ -42,7 +50,8 @@ def game_of_fifteen(): while not check_win(board): display_board(board) - move = input("Enter the number you want to move (1-15) or 'Q' to quit: ") + move = input( + "Enter the number you want to move (1-15) or 'Q' to quit: ") if move.lower() == 'q': print("Quitting the game...") @@ -66,5 +75,6 @@ def game_of_fifteen(): if check_win(board): print("Congratulations! You solved the puzzle.") + if __name__ == "__main__": game_of_fifteen()