Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Go で始める将棋 AI
Search
mururu
April 23, 2022
Programming
3.3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go で始める将棋 AI
Go Conference 2022 Spring
mururu
April 23, 2022
More Decks by mururu
See All by mururu
カンム と React Native / Kanmu React Native
mururu
0
4k
Go製のネットワーククライアントに対する継続的 / Fuzzing for network client in Go
mururu
4
3k
カンムでの React Native の 歴史と現在 / React Native in Kanmu
mururu
1
620
Building FIDO2 server in Go
mururu
2
7.5k
「ElixirがリアルタイムWebに強い」 というのは本当か?
mururu
13
6.7k
Erlang: Improve the performance of cryptographic functions by AES-NI
mururu
1
300
Treasure Data Summer Intern 2015 Final Report
mururu
0
3.2k
Elixir 1.0
mururu
3
920
Why Elixir
mururu
9
2.1k
Other Decks in Programming
See All in Programming
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
270
Foundry Localでエージェント開発
seosoft
0
180
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
150
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
Security issues being discussed on Web Platforms
petamoriken
0
820
ALB ログから Trace を気合で繋げる技術
fohte
7
890
Heart of Swift Concurrency
koher
0
330
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
6
1.7k
App Intentsのビルドプロセスを支える技術
kntkymt
0
310
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
370
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
700
Featured
See All Featured
HDC tutorial
michielstock
2
860
Navigating Weather and Climate Data
rabernat
0
520
Building Flexible Design Systems
yeseniaperezcruz
330
41k
For a Future-Friendly Web
brad_frost
183
10k
エンジニアに許された特別な時間の終わり
watany
108
250k
Prompt Engineering for Job Search
mfonobong
0
450
How to train your dragon (web standard)
notwaldorf
97
6.8k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
680
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
270
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
410
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
430
Transcript
Go で始める将棋 AI 伊藤 友気 Go Conference 2022 Spring
Copyright Kanmu, Inc. All right reserved. 2 伊藤 友気 CTO
at Kanmu, Inc. @mururu @mururururu 自己紹介
Copyright Kanmu, Inc. All right reserved. 3 将棋好きですか?
Copyright Kanmu, Inc. All right reserved. 4 これは自分で作った 将棋AIと対戦してみたく なった話です
Copyright Kanmu, Inc. All right reserved. 5 今日のゴール 将棋 AI
/ 将棋ソフトの基本的な仕組みを知り、 実際に Go で実装して対戦できるようになること
Copyright Kanmu, Inc. All right reserved. 6 Go で将棋 AI
を作るとは gshogi の紹介 思考エンジンを育てる 1 2 3 アジェンダ
Copyright Kanmu, Inc. All right reserved. そもそも将棋とは ? 7 0
• 1対1で行うボードゲーム • 動きが異なる8種類の駒を交互 に動かして相手の王様を動け なくしたら勝ち
Go で将棋 AI を作る 1
Copyright Kanmu, Inc. All right reserved. 将棋ソフトの基本的なアーキテクチャ 9 1 テキストを入れたり。テキストを入れたり。テキストを入れた
り。テキストを入れたり。テキストを入れたり。テキストを入 れたり。テキストを入れたり。テキストを入れたり。 GUI 思考エンジン 通信
Copyright Kanmu, Inc. All right reserved. 将棋ソフトの基本的なアーキテクチャ 10 1 テキストを入れたり。テキストを入
れたり。テキストを入れたり。テキ ストを入れたり。テキストを入れた り。テキストを入れたり。テキスト を入れたり。テキストを入れたり。 GUI 思考エンジン • 盤面を表示したりユーザーが操 作する GUI と、手を探す思考 エンジンは別のソフトウェアとし て実装されている • これにより独立して開発し組み 合わせて使用することができる • それらが USI というプロトコル で通信しながら対局を進める 通信
Copyright Kanmu, Inc. All right reserved. Go で将棋 AI を作るとは
11 1 テキストを入れたり。テキストを入れたり。テキストを入れた り。テキストを入れたり。テキストを入れたり。テキストを入 れたり。テキストを入れたり。テキストを入れたり。 GUI 思考エンジン 通信
Copyright Kanmu, Inc. All right reserved. 12 1 Go で将棋
AI を作るとは GUI 思考エンジン 通信 これらを実装する
Copyright Kanmu, Inc. All right reserved. USI プロトコル 13 1
• GUIソフトと思考エンジンが通信をするための双方向かつ非同期 なプロトコル • 標準入出力を使ってやり取りする • GUIソフトが盤面のデータを送り、思考エンジンが最善手を返 す、というのが基本の動作
Copyright Kanmu, Inc. All right reserved. USI プロトコル - 例
14 1 GUI 思考エンジン position sfen lnsgkgsnl/9/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LN SGKGSNL w - 1 moves 5a6b 7g7f 3a3b go bestmove 8c8d 思考
Copyright Kanmu, Inc. All right reserved. 思考エンジン 15 1 •
将棋のルールを実装する ◦ 細かな将棋のルールを正しく実装していかなければならない • 外部のプログラムとのインターフェースを実装する ◦ 今回は USI • 与えられた盤面に対し次に指すべき手を探す ◦ この精度が将棋の強さ
Copyright Kanmu, Inc. All right reserved. 思考エンジン 16 1 •
将棋のルールを実装する ◦ 細かい将棋のルールを正しく実装していかなければならない • 外部のプログラムとのインターフェースを実装する ◦ 今回は USI • 与えられた盤面に対し次に指すべき手を探す ◦ この精度が将棋の強さ ◦ これだけに集中したい
gshogi の紹介 2
Copyright Kanmu, Inc. All right reserved. gshogi 18 2 •
https://github.com/mururu/gshogi • 合法手の生成などができる Go の将棋ライブラリ • python-shogi をベースにしている (Thanks!) • USIプロトコル(の一部)を実装しており、思考エンジンのロジック を実装すればすぐさま GUI ソフトを介して対戦ができる • パフォーマンスは全く気にしていない
Copyright Kanmu, Inc. All right reserved. gshogi - 例 19
2 これを go build して生 成されたバイナリを、GUI ソフトから指定すればそ のまま対戦できる
思考エンジンを育てる 3
Copyright Kanmu, Inc. All right reserved. ランダム 21 3 •
次に指すべき手の選択として一番素朴 • 可能な手の中からランダムに一つ選ぶ
Copyright Kanmu, Inc. All right reserved. ランダム - 実装 22
3
Copyright Kanmu, Inc. All right reserved. 駒の損得を考える 1 23 3
• 「駒を多く持っている方が有利そうである」という直感に従ってみ る • 可能な手の中で、指した後に駒が多くなりそうなものの中からラ ンダムに一つ選ぶ
Copyright Kanmu, Inc. All right reserved. 駒の損得を考える 1 - 実装
24 3
Copyright Kanmu, Inc. All right reserved. 駒の損得を考える 2 25 3
• 「より強い 駒を多く持っている方が有利そうである」と制限を強く してみる • 駒の種類ごとにポイントを割り振り、可能な手の中で、指した後 の合計ポイントが最も多くなりそうなものの中からランダムに一 つ選ぶ
Copyright Kanmu, Inc. All right reserved. 駒の損得を考える 2 - 実装
26 3
Copyright Kanmu, Inc. All right reserved. より強くするには - 評価関数の精度 27
3 • ある局面がどれくらい良いか=勝ちやすいかを示す指標を評価 値とよび、それを求める関数を評価関数という • 今回の例だと「駒の数」「駒のポイントの合計」が評価値であり、 それらを計算するロジック(countPiece, calculatePoint)が評価 関数である • より高度な将棋の知識を用いたり、大量の棋譜を学習させるな どして評価関数の精度を高めることが可能
Copyright Kanmu, Inc. All right reserved. より強くするには - より先の局面まで考慮する 28
3 • 今回の例では可能な指し手を打った直後の局面のみを考えてい たが、その次の局面で逆転されるかもしれないと考えると、さら に先の局面を考慮にいれたほうがより良く評価できるはず ◦ より深い木構造を辿りながら評価をする • 最終的に決着がつく局面まで探索はなかなかできないのでパ フォーマンスが大事になる
Copyright Kanmu, Inc. All right reserved. 29 まとめ • 自作の将棋AI/将棋ソフトと対戦するために必要なソフトウェアの
概要を説明し、Go でその実装を簡単に行うための gshogi を紹 介した • 思考エンジンに関する最もベーシックなアイデアを解説し、 gshogi を用いた実装を紹介した