Skip to content

Commit

Permalink
Merge pull request #50 from VincentAuriau/actions/black
Browse files Browse the repository at this point in the history
Format Python code with psf/black push
  • Loading branch information
VincentAuriau authored Nov 17, 2023
2 parents d70af82 + a83d23b commit 79ff5bc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
3 changes: 1 addition & 2 deletions pyalapin/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pyalapin/engine/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 18 additions & 16 deletions pyalapin/player/stockfish_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -78,4 +81,3 @@ def time_to_play(self, board):

fen_repr = board.to_fen()
return self.get_move_from_fen(fen_repr)

35 changes: 19 additions & 16 deletions tests/stockfish_localtest.py
Original file line number Diff line number Diff line change
@@ -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()
game.move_from_coordinates(game.player1, *co1, *co2)
game.board.draw()

# sfp.quit()

0 comments on commit 79ff5bc

Please sign in to comment.