Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR - Translate move string to human readable description of the move #111

Open
FalcoGer opened this issue Jul 29, 2022 · 1 comment
Open

Comments

@FalcoGer
Copy link

FalcoGer commented Jul 29, 2022

I have written a function that would take a stockfish move and translate it into a human readable string. Maybe you want to implement that in the library so I thought I'd share. Feel free to close if you do not.

class Player:
    WHITE = "White"
    BLACK = "Black"

def getNTM(stockfish: Stockfish) -> str:
    return Player.WHITE if (stockfish.get_fen_position().find(" w ") > 0) else Player.BLACK

def describeMove(stockfish: Stockfish, move: str) -> str:
    if (stockfish.is_move_correct(move)):
        # move stuff
        src = move[0:2]
        dst = move[2:4]
        turnsInto = move[4:5].lower()
        cap = None
        pieceMoving = str(stockfish.get_what_is_on_square(src)).replace("Piece.", "")

        ret = f"{pieceMoving} from {src} to {dst}"

        # if capture
        cap = stockfish.will_move_be_a_capture(move)

        if cap == Stockfish.Capture.DIRECT_CAPTURE:
            tgt = stockfish.get_what_is_on_square(dst)
            tgt = str(tgt).replace("Piece.", "")
            ret = ret + f" capturing {tgt}"
        elif cap == Stockfish.Capture.EN_PASSANT:
            tgt = Stockfish.Piece.WHITE_PAWN if getNTM(stockfish) == Player.BLACK else Stockfish.Piece.BLACK_PAWN
            tgt = str(tgt).replace("Piece.", "")
            ret = ret + f" capturing {tgt} en passant"

        # turning pawn into something else.
        if turnsInto != '':
            if turnsInto == 'q':
                turnsInto = Stockfish.Piece.WHITE_QUEEN if getNTM(stockfish) == Player.WHITE else Stockfish.Piece.BLACK_QUEEN
            elif turnsInto == 'n':
                turnsInto = Stockfish.Piece.WHITE_KNIGHT if getNTM(stockfish)== Player.WHITE else Stockfish.Piece.BLACK_KNIGHT
            elif turnsInto == 'b':
                turnsInto = Stockfish.Piece.WHITE_BISHOP if getNTM(stockfish)== Player.WHITE else Stockfish.Piece.BLACK_BISHOP
            elif turnsInto == 'r':
                turnsInto = Stockfish.Piece.WHITE_ROOK if getNTM(stockfish)== Player.WHITE else Stockfish.Piece.BLACK_ROOK
            # remove 'Piece.'
            turnsInto = str(turnsInto).replace('Piece.', '')
            # color
            if cap != None:
                ret = ret + " and"
            ret = ret + f" turning into {turnsInto}"
        return ret
    else:
        return "Invalid Move"
@kieferro
Copy link
Contributor

kieferro commented Mar 7, 2023

Hello, this project is no longer maintained in this repo but on this fork. (For more information about this please look here).
Since this issue has no comments, it should be quite easy to copy the content and title into a new issue over there. (For more specific information on that, look here).
This makes it easier for us to keep track of things, and it's more convenient because we then have the issues right where they are being worked on. So please create a new issue in the new repo and then close this one. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants