### Install python-shogi using pip Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Provides the command to install the python-shogi library using the pip package manager. This is the standard method for adding the library to a Python environment. ```bash pip install python-shogi ``` -------------------------------- ### Create and Manage Shogi Board State with Python Source: https://context7.com/gunyarakun/python-shogi/llms.txt Demonstrates how to create and manage a shogi board using the `shogi.Board` class. It covers initializing with the starting position, creating from SFEN strings, displaying the board in ASCII and KIF formats, checking the current turn, and retrieving pieces from specific squares. ```python import shogi # Create board with starting position board = shogi.Board() print(board.sfen()) # Output: lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 # Create board from SFEN string custom_board = shogi.Board("lnsgkgsnl/1r5b1/ppppppppp/9/9/2P6/PP1PPPPPP/1B5R1/LNSGKGSNL w - 2") # Display ASCII board print(board) # l n s g k g s n l # . r . . . . . b . # p p p p p p p p p # . . . . . . . . . # . . . . . . . . . # . . . . . . . . . # P P P P P P P P P # . B . . . . . R . # L N S G K G S N L # Display Japanese KIF-style board print(board.kif_str()) # Check current turn (BLACK=0, WHITE=1) print(board.turn) # Output: 0 (BLACK's turn) # Get piece at a square piece = board.piece_at(shogi.I5) # King position print(piece) # Output: K ``` -------------------------------- ### Generate SFEN String and Get Piece at Square in Python Shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Shows how to generate the Shogi board's state in Forsyth–Edwards Notation (SFEN) using `sfen()` and how to retrieve the piece at a specific square using `piece_at()` in python-shogi. ```python >>> board.sfen() 'lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1' >>> board.piece_at(shogi.I5) Piece.from_symbol('K') ``` -------------------------------- ### Access Shogi Game Data Source: https://context7.com/gunyarakun/python-shogi/llms.txt Demonstrates how to access various game-related data from a shogi game object, including player names, starting position in SFEN format, move list, and game result. Assumes a 'game' object is already initialized. ```python print(game['names']) # Player names print(game['sfen']) # Starting position print(game['moves']) # Move list in USI format print(game['win']) # Result: 'b', 'w', or '-' ``` -------------------------------- ### Game State Detection (Checkmate, Stalemate, Check, Repetition) Source: https://context7.com/gunyarakun/python-shogi/llms.txt This section covers detecting various game-ending conditions in Shogi using the shogi library. It includes examples for checkmate, stalemate, check, and fourfold repetition (sennichite), along with basic attack detection. ```python import shogi # Checkmate detection board = shogi.Board() for move in ['7g7f', '3c3d', '8h2b+', '4a5b', 'B*4b', '5a4a', '2b3a']: board.push_usi(move) print(board.is_checkmate()) # Output: True print(board.is_game_over()) # Output: True # Stalemate detection (rare in shogi) stalemate_board = shogi.Board("+R+N+SGKG+S+N+R/+B+N+SG+LG+S+N+B/1P2P2P1/9/9/9/9/6k2 b - 200") print(stalemate_board.is_stalemate()) # Output: True # Check detection board2 = shogi.Board("kn7/9/1G7/9/9/9/9/9/9 b P 1") print(board2.is_check()) # Output: False board2.push_usi('8c8b') print(board2.is_check()) # Check if king is in check # Fourfold repetition (sennichite) rep_board = shogi.Board("ln3g2l/1r2g1sk1/1pp1ppn2/p2ps1ppp/1PP6/2GP4P/P1N1PPPP1/1R2S1SK1/L4G1NL w Bb 44") repetition_moves = ['9d9e', '8h6h', '8b6b', '6h8h', '6b8b', '8h6h', '8b6b', '6h8h', '6b8b', '8h6h', '8b6b', '6h8h', '6b8b'] for m in repetition_moves: rep_board.push_usi(m) print(rep_board.is_fourfold_repetition()) # Output: True # Attack detection board3 = shogi.Board() print(board3.is_attacked_by(shogi.BLACK, shogi.A4)) # Is square attacked by black? attackers = board3.attackers(shogi.BLACK, shogi.H5) print(shogi.H2 in attackers) # Check if specific square attacks target ``` -------------------------------- ### Parse CSA String Format Source: https://context7.com/gunyarakun/python-shogi/llms.txt Shows how to parse a string containing Shogi's CSA (Computer Shogi Association) format. This includes parsing game setup information and move lists. The `shogi.CSA.Parser.parse_str` function is used for this purpose. ```python csa_content = """ V2.2 N+Player1 N-Player2 PI + +7776FU -3334FU +8822UM %TORYO """ parsed = shogi.CSA.Parser.parse_str(csa_content) print(parsed[0]['moves']) # Output: ['7g7f', '3c3d', '8h2b+'] ``` -------------------------------- ### Access Shogi Board Constants Source: https://context7.com/gunyarakun/python-shogi/llms.txt This snippet shows how to access various constants related to the Shogi board, including colors (black/white), piece types (pawn, rook, etc.), and square coordinates. It also provides access to the starting position in SFEN format and Japanese number symbols. ```python import shogi # Colors print(shogi.BLACK) # 0 print(shogi.WHITE) # 1 print(shogi.COLORS) # [0, 1] # Piece types print(shogi.PAWN) # 1 print(shogi.LANCE) # 2 print(shogi.KNIGHT) # 3 print(shogi.SILVER) # 4 print(shogi.GOLD) # 5 print(shogi.BISHOP) # 6 print(shogi.ROOK) # 7 print(shogi.KING) # 8 print(shogi.PROM_PAWN) # 9 (と) print(shogi.PROM_BISHOP) # 13 (馬) print(shogi.PROM_ROOK) # 14 (龍) # Square indices (0-80) print(shogi.A9) # 0 (top-left) print(shogi.I1) # 80 (bottom-right) print(shogi.E5) # 40 (center) # Square names print(shogi.SQUARE_NAMES[shogi.A9]) # '9a' print(shogi.SQUARE_NAMES[shogi.I1]) # '1i' # Starting position SFEN print(shogi.STARTING_SFEN) # Output: lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 # Japanese number symbols (for KIF) print(shogi.NUMBER_JAPANESE_NUMBER_SYMBOLS) # ['0', '1', '2', ...] print(shogi.NUMBER_JAPANESE_KANJI_SYMBOLS) # ['零', '一', '二', ...] ``` -------------------------------- ### KIF Parser - Read KIF Format Game Records Source: https://context7.com/gunyarakun/python-shogi/llms.txt Details how to parse Shogi game records from KIF (Kifu) format files or strings. It shows how to access game metadata like player names, starting position (SFEN), and the list of moves, supporting various handicap positions. ```python import shogi import shogi.KIF # Parse KIF file games = shogi.KIF.Parser.parse_file('data/games/habu-fujii-2006.kif') game = games[0] # Access game metadata print(game['names'][shogi.BLACK]) # Output: 羽生善治 print(game['names'][shogi.WHITE]) # Output: 藤井猛 print(game['sfen']) # Starting position SFEN print(game['win']) # 'b' for black, 'w' for white, '-' for draw # Get all moves in USI format print(game['moves'][:5]) # First 5 moves # Output: ['7g7f', '3c3d', ...] # Parse KIF from string kif_content = """ 先手:Player1 後手:Player2 手合割:平手 手数----指手---------消費時間-- 1 7六歩(77) 2 3四歩(33) 3 投了 まで2手で後手の勝ち """ parsed = shogi.KIF.Parser.parse_str(kif_content) print(parsed[0]['moves']) # Output: ['7g7f', '3c3d'] # Supported handicaps print(shogi.KIF.Parser.HANDYCAP_SFENS.keys()) # 平手, 香落ち, 角落ち, 飛車落ち, 二枚落ち, etc. ``` -------------------------------- ### CSA Parser - Read CSA Format Source: https://context7.com/gunyarakun/python-shogi/llms.txt Shows how to parse Shogi game records from CSA (Computer Shogi Association) format files. This format is commonly used for professional game records and server communication. The example demonstrates parsing a file and accessing the first game's data. ```python import shogi import shogi.CSA # Parse CSA file games = shogi.CSA.Parser.parse_file('game.csa') game = games[0] ``` -------------------------------- ### Run Tests for python-shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Shows how to execute the test suite for the python-shogi library using the 'make test' command. This is essential for verifying the library's integrity and functionality. ```bash > make test ``` -------------------------------- ### Initialize and Play a Shogi Game in Python Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Demonstrates how to initialize a Shogi board and make moves using the python-shogi library. It shows basic move notation and how to check for checkmate. ```python >>> import shogi >>> board = shogi.Board() >>> board.push(shogi.Move.from_usi('7g7f')) >>> board.push_usi('3c3d') Move.from_usi('3c3d') >>> board.push_usi('8h2b+') Move.from_usi('8h2b+') >>> board.push_usi('4a5b') Move.from_usi('4a5b') >>> board.push_usi('B*4b') Move.from_usi('B*4b') >>> board.push_usi('5a4a') Move.from_usi('5a4a') >>> board.push_usi('2b3a') Move.from_usi('2b3a') >>> board.is_checkmate() True ``` -------------------------------- ### Configure TestPyPI Repository for python-shogi Release Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Details the steps to configure the poetry tool to use the TestPyPI repository for uploading packages. This is a crucial step before releasing to the main PyPI. ```bash poetry config repositories.testpypi https://test.pypi.org/legacy/ # poetry config pypi-token.testpypi "Test PyPI API Token" ``` -------------------------------- ### Run Nosetests with Standard Output for python-shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Illustrates how to run nosetests with the '-s' flag to print lines from the standard output. This is useful for debugging and observing detailed test execution. ```bash > poetry run nosetests -s ``` -------------------------------- ### Process USI Position Command Directly Source: https://context7.com/gunyarakun/python-shogi/llms.txt Demonstrates how to initialize a Shogi board and set its position using a USI (Universal Shogi Interface) command, then prints the board's SFEN (Shogi Federation of Japan Electronic Notation) representation. ```python import shogi board2 = shogi.Board() board2.push_usi_position_cmd("position startpos moves 7g7f 3c3d 2g2f") print(board2.sfen()) ``` -------------------------------- ### Create and Parse Shogi Moves with Python Source: https://context7.com/gunyarakun/python-shogi/llms.txt Illustrates the creation and parsing of shogi moves using the `shogi.Move` class. It covers generating moves from USI notation, including promotions and piece drops, as well as creating moves programmatically and handling null moves. ```python import shogi # Create move from USI string move = shogi.Move.from_usi('7g7f') # Pawn advance print(move.from_square) # Source square index print(move.to_square) # Destination square index print(move.usi()) # Output: 7g7f # Create promotion move promo_move = shogi.Move.from_usi('8h2b+') # Bishop captures and promotes print(promo_move.promotion) # Output: True # Create piece drop move drop_move = shogi.Move.from_usi('B*4b') # Drop bishop at 4b print(drop_move.drop_piece_type) # Output: 6 (BISHOP) # Create move programmatically manual_move = shogi.Move(shogi.G7, shogi.F7) # From G7 to F7 print(manual_move.usi()) # Output: 7g7f # Null move (passes turn) null_move = shogi.Move.null() print(bool(null_move)) # Output: False ``` -------------------------------- ### Upload python-shogi to PyPI Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Shows the command to upload the final release of the python-shogi package to the main PyPI repository. This command is executed after successful testing and TestPyPI upload. ```bash # poetry config pypi-token.pypi "PyPI API Token" make upload ``` -------------------------------- ### Display KIF Style Board in Python Shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Shows how to generate and display a Shogi board in the traditional KIF (Kakinoki File) format using the `board.kif_str()` method in python-shogi. This is useful for compatibility with other Shogi software. ```python >>> print(board.kif_str()) 後手の持駒: 9 8 7 6 5 4 3 2 1 +---------------------------+ |v香v桂v銀v金 ・v玉 馬v桂v香|一 | ・v飛 ・ ・v金 角 ・ ・ ・|二 |v歩v歩v歩v歩v歩v歩 ・v歩v歩|三 | ・ ・ ・ ・ ・ ・v歩 ・ ・|四 | ・ ・ ・ ・ ・ ・ ・ ・ ・|五 | ・ ・ 歩 ・ ・ ・ ・ ・ ・|六 | 歩 歩 ・ 歩 歩 歩 歩 歩 歩|七 | ・ ・ ・ ・ ・ ・ ・ 飛 ・|八 | 香 桂 銀 金 玉 金 銀 桂 香|九 +---------------------------+ 先手の持駒: 銀 ``` -------------------------------- ### Export Shogi Game Summary to KIF Format in Python Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Illustrates how to export Shogi game data, provided as a summary dictionary, into the KIF (Kakinoki File) format using `shogi.KIF.Exporter`. This is useful for saving game records. ```python >>> import shogi >>> import shogi.KIF >>> board = shogi.Board() >>> shogi.KIF.Exporter.kif_move_from('7g7f', board) '7六歩(77)' >>> sfen_summary = {'moves': ['7g7f', '3c3d'], 'sfen': 'lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1', 'names': ['羽生善治', '藤井猛'], 'win': 'w'} >>> shogi.KIF.Exporter.kif(sfen_summary) 開始日時: \r 終了日時: \r 手合割:平手\r 先手:羽生善治\r 後手:藤井猛\r 手数----指手---------消費時間-- \r 1 7六歩(77) \r ``` -------------------------------- ### Upload python-shogi to TestPyPI Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Provides the command to upload the python-shogi package to the TestPyPI repository. This command is typically part of the release process. ```bash make test-upload ``` -------------------------------- ### KIF Exporter - Write KIF Format Source: https://context7.com/gunyarakun/python-shogi/llms.txt Provides instructions on exporting Shogi game data into the KIF format. It demonstrates creating a game summary dictionary and using the exporter to generate KIF output, including converting individual moves and piece drops to KIF notation. ```python import shogi import shogi.KIF # Create game summary game_summary = { 'sfen': shogi.STARTING_SFEN, 'moves': ['7g7f', '3c3d', '2g2f', '8c8d'], 'names': ['羽生善治', '藤井猛'], 'win': 'w' } # Export to KIF format kif_output = shogi.KIF.Exporter.kif(game_summary) print(kif_output) # Output: # 開始日時: # 終了日時: # 手合割:平手 # 先手:羽生善治 # 後手:藤井猛 # 手数----指手---------消費時間-- # 1 7六歩(77) # 2 3四歩(33) # 3 2六歩(27) # 4 8四歩(83) # 5 投了 # まで4手で後手の勝ち # Convert single move to KIF notation board = shogi.Board() kif_move = shogi.KIF.Exporter.kif_move_from('7g7f', board) print(kif_move) # Output: 7六歩(77) # Piece drop notation board2 = shogi.Board("4k4/9/9/9/9/9/9/9/4K4 b B 1") drop_kif = shogi.KIF.Exporter.kif_move_from('B*5e', board2) print(drop_kif) # Output: 5五角打 ``` -------------------------------- ### Display ASCII Board in Python Shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Demonstrates how to print a simple ASCII representation of the Shogi board using the `print(board)` command in python-shogi. This provides a quick visual of the game state. ```python >>> print(board) l n s g . k +B n l . r . . g B . . . p p p p p p . p p . . . . . . p . . . . . . . . . . . . . P . . . . . . P P . P P P P P P . . . . . . . R . L N S G K G S N L S*1 ``` -------------------------------- ### Connect and Play via CSA TCP Protocol Source: https://context7.com/gunyarakun/python-shogi/llms.txt This snippet demonstrates how to connect to a CSA-compatible shogi server using the `shogi.CSA.TCPProtocol`. It covers login, waiting for matches, handling game turns, making moves, and logging out. It requires server address, port, username, and password. ```python import shogi import shogi.CSA # Connect to CSA server protocol = shogi.CSA.TCPProtocol() protocol.open('wdoor.c.u-tokyo.ac.jp', 4081) # Login protocol.login('username', 'password') # Or extended login for floodgate protocol.login_ex('username', 'password') # Wait for match match_info = protocol.wait_match(block=True) print(match_info['my_color']) # Your assigned color print(match_info['summary']) # Game summary with SFEN # Accept match protocol.agree() # Or reject # protocol.reject() # Game loop board = shogi.Board(match_info['summary']['sfen']) while not board.is_game_over(): # Wait for opponent's move or server message color, usi, time, message = protocol.wait_server_message(board, block=True) if message is not None: # Game ended if message == shogi.CSA.WIN: print("You win!") elif message == shogi.CSA.LOSE: print("You lose!") break if usi: # Opponent moved board.push_usi(usi) if board.turn == match_info['my_color']: # Your turn - make a move move = list(board.legal_moves)[0] # Simple: pick first legal move piece_type = board.piece_type_at(move.to_square) if move.from_square else move.drop_piece_type protocol.move(piece_type, match_info['my_color'], move) board.push(move) # Resign if needed # protocol.resign() # Logout protocol.logout() ``` -------------------------------- ### Make and Unmake Moves in Python Shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Illustrates how to undo the last move made on a Shogi board and then reapply it using the `pop()` and `push()` methods in python-shogi. This is essential for move generation and analysis. ```python >>> last_move = board.pop() # Unmake last move >>> last_move Move.from_usi('2b3a') >>> board.push(last_move) # Restore ``` -------------------------------- ### Parse Shogi Game from KIF File in Python Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Demonstrates how to parse a Shogi game record from a KIF (Kakinoki File) format file using the `shogi.KIF.Parser` in python-shogi. It extracts game metadata like player names, moves, and the winner. ```python >>> import shogi.KIF >>> kif = shogi.KIF.Parser.parse_file('data/games/habu-fujii-2006.kif')[0] >>> kif['names'][shogi.BLACK] '羽生善治' >>> kif['names'][shogi.WHITE] '藤井猛' >>> kif['moves'] # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE ['7g7f', '3c3d', ..., '9a9b', '7a7b+'] >>> kif['win'] 'b' ``` -------------------------------- ### Make and Unmake Shogi Moves with Python Source: https://context7.com/gunyarakun/python-shogi/llms.txt Details the process of making and unmaking moves on a shogi board using the `shogi` library. It demonstrates pushing moves via USI notation or `Move` objects, playing sequences of moves, checking game states like checkmate and check, undoing moves, and peeking at the last move. ```python import shogi board = shogi.Board() # Make a move using USI notation board.push_usi('7g7f') print(board.move_number) # Output: 2 # Make move using Move object move = shogi.Move.from_usi('3c3d') board.push(move) # Play a sequence of moves (scholar's mate) moves = ['8h2b+', '4a5b', 'B*4b', '5a4a', '2b3a'] for m in moves: board.push_usi(m) # Check game state print(board.is_checkmate()) # Output: True print(board.is_check()) # Output: True # Undo last move last_move = board.pop() print(last_move.usi()) # Output: 2b3a print(board.is_checkmate()) # Output: False # Get last move without popping if board.move_stack: peek_move = board.peek() print(peek_move.usi()) ``` -------------------------------- ### Generate and Validate Legal Shogi Moves in Python Source: https://context7.com/gunyarakun/python-shogi/llms.txt Explains how to generate and validate legal shogi moves using the `shogi` library. It covers obtaining all legal moves, checking move legality, generating pseudo-legal moves, filtering moves by piece type, and verifying specific move validity. ```python import shogi board = shogi.Board() # Get all legal moves legal_moves = list(board.legal_moves) print(f"Number of legal moves: {len(legal_moves)}") # Output: 30 # Check if a specific move is legal move = shogi.Move.from_usi('7g7f') print(move in board.legal_moves) # Output: True # Invalid move check invalid_move = shogi.Move.from_usi('9c9d') # Wrong turn print(invalid_move in board.legal_moves) # Output: False # Generate pseudo-legal moves (faster, no suicide check) pseudo_moves = list(board.pseudo_legal_moves) # Filter moves by piece type pawn_moves = list(board.generate_legal_moves( pawns=True, lances=False, knights=False, silvers=False, golds=False, bishops=False, rooks=False, king=False )) # Check specific move validity print(board.is_legal(move)) # Output: True print(board.is_pseudo_legal(move)) # Output: True ``` -------------------------------- ### Parse Professional Shogi Player Names with python-shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Demonstrates how to use the shogi.Person.Name module to check if a given Shogi player name belongs to a professional player. This is useful for data validation and categorization of player information. ```python import shogi.Person shogi.Person.Name.is_professional('羽生 善治 名人・棋聖・王位・王座') ``` -------------------------------- ### Piece Representation and Conversion Source: https://context7.com/gunyarakun/python-shogi/llms.txt Explains how to work with individual Shogi pieces using the `Piece` class. It covers creating pieces from symbols (Western and Japanese), checking promotion status, and accessing all defined piece types and their properties. ```python import shogi # Create piece from symbol piece = shogi.Piece.from_symbol('P') # Black pawn print(piece.piece_type) # Output: 1 (PAWN) print(piece.color) # Output: 0 (BLACK) print(piece.symbol()) # Output: P # White pieces use lowercase white_piece = shogi.Piece.from_symbol('p') print(white_piece.color) # Output: 1 (WHITE) # Japanese symbols print(piece.japanese_symbol()) # Output: 歩 # Promoted pieces promoted = shogi.Piece.from_symbol('+P') print(promoted.is_promoted()) # Output: True print(promoted.japanese_symbol()) # Output: と # All piece types print(shogi.PAWN) # 1 print(shogi.LANCE) # 2 print(shogi.KNIGHT) # 3 print(shogi.SILVER) # 4 print(shogi.GOLD) # 5 print(shogi.BISHOP) # 6 print(shogi.ROOK) # 7 print(shogi.KING) # 8 # Get piece at board position board = shogi.Board() king = board.piece_at(shogi.I5) print(king.symbol()) # Output: K print(king.japanese_symbol()) # Output: 玉 ``` -------------------------------- ### Convert Moves to USI Format in Python Shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Demonstrates how to convert a Shogi move object into its Universal Shogi Interface (USI) string representation using the `usi()` method in python-shogi. This is crucial for interoperability with other Shogi engines. ```python >>> board = shogi.Board() >>> shogi.Move(shogi.E2, shogi.E4).usi() '2e4e' ``` -------------------------------- ### Detect Checks and Attacks in Python Shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Shows how to determine if the current board state is in check, and how to identify which pieces are attacking a specific square using `is_check()`, `is_attacked_by()`, and `attackers()` in python-shogi. ```python >>> board.is_check() True >>> board.is_attacked_by(shogi.BLACK, shogi.A4) True >>> attackers = board.attackers(shogi.BLACK, shogi.H5) >>> attackers SquareSet(0b111000010000000000000000000000000000000000000000000000000000000000000000000000) >>> shogi.H2 in attackers True >>> print(attackers) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 . . . . 1 1 1 . . . ``` -------------------------------- ### Detect Checkmate and Stalemate in Python Shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Demonstrates how to check for game-ending conditions like checkmate and stalemate using the `is_checkmate()` and `is_stalemate()` methods in python-shogi. It also shows how to check if the game is over. ```python >>> board.is_stalemate() False >>> board.is_game_over() True ``` -------------------------------- ### Detect Professional Shogi Players Source: https://context7.com/gunyarakun/python-shogi/llms.txt Provides functions to identify professional shogi players from their names. It includes normalization capabilities to handle titles and variations in name formatting. Supports checking for both male and female professionals. ```python import shogi.Person # Check if name is a professional player print(shogi.Person.Name.is_professional('羽生善治')) # Output: True print(shogi.Person.Name.is_professional('藤井聡太')) # Output: True # Handles name suffixes and titles print(shogi.Person.Name.is_professional('羽生 善治 名人・棋聖・王位・王座')) # Output: True # Normalize names (remove spaces, titles) normalized = shogi.Person.Name.normalize('羽生 善治 名人') print(normalized) # Output: 羽生善治 # Check ladies professional print(shogi.Person.Name.is_ladies_professional('里見香奈')) # Output: True print(shogi.Person.Name.is_ladies_professional('藤田綾')) # Output: True # Non-professional returns False print(shogi.Person.Name.is_professional('山田太郎')) # Output: False ``` -------------------------------- ### Validate Legal Moves in Python Shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Shows how to check if a given move is legal on the current Shogi board using the python-shogi library. This is useful for move validation within a game. ```python >>> shogi.Move.from_usi("5i5a") in board.legal_moves False ``` -------------------------------- ### Detect Repetitions and Half Move Clock in Python Shogi Source: https://github.com/gunyarakun/python-shogi/blob/master/README.rst Explains how to detect fourfold repetitions and access the half move clock count using `is_fourfold_repetition()` and `move_number` in python-shogi. These are important rules for Shogi draws. ```python >>> board.is_fourfold_repetition() False >>> board.move_number 8 ``` -------------------------------- ### CSA Piece Symbols Mapping Source: https://context7.com/gunyarakun/python-shogi/llms.txt Accesses and prints the mapping of CSA piece symbols used in the Shogi protocol. This is useful for understanding or translating piece representations. ```python print(shogi.CSA.PIECE_SYMBOLS) # ['* ', 'FU', 'KY', 'KE', 'GI', 'KI', 'KA', 'HI', 'OU', 'TO', 'NY', 'NK', 'NG', 'UM', 'RY'] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.