Giter Site home page Giter Site logo

ayane's Introduction

Ayaneとは?

Ayaneとは、python Adaptor to YaneuraOuの略で、やねうら王をpythonから呼び出して便利に使えてしまうアダプターです。

  • ※ AdaptorのAと、YaneuraOuのYaneの部分でAyaneです。また、YaneuraOuのYane-r--uの部分を取って、Ayaneru(あやねる)の愛称で呼ぶことがあります。

python側で少しコードを書くだけで棋譜解析や並列自己対局などができます。

USIプロトコルのエンジンであれば他のエンジンでもpythonから呼び出して使えますが、USIプロトコルでは規定されていない拡張を使いたいので、やねうら王以外のサポートはしません。

動作を確認しているpythonは3.7系です。それ以前のpythonの動作確認はしていません。

使い方

import shogi.Ayane

# 通常探索用の思考エンジンの接続テスト
# 同期的に思考させる。
def test_ayane1():

    # エンジンとやりとりするクラス
    usi = ayane.UsiEngine()

    # デバッグ用にエンジンとのやりとり内容を標準出力に出力する。
    # usi.debug_print = True

    # エンジンオプション自体は、基本的には"engine_options.txt"で設定する。(やねうら王のdocs/を読むべし)
    # 特定のエンジンオプションをさらに上書きで設定できる
    usi.set_engine_options({"Hash":"128","Threads":"4","NetworkDelay":"0","NetworkDelay2":"0"})

    # エンジンに接続
    # 通常の思考エンジンであるものとする。
    usi.connect("exe/YaneuraOu.exe")

    # 開始局面から76歩の局面
    # ※ "position"コマンド、"go"コマンドなどについては、USIプロトコルの説明を参考にしてください。
    # cf.「USIプロトコルとは」: http://shogidokoro.starfree.jp/usi.html
    usi.usi_position("startpos moves 7g7f")

    # multipv 4で探索させてみる
    # 2秒思考して待機させる。
    usi.send_command("multipv 4")
    usi.usi_go_and_wait_bestmove("btime 0 wtime 0 byoyomi 2000")

    # 思考内容を表示させてみる。
    print("=== UsiThinkResult ===\n" + usi.think_result.to_string())

    # エンジンを切断
    usi.disconnect()

if __name__ == "__main__":
    test_ayane1()

ね、簡単でしょう?

  • Ayaneを使えば、エンジン同士の対局をさせるのも、わずかなコードで実現できます。

  • sfen文字列の取扱いなどは、下記のライブラリを使うと便利だと思います。

ニュース記事

あやねるサーバー

自己対局のための補助クラス。

import shogi.Ayane as ayane
import time

# あやねるサーバーを使った対局例    
def test_ayane5(self):
    print("test_ayane5 : ")

    server = ayane.AyaneruServer()
    for engine in server.engines:
        engine.set_engine_options({"Hash":"128","Threads":"1","NetworkDelay":"0","NetworkDelay2":"0","MaxMovesToDraw":"320" \
            , "MinimumThinkingTime":"0"})
        engine.connect("exe/YaneuraOu.exe")

    # 持ち時間設定。
    server.set_time_setting("byoyomi 100")                 # 1手0.1秒
    # server.set_time_setting("time 1000 inc 2000")        # 1秒 + 1手2秒

    # これで対局が開始する
    server.game_start()

    # 対局が終了するのを待つ
    while not server.game_result.is_gameover():
        time.sleep(1)

    # 対局棋譜の出力
    print("game sfen = " + server.sfen)
    print("game_result = " + str(server.game_result))

    server.terminate()

if __name__ == "__main__":
    test_ayane5()

マルチあやねるサーバー

あやねるサーバーの並列対局版。クラス名 : MultiAyaneruServer

あやねるコロシアム

マルチあやねるサーバーを用いた並列対局を実現するスクリプト。 勝率、レーティング差、95%信頼下限~信頼上限のレーティング差などを自動計算して表示。

あやねるゲート

あやねるサーバーを用いた複数ソフト間の対局を自動化するスクリプト。

License

Apache License Version 2.0とします。

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.