From a83d23bfabf9526549095ce3a50fd0185153ee7e Mon Sep 17 00:00:00 2001 From: VincentAuriau Date: Fri, 17 Nov 2023 21:46:03 +0000 Subject: [PATCH] :art: Format Python code with psf/black --- pyalapin/engine/engine.py | 3 +-- pyalapin/engine/material.py | 3 ++- pyalapin/player/stockfish_player.py | 34 +++++++++++++++------------- tests/stockfish_localtest.py | 35 ++++++++++++++++------------- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/pyalapin/engine/engine.py b/pyalapin/engine/engine.py index 4d26ab7..c202394 100644 --- a/pyalapin/engine/engine.py +++ b/pyalapin/engine/engine.py @@ -1044,7 +1044,7 @@ def to_fen(self): def is_castling_possible(self, is_white_player): """Creates FEN representation of possible castling - + Parameters ---------- is_white_player: bool @@ -1114,7 +1114,6 @@ def fen_en_passant(self): else: return "-" - def is_finished(self): """ Method to know if the game is still active or finished (i.e. pat or mat) diff --git a/pyalapin/engine/material.py b/pyalapin/engine/material.py index a76941c..3d6971c 100644 --- a/pyalapin/engine/material.py +++ b/pyalapin/engine/material.py @@ -495,7 +495,8 @@ def get_str(self): str String representation of the piece """ - return " P " + repr = " P " + return repr if self.is_white() else repr.lower() class Bishop(Piece): diff --git a/pyalapin/player/stockfish_player.py b/pyalapin/player/stockfish_player.py index 9da2cba..3793d5d 100644 --- a/pyalapin/player/stockfish_player.py +++ b/pyalapin/player/stockfish_player.py @@ -9,7 +9,9 @@ class StockfishPlayer(Player): A first AI that plays totally randomly. Selects one move among all possibles and plays it. """ - def __init__(self, path_to_dirsave, elo=1000, depth=18, threads=1, hash_pow=4, **kwargs): + def __init__( + self, path_to_dirsave, elo=1000, depth=18, threads=1, hash_pow=4, **kwargs + ): super().__init__(**kwargs) self.elo = elo self.path_to_dirsave = path_to_dirsave @@ -18,21 +20,23 @@ def __init__(self, path_to_dirsave, elo=1000, depth=18, threads=1, hash_pow=4, * self.hash = 2**hash_pow params = { - "Threads": self.threads, - "Hash": self.hash, - "UCI_Elo": self.elo, + "Threads": self.threads, + "Hash": self.hash, + "UCI_Elo": self.elo, } - self.stockfish = Stockfish(path=self.path_to_dirsave, depth=self.depth, parameters=params) + self.stockfish = Stockfish( + path=self.path_to_dirsave, depth=self.depth, parameters=params + ) self.letter_to_coordinate = { - "a": 7, - "b": 6, - "c": 5, - "d": 4, - "e": 3, - "f": 2, - "g": 1, - "h": 0, + "a": 7, + "b": 6, + "c": 5, + "d": 4, + "e": 3, + "f": 2, + "g": 1, + "h": 0, } def __str__(self): @@ -50,8 +54,7 @@ def quit(self): self.stockfish.send_quit_command() def _sf_to_own_coordinates(self, coordinates): - return (int(coordinates[1])-1, self.letter_to_coordinate[coordinates[0]]) - + return (int(coordinates[1]) - 1, self.letter_to_coordinate[coordinates[0]]) def get_move_from_fen(self, fen): self.stockfish.set_fen_position(fen) @@ -78,4 +81,3 @@ def time_to_play(self, board): fen_repr = board.to_fen() return self.get_move_from_fen(fen_repr) - diff --git a/tests/stockfish_localtest.py b/tests/stockfish_localtest.py index 852c139..bfb6e63 100644 --- a/tests/stockfish_localtest.py +++ b/tests/stockfish_localtest.py @@ -1,22 +1,25 @@ -if __name__=="__main__": - import sys - sys.path.append("../pyalapin") +if __name__ == "__main__": + import sys - import os - print(os.listdir()) - print(os.listdir("pyalapin")) + sys.path.append("../pyalapin") - from pyalapin.player.stockfish_player import StockfishPlayer - from pyalapin.engine import ChessGame + import os + print(os.listdir()) + print(os.listdir("pyalapin")) - sfp = StockfishPlayer("/Users/vincent.auriau/Python/stockfish/bin/stockfish", white_side=True) - game = ChessGame() - print("FEN:", game.to_fen()) - co1, co2 = sfp.get_move_from_fen(game.to_fen()) - game.board.draw() + from pyalapin.player.stockfish_player import StockfishPlayer + from pyalapin.engine import ChessGame - game.move_from_coordinates(game.player1, *co1, *co2) - game.board.draw() + sfp = StockfishPlayer( + "/Users/vincent.auriau/Python/stockfish/bin/stockfish", white_side=True + ) + game = ChessGame() + print("FEN:", game.to_fen()) + co1, co2 = sfp.get_move_from_fen(game.to_fen()) + game.board.draw() - # sfp.quit() \ No newline at end of file + game.move_from_coordinates(game.player1, *co1, *co2) + game.board.draw() + + # sfp.quit()