From 4fb15f6caefceacd2d116ecad9f27d1a2d150b1a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 00:26:43 +0100 Subject: [PATCH] :art: Format Python code with psf/black (#30) Co-authored-by: VincentAuriau --- pyalapin/__init__.py | 2 +- pyalapin/engine/engine.py | 1 - pyalapin/engine/material.py | 3 --- pyalapin/interface/interface.py | 20 +++++++++++------ pyalapin/player/ai_player.py | 13 +++++------ pyalapin/setup.py | 38 ++++++++++++++++----------------- utils/profile_game.py | 2 +- 7 files changed, 41 insertions(+), 38 deletions(-) diff --git a/pyalapin/__init__.py b/pyalapin/__init__.py index 9fa2b96..33749f8 100644 --- a/pyalapin/__init__.py +++ b/pyalapin/__init__.py @@ -3,4 +3,4 @@ """ __version__ = "0.0.1" -__author__ = 'Vincent Auriau' \ No newline at end of file +__author__ = "Vincent Auriau" diff --git a/pyalapin/engine/engine.py b/pyalapin/engine/engine.py index b62609c..647ef4b 100644 --- a/pyalapin/engine/engine.py +++ b/pyalapin/engine/engine.py @@ -985,7 +985,6 @@ def __init__(self, player1=None, player2=None, automatic_draw=True, ai=False): self.player1 = player1 elif player1 is None: - if ai: self.player1 = EasyAIPlayer(True) else: diff --git a/pyalapin/engine/material.py b/pyalapin/engine/material.py index 4c06f49..a76941c 100644 --- a/pyalapin/engine/material.py +++ b/pyalapin/engine/material.py @@ -416,7 +416,6 @@ def get_potential_moves(self, x, y): return possible_moves - @abstractmethod def get_threatened_cells_on_board(self, board): """ @@ -436,7 +435,6 @@ def get_threatened_cells_on_board(self, board): cells_threatened = [] if self.is_white(): - if x < 7: # Diagonal cells if y - 1 >= 0: @@ -446,7 +444,6 @@ def get_threatened_cells_on_board(self, board): # Symmetric for black pawns else: - if x > 0: if y - 1 >= 0: cells_threatened.append((x - 1, y - 1)) diff --git a/pyalapin/interface/interface.py b/pyalapin/interface/interface.py index e9dcaca..2a25e57 100644 --- a/pyalapin/interface/interface.py +++ b/pyalapin/interface/interface.py @@ -38,6 +38,7 @@ def __init__(self, **kwargs): class DisplayableCell(Button): """Base class to represent a Cell as Button""" + def __init__(self, row, column, **kwargs): """ Initialization of the representation of the cell. @@ -78,6 +79,7 @@ class TableScreen(GridLayout): cells: list of DisplayableCells List of cells constituting the board """ + def __init__(self, game, **kwargs): """ Initialization of the board display. @@ -125,7 +127,7 @@ def __init__(self, game, **kwargs): path_to_img = c_img if piece.is_white(): - piece_color = (1, 1, 1, 1) # For text color, could be removed + piece_color = (1, 1, 1, 1) # For text color, could be removed path_to_img += "w" else: piece_color = (0, 0, 0, 1) @@ -152,7 +154,7 @@ def __init__(self, game, **kwargs): else: # No piece to display piece = "" - piece_color = (1, 1, 1, 1) # For text color could be removed + piece_color = (1, 1, 1, 1) # For text color could be removed path_to_img = c_img + ".png" # Unclicked path_to_down_img = "down_" + path_to_img @@ -269,7 +271,7 @@ def click_cell(self, event): self.cells[event.row][event.column].background_down, self.cells[event.row][event.column].background_normal, ) - # If no previous cell has been clicked, then it's the start cell that has been clicked, + # If no previous cell has been clicked, then it's the start cell that has been clicked, # In this case it is store, waiting fot the click on the landinc cell. if self.first_cell_clicked is None: self.first_cell_clicked = (event.row, event.column) @@ -325,9 +327,14 @@ def click_cell(self, event): # In this case, game was not possible, reset last clicks so that the player can restart # and redefine its move. else: - popup = Popup(title='Unable Move', - content=Label(text='Your selected move is not possible, please, select another one.'), - size_hint=(None, None), size=(15, 15)) + popup = Popup( + title="Unable Move", + content=Label( + text="Your selected move is not possible, please, select another one." + ), + size_hint=(None, None), + size=(15, 15), + ) popup.open() # Resets values befor next move @@ -353,6 +360,7 @@ class MyApp(App): """ Main app to use to play game, by calling MyApp().buil() and then player. """ + def __init__(self, play_with_ai=False, **kwargs): """ Initialization, with precision whether or not playing with AI. diff --git a/pyalapin/player/ai_player.py b/pyalapin/player/ai_player.py index 11705c4..61268f4 100644 --- a/pyalapin/player/ai_player.py +++ b/pyalapin/player/ai_player.py @@ -20,6 +20,7 @@ class EasyAIPlayer(Player): pieces_positions_weights: dict Values for each piece to be on a certain position. """ + piece_weights = { "pawn": 10, "knight": 30, @@ -337,11 +338,11 @@ def _alpha_beta( best_move = [best_move, p_mv][np.argmax([best_score, score])] best_score = np.max([best_score, score]) - + if best_score >= beta: return best_score, best_move alpha = np.max((alpha, best_score)) - + return best_score, best_move else: @@ -363,7 +364,7 @@ def _alpha_beta( best_move = [best_move, p_mv][np.argmin([best_score, score])] best_score = np.min([best_score, score]) - + if best_score <= alpha: return best_score, best_move beta = np.min([beta, best_score]) @@ -423,7 +424,7 @@ def time_to_play(self, board, depth=3, draw_board=False): board.draw() # current_score = self._score_board(board) sel_score, sel_move = self._alpha_beta(board, depth=depth) - + return sel_move def _score_board(self, board): @@ -447,7 +448,7 @@ def _score_board(self, board): score += self.piece_positions_weights[piece_type][piece.x][piece.y] own_king = board.all_material[self.color]["alive"]["king"] if len(own_king) == 0: - score -= 1000 + score -= 1000 else: own_king = own_king[0] if board.get_cell(own_king.x, own_king.y).is_threatened( @@ -464,7 +465,7 @@ def _score_board(self, board): adv_king = board.all_material[adv_color]["alive"]["king"] if len(adv_king) == 0: - score -= 1000 + score -= 1000 else: adv_king = adv_king[0] if board.get_cell(adv_king.x, adv_king.y).is_threatened( diff --git a/pyalapin/setup.py b/pyalapin/setup.py index f294ebf..db26aab 100644 --- a/pyalapin/setup.py +++ b/pyalapin/setup.py @@ -1,4 +1,3 @@ - from setuptools import setup, find_packages VERSION = "0.0.1" @@ -11,22 +10,21 @@ # Setting up setup( - name="pyalapin", - version=VERSION, - author="Vincent Auriau", - author_email="", - description=DESCRIPTION, - long_description=LONG_DESCRIPTION, - packages=find_packages(), - install_requires=["numpy"], - - keywords=['python', 'first package'], - classifiers= [ - "Development Status :: 3 - Alpha", - "Intended Audience :: Anyone", - "Programming Language :: Python :: 3", - "Operating System :: MacOS :: MacOS X", - "Operating System :: Microsoft :: Windows", - "Operating System :: Linux :: Linux", - ] -) \ No newline at end of file + name="pyalapin", + version=VERSION, + author="Vincent Auriau", + author_email="", + description=DESCRIPTION, + long_description=LONG_DESCRIPTION, + packages=find_packages(), + install_requires=["numpy"], + keywords=["python", "first package"], + classifiers=[ + "Development Status :: 3 - Alpha", + "Intended Audience :: Anyone", + "Programming Language :: Python :: 3", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + "Operating System :: Linux :: Linux", + ], +) diff --git a/utils/profile_game.py b/utils/profile_game.py index 618389a..2f8c633 100644 --- a/utils/profile_game.py +++ b/utils/profile_game.py @@ -27,4 +27,4 @@ game_is_on = game.move(ai_move, game.player2) score = my_player._score_board(game.board) print(my_player.model.summary()) -""" \ No newline at end of file +"""