Coder Social home page Coder Social logo

tadaoyamaoka / cshogi Goto Github PK

View Code? Open in Web Editor NEW
123.0 5.0 25.0 6.22 MB

高速なPythonの将棋ライブラリ (A Fast Shogi Library for Python)

Home Page: https://tadaoyamaoka.github.io/cshogi/

License: GNU General Public License v3.0

C++ 69.13% Python 17.16% JavaScript 1.87% HTML 2.31% Cython 8.68% C 0.85%

cshogi's Introduction

cshogi: A Fast Shogi Library for Python

PyPI package

概要

cshogi is a fast Python shogi library that provides board management, legal move generation, move verification, USI protocol, and support for machine learning formats. Below is an example of creating a board, generating legal moves at the starting position, displaying them, and making a move.

cshogiは、盤面管理、合法手生成、指し手の検証、USIプロトコル、および機械学習向けフォーマットのサポートを備えた高速なPythonの将棋ライブラリです。 以下は、盤を作成して、開始局面で合法手を生成して表示し、1手指す処理の例です。

>>> import cshogi

>>> board = cshogi.Board()

>>> for move in board.legal_moves:
...     print(cshogi.move_to_usi(move))
1g1f
2g2f
3g3f
4g4f
5g5f
6g6f
7g7f
...
>>> board.push_usi('7g7f')

機能

  • Python 3.5以上とCython 0.29以上をサポート

  • IPython/Jupyter Notebookと統合

    >>> board
    https://raw.githubusercontent.com/wiki/TadaoYamaoka/cshogi/images/board.svg?sanitize=true
  • 指す/手を戻す

    >>> move = board.push_usi('7g7f') # 指す
    
    >>> board.pop() # 手を戻す
  • テキスト形式で盤面を表示

    >>> board = Board('ln4skl/3r1g3/1p2pgnp1/p1ppsbp1p/5p3/2PPP1P1P/PPBSSG1P1/2R3GK1/LN5NL b P 43')
    >>> print(board)
    '  9  8  7  6  5  4  3  2  1
    P1-KY-KE *  *  *  * -GI-OU-KY
    P2 *  *  * -HI * -KI *  *  *
    P3 * -FU *  * -FU-KI-KE-FU *
    P4-FU * -FU-FU-GI-KA-FU * -FU
    P5 *  *  *  *  * -FU *  *  *
    P6 *  * +FU+FU+FU * +FU * +FU
    P7+FU+FU+KA+GI+GI+KI * +FU *
    P8 *  * +HI *  *  * +KI+OU *
    P9+KY+KE *  *  *  *  * +KE+KY
    P+00FU
    +
    
  • 王手判定、終局判定、入玉宣言法判定

    >>> board.is_check()
    False
    >>> board.is_game_over()
    True
    >>> board.is_nyugyoku()
    False
  • 千日手判定

    >>> board.is_draw() == REPETITION_DRAW # 同一局面が1つ以上ある
    False
  • 指し手の表現

    指し手は数値で扱う。ヘルパー関数でUSIまたはCSA形式に変換できる。

    >>> move = [move for move in board.legal_moves][0]
    >>> move
    66309
    >>> move_to_usi(move)
    '1g1f'
    >>> move_to_csa(move)
    '1716FU'

    USIまたはCSA形式から数値の指し手に変換できる。

    >>> board.move_from_usi('7g7f')
    73275
    >>> board.move_from_csa('7776FU')
    73275
  • 局面の圧縮形式

    Apery、やねうら王で生成した教師局面を読み込むことができる。

    >>> import numpy as np
    
    >>> hcpes = np.fromfile('teacher.hcpe', dtype=cshogi.HuffmanCodedPosAndEval) # Aperyの教師局面(HuffmanCodedPosAndEval)
    >>> board.set_hcp(hcpes[0]['hcp'])
    
    >>> psfens = np.fromfile('sfen.bin', dtype=cshogi.PackedSfenValue) # やねうら王の教師局面(PackedSfenValue)
    >>> board.set_psfen(psfens[0]['sfen'])

    局面をAperyの圧縮形式で保存できる。

    >>> hcps = np.empty(1, dtype=cshogi.HuffmanCodedPos)
    >>> board.to_hcp(hcps)
    >>> hcps.tofile('hcp')
  • USIエンジンの操作

    USIエンジンを起動して操作できる。

    >>> from cshogi.usi import Engine
    
    >>> engine = Engine('/content/LesserkaiSrc/Lesserkai/Lesserkai')
    >>> engine.isready()
    >>> engine.position(sfen='sfen 7nl/5kP2/3p2g1p/2p1gp3/p6sP/s1BGpN3/4nPSp1/1+r4R2/L1+p3K1L w GSNLPb6p 122')
    >>> engine.go()
  • USIエンジン同士の対局

    >>> from cshogi import cli
    
    >>> cli.main('/content/LesserkaiSrc/Lesserkai/Lesserkai', '/content/LesserkaiSrc/Lesserkai/Lesserkai')

インストール

  • GitHubのソースからインストール

以下のコマンドでインストールします。インストールにはCythonと対応したC++コンパイラが必要です。

pip install git+https://github.com/TadaoYamaoka/cshogi
  • PYPIからインストール
pip install cshogi

pipのバージョン19.0以上が必要です。19.0未満の場合は、事前にpipの アップグレード が必要です。

インストールに失敗して、再実行する際は、--no-cache-dirオプションを付けて実行してください。

pip install --no-cache-dir cshogi

cshogi.webパッケージを使用する場合は、以下のコマンドで追加の依存パッケージをインストールできます。

pip install cshogi[web]

ドキュメント

謝辞

高速化のために多くの部分で Apery のソースを流用しています。

ライセンス

cshogiはGPL3の元にライセンスされています。詳細はLICENSEを確認してください。

cshogi's People

Contributors

bleu48 avatar hmatsuya avatar jh85 avatar mizar avatar quiver avatar shibacho avatar tadaoyamaoka avatar tatsy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cshogi's Issues

PackedSfen::init

PackedSfenはデフォルトで初期化されていないようですが
使ってないからですか?

盤面の日本語表示

どうしても見づらいので実装してみました。
そのままでなくても構わないので取り入れて頂けませんか?
例えば漢数字などは現行のListを拡張する方が当然スマートです。

PIECE_JAPANESE_SYMBOLS=[
	" ・", " 歩", " 香", " 桂", " 銀", " 角", " 飛", " 金", " 玉", " と", " 杏", " 圭", " 全", " 馬", " 龍", " 菌",
	" 王", "v歩", "v香", "v桂", "v銀", "v角", "v飛", "v金", "v玉", "vと", "v杏", "v圭", "v全", "v馬", "v龍", "v菌",
]
NUMBER_JAPANESE_SYMBOLS = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九",
	"十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九"]

def printj(board):
    buf = "後手の持駒:"
    for i in range(7):
        if (k:=board.pieces_in_hand[cshogi.WHITE][i]) > 0:
            buf += cshogi.HAND_PIECE_JAPANESE_SYMBOLS[i]
            if k > 1:
                buf += NUMBER_JAPANESE_SYMBOLS[k]
    print(buf)
    print("  9 8 7 6 5 4 3 2 1\n+---------------------------+")
    for r in range(9):
        buf = "|"
        for f in reversed(range(9)):
            buf += PIECE_JAPANESE_SYMBOLS[board.piece(f*9+r)]
        print(buf + "|"+NUMBER_JAPANESE_SYMBOLS[r+1])
    print("+---------------------------+")
    buf = "先手の持駒:"
    for i in range(7):
        if (k:=board.pieces_in_hand[cshogi.BLACK][i]) > 0:
            buf += cshogi.HAND_PIECE_JAPANESE_SYMBOLS[i]
            if k > 1:
                buf += NUMBER_JAPANESE_SYMBOLS[k]
    print(buf)
    if board.turn == cshogi.BLACK:
        print("先手番")
    else:
        print("後手番")
    print("{}手目".format(board.move_number))

Parserのバグ(同種の持ち駒複数の場合のto_sfen())

CSA.Parser.parse_csa()の持ち駒の処理にまた別のバグがあるように思えます。
同種の持ち駒が複数枚ある時、sfen形式では枚数の後に駒種を書き表しますが、逆になっています。

具体的な箇所は、cshogi/src/parser.h の430~433行目です。
430行目で持ち駒の駒種の処理をしていますが、
これは431~433行目の枚数の処理の後にすべきだと思います。

ご確認の上、修正頂けますと幸いです。

インストールできない

以下のエラーが表示されてインストールできません。

$ pip install cshogi
Collecting cshogi
  Using cached cshogi-0.5.5.tar.gz (107 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: cshogi
  Building wheel for cshogi (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [55 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-x86_64-cpython-310
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/elo.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/KIF.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/cli.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/KI2.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/CSA.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/PGN.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/usi
      copying cshogi/usi/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/usi
      copying cshogi/usi/Engine.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/usi
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/gym_shogi
      copying cshogi/gym_shogi/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/gym_shogi
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/gym_shogi/envs
      copying cshogi/gym_shogi/envs/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/gym_shogi/envs
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/dlshogi
      copying cshogi/dlshogi/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/dlshogi
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web
      copying cshogi/web/app.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web/templates
      copying cshogi/web/templates/board.html -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web/templates
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web/static
      copying cshogi/web/static/board.js -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web/static
      running build_ext
      cythoning cshogi/_cshogi.pyx to cshogi/_cshogi.cpp
      /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/zd/rttxr3kd54g0_wqtw5_y_cgc0000gn/T/pip-install-k55k7q8j/cshogi_8f8ff5e203514294ba2af1bdd1e5c234/cshogi/_cshogi.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      cythoning cshogi/gym_shogi/envs/shogi_env.pyx to cshogi/gym_shogi/envs/shogi_env.cpp
      /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/zd/rttxr3kd54g0_wqtw5_y_cgc0000gn/T/pip-install-k55k7q8j/cshogi_8f8ff5e203514294ba2af1bdd1e5c234/cshogi/gym_shogi/envs/shogi_env.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      cythoning cshogi/gym_shogi/envs/shogi_vec_env.pyx to cshogi/gym_shogi/envs/shogi_vec_env.cpp
      /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/zd/rttxr3kd54g0_wqtw5_y_cgc0000gn/T/pip-install-k55k7q8j/cshogi_8f8ff5e203514294ba2af1bdd1e5c234/cshogi/gym_shogi/envs/shogi_vec_env.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      building 'cshogi._cshogi' extension
      creating build/temp.macosx-10.9-x86_64-cpython-310
      creating build/temp.macosx-10.9-x86_64-cpython-310/cshogi
      creating build/temp.macosx-10.9-x86_64-cpython-310/src
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/paalon/.pyenv/versions/miniconda3-latest/include -fPIC -O2 -isystem /Users/paalon/.pyenv/versions/miniconda3-latest/include -DHAVE_SSE4 -DHAVE_SSE42 -DHAVE_AVX2 -Isrc -I/Users/paalon/.pyenv/versions/miniconda3-latest/include/python3.10 -I/Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include -c cshogi/_cshogi.cpp -o build/temp.macosx-10.9-x86_64-cpython-310/cshogi/_cshogi.o -msse4.2 -mavx2
      In file included from cshogi/_cshogi.cpp:770:
      In file included from /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include/numpy/arrayobject.h:5:
      In file included from /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include/numpy/ndarrayobject.h:12:
      In file included from /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include/numpy/ndarraytypes.h:1940:
      /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: "Using deprecated NumPy API, disable it with "          "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
      #warning "Using deprecated NumPy API, disable it with " \
       ^
      cshogi/_cshogi.cpp:778:10: fatal error: 'init.hpp' file not found
      #include "init.hpp"
               ^~~~~~~~~~
      1 warning and 1 error generated.
      error: command '/usr/local/opt/llvm/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cshogi
  Running setup.py clean for cshogi
Failed to build cshogi
Installing collected packages: cshogi
  Running setup.py install for cshogi ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for cshogi did not run successfully.
  │ exit code: 1
  ╰─> [51 lines of output]
      running install
      /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-x86_64-cpython-310
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/elo.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/KIF.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/cli.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/KI2.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/CSA.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      copying cshogi/PGN.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/usi
      copying cshogi/usi/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/usi
      copying cshogi/usi/Engine.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/usi
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/gym_shogi
      copying cshogi/gym_shogi/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/gym_shogi
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/gym_shogi/envs
      copying cshogi/gym_shogi/envs/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/gym_shogi/envs
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/dlshogi
      copying cshogi/dlshogi/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/dlshogi
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web
      copying cshogi/web/app.py -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web/templates
      copying cshogi/web/templates/board.html -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web/templates
      creating build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web/static
      copying cshogi/web/static/board.js -> build/lib.macosx-10.9-x86_64-cpython-310/cshogi/web/static
      running build_ext
      skipping 'cshogi/_cshogi.cpp' Cython extension (up-to-date)
      skipping 'cshogi/gym_shogi/envs/shogi_env.cpp' Cython extension (up-to-date)
      skipping 'cshogi/gym_shogi/envs/shogi_vec_env.cpp' Cython extension (up-to-date)
      building 'cshogi._cshogi' extension
      creating build/temp.macosx-10.9-x86_64-cpython-310
      creating build/temp.macosx-10.9-x86_64-cpython-310/cshogi
      creating build/temp.macosx-10.9-x86_64-cpython-310/src
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/paalon/.pyenv/versions/miniconda3-latest/include -fPIC -O2 -isystem /Users/paalon/.pyenv/versions/miniconda3-latest/include -DHAVE_SSE4 -DHAVE_SSE42 -DHAVE_AVX2 -Isrc -I/Users/paalon/.pyenv/versions/miniconda3-latest/include/python3.10 -I/Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include -c cshogi/_cshogi.cpp -o build/temp.macosx-10.9-x86_64-cpython-310/cshogi/_cshogi.o -msse4.2 -mavx2
      In file included from cshogi/_cshogi.cpp:770:
      In file included from /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include/numpy/arrayobject.h:5:
      In file included from /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include/numpy/ndarrayobject.h:12:
      In file included from /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include/numpy/ndarraytypes.h:1940:
      /Users/paalon/.pyenv/versions/miniconda3-latest/lib/python3.10/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: "Using deprecated NumPy API, disable it with "          "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
      #warning "Using deprecated NumPy API, disable it with " \
       ^
      cshogi/_cshogi.cpp:778:10: fatal error: 'init.hpp' file not found
      #include "init.hpp"
               ^~~~~~~~~~
      1 warning and 1 error generated.
      error: command '/usr/local/opt/llvm/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> cshogi

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

Visual Studio以外の環境でのビルド

初歩的な質問で申し訳ないのですが、cshogiはVisualStudio以外の環境、例えばUbuntu上でpython3 setup.py buildなどとすればビルドできるのでしょうか。Ubuntu上で動かせるようにしたいのですがビルド方法が分からなかったので教えていただけるとありがたいです。

歩が消える

push_usiやboard.move_from_csaだと問題ないのですがcshogi.move_from_csaで生成した指し手だと
取った歩が持ち歩になっていないですね。
これは仕様のうちでしょうか?

> import cshogi
> 
> board = cshogi.Board('ln2k1snl/1r1sg1gb1/p1p1pppp1/3p3Pp/1p7/2P6/PPBPPPP1P/2GS2SR1/LN2KG1NL w - 1')
> print(board)
> 
> move = cshogi.move_from_csa('2324FU')
> # move = board.move_from_csa('2324FU')
> board.push(move)
> 
> # board.push_usi('2c2d')
> 
> print(board)

Problem when using pyinstaller

Traceback (most recent call last):
  File "ShogiBar1.py", line 1, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "cshogi\__init__.py", line 1, in <module>
  File "cshogi\\_cshogi.pyx", line 1, in init cshogi._cshogi
ImportError: numpy.core.multiarray failed to import (auto-generated because you didn't call 'numpy.import_array()' after cimporting numpy; use '<void>numpy._import_array' to disable if you are certain you don't need it).
[14524] Failed to execute script 'ShogiBar1' due to unhandled exception!

When my script (using cshogi) is exported as a pyinstaller exe, it fails to load with this stack trace.

自玉王手時の王手放置一手詰め判定バグ

自玉が王手されている際に「mate_move_in_1ply」を使用すると、王手放置で一手詰め(反則手)の着手を返すようです。

例:
position sfen rrll1pppp/llbgggg2/ppppssssK/2n1p4/3nkn3/5n3/B8/9/9 b 9p 1 moves 9g8h
go
bestmove 3b2b

Cannot install through PyPI

C:\Users\MY PC>pip install cshogi
Collecting cshogi
  Downloading cshogi-0.6.5.tar.gz (120 kB)
     ---------------------------------------- 120.7/120.7 kB 883.7 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [59 lines of output]
      running egg_info
      writing cshogi.egg-info\PKG-INFO
      writing dependency_links to cshogi.egg-info\dependency_links.txt
      writing requirements to cshogi.egg-info\requires.txt
      writing top-level names to cshogi.egg-info\top_level.txt
      Traceback (most recent call last):
        File "C:\Users\MY PC\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\Users\MY PC\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\MY PC\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\build_meta.py", line 355, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in _get_build_requires
          self.run_setup()
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\build_meta.py", line 507, in run_setup
          super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in run_setup
          exec(code, locals())
        File "<string>", line 33, in <module>
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
          dist.run_commands()
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\dist.py", line 989, in run_command
          super().run_command(command)
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
          cmd_obj.run()
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 318, in run
          self.find_sources()
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 326, in find_sources
          mm.run()
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 548, in run
          self.add_defaults()
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\command\egg_info.py", line 586, in add_defaults
          sdist.add_defaults(self)
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\command\sdist.py", line 113, in add_defaults
          super().add_defaults()
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\_distutils\command\sdist.py", line 251, in add_defaults
          self._add_defaults_ext()
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\_distutils\command\sdist.py", line 335, in _add_defaults_ext
          build_ext = self.get_finalized_command('build_ext')
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 305, in get_finalized_command
          cmd_obj.ensure_finalized()
        File "C:\Users\MY PC\AppData\Local\Temp\pip-build-env-0h2b1lkj\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 111, in ensure_finalized
          self.finalize_options()
        File "<string>", line 14, in finalize_options
      AttributeError: 'dict' object has no attribute '__NUMPY_SETUP__'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

インストールできない

pip install cshogiまたはpip install --no-cache-dir cshogiを実行し、インストールしようとすると以下のエラーが出ます
Collecting cshogi
Using cached cshogi-0.5.5.tar.gz (107 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: cshogi
Building wheel for cshogi (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [55 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-cpython-39
creating build/lib.macosx-10.9-x86_64-cpython-39/cshogi
copying cshogi/elo.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi
copying cshogi/KIF.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi
copying cshogi/init.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi
copying cshogi/cli.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi
copying cshogi/KI2.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi
copying cshogi/CSA.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi
copying cshogi/PGN.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi
creating build/lib.macosx-10.9-x86_64-cpython-39/cshogi/usi
copying cshogi/usi/init.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi/usi
copying cshogi/usi/Engine.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi/usi
creating build/lib.macosx-10.9-x86_64-cpython-39/cshogi/gym_shogi
copying cshogi/gym_shogi/init.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi/gym_shogi
creating build/lib.macosx-10.9-x86_64-cpython-39/cshogi/gym_shogi/envs
copying cshogi/gym_shogi/envs/init.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi/gym_shogi/envs
creating build/lib.macosx-10.9-x86_64-cpython-39/cshogi/dlshogi
copying cshogi/dlshogi/init.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi/dlshogi
creating build/lib.macosx-10.9-x86_64-cpython-39/cshogi/web
copying cshogi/web/app.py -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi/web
creating build/lib.macosx-10.9-x86_64-cpython-39/cshogi/web/templates
copying cshogi/web/templates/board.html -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi/web/templates
creating build/lib.macosx-10.9-x86_64-cpython-39/cshogi/web/static
copying cshogi/web/static/board.js -> build/lib.macosx-10.9-x86_64-cpython-39/cshogi/web/static
running build_ext
cythoning cshogi/_cshogi.pyx to cshogi/_cshogi.cpp
/Users/user/opt/anaconda3/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/gr/gzk65rh97vgd833zrtsxqs4r0000gn/T/pip-install-gtd90w2b/cshogi_24f099c3032f4b6fb5be3b7fda1daef2/cshogi/_cshogi.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
cythoning cshogi/gym_shogi/envs/shogi_env.pyx to cshogi/gym_shogi/envs/shogi_env.cpp
/Users/user/opt/anaconda3/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/gr/gzk65rh97vgd833zrtsxqs4r0000gn/T/pip-install-gtd90w2b/cshogi_24f099c3032f4b6fb5be3b7fda1daef2/cshogi/gym_shogi/envs/shogi_env.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
cythoning cshogi/gym_shogi/envs/shogi_vec_env.pyx to cshogi/gym_shogi/envs/shogi_vec_env.cpp
/Users/user/opt/anaconda3/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/gr/gzk65rh97vgd833zrtsxqs4r0000gn/T/pip-install-gtd90w2b/cshogi_24f099c3032f4b6fb5be3b7fda1daef2/cshogi/gym_shogi/envs/shogi_vec_env.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building 'cshogi._cshogi' extension
creating build/temp.macosx-10.9-x86_64-cpython-39
creating build/temp.macosx-10.9-x86_64-cpython-39/cshogi
creating build/temp.macosx-10.9-x86_64-cpython-39/src
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/user/opt/anaconda3/include -arch x86_64 -I/Users/haruni20/opt/anaconda3/include -fPIC -O2 -isystem /Users/user/opt/anaconda3/include -arch x86_64 -DHAVE_SSE4 -DHAVE_SSE42 -DHAVE_AVX2 -Isrc -I/Users/user/opt/anaconda3/include/python3.9 -I/Users/user/opt/anaconda3/lib/python3.9/site-packages/numpy/core/include -c cshogi/_cshogi.cpp -o build/temp.macosx-10.9-x86_64-cpython-39/cshogi/_cshogi.o -msse4.2 -mavx2
In file included from cshogi/_cshogi.cpp:766:
In file included from /Users/user/opt/anaconda3/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:5:
In file included from /Users/user/opt/anaconda3/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12:
In file included from /Users/user/opt/anaconda3/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1940:
/Users/user/opt/anaconda3/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
#warning "Using deprecated NumPy API, disable it with "
^
cshogi/_cshogi.cpp:774:10: fatal error: 'init.hpp' file not found
#include "init.hpp"
^~~~~~~~~~
1 warning and 1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for cshogi
Running setup.py clean for cshogi
Failed to build cshogi
ERROR: Could not build wheels for cshogi, which is required to install pyproject.toml-based projects

Boardをhashableに

BoardオブジェクトをbookKeyをhash値にしてhashableにするのは如何でしょうか?
ちょっとした差なのですが色々と簡便に書けるようになります。

Poetryでインストールに失敗する

エラー文:

Using version ^0.5.1 for cshogi

Updating dependencies
Resolving dependencies... Downloading https://files.pythonhosted.org/packages/06/20/ad71af28e35fd3b4990bfed531be4d3660bdf7d08f76817e4878fe55134f/cshogi-0.5.1-cp
Resolving dependencies... (0.3s)

Writing lock file

Package operations: 1 install, 0 updates, 0 removals

  • Installing cshogi (0.5.1): Failed

  ChefBuildError

  Backend subprocess exited when trying to invoke get_requires_for_build_wheel

  running egg_info
  writing cshogi.egg-info/PKG-INFO
  writing dependency_links to cshogi.egg-info/dependency_links.txt
  writing top-level names to cshogi.egg-info/top_level.txt
  Traceback (most recent call last):
    File "/usr/local/Cellar/poetry/1.4.2/libexec/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/usr/local/Cellar/poetry/1.4.2/libexec/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/Cellar/poetry/1.4.2/libexec/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
      return hook(config_settings)
             ^^^^^^^^^^^^^^^^^^^^^
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires
      self.run_setup()
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/build_meta.py", line 485, in run_setup
      self).run_setup(setup_script=setup_script)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/build_meta.py", line 335, in run_setup
      exec(code, locals())
    File "<string>", line 33, in <module>
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/__init__.py", line 108, in setup
      return distutils.core.setup(**attrs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup
      return run_commands(dist)
             ^^^^^^^^^^^^^^^^^^
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
      dist.run_commands()
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
      self.run_command(cmd)
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/dist.py", line 1221, in run_command
      super().run_command(command)
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
      cmd_obj.run()
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 318, in run
      self.find_sources()
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 326, in find_sources
      mm.run()
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 570, in run
      self.add_defaults()
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 608, in add_defaults
      sdist.add_defaults(self)
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/command/sdist.py", line 106, in add_defaults
      super().add_defaults()
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/sdist.py", line 251, in add_defaults
      self._add_defaults_ext()
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/sdist.py", line 335, in _add_defaults_ext
      build_ext = self.get_finalized_command('build_ext')
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 305, in get_finalized_command
      cmd_obj.ensure_finalized()
    File "/private/var/folders/wy/8gl91dzn1jdffgspj41txp1c0000gn/T/tmparsi1a3i/.venv/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 111, in ensure_finalized
      self.finalize_options()
    File "<string>", line 14, in finalize_options
  AttributeError: 'dict' object has no attribute '__NUMPY_SETUP__'


  at /usr/local/Cellar/poetry/1.4.2/libexec/lib/python3.11/site-packages/poetry/installation/chef.py:152 in _prepare
      148│
      149│                 error = ChefBuildError("\n\n".join(message_parts))
      150│
      151│             if error is not None:
    → 152│                 raise error from None
      153│
      154│             return path
      155│
      156│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with cshogi (0.5.1) not supporting PEP 517 builds. You can verify this by running 'pip wheel --use-pep517 "cshogi (==0.5.1)"'.

push_usiで着手が反映されない

python3.7で v0.3.9を使用しています。
以下の13手目の着手「3h2h」がboardに反映されません。

import cshogi
sfen = ['7g7f', '3c3d', '6g6f', '8b4b', '2h6h', '5a6b', '5i4h', '6b7b', '7i7h', '4b3b', '4h3h', '4a5b', '3h2h','7b8b']

board = cshogi.Board()
for move in sfen:
x = board.push_usi(move)
display(board)

着手候補 board.legal_moves にも含まれないようです。

RuntimeError: incorrect move string

Python 3.11+cshogi 0.8.5

import cshogi
board = cshogi.Board()
board.set_position('sfen 4+Rrkn1/4S4/6+S2/4gppp1/4N4/9/9/9/9 b L2b3g2s2n3l15p 1 moves 5a4b')

上記コードがRuntimeErrorを送出します。
board.set_position('sfen 4+Rrkn1/4S4/6+S2/4gppp1/4N4/9/9/9/9 b L2b3g2s2n3l15p 1)
とした時、board.legal_movesには'5a4b'の数値の指し手は含まれておらず、
board.push_usi('5a4b')は0を返します。

mate_move_in_1ply()について

初めまして。私の環境だけかもしれませんが、念のため確認いただけると助かります。

mate_move_in_1ply()について、手番側に王手がかかっている場合でも詰めると判定しています
(合法手でない手を選択しているようです)

import cshogi
board = cshogi.Board('1+R6l/g2g2+P2/1s2s4/2np2ppp/1pPkN2+b1/P2NS+b3/1P1+s2P1P/4PK+R2/3g3+lL w N5Pglp 3')
xxx = board.mate_move_in_1ply()
print(cshogi.move_to_usi(xxx))
→ 2e5h (本来ならNoneと帰ってくるはず)

v0.6.6のオーソライズ

v0.6.6をPYPIにオーソライズしないのでしょうか?
早く使いたいのでよろしくお願い致します。

KIFファイルの変換に失敗する

今回の電竜戦TSECの次のKIF形式のファイルの変換に失敗するようです。

dr4tsec+buoy_三間歩得型_tesc4y1-11-top_33_nibanshibori_hisui-120-2F+nibanshibori+hisui+20230701030201.kif

例)

kif = KIF.Parser.parse_file(filename)
print(" ".join([cshogi.move_to_usi(move) for move in kif.moves]))

7g7f 8c8d 2h7h 8d8e 8h7g 3c3d 6g6f 7a6b 7i6h 5a4b 1g1f 1c1d 5i4h 4b3b 3i3h 6a5b 6i5h 2b3c 6h6g 5c5d 4h3i 3b2b 3i2h 3a3b 7f7e 6c6d 6g5f 2c2d 5f4e 3b2c 4e5d 6b6c 5d4e 4a3b 4g4f 9c9d 7h6h 2b1b 4e5f 6c5d 6f6e 3c7g+ 8i7g 6h6g 8e8f 8g8f 8b8f 6e6d 8f8i+ 6d8i+ 5d8i 7b8i+ 6c5b 6f6g+ 5h8i 8i9i 5b4a 5a5f 7g6e 6g6h 5f5g 6h6e 7h6i 5h4g 8h6h+ 5g5f 1f1e 5h5i+ 1e1d 5i4i 2g2f 4i4h 1b2b 1c1a+ 2b2b 1d1c+ 4h3h 4g2b 6h2b

この43手目は、77桂(8i7g)で、
この44手目は、33角打なのですが、この指し手の変換に失敗して、欠落し、
次の45手目の、67飛(6h7g)が生成されています。

上の引用部の"8i7g 6h7g"となっているところがそれです。

この変換元のKIFファイルの当該部分は以下のようになっています。

 43 同 桂(89)           ( 0:00/00:01:01)
**対局 評価値 -186 読み筋 △3三角打(00) ▲6七飛(68) △8六歩(85) ▲8六歩(87) △8六飛(82) ▲6四歩(65) △8九飛成(86) ▲7二角打(00) △6三歩打(00) ▲6三歩成(64) △6三銀(54) ▲6三角成(72) △6六歩打(00) ▲5二馬(63) △6七歩成(66) ▲6七金(58) △8八飛打(00) ▲6八歩打(00) △9九龍(89) ▲6五桂(77) △6六香打(00) ▲5八銀打(00) △6七香成(66) ▲6七銀(56) △7七角成(33) ▲5三桂成(65) △6八飛成(88) ▲6九歩打(00) △6七馬(77) ▲6七銀(58) △6九龍(99) ▲3九金打(00) △4七銀打(00) ▲5八角打(00) △4九龍(69) ▲4九金(39) △4八金打(00) ▲4八金(49) △4八銀成(47) ▲4九金打(00) △4九成銀(48) ▲4九銀(38) △6六歩打(00) ▲6九歩打(00) △6七歩成(66) ▲6八歩(69) △5一歩打(00)
 44 3三角打(00)           ( 0:07/00:01:00)
**対局 評価値 -10 読み筋 ▲8六歩(85) △8六歩(87) ▲3三角打(00) △6七飛(68) ▲8六飛(82) △6四歩(65) ▲7二角打(00) △5四角成(72) ▲6六香打(00) △6六角(33) ▲7六馬成(54) △7九飛打(00) ▲6八金(58) △7七角成(66) ▲7七金成(68) △5八歩打(00) ▲1五歩(16) △6六桂打(00) ▲8五歩成(58) △8八飛成(77) ▲1四歩(15) △8五馬(88) ▲1三銀打(00) △1三桂(21) ▲1三歩成(14) △2一玉(12) ▲2三と(13) △1九香成(11) ▲1二銀打(00) △3一玉(21) ▲1九玉(28) △3九銀打(00) ▲2八香打(00) △1一香打(00) ▲1三角打(00) △4一玉(31) ▲3二と(23) △3二玉(41) ▲1一銀(12)
 45 6七飛(68)           ( 0:00/00:01:01)
**対局 評価値 -156 読み筋 △8六歩(85) ▲8六歩(87) △8六飛(82) ▲6四歩(65) △8九飛成(86) ▲7二角打(00) △6三歩打(00) ▲6三歩成(64) △6三銀(54) ▲6三角成(72) △6六歩打(00) ▲5二馬(63) △6七歩成(66) ▲6七金(58) △8八飛打(00) ▲6八歩打(00) △9九龍(89) ▲4一馬(52) △8九飛成(88) ▲3九金打(00) △4二金(32) ▲3一馬(41) △3二金(42) ▲4一馬(31)

CSA.Parserのバグ

CSA.Parser.parse_csa()の持ち駒の処理にバグがあるように思えます。
具体的な箇所は、cshogi/src/parser.h の311行目のwhile(true)文です。
このwhile文の最後で index += 2; した上で、while( line.length() > index) などとする必要があると思います。
どうかご確認下さい。

cshogi/_cshogi.cpp:778:10: fatal error: 'init.hpp' file not found #include "init.hpp"

pipでのインストール時に以下のエラーが出ます。
ほかの依存しているライブラリはインストール済みです。
初心者ですので、間違っていればご教授いただきたいです。

なお、freeBSDを使用しています。gccではなく、clangを使用中です。

 /usr/local/bin/python3.9 -m pip install --no-cache-dir cshogi
Defaulting to user installation because normal site-packages is not writeable
Collecting cshogi
  Downloading cshogi-0.5.5.tar.gz (107 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 107.8/107.8 kB 10.8 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: cshogi
  Building wheel for cshogi (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [55 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39
      creating build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi
      copying cshogi/CSA.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi
      copying cshogi/KI2.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi
      copying cshogi/KIF.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi
      copying cshogi/PGN.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi
      copying cshogi/__init__.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi
      copying cshogi/cli.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi
      copying cshogi/elo.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi
      creating build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/usi
      copying cshogi/usi/Engine.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/usi
      copying cshogi/usi/__init__.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/usi
      creating build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/gym_shogi
      copying cshogi/gym_shogi/__init__.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/gym_shogi
      creating build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/gym_shogi/envs
      copying cshogi/gym_shogi/envs/__init__.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/gym_shogi/envs
      creating build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/dlshogi
      copying cshogi/dlshogi/__init__.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/dlshogi
      creating build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/web
      copying cshogi/web/app.py -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/web
      creating build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/web/templates
      copying cshogi/web/templates/board.html -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/web/templates
      creating build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/web/static
      copying cshogi/web/static/board.js -> build/lib.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/web/static
      running build_ext
      cythoning cshogi/_cshogi.pyx to cshogi/_cshogi.cpp
      /home/web-tools/.local/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-7_yxtk06/cshogi_fb82950b0ec047b68583f4b4becb4136/cshogi/_cshogi.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      cythoning cshogi/gym_shogi/envs/shogi_env.pyx to cshogi/gym_shogi/envs/shogi_env.cpp
      /home/web-tools/.local/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-7_yxtk06/cshogi_fb82950b0ec047b68583f4b4becb4136/cshogi/gym_shogi/envs/shogi_env.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      cythoning cshogi/gym_shogi/envs/shogi_vec_env.pyx to cshogi/gym_shogi/envs/shogi_vec_env.cpp
      /home/web-tools/.local/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-7_yxtk06/cshogi_fb82950b0ec047b68583f4b4becb4136/cshogi/gym_shogi/envs/shogi_vec_env.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      building 'cshogi._cshogi' extension
      creating build/temp.freebsd-13.1-RELEASE-p2-amd64-cpython-39
      creating build/temp.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi
      creating build/temp.freebsd-13.1-RELEASE-p2-amd64-cpython-39/src
      cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -fPIC -DHAVE_SSE4 -DHAVE_SSE42 -DHAVE_AVX2 -Isrc -I/usr/local/include/python3.9 -I/home/web-tools/.local/lib/python3.9/site-packages/numpy/core/include -c cshogi/_cshogi.cpp -o build/temp.freebsd-13.1-RELEASE-p2-amd64-cpython-39/cshogi/_cshogi.o -msse4.2 -mavx2
      In file included from cshogi/_cshogi.cpp:770:
      In file included from /home/web-tools/.local/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:5:
      In file included from /home/web-tools/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12:
      In file included from /home/web-tools/.local/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1940:
      /home/web-tools/.local/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: "Using deprecated NumPy API, disable it with "          "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
      #warning "Using deprecated NumPy API, disable it with " \
       ^
      cshogi/_cshogi.cpp:778:10: fatal error: 'init.hpp' file not found
      #include "init.hpp"
               ^~~~~~~~~~
      1 warning and 1 error generated.
      error: command '/usr/bin/cc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cshogi
  Running setup.py clean for cshogi
Failed to build cshogi
ERROR: Could not build wheels for cshogi, which is required to install pyproject.toml-based projects

mateのMovePicker が非合法手を削除しない

mate.cpp のMovePicker ですが、

if(!pos.pseudoLegalMoveIsEvasion(curr->move, pinned)){}

は、王手に対して敵の遠隔駒の利きに逃げるような非合法手を検出することが出来ないので、

if(!pos.moveIsPseudoLegal< false >( curr->move )){}

とすべきだと思います。

mateMoveIn1Ply()が詰まない局面で詰みを返す

__Board::mateMoveIn1Ply()が以下の局面が詰みでないのに、詰ます手として8八竜を返すようです。
sfen l4S1Gl/6gP1/3Bppkp1/p1p+B1sN1p/3Sn4/P1PK1PP1P/3PPsN2/5+r3/L1N4RL w 2g4p

調べていくとどうやら、Directions direc_table[SquareNum + 1][SquareNum + 1]; の初期化がされていないことが原因のようで、
手元の環境では以下のコードで事前に初期化することで少なくとも問題の局面では正常に動作するようになりました。
ほぼyaneuraou bitboard.cpp のコードそのままです。

inline void Effect8::init() {
    // ------------------------------------------------------------
    //        Bitboard関係のテーブルの初期化
    // ------------------------------------------------------------

    // 1) SquareWithWallテーブルの初期化。

    for (auto sq = SQ11; sq < SquareNum; ++sq) {
        sqww_table[sq] = SquareWithWall(SQWW_11 + (int32_t)makeFile(sq) * SQWW_L + (int32_t)makeRank(sq) * SQWW_D);
    }

    // 2) direct_tableの初期化

    for (auto sq1 = SQ11; sq1 < SquareNum; ++sq1) {
        // 各sq1 から、8方向を探索
        for (auto dir = Effect8::DIRECT_ZERO; dir < Effect8::DIRECT_NB; ++dir)
        {
            // dirの方角に壁にぶつかる(盤外)まで延長していく。このとき、sq1から見てsq2のDirectionsは (1 << dir)である。
            auto delta = Effect8::DirectToDeltaWW(dir);
            for (auto sq2 = to_sqww(sq1) + delta; is_ok(sq2); sq2 += delta)
                Effect8::direc_table[sq1][sqww_to_sq(sq2)] = Effect8::to_directions(dir);
        }
    }
} 

自己対局を後手番から始めると、エンジンが表記と逆になる

cshogi.cli.main() にて、
初期局面でmovesが奇数個指定されるなどして後手番から対局を開始すると、後手番をengines_order[0]が指すことになるため、記録される対局者名と実際に指したエンジンが逆になるのではないでしょうか?

while not is_game_over:
for engine, listener, byoyomi in zip(engines_order, listeners_order, byoyomi_order):

Crashes when I build by myself

There is no setup.py in the downloaded codes.
So I tried to build it by myself, but it crashes when I tried to call set_pieces with an array without the black king.
I think it is weird because it works when removing the white king.
So I guess it might be the setup problem. Can you provide the setup.py file for compiling the _cshogi.pyx?
Thanks.

Wrong move notation

In this position, the move 5c4d is converted from USI to KI2 as 同銀上 instead of the correct 同銀右.
image

set_positionが間違ったsfenでTrueを返す

Discordから転記

import cshogi

board = cshogi.Board()
OK = board.set_position("sfen sfen")
print(OK)
# incorrect SFEN string : sfen 
# True

これTrueが返ってきます。cshogi.Boardのset_position()で先頭に"sfen"をつけずに渡してしまい、エラーになることがあるのですが(これわりとハマりやすい。sfenが先頭についてなくて、先頭が"startpos"でもないなら、sfen文字列に決まってるので、sfen文字列として扱って欲しい)、"sfen"をつけなきゃつけなきゃと思っていると二重にコードを書いてしまい、二重のsfenになっていました。

このとき、set_positionで"incorrect SFEN string : sfen"と表示され(これも困る。勝手に標準出力に文字を出さないで欲しい)、おまけにこのメソッドがTrueを返してきました。(これだとこのあとの処理系で大変なことになる)

mateMoveInEvenPly() のバグ

mate.cpp のmateMoveInEvenPly(Position&, const int) に、

    else if (depth == 2) {
        // 1手詰めかどうか
        if (!pos.mateMoveIn1Ply()) {
            // 1手詰めでない場合
            // 詰みが見つからなかった時点で終了
            pos.undoMove(ml.move);
            return false;
        }
    }

とありますが、以下のようにif(){} の前に王手のcheck を挟む必要があるような気がしています。

    else if (depth == 2) {
	if (givesCheck) {
		pos.undoMove(ml.move);
		return false;    // 不詰みとみなす
	}

        // 1手詰めかどうか
        if (!pos.mateMoveIn1Ply()) {
            // 1手詰めでない場合
            // 詰みが見つからなかった時点で終了
            pos.undoMove(ml.move);
            return false;
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.