Closed10

ColorShapeLinksの導入を行う

ganyariyaganyariya

https://videojogoslusofona.github.io/color-shape-links-ai-competition/docs/html/index.html

のQuickStartを行う.
そのためにUnityと.NET, Visual StudioをMacに導入する.
brew cask で殴ると楽.

このとき,https://dotnet.microsoft.com/download .NETを入れても dotnetコマンドが動かなかった.

これは以下のようにシンボリックリンクを貼ることで,コマンドが動くようになった

 ln -s /usr/local/share/dotnet/dotnet /usr/local/bin 

もしくは環境変数PATHに /usr/local/shareを入れてもいいかも

ganyariyaganyariya

Testing the AI in the console

コンソールで AI と 相手のAIを対戦させることができる.
まず,/color-shape-links-ai-competition/ConsoleApp/ColorShapeLinks/TextBased/App パスに移動する.

そして,以下を打ち込む
これは,match・試合をさせており,名前空間ColorShapeLinks.Common.AI.ExamplesのAI同士を対戦させている. tはプレイ時間

dotnet run -- match -W ColorShapeLinks.Common.AI.Examples.MinimaxAIThinker -R ColorShapeLinks.Common.AI.Examples.RandomAIThinker -t 1000

--は https://www.baeldung.com/linux/double-dash-in-shell-commands にある通り, --から始まるオプションはすでにこれで全部で, これ以降は-xタイプのオプションと引数のみですよ ということを表す.

ganyariyaganyariya

Unity 2020.3.4f1 で UnityApp を開こうとしたら アセットに画像が入ってないよ エラーが出た.
おそらくgit-lfsで アセットパスを持ってくるのに失敗したためと睨んだ.

そのため,一回ColorShapeLinksディレクトリを削除して先にgit-lfsをインストールした.

brew install git-lfs

その後 もっかいGitHubからクローンした.
その結果,UnityAppディレクトリをUnityで開くと画像などのエラーがなくなった.

git clone --recurse-submodules https://github.com/VideojogosLusofona/color-shape-links-ai-competition.git
ganyariyaganyariya

勢いに乗って,Thinker implementation guide もやっちゃう

AbstractThinkerクラスを継承して自分だけのAIを作ろう!
オーバーライドするメソッドは3つあって,基本2つだけオーバーライドすれば良さそう.

Setup()メソッドは,AIの準備メソッドでコンストラクタっぽいことをすれば良さそう
Thiknk()はボードが与えられるので,次のActionを返せばいい.

親クラスのAbstractThinkerには,読み取り専用のprotected変数である 列吸う,行数,これまでの操作列 などが格納されているっぽい

ganyariyaganyariya

Setup メソッドについて

AIThinkerを設定するのが,このメソッドで引数には「起動時に与える文字列パラーメタ」を設定できる.
たとえば,仮に depth=3,alpha=2という文字列をSetupに与えれば,深さ探索を3,\alphaを2に設定できる.
このように文字列で与えることで,対戦時に動的にパラメータを与えることができる.(いろんな思考AIを文字列で試すことができる)
ただし,与えられた文字列はユーザ自身でパースする必要がある.

また,toStringメソッドをオーバライドして,与えられた文字列パラーメタなどを含めておけば,どのAIが対戦しているかわかりやすい.

ganyariyaganyariya

Thinkは game boardを受けとって,次の手Further Move を返す関数.

キャンセルトークンも引数に与えられる.
これは実行時間が切れるなどしたときを教えてくれるので,そういうときはすぐにFurtureMove.NoMoveを返して手を決めてしまおう(おそらく これをしないとTLEになり,即時負けになる)

ゲームボードインスタンスは,すでにコピーされたものなので自由にいじくり回していい.
DoMoveメソッドなどをすると,ある手を打ったあとの次のボードになる.(使いやすくて良い)

CheckWinnerメソッドも実装されており,勝敗をチェックしてくれるので便利.
winCorridorsはよくわかってない

以下の状態で強制的に負ける

  • 例外が発生する
  • 時間がかかる
  • 範囲外の手
ganyariyaganyariya

Setting up the development environment

mkdir dev-color-shape-links
cd dev-color-shape-links

git clone --recurse-submodules https://github.com/VideojogosLusofona/color-shape-links-ai-competition.git

mkdir ganariya-solution
cd ganariya-solution

git init
系

# now ganariya-solution directory
dotnet new classlib -n MyAI -f netstandard2.0
rm MyAI/Class1.cs

# now ganariya-solution directory
# 依存関係の登録
dotnet add MyAI reference ../color-shape-links-ai-competition/ConsoleApp/ColorShapeLinks/Common

# now ganariya-solution directory
vi MyAI/test.cs
# ページに有るソースコードの作成

# now ganariya-solution directory
dotnet build MyAI
dotnet run -p ../color-shape-links-ai-competition/ConsoleApp/ColorShapeLinks/TextBased/App -- info -a $(pwd)/MyAI/bin/Debug/netstandard2.0/MyAI.dll

dotnet run -p ../color-shape-links-ai-competition/ConsoleApp/ColorShapeLinks/TextBased/App -- match -a $(pwd)/MyAI/bin/Debug/netstandard2.0/MyAI.dll -W ColorShapeLinks.Common.AI.Examples.RandomAIThinker -R GanariyaSolution.MyAI.MyThinker
ganyariyaganyariya

Testing an AI thinker in isolation

言われたとおりにやった.
MySolutionをぼくはganariya-solutionというディレクトリに変えたので
GanariyaSolutionにすべて変える必要があることに注意.

Visual Studio for Mac で slnを開いたが,エラーが出るので,どうすればいいんだろう(後々のチュートリアルで出てくるのだろうか)

ganyariyaganyariya

Testing an AI thinker in isolation 以降は指定通りに行った

覚えきれなかったのでMakefileを入れた

ganariya-solutionという名前が適当すぎて,のちのちのチーム開発でマージしづらいので来週相談する

https://github.com/Ganariya/ganariya-solution

このスクラップは2021/06/07にクローズされました