tag:crieit.net,2005:https://crieit.net/tags/%E3%82%B3%E3%83%B3%E3%83%94%E3%83%A5%E3%83%BC%E3%82%BF%E3%83%BC%E5%9B%B2%E7%A2%81/feed
「コンピューター囲碁」の記事 - Crieit
Crieitでタグ「コンピューター囲碁」に投稿された最近の記事
2019-09-20T03:43:34+09:00
https://crieit.net/tags/%E3%82%B3%E3%83%B3%E3%83%94%E3%83%A5%E3%83%BC%E3%82%BF%E3%83%BC%E5%9B%B2%E7%A2%81/feed
tag:crieit.net,2005:PublicArticle/15390
2019-09-12T20:14:47+09:00
2019-09-20T03:43:34+09:00
https://crieit.net/posts/bbb87e9c13cbe3749e91325f25878c5d
コンピューター囲碁を作ろうぜ☆(^~^)?<書きかけ>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 コンピューター囲碁を作るかだぜ☆<br />
↓ググれば なんでも載ってるだろ……☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://qiita.com/7ma7X/items/479ad9025a3368c2348f">Rust で TCP/IP ソケット通信をする際のモデル</a></p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 コンピューター囲碁のポート番号は <code>9696</code> だったかだぜ☆?」</p>
<p><code>C:\Users\むずでょ\source\repos\kifuwarabe-air2019</code></p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 ↑ソース・レポジトリ作っておくわよ」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://github.com/muzudho/kifuwarabe-air2019">kifuwarabe-air2019</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ギットハブも用意しておいたぜ☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://www.rust-lang.org/">Rust</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑近年 Rustは仕様が変わったみたいだし見ておくかだぜ☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://doc.rust-lang.org/book/">book</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑説明書はこれかだぜ☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://doc.rust-lang.org/book/ch01-01-installation.html">installation</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑Rustのインストールには <code>rustup</code> を使えと書いてあるぜ☆<br />
わたしは既に古いのが入っているから アップグレードだな☆」</p>
<p><a href="https://crieit.now.sh/upload_images/266b9eb99210fc692c6ab854a5760a7d5d7a2b6074953.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/266b9eb99210fc692c6ab854a5760a7d5d7a2b6074953.png?mw=700" alt="20190912igo1.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑Visual Studio Code には Terminal も付いている☆ Powershell でやってしまおうぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/ef988f3aa6a596db4f611b502ae1f3f25d7a2c47ca567.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/ef988f3aa6a596db4f611b502ae1f3f25d7a2c47ca567.png?mw=700" alt="20190912igo2b1.png" /></a></p>
<pre><code>rustc --version
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑よし、最新版になったぜ☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://doc.rust-lang.org/book/ch01-03-hello-cargo.html">Hello, Cargo!</a></p>
<pre><code>cargo --version
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑まあ 基本 <code>cargo</code> を使うんだけど☆」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 きふわらべちゃんのプロジェクトを作りましょう!」</p>
<p><a href="https://crieit.now.sh/upload_images/c06a850ba77777a6edc2f2c66941f1865d7a2e7e467aa.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/c06a850ba77777a6edc2f2c66941f1865d7a2e7e467aa.png?mw=700" alt="20190912igo3b1.png" /></a></p>
<pre><code>cargo new kifuwarabe-air2019
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑はい☆」</p>
<p><a href="https://crieit.now.sh/upload_images/d12c09ebbae51b21ba9f52d54d3004835d7a2f66509e9.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/d12c09ebbae51b21ba9f52d54d3004835d7a2f66509e9.png?mw=700" alt="20190912igo4b1.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ <code>Cargo.toml</code> の内容は何もいじらなくても書かれていたぜ☆ 完璧だぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5bf80ffcac3937e2e1981d0d3f3e0f035d7a30bdd0bbe.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5bf80ffcac3937e2e1981d0d3f3e0f035d7a30bdd0bbe.png?mw=700" alt="20190912igo5b1.png" /></a></p>
<pre><code>cargo build
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ <code>.exe</code> ファイルも作られているな☆」</p>
<p><a href="https://crieit.now.sh/upload_images/74c863e13c721ab5d00cba6f23bb484c5d7a319d35da5.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/74c863e13c721ab5d00cba6f23bb484c5d7a319d35da5.png?mw=700" alt="20190912igo6b1.png" /></a></p>
<pre><code>cargo run
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ ちゃんと実行もされるぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 Visual Studio Code で十分だな☆」</p>
<p><a href="https://crieit.now.sh/upload_images/e7aae78662c0a167bd541eed76be6efc5d7a32b7800df.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e7aae78662c0a167bd541eed76be6efc5d7a32b7800df.png?mw=700" alt="20190912igo7.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ しかし ソース・レポジトリのコードを GitHub の ローカル・レポジトリにコピーするのは めんどくさいよな☆」</p>
<p>go-to-git.ps1</p>
<pre><code># +
# | UTF-8 with BOM (Powershell)
# |
# | Folder copy.
# +
# +
# | フォルダをゴミ箱に移動する
# +
function Remove-FolderToRecycleBin($dir) {
if (Test-Path $dir -PathType Container) {
$fullpath = (Get-Item $dir).FullName
# +
# | こんな変なパスぜったい間違う☆(^~^)チェックだぜ☆(^~^)
# +
if ($fullpath -cmatch ".*\\kifuwarabe-air2019\\kifuwarabe-air2019") {
Write-Host "Remove | [$fullpath] directory."
Remove-Item $fullpath -Recurse
}
else {
Write-Host "Ignore | [$fullpath] directory."
}
}
else {
Write-Host "Ignore | [$dir] is not directory or not found."
}
}
$sr = "C:\Users\むずでょ\source\repos\kifuwarabe-air2019\kifuwarabe-air2019"
$ds = "C:\Users\むずでょ\Documents\GitHub\kifuwarabe-air2019\kifuwarabe-air2019"
Remove-FolderToRecycleBin($ds)
Write-Host "Copy | [$sr] --to--> [$ds]."
Copy-Item $sr -destination $ds -recurse
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ 必死こいて Powershell 書く☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 <code>powershell ./go-to-git.ps1</code> と打鍵するのが うんこ じゃないか☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 Visual studio code の Explorer で右クリックして File explorer 開いて .ps1 ファイルをダブルクリックするからOK☆」</p>
<p><a href="https://crieit.now.sh/upload_images/fff364242c609825f2eda573b64207fb5d7a3cd785fed.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/fff364242c609825f2eda573b64207fb5d7a3cd785fed.png?mw=700" alt="20190912igo8.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ あとは Git hub desktop でなんとかする☆」</p>
<pre><code>cargo check
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ コーディングのチェックをしてくれたりするのだろうか☆? あとで使おう☆」</p>
<pre><code>cargo build --release
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ デバッグを外して .exe を作るには <code>--release</code> を付ければいいらしい☆ これ1つ忘れるだけで大会では クソとノーマルの差が分かれる☆」</p>
<h1 id="ロガーを用意しろだぜ☆(^~^)"><a href="#%E3%83%AD%E3%82%AC%E3%83%BC%E3%82%92%E7%94%A8%E6%84%8F%E3%81%97%E3%82%8D%E3%81%A0%E3%81%9C%E2%98%86%EF%BC%88%EF%BC%BE%EF%BD%9E%EF%BC%BE%EF%BC%89">ロガーを用意しろだぜ☆(^~^)</a></h1>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ロギングできるかどうかで プログラマーは クソとノーマルに大きく分かれるのに 公式のマニュアルに書いてないな☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://qiita.com/fujitayy/items/590145c0f4b4e7d06de7">Rust:logでログ出力を行う</a><br />
<a target="_blank" rel="nofollow noopener" href="https://qiita.com/Dsuke-K/items/163a312bdd2b8a260615">Rustでのロギング</a><br />
<a target="_blank" rel="nofollow noopener" href="https://docs.rs/log/0.4.8/log/">Crate log</a><br />
<a target="_blank" rel="nofollow noopener" href="https://rust-lang-nursery.github.io/rust-cookbook/development_tools/debugging/config_log.html">Configure Logging</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ここらへんの連中は ログをファイルに書き込まないのだろうか☆?<br />
<code>stderr</code> へのストリーム出力から ファイルへリダイレクトが基本かだぜ☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 遅~いロガーを掴んだら コンピューターは弱くなるわよ?」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://crates.io/crates/env_logger">env_logger</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 じゃあ <code>env_logger</code> 一択な気がするな……☆ 使ってみるかだぜ☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/3bdfbe3e6daffc2a78092c28b9d1dbae5d7a46c045e8d.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3bdfbe3e6daffc2a78092c28b9d1dbae5d7a46c045e8d.png?mw=700" alt="20190912igo9b1.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 こんな風に 真似して <code>Cargo.toml</code> を書いていけばいい☆<br />
1990年代のジャパンなら 友だちの友だちをたどっていけば パソコンオタクの眼鏡のお兄さんがどこかに居て<br />
家までやってきて パソコンのコマンドの叩き方とか教えてくれたが、<br />
2019年頃のジャパンでは 学校のパソコン部に入ったのに何もせずに卒業して ブログのエントリを書いて<br />
いいね! が付くのが流行りみたいだぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 何も いいね! ではないわよね。 何が いいの かしら?」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 承認欲求が満たされたのだろう☆」</p>
<p>main.rs</p>
<pre><code>#[macro_use]
extern crate log;
extern crate env_logger;
fn main() {
env_logger::init();
println!("Hello, println!");
trace!("Hello, trace!");
debug!("Hello, debug!");
info!("Hello, info!");
warn!("Hello, warn!");
error!("Hello, error!");
}
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑こういうコードがあるとして……☆」</p>
<p><a href="https://crieit.now.sh/upload_images/8520b184eb63c30e1f12da236531104f5d7a4dde37cd4.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/8520b184eb63c30e1f12da236531104f5d7a4dde37cd4.png?mw=700" alt="20190912igo10.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑環境変数を使って これだけ使い分けれれば十分だろう……☆<br />
なんか <code>Hello, println!</code> の出るタイミングがバラバラだな……、非同期か☆」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 で、 PowerShell って どうやって ストリームをリダイレクトするんだぜ☆?」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://qiita.com/toshihirock/items/936b33f0c15723565dce">PowerShellでのエラーハンドリングについて</a></p>
<pre><code>command 2>&1 >> ./kifuwarabe-air2019.log
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 ↑で いいのでは☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ほんとか☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/3c4bf99b25ffc6a706d6db8d966061075d7a4ff216272.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3c4bf99b25ffc6a706d6db8d966061075d7a4ff216272.png?mw=700" alt="20190912igo11.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑コマンドの一覧が ログ・ファイルに書き出された……☆ ということは☆」</p>
<pre><code>cargo run 2>&1 >> ./kifuwarabe-air2019.log
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑こうかだぜ☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 それだと cargo の引数になるんじゃない?」</p>
<p><a href="https://crieit.now.sh/upload_images/7a53a989b0834f8e755346390740dae85d7a51538b796.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/7a53a989b0834f8e755346390740dae85d7a51538b796.png?mw=700" alt="20190912igo12.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 一応 <code>>></code> が利いたのか ファイルに 追加書き込みされているが、標準出力に何もでなくなったぜ☆」</p>
<pre><code>cargo run 2>> ./kifuwarabe-air2019.log
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 だったら単に 標準エラーの2 を追加書き込みのリダイレクト <code>>></code> でファイルに送る指定だけする☆<br />
これで平和だぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 それだと 標準出力にエラーが出てこない☆」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 リダイレクト先を2つに増やすことはできないんじゃないか☆?<br />
とりあえず ログを取るときは しばらくこれで☆」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 コマンドの打鍵がめんどくさくない?」</p>
<pre><code>/*
# - Log level.
#$env:RUST_LOG = "trace"
#$env:RUST_LOG = "debug"
$env:RUST_LOG = "info"
#$env:RUST_LOG = "warn"
#$env:RUST_LOG = "error"
# - Log redirect.
cargo run 2>> ./kifuwarabe-air2019.log
*/
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 main.rs の冒頭にコメントを書いておいて これを貼り付ければいいだろ……☆」</p>
<h1 id="TCP/IP 通信"><a href="#TCP%2FIP+%E9%80%9A%E4%BF%A1">TCP/IP 通信</a></h1>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 次は通信書くか……☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://rohki.hatenablog.com/entry/2018/08/03/200805">Rust のお試しコードを実行する: cargo run --example</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑rust には サンプル・プログラムの書き方がある☆」</p>
<p><a href="https://crieit.now.sh/upload_images/25adb0101818f1baee11a624e666bce75d7bf4644db04.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/25adb0101818f1baee11a624e666bce75d7bf4644db04.png?mw=700" alt="20190914igo13b1.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 <code>examples</code> ディレクトリの下にあるファイルは <code>cargo run --example</code> を使って実行できる☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://qiita.com/7ma7X/items/479ad9025a3368c2348f">Rust で TCP/IP ソケット通信をする際のモデル</a><br />
<a target="_blank" rel="nofollow noopener" href="https://cha-shu00.hatenablog.com/entry/2019/03/02/174532">Rustにっき/8日目・TCPサーバ</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 接続に失敗するな……、ポート番号調べてみるか☆」</p>
<pre><code>### Linux
lsof -i:3000
### Windows
netstat -aon | findstr 3000
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 何も出てこないな☆ 3000番ポートは空いてるはず☆」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 接続される側で 待ち受けているサーバーが無いのだから、接続できるわけないんじゃないの?」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 だったら そういうサンプルだと説明が欲しいぜ☆<br />
サーバー書くか……☆」</p>
<h2 id="クライアントとサーバー"><a href="#%E3%82%AF%E3%83%A9%E3%82%A4%E3%82%A2%E3%83%B3%E3%83%88%E3%81%A8%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC">クライアントとサーバー</a></h2>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 接続するだけなら 次のように書けばいい☆」</p>
<p>examples/server.rs</p>
<pre><code>/*
# Current directory
# cd ./kifuwarabe-air2019
cd C:\Users\むずでょ\source\repos\kifuwarabe-air2019\kifuwarabe-air2019
cargo run --example server
*/
use std::net::{TcpListener, TcpStream, ToSocketAddrs};
use std::io::{BufRead, BufReader, BufWriter, Error, Read, Write};
use std::thread;
/**
* See: [Rustにっき/8日目・TCPサーバ](https://cha-shu00.hatenablog.com/entry/2019/03/02/174532)
*/
fn main(){
let host = "localhost";
let port = 9696;
let url = format!("{}:{}", host, port);
let mut addrs = url.to_socket_addrs().unwrap();
// Change to ip v4.
if let Some(addr) = addrs.find(|x| (*x).is_ipv4()) {
// Success addr:127.0.0.1:9696
println!("Success sever-addr:{}", addr);
// Wait for connection.
let listener = TcpListener::bind(addr).expect("Error. failed to bind.");
for streams in listener.incoming() {
match streams {
Err(e) => { eprintln!("error: {}", e)},
Ok(stream) => {
println!("Create the thread.")
/*
// TODO: Create the thread.
thread::spawn(move || {
handler(stream).unwrap_or_else(|error| eprintln!("{:?}", error));
});
*/
}
}
}
} else {
eprintln!("Invalid Host:Port Number");
}
}
</code></pre>
<p>examples/client.rs</p>
<pre><code>/*
# Current directory
# cd ./kifuwarabe-air2019
cd C:\Users\むずでょ\source\repos\kifuwarabe-air2019\kifuwarabe-air2019
cargo run --example client
*/
use std::net::{TcpStream, ToSocketAddrs};
use std::io::{BufRead, BufReader, BufWriter, Write};
/**
* See: [Rust で TCP/IP ソケット通信をする際のモデル](https://qiita.com/7ma7X/items/479ad9025a3368c2348f)
*/
fn main(){
let host = "localhost";
let port = 9696;
let url = format!("{}:{}", host, port);
let mut addrs = url.to_socket_addrs().unwrap();
// Change to ip v4.
if let Some(addr) = addrs.find(|x| (*x).is_ipv4()) {
// Success addr:127.0.0.1:3000
println!("Success client-addr:{}", addr);
match TcpStream::connect(addr) {
Err(_) => {
println!("Connection NG.");
}
Ok(stream) => {
println!("Connection Ok.");
// Buffering.
let mut reader = BufReader::new(&stream);
let mut writer = BufWriter::new(&stream);
read_something(&mut reader);
write_something(&mut writer, "hoge");
}
}
} else {
eprintln!("Invalid Host:Port Number");
}
}
fn read_something (reader: &mut BufReader<&TcpStream>) {
let mut msg = String::new();
reader.read_line(&mut msg).expect("RECEIVE FAILURE!!!");
// read_line は改行文字まで読む。
// 他のread系のメソッドもある (https://doc.rust-lang.org/std/io/trait.BufRead.html)
println!("{}", msg);
}
fn write_something (writer: &mut BufWriter<&TcpStream>, comment: &str) {
let msg = format!("MESSAGE: {}\n", comment);
// 送る側もたぶん改行文字を付けたほうがよいでしょう。
writer.write(msg.as_bytes()).expect("SEND FAILURE!!!");
writer.flush().unwrap();
}
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 で、使うには server.rs を実行して待機させておいてから、 client.rs で接続する☆<br />
Visual studio code は Terminal ビューを1つしか出せないかもしれないので、<br />
Visual studio code の2つ目を起動して Terminal ビューを使う☆」</p>
<p><a href="https://crieit.now.sh/upload_images/04e91cac753dd345ba90087c43d5ed1c5d7f3bf379721.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/04e91cac753dd345ba90087c43d5ed1c5d7f3bf379721.png?mw=700" alt="20190916igo14a1b1.png" /></a></p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 そんな使い方で 何かが 混線しないか 知らんけどな☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 コンピューター囲碁の通信プログラムって どんなもんだぜ☆?」</p>
<h1 id="GTPではなく、nngs通信プロトコル"><a href="#GTP%E3%81%A7%E3%81%AF%E3%81%AA%E3%81%8F%E3%80%81nngs%E9%80%9A%E4%BF%A1%E3%83%97%E3%83%AD%E3%83%88%E3%82%B3%E3%83%AB">GTPではなく、nngs通信プロトコル</a></h1>
<p><a target="_blank" rel="nofollow noopener" href="https://www.igoshogi.net/ai_ryusei/01/protocols.html">通信対局規約</a><br />
<a target="_blank" rel="nofollow noopener" href="https://www.gnu.org/software/gnugo/gnugo_19.html">19. The Go Text Protocol</a><br />
<a target="_blank" rel="nofollow noopener" href="http://www.lysator.liu.se/~gunnar/gtp/">GTP - Go Text Protocol</a><br />
<a target="_blank" rel="nofollow noopener" href="https://senseis.xmp.net/?GoTextProtocol">Go Text Protocol</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 Go text protocol だろう☆ 大会で使うコマンドは6つしかない☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="http://www.yss-aya.com/cgfgoban.html">CgfGoBan and Nngs_try</a><br />
<a target="_blank" rel="nofollow noopener" href="http://www9.plala.or.jp/sgwr-t/c_sub/ascii.html">ASCIIコード表</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑例えば Cgf Go Ban の cgf_pipe.cpp というファイルに実装が書いてあるぜ☆<br />
ASCIIコード表は助けになるだろう☆」</p>
<ul>
<li>コマンドは Ascii文字。</li>
<li>コマンドは 2048文字未満。これを超えたらエラー。</li>
<li>コマンドは <code>\n</code> (Asciiコード 10)で終了。</li>
<li><code>\n</code> を除く 32未満のAsciiコードはすべて無視。例えば <code>\r</code> (Asciiコード 13) などを無視。</li>
<li><code>\t</code> (水平タブ; Asciiコード 9) を 半角スペース (Asciiコード 32) に置換しているコードがあるが、これは働いてないと思う。</li>
<li>コマンド先頭が <code>#</code> ならコメント行だから無視。まだコマンドは送られてくる。</li>
<li>空行(<code>\n</code> だけの行)は無視。まだコマンドは送られてくる。</li>
</ul>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 あと、プロトコルの通信ログを見ないと分からないところだが☆、」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://www.gnu.org/software/gnugo/gnugo_19.html">19. The Go Text Protocol</a></p>
<pre><code>virihaure 462% ./gnugo --mode gtp
1 boardsize 7
=1
2 clear_board
=2
3 play black D5
=3
4 genmove white
=4 C3
5 play black C3
?5 illegal move
6 play black E3
=6
7 showboard
=7
A B C D E F G
7 . . . . . . . 7
6 . . . . . . . 6
5 . . + X + . . 5
4 . . . + . . . 4
3 . . O . X . . 3
2 . . . . . . . 2 WHITE (O) has captured 0 stones
1 . . . . . . . 1 BLACK (X) has captured 0 stones
A B C D E F G
8 quit
=8
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 サーバーは イコールを付けて ひと桁の数を返してくる☆<br />
イコールと数の2文字だけが飛んで来たら無視しろだぜ☆ 3文字以上なら何か命令かもしれない☆」</p>
<ul>
<li>4文字目以降を move とする。例えば <code>=4 C3</code> なら <code>C3</code> が move。</li>
<li>パスは move が <code>pass</code>。 GnuGoは"PASS"と送ってくるから大文字・小文字を区別しないようにする。</li>
<li>投了は move が <code>resign</code>。 SGMPは非対応。nngsは相手が落ちるかも?</li>
<li>move の1文字目はアルファベット。筋(列)に対応。<code>I</code> は無いから詰めること。</li>
<li>move の2文字目以降は段(行)数。</li>
</ul>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 Go text protocol は いろいろコマンドがあるんだが 大会では 5つのコマンドしか送んな、ということだし<br />
それだけ 実装すればいいんだが、一応 Cgp Go Ban にあるコマンドを見ておこう☆」</p>
<ul>
<li><code>boardsize %d\n</code> - ban_size 何路盤。</li>
<li><code>clear_board\n</code> - 盤面を初期化</li>
<li><code>komi %.1f\n</code> - komi, - コミを設定</li>
<li><code>name\n</code> - 名前を要求。</li>
<li><code>version\n</code> - バージョンを要求。</li>
<li><code>genmove black\n</code> - GnuGo に黒番打たせる。</li>
<li><code>genmove white\n</code> - GnuGo に白番打たせる。</li>
<li><code>play black %s\n</code> - GnuGo の盤面に黒石を置く。符号は <code>Q4</code> みたいなやつ。</li>
<li><code>play white %s\n</code> - GnuGo の盤面に白石を置く。</li>
<li><code>final_status %s\n</code> - GnuGo に死活判定を聞く。符号は <code>Q4</code> みたいなやつ。結果は次の6つ。
<ul>
<li><code>alive</code></li>
<li><code>dead</code></li>
<li><code>seki</code></li>
<li><code>white_territory</code></li>
<li><code>black_territory</code></li>
<li><code>dame</code></li>
</ul></li>
</ul>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 どれも大会で使わなさそう☆」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 こっちから 通信で送るのは cgf_win.cpp の <code>SendUpdateSetKifu</code> 関数から辿っていけば 見つかるだろう……☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 cgf_term.cpp にいろいろ書いてあるが、 <code>SGMP</code> 使ってそう☆」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 大会は <code>NNGS 1.1.22 を拡張したプロトコル</code> だから、 NNGS 1.1.22 が何を使ってるか調べるか……☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="http://www.computer-go.jp/gifu2005/regulations/communication.html">通信対戦について</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 <code>GTP</code> とは また違うのか☆ うーむ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 <code>cgf_wsk.cpp</code> に、nngs への接続プログラムが書かれているぜ☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="http://www.computer-go.jp/gifu2005/regulations/nngs/playera.html">playera側の記録</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 通信ログが上記のようなものだとして……☆」</p>
<p>Send:</p>
<pre><code>telnet nngs.computer-go.jp 9696
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 テルネットで接続すればいいらしい☆」</p>
<p>Send:</p>
<pre><code>playera
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 そのあと有無を言わさず 自分の名前を送るらしい☆」</p>
<p>Receive:</p>
<pre><code>No Name Go Server (NNGS) version 1.1.14
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 次はこんな行が送られてくるから、<br />
<code>No Name Go Server (NNGS) version</code> という文字列を当てに行く☆ 当たれば☆、」</p>
<p>Send:</p>
<pre><code>set client TRUE\n
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 こんな文字列を 有無を言わさず送る☆<br />
大会では <code>"set client FALSE"</code> と書いてあって どうすればいいのか☆」</p>
<p>Receive:</p>
<pre><code>Set client to be True
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 よく分からんが client モードが True になった、と受信すれば……☆」</p>
<pre><code>match %s B %d %d 0\n",nngs_player_name[1-fTurn],ban_size,nngs_minutes
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 matchコマンドで黒番に対局を申し込むのか☆ わたしは白番か☆」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 対局を申し込まれた <code>playerb</code> の方は☆、」</p>
<pre><code>Match [19x19] in 40 minutes requested with playera as Black.
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑みたいな文字列を受け取る☆<br />
<code>"Match [%dx%d]",ban_size,ban_size</code> みたいな感じで当てに行く☆」</p>
<pre><code>match playerb B 19 40 0
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 そして<br />
<code>"match %s W %d %d 0\n",nngs_player_name[1-fTurn],ban_size,nngs_minutes</code><br />
みたいな感じの文字列を 有無を言わさず送る☆<br />
わたしのプレイヤー名は <code>playerb</code>、 黒番で 19路、 持ち時間は 40分とか そんな感じだろうか☆」</p>
<p>Received:</p>
<pre><code>accepted.
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 黒番のときは <code>accepted.</code> を受信するとのことだぜ☆ この直後から初手を送れるとのことだぜ☆」</p>
<pre><code>Illegal
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 エラーがあった場合、 <code>illegal</code> という文字が含まれているらしいぜ☆ こうなりゃ終了☆」</p>
<pre><code>sprintf(tmp,"(%s): ",stone_str[1-fTurn]);
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 これはただの表示かだぜ☆」</p>
<pre><code>Pass
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 これを受け取ったら、相手はパス☆<br />
送るのは <code>pass</code> なのに、受け取るのは <code>Pass</code> なのか☆」</p>
<pre><code>T10
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 よく分からんが 指し手 は そのまんま飛んでくるのか? よく分からん☆」</p>
<pre><code>14 |. # # O O # # . # O # # O O O # O O #| 14
13 |# # O # # # . # O O O # # # O O O . O| 13 Last Move: J1
12 |# O O # O . . # # O . O O O O . O O .| 12 #216 O (White)
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 盤の右横に指し手が書いてるんじゃないか☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 なんで そんなところに……☆ よく誤検知しないものだぜ☆ A1 とか B10 とか☆」</p>
<p>Received:</p>
<pre><code>You can check your score
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 自分が <code>pass</code> したあとに相手が <code>pass</code> すると、 <code>Pass</code> は受信せず上のメッセージを受信するみたいだぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a></p>
<p>「 これは プロトコル なのかだぜ☆?!」</p>
<p>Send:</p>
<pre><code>done
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 地を計算するんだが めんどくさいんで <code>done\n</code> を送る☆ すると☆、」</p>
<p>Received:</p>
<pre><code>resigns.
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 というメッセージを受信して 通信完了だぜ☆ 棋譜はサーバーに保存されているはずだぜ☆」</p>
<p>Received:</p>
<pre><code>9 {Game 1: test2 vs test1 : Black resigns. W 10.5 B 6.0}
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 対局が終わると 上記のようなメッセージを受信するので……☆」</p>
<pre><code>strstr(str,"9 {Game") && strstr(str,"resigns.")
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 <code>9 {Game</code> と <code>resigns.</code> を含む行を当てに行き……☆」</p>
<pre><code>sprintf(tmp,"%s vs %s",nngs_player_name[1],nngs_player_name[0]);
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 <code>playera vs playerb</code> みたいな文字列を作って また当てに行き、当たったら 対局終了だぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 JSONでプロトコルを書き直しましょうよ!」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 大会のサーバーと通信することが優先だぜ☆」</p>
<p>Received:</p>
<pre><code>{%s has disconnected}
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 対戦相手が接続を切ったときは 上のメッセージが飛んでくる☆ <code>%s</code> は相手プレイヤー名だぜ☆」</p>
<p>Received:</p>
<pre><code>forfeits on time
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 どちらかの持ち時間が切れた場合は、上のメッセージと同じ行に 両プレイヤー名が載っているはずだぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 こんなけ分かれば 疑似サーバー を作れるだろ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 要点を まとめないとな☆」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 ユーザー名と パスワードの送信って どうやんの?」</p>
<p><a target="_blank" rel="nofollow noopener" href="http://www.wing.gr.jp/explore_b.html">WINGの歩き方 Ver 1.10</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 もっと古い時代に NNGS を使っていた Wing のサイトも見てみるかだぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 パスワードを変える方法はあっても、パスワードを入力する説明は見当たらないな☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 CgfGoBan でパスワードを入れたことは無いだろ☆ パスワード無しでやろうぜ☆」</p>
<ul>
<li>Send: <code>telnet nngs.computer-go.jp 9696</code></li>
<li>Send: <code>playera</code></li>
<li>Received: <code>No Name Go Server (NNGS) version</code></li>
<li>Send: <code>set client TRUE</code></li>
<li>Received: <code>Set client to be True</code></li>
<li>Send: <code>match %s B %d %d 0\n",nngs_player_name[1-fTurn],ban_size,nngs_minutes</code></li>
<li>Received: <code>Match [19x19]</code></li>
<li>Send: <code>match %s W %d %d 0\n",nngs_player_name[1-fTurn],ban_size,nngs_minutes</code></li>
<li>Received: <code>accepted.</code></li>
<li>Received: <code>Illegal</code></li>
<li>Received: <code>Pass</code></li>
<li>Send: <code>T10</code></li>
<li>Send: <code>pass</code></li>
<li>Received: <code>You can check your score</code></li>
<li>Send: <code>done</code></li>
<li>Received: <code>9 {Game 1: test2 vs test1 : Black resigns. W 10.5 B 6.0}</code></li>
<li>Received: <code>{%s has disconnected}</code></li>
<li>Received: <code>forfeits on time</code></li>
</ul>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 まだ マッチングのところが よく分からんな……☆」</p>
<h2 id="マッチング"><a href="#%E3%83%9E%E3%83%83%E3%83%81%E3%83%B3%E3%82%B0">マッチング</a></h2>
<p><a target="_blank" rel="nofollow noopener" href="http://www.computer-go.jp/gifu2005/regulations/communication.html">通信対戦について</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑説明を1つ1つ読んでいくかだぜ☆」</p>
<ul>
<li>プレイヤがサーバにログイン</li>
</ul>
<p>Send:</p>
<pre><code>telnet nngs.computer-go.jp 9696
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ログインは 通信プロトコルと関係ないよな☆ 接続を確立するまでは TCP/IP だぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 ここから先は とにかく2人以上が サーバーにぶら下がっているという前提みたいだぜ☆」</p>
<ul>
<li>一方(例えばplayeraという名前でログインしている)が相手に「match」コマンドで対局を申し込む。playerbという名前のプレイヤに、19路盤、自分が黒番、持ち時間は40分、秒読みなしという条件で申し込む場合には、「match playerb B 19 40 0」というコマンドをサーバに送信する。</li>
</ul>
<p>Send:</p>
<pre><code>match playerb B 19 40 0
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 相手のプレイヤー名も知っているという前提だな☆ 大会でなら知ってるしな☆」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 少しずつ 分かってきた感じがするな☆」</p>
<ul>
<li>相手が同じく「match」コマンドで対局を受けたら対局開始(match playera W 19 40 0)</li>
</ul>
<p>Send (Opponent):</p>
<pre><code>match playera W 19 40 0
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 サーバー側で シェイクハンド を監視しないといけないな☆」</p>
<ul>
<li>対局開始</li>
</ul>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 具体的なことが分からん☆」</p>
<ul>
<li>互いに自分の手を送信していく(「d3」というような座標を送信する)</li>
</ul>
<p>Send:</p>
<pre><code>d3
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 どっちの手番か分かるのかだぜ☆?」</p>
<ul>
<li>一方のプレイヤが「pass」を送信</li>
<li>もう一方のプレイヤが「pass」を送信</li>
</ul>
<p>Send (Self/Opponent):</p>
<pre><code>pass
</code></pre>
<p>Send (Opponent/Self):</p>
<pre><code>pass
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 これは棋譜の上で2者が続けて <code>pass</code> を送信するということだな☆」</p>
<ul>
<li>双方が「done」コマンドを送信(死に石の情報を送信する必要はありません。また、サーバからのメッセージは無視してください)</li>
</ul>
<p>Send (Self/Opponent):</p>
<pre><code>done
</code></pre>
<p>Send (Opponent/Self):</p>
<pre><code>done
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 これは本当は 郵便囲碁でお互いが 地計算して どれが生き石、どれが死に石 と言い合うところなんだが、<br />
大会では めんどくさいんで スキップしようぜ、という意味合いだぜ☆」</p>
<ul>
<li>それぞれのプログラムはそのコンピュータのモニタ上に、盤面情報、死に石の情報、地の計算結果を表示します</li>
<li>プログラムの操作者がお互いに双方のプログラムの表示している結果を比較してください(これまでのRS232C接続の際の終局時と同様です)</li>
<li>双方のプログラムの結果が一致しない時には、審判が不一致部分の判定を行ない、結果を確定します</li>
</ul>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 これだけ実装すれば 疑似サーバーは作れそうだな☆」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 しかし、白番が先にログインして 黒番は後から入れ、とか 何か しきたり がなかったかだぜ☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 Cgf Go Ban のしきたりなんじゃないか☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 2人しか接続してこないという前提で プログラム書けば 早くできるんじゃないの?」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 そのあたりの仕様を もう少し詰めようぜ☆」</p>
<h1 id="TCP/IP通信その2"><a href="#TCP%2FIP%E9%80%9A%E4%BF%A1%E3%81%9D%E3%81%AE%EF%BC%92">TCP/IP通信その2</a></h1>
<pre><code> // Create the thread.
thread::spawn(move || {
handler(stream).unwrap_or_else(|error| eprintln!("{:?}", error));
});
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5ac9fa3b390b658160717a7c1ef5008a5d7a26458e30d.gif?mw=700" alt="KIFUWARABE_80x100x8_01_Futu.gif" /></a><br />
「 スポーンしたあとは どうすんだぜ☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 Rust でどう書けばいいのか分からん☆ とりあえず <code>quit</code> を送ったらループから抜けるようにするかだぜ☆」</p>
<p><a target="_blank" rel="nofollow noopener" href="https://doc.rust-lang.org/1.2.0/std/io/struct.BufStream.html">Struct std::io::BufStream</a><br />
<a target="_blank" rel="nofollow noopener" href="https://crates.io/crates/bufstream">bufstream 0.1.4</a></p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑Read も Write もしたいバッファー・ストリームは どう書けばいいんだぜ☆?」</p>
<pre><code>bufstream = "0.1.4"
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑これを <code>Cargo.toml</code> に書いて☆、」</p>
<pre><code>extern crate bufstream;
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑これを main.rs の冒頭に書いておくかだぜ☆」</p>
<pre><code> // Buffering.
let mut reader = BufReader::new(&stream);
let mut writer = BufWriter::new(&stream);
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑いや、そんなことをしなくても これでいけたのか……☆?」</p>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 ↑ <code>\n</code> を末尾に付けておかないと <code>read_line</code> が いつまで経っても終わらないぜ☆」</p>
<h1 id="ソケット間で共有するスコープとかない"><a href="#%E3%82%BD%E3%82%B1%E3%83%83%E3%83%88%E9%96%93%E3%81%A7%E5%85%B1%E6%9C%89%E3%81%99%E3%82%8B%E3%82%B9%E3%82%B3%E3%83%BC%E3%83%97%E3%81%A8%E3%81%8B%E3%81%AA%E3%81%84">ソケット間で共有するスコープとかない</a></h1>
<p><a href="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/3da2d4690cf2c3f101c5cbc0e48729f55d7a25f728bdc.gif?mw=700" alt="KITASHIRAKAWA_Chiyuri_80x100x8_01_Futu.gif" /></a><br />
「 そうか、クライアントのスレッド と サーバーのスレッド との間は グローバル変数でやりとりするのではなく、<br />
通信して やりとりするのかだぜ☆」</p>
<p><a href="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/058791c2dd4c1604ce1bd9ec26d490ae5d7a271c2fbbc.gif?mw=700" alt="OKAZAKI_Yumemi_80x80x8_02_Syaberu.gif" /></a><br />
「 Rust で Postgresql データベースを使えたりしないの?」</p>
<p><書きかけ></p>
むずでょ