コンピュータとオセロ対戦49　～AI実装と性能評価～

https://qiita.com/tt_and_tk/items/068f2afde6db637e189f

[前回](https://qiita.com/tt_and_tk/items/d8f662c430ac277a4d20)

# 今回の目標
前回作成したネットワークを使用して対戦AIを作る。
また、[34　～性能評価～](https://qiita.com/tt_and_tk/items/13be9077d3b136c20375)のように、その強さを客観的に評価する。
# 使用バージョン
* Java 17.0.1
* MyNet 1.2.4
# ここから本編
## 対戦AIを作る
まずは前回作成したネットワークを使えるようにしていきます。
なお、ここではそのネットワークを「oseroAI.net」という名前に変更しています。
### クラス構成
四つの引数を受け取り、倍精度実数を返す関数を格納するFourFunctionクラスも使用しています。
OseroBaseとOseroクラスについては、前回から変更していません。

```
OseroBase  // オセロの基本機能を実装
↓ 継承
Osero      // オセロの思考方法を実装
↓ 継承
OseroAI    // オセロAIを実装
```

### OseroAI.java
オセロAIを実装する。基本的には[33　～勝敗予測AIと対戦～](https://qiita.com/tt_and_tk/items/4179c1e25d689bccce8a)（Pythonでやった時）と大差ないが、探索をOseroクラスのexploreAssistに任せ、スコアを返すアルゴリズムをそのメソッドに渡しています。
また、対戦結果を返すplayAndGetResultメソッドを作成しました。
なお、コンストラクタで必ずネットワークの名前を指定する必要があります。
他に特筆すべきことはないので、全文載せます。

<details><summary>OseroAI.java</summary>

```OseroAI.java
import java.util.function.BiConsumer;
import java.util.ArrayList;

import org.MyNet.network.*;
import org.MyNet.nodes.activationFunction.*;
import org.MyNet.layer.*;
import org.MyNet.matrix.*;

public class OseroAI extends Osero {
    protected static Network net = null;

    public OseroAI(ArrayList<BiConsumer<long[], Boolean>> playMethod, String netName){
        this.setup();
        this.playMethod = playMethod;
        this.loadNet(netName);
    }

    public OseroAI(BiConsumer<long[], Boolean> black, BiConsumer<long[], Boolean> white, String netName){
        this.setup();
        this.playMethod.add(black);
        this.playMethod.add(white);
        this.loadNet(netName);
    }

    public int[] playAndGetResult(){
        boolean can = true, oldCan = true;

        while ((can = this.checkAll()) || oldCan){
            if (can){
                this.playMethod.get(this.turn ? 1:0).accept(this.bw, this.turn);
            }

            this.turn = !this.turn;
            oldCan = can;
        }

        int[] rtn = {this.popCount(this.bw[0]), this.popCount(this.bw[1])};
        return rtn;
    }

    protected void loadNet(String netName){
        net = new Network(
            192,
            new Input(100, AF.RELU),
            new Dense(50, AF.SIGMOID),
            new Output(1, AF.RELU)
        );
        net.load(netName);
    }

    public static void oseroAI(long board[], boolean turn){
        Osero.exploreAssist(board, turn, OseroAI::exploreAI);
    }

    protected static double exploreAI(long[] board, boolean nowTurn, boolean turn, int num){
        if (num >= Osero.readGoal[(nowTurn ? 1:0)]) return OseroAI.predict(board, nowTurn);

        double score = 0, placeNum = 0;
        int row = -1, col = 0;
        long[] boardLeaf = new long[2];
        for (int place = 0; place < OseroBase.SIZE << OseroBase.SHIFTNUM; place++){
            row++;
            if (row >= OseroBase.SIZE){
                row = 0;
                col++;
            }
            if (!OseroBase.check(row, col, board, turn)) continue;
            placeNum += 1;
            boardLeaf[0] = board[0]; boardLeaf[1] = board[1];
            OseroBase.put(row, col, boardLeaf, turn);
            score += OseroAI.exploreAI(
                boardLeaf,
                nowTurn,
                !turn,
                num + 1    
            );
        }
        
        if (placeNum > 0) return score / placeNum;
        else              return OseroAI.predict(board, nowTurn);
    }

    protected static double predict(long board[], boolean turn){
        Matrix x;
        ArrayList<ArrayList<Double>> x_list = new ArrayList<ArrayList<Double>>();
        x_list.add(new ArrayList<Double>());

        long place = 1;
        int my, opp;
        boolean myStone, oppStone;

        if (turn){
            my = 1; opp = 0;
        }else{
            my = 0; opp = 1;
        }

        while (place != 0){
            x_list.get(0).add((myStone = ((board[my] & place) != 0)) ? 1.0 : 0.0);
            x_list.get(0).add((oppStone = ((board[opp] & place) != 0)) ? 1.0 : 0.0);
            x_list.get(0).add(myStone || oppStone ? 0.0 : 1.0);
            place = place << 1;
        }

        x = new Matrix(x_list);

        return OseroAI.net.forward(x).matrix[0][0];
    }
}
```
</details>

### Run.java
OseroAIクラスをインスタンス化し、一度試合を行います。

```Run.java
public class Run {
    public static void main(String[] str){
        Osero run = new OseroAI(OseroAI::oseroAI, OseroAI::oseroAI, "oseroAI.net");
        run.play(Osero.PRINT);
    }
}
```

### 実行結果
対戦結果を載せますが、長いので気になる人だけ見てください。
人力でチェックしたところ、一応おかしな点はありませんでした。

<details><summary>対戦結果</summary>

```
   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |  |  |  |  |
 -------------------------
3|  |  |  |  |  |  |  |  |
 -------------------------
4|  |  |  |O |@ |  |  |  |
 -------------------------
5|  |  |  |@ |O |  |  |  |
 -------------------------
6|  |  |  |  |  |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |  |  |  |  |
 -------------------------
3|  |  |  |@ |  |  |  |  |
 -------------------------
4|  |  |  |@ |@ |  |  |  |
 -------------------------
5|  |  |  |@ |O |  |  |  |
 -------------------------
6|  |  |  |  |  |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |  |  |  |  |
 -------------------------
3|  |  |  |@ |O |  |  |  |
 -------------------------
4|  |  |  |@ |O |  |  |  |
 -------------------------
5|  |  |  |@ |O |  |  |  |
 -------------------------
6|  |  |  |  |  |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |  |  |  |  |
 -------------------------
3|  |  |  |@ |@ |@ |  |  |
 -------------------------
4|  |  |  |@ |@ |  |  |  |
 -------------------------
5|  |  |  |@ |O |  |  |  |
 -------------------------
6|  |  |  |  |  |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |O |  |  |  |
 -------------------------
3|  |  |  |@ |O |@ |  |  |
 -------------------------
4|  |  |  |@ |O |  |  |  |
 -------------------------
5|  |  |  |@ |O |  |  |  |
 -------------------------
6|  |  |  |  |  |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |O |  |  |  |
 -------------------------
3|  |  |  |@ |O |@ |  |  |
 -------------------------
4|  |  |  |@ |@ |  |  |  |
 -------------------------
5|  |  |  |@ |@ |@ |  |  |
 -------------------------
6|  |  |  |  |  |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |O |  |  |  |
 -------------------------
3|  |  |  |O |O |@ |  |  |
 -------------------------
4|  |  |O |@ |@ |  |  |  |
 -------------------------
5|  |  |  |@ |@ |@ |  |  |
 -------------------------
6|  |  |  |  |  |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |O |  |  |  |
 -------------------------
3|  |  |@ |@ |@ |@ |  |  |
 -------------------------
4|  |  |O |@ |@ |  |  |  |
 -------------------------
5|  |  |  |@ |@ |@ |  |  |
 -------------------------
6|  |  |  |  |  |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |O |  |  |  |
 -------------------------
3|  |  |@ |@ |O |@ |  |  |
 -------------------------
4|  |  |O |@ |O |  |  |  |
 -------------------------
5|  |  |  |O |O |@ |  |  |
 -------------------------
6|  |  |  |  |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |O |  |  |  |
 -------------------------
3|  |  |@ |@ |O |@ |  |  |
 -------------------------
4|  |  |O |@ |@ |  |  |  |
 -------------------------
5|  |  |  |@ |O |@ |  |  |
 -------------------------
6|  |  |@ |  |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |O |  |  |  |
 -------------------------
3|  |  |@ |@ |O |@ |  |  |
 -------------------------
4|  |  |O |O |@ |  |  |  |
 -------------------------
5|  |  |O |O |O |@ |  |  |
 -------------------------
6|  |  |@ |  |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |O |  |  |  |
 -------------------------
3|  |  |@ |@ |O |@ |  |  |
 -------------------------
4|  |  |@ |O |@ |  |  |  |
 -------------------------
5|  |@ |@ |@ |@ |@ |  |  |
 -------------------------
6|  |  |@ |  |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |  |  |  |O |  |  |  |
 -------------------------
3|  |O |O |O |O |@ |  |  |
 -------------------------
4|  |  |O |O |@ |  |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |  |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |@ |  |  |O |  |  |  |
 -------------------------
3|  |O |@ |O |O |@ |  |  |
 -------------------------
4|  |  |O |@ |@ |  |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |  |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |@ |  |  |O |  |  |  |
 -------------------------
3|  |O |@ |O |O |@ |  |  |
 -------------------------
4|  |  |O |O |O |O |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |  |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |  |  |  |  |  |  |  |
 -------------------------
2|  |@ |  |  |O |@ |  |  |
 -------------------------
3|  |O |@ |O |@ |@ |  |  |
 -------------------------
4|  |  |O |@ |O |O |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |  |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |O |  |  |  |  |  |  |
 -------------------------
2|  |O |  |  |O |@ |  |  |
 -------------------------
3|  |O |@ |O |@ |@ |  |  |
 -------------------------
4|  |  |O |@ |O |O |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |  |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |O |  |  |  |  |  |  |
 -------------------------
2|  |O |  |  |O |@ |  |  |
 -------------------------
3|  |O |@ |O |@ |@ |  |  |
 -------------------------
4|  |  |O |@ |O |O |  |  |
 -------------------------
5|  |@ |@ |@ |@ |@ |  |  |
 -------------------------
6|  |  |@ |@ |O |  |  |  |
 -------------------------
7|  |  |  |  |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|  |O |  |  |  |  |  |  |
 -------------------------
2|  |O |  |  |O |@ |  |  |
 -------------------------
3|  |O |@ |O |@ |@ |  |  |
 -------------------------
4|  |  |O |O |O |O |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |O |O |  |  |  |
 -------------------------
7|  |  |  |O |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |  |  |  |  |  |
 -------------------------
2|  |@ |  |  |O |@ |  |  |
 -------------------------
3|  |O |@ |O |@ |@ |  |  |
 -------------------------
4|  |  |O |O |O |O |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |O |O |  |  |  |
 -------------------------
7|  |  |  |O |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |  |  |O |  |  |
 -------------------------
2|  |@ |  |  |O |O |  |  |
 -------------------------
3|  |O |@ |O |@ |O |  |  |
 -------------------------
4|  |  |O |O |O |O |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |O |O |  |  |  |
 -------------------------
7|  |  |  |O |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |  |  |O |  |  |
 -------------------------
2|  |@ |@ |  |O |O |  |  |
 -------------------------
3|  |O |@ |@ |@ |O |  |  |
 -------------------------
4|  |  |O |O |@ |O |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |O |O |  |  |  |
 -------------------------
7|  |  |  |O |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |@ |O |  |O |O |  |  |
 -------------------------
3|  |O |@ |@ |@ |O |  |  |
 -------------------------
4|  |  |O |O |@ |O |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |O |O |  |  |  |
 -------------------------
7|  |  |  |O |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |@ |O |  |O |O |  |  |
 -------------------------
3|  |O |@ |@ |@ |@ |@ |  |
 -------------------------
4|  |  |O |O |@ |@ |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |O |O |  |  |  |
 -------------------------
7|  |  |  |O |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |@ |O |  |O |O |  |  |
 -------------------------
3|  |O |@ |@ |@ |@ |@ |  |
 -------------------------
4|  |  |O |O |@ |@ |  |  |
 -------------------------
5|  |@ |O |O |@ |@ |  |  |
 -------------------------
6|  |  |O |O |O |  |  |  |
 -------------------------
7|  |  |O |O |  |  |  |  |
 -------------------------
8|  |  |  |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |@ |O |  |O |O |  |  |
 -------------------------
3|  |O |@ |@ |@ |@ |@ |  |
 -------------------------
4|  |  |@ |O |@ |@ |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |O |@ |  |  |  |
 -------------------------
7|  |  |@ |@ |  |  |  |  |
 -------------------------
8|  |  |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |@ |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |@ |@ |@ |  |
 -------------------------
4|  |  |@ |O |@ |@ |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |O |@ |  |  |  |
 -------------------------
7|  |  |@ |@ |  |  |  |  |
 -------------------------
8|  |  |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |@ |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |@ |@ |@ |  |
 -------------------------
4|  |  |@ |O |@ |@ |  |  |
 -------------------------
5|  |@ |@ |O |@ |@ |  |  |
 -------------------------
6|  |  |@ |@ |@ |  |  |  |
 -------------------------
7|  |  |@ |@ |@ |  |  |  |
 -------------------------
8|  |  |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |@ |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |  |
 -------------------------
4|  |  |@ |O |@ |O |  |  |
 -------------------------
5|  |@ |@ |O |O |O |O |  |
 -------------------------
6|  |  |@ |@ |@ |  |  |  |
 -------------------------
7|  |  |@ |@ |@ |  |  |  |
 -------------------------
8|  |  |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |@ |O |O |O |O |  |  |
 -------------------------
3|  |@ |@ |O |O |@ |@ |  |
 -------------------------
4|  |@ |@ |O |@ |O |  |  |
 -------------------------
5|  |@ |@ |O |O |O |O |  |
 -------------------------
6|  |  |@ |@ |@ |  |  |  |
 -------------------------
7|  |  |@ |@ |@ |  |  |  |
 -------------------------
8|  |  |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |O |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |  |
 -------------------------
4|  |O |@ |O |@ |O |  |  |
 -------------------------
5|  |O |O |O |O |O |O |  |
 -------------------------
6|  |O |@ |@ |@ |  |  |  |
 -------------------------
7|  |  |@ |@ |@ |  |  |  |
 -------------------------
8|  |  |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |O |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |  |
 -------------------------
4|  |@ |@ |O |@ |O |  |  |
 -------------------------
5|@ |O |O |O |O |O |O |  |
 -------------------------
6|  |@ |@ |@ |@ |  |  |  |
 -------------------------
7|  |  |@ |@ |@ |  |  |  |
 -------------------------
8|  |  |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |O |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |O |  |
 -------------------------
4|  |@ |@ |O |@ |O |  |O |
 -------------------------
5|@ |O |O |O |O |O |O |  |
 -------------------------
6|  |@ |@ |@ |@ |  |  |  |
 -------------------------
7|  |  |@ |@ |@ |  |  |  |
 -------------------------
8|  |  |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |O |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |O |  |
 -------------------------
4|  |@ |@ |O |@ |O |  |O |
 -------------------------
5|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------
6|  |@ |@ |@ |@ |  |  |  |
 -------------------------
7|  |  |@ |@ |@ |  |  |  |
 -------------------------
8|  |  |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |O |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |O |  |
 -------------------------
4|  |@ |@ |O |@ |O |  |O |
 -------------------------
5|@ |@ |@ |@ |O |@ |@ |@ |
 -------------------------
6|  |@ |@ |O |@ |  |  |  |
 -------------------------
7|  |  |O |@ |@ |  |  |  |
 -------------------------
8|  |O |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |O |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |@ |
 -------------------------
4|  |@ |@ |O |@ |O |  |@ |
 -------------------------
5|@ |@ |@ |@ |O |@ |@ |@ |
 -------------------------
6|  |@ |@ |O |@ |  |  |  |
 -------------------------
7|  |  |O |@ |@ |  |  |  |
 -------------------------
8|  |O |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |O |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |@ |
 -------------------------
4|  |@ |@ |O |@ |O |  |@ |
 -------------------------
5|@ |@ |@ |@ |O |@ |O |@ |
 -------------------------
6|  |@ |@ |O |@ |  |  |O |
 -------------------------
7|  |  |O |@ |@ |  |  |  |
 -------------------------
8|  |O |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |O |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |@ |
 -------------------------
4|  |@ |@ |@ |@ |O |  |@ |
 -------------------------
5|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------
6|  |@ |@ |O |@ |@ |  |O |
 -------------------------
7|  |  |O |@ |@ |  |  |  |
 -------------------------
8|  |O |@ |  |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |O |  |O |  |O |  |  |
 -------------------------
2|  |O |O |O |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |@ |
 -------------------------
4|  |@ |@ |@ |@ |O |  |@ |
 -------------------------
5|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------
6|  |@ |@ |O |@ |@ |  |O |
 -------------------------
7|  |  |O |O |@ |  |  |  |
 -------------------------
8|  |O |O |O |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|  |O |@ |@ |O |O |  |  |
 -------------------------
3|  |O |@ |O |@ |@ |@ |@ |
 -------------------------
4|  |@ |@ |@ |@ |@ |  |@ |
 -------------------------
5|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------
6|  |@ |@ |O |@ |@ |  |O |
 -------------------------
7|  |  |O |O |@ |  |  |  |
 -------------------------
8|  |O |O |O |  |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|  |O |@ |@ |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |@ |
 -------------------------
4|  |@ |@ |@ |O |@ |  |@ |
 -------------------------
5|@ |@ |@ |@ |O |@ |@ |@ |
 -------------------------
6|  |@ |@ |O |O |@ |  |O |
 -------------------------
7|  |  |O |O |O |  |  |  |
 -------------------------
8|  |O |O |O |O |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |@ |@ |O |O |  |  |
 -------------------------
3|  |@ |@ |O |O |@ |@ |@ |
 -------------------------
4|  |@ |@ |@ |O |@ |  |@ |
 -------------------------
5|@ |@ |@ |@ |O |@ |@ |@ |
 -------------------------
6|  |@ |@ |O |O |@ |  |O |
 -------------------------
7|  |  |O |O |O |  |  |  |
 -------------------------
8|  |O |O |O |O |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |O |@ |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |@ |
 -------------------------
4|O |O |O |O |O |@ |  |@ |
 -------------------------
5|@ |O |@ |@ |O |@ |@ |@ |
 -------------------------
6|  |@ |O |O |O |@ |  |O |
 -------------------------
7|  |  |O |O |O |  |  |  |
 -------------------------
8|  |O |O |O |O |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |O |@ |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |@ |
 -------------------------
4|O |O |O |O |O |@ |  |@ |
 -------------------------
5|@ |O |@ |@ |O |@ |@ |@ |
 -------------------------
6|  |@ |O |O |@ |@ |  |O |
 -------------------------
7|  |  |O |O |O |@ |  |  |
 -------------------------
8|  |O |O |O |O |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |O |@ |O |O |  |  |
 -------------------------
3|  |O |@ |O |O |@ |@ |@ |
 -------------------------
4|O |O |O |O |O |@ |  |@ |
 -------------------------
5|@ |O |O |@ |O |@ |@ |@ |
 -------------------------
6|  |O |O |O |@ |@ |  |O |
 -------------------------
7|O |  |O |O |O |@ |  |  |
 -------------------------
8|  |O |O |O |O |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |O |@ |O |O |  |  |
 -------------------------
3|@ |@ |@ |O |O |@ |@ |@ |
 -------------------------
4|@ |O |O |O |O |@ |  |@ |
 -------------------------
5|@ |O |O |@ |O |@ |@ |@ |
 -------------------------
6|  |O |O |O |@ |@ |  |O |
 -------------------------
7|O |  |O |O |O |@ |  |  |
 -------------------------
8|  |O |O |O |O |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |O |@ |O |O |  |  |
 -------------------------
3|@ |@ |@ |O |O |@ |@ |@ |
 -------------------------
4|@ |O |O |O |O |@ |  |@ |
 -------------------------
5|@ |O |O |@ |O |@ |@ |@ |
 -------------------------
6|  |O |O |O |@ |O |  |O |
 -------------------------
7|O |  |O |O |O |O |O |  |
 -------------------------
8|  |O |O |O |O |  |  |  |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |O |@ |O |O |  |  |
 -------------------------
3|@ |@ |@ |O |O |@ |@ |@ |
 -------------------------
4|@ |O |O |@ |O |@ |  |@ |
 -------------------------
5|@ |O |O |@ |@ |@ |@ |@ |
 -------------------------
6|  |O |O |O |@ |@ |  |O |
 -------------------------
7|O |  |O |O |O |O |@ |  |
 -------------------------
8|  |O |O |O |O |  |  |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |O |@ |O |O |  |  |
 -------------------------
3|@ |@ |@ |O |O |O |@ |@ |
 -------------------------
4|@ |O |O |@ |O |O |O |@ |
 -------------------------
5|@ |O |O |@ |@ |O |@ |@ |
 -------------------------
6|  |O |O |O |O |@ |  |O |
 -------------------------
7|O |  |O |O |O |O |@ |  |
 -------------------------
8|  |O |O |O |O |  |  |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |O |@ |O |O |  |  |
 -------------------------
3|@ |@ |@ |O |O |O |@ |@ |
 -------------------------
4|@ |O |O |@ |O |O |O |@ |
 -------------------------
5|@ |O |O |@ |@ |O |@ |@ |
 -------------------------
6|  |O |O |O |@ |@ |  |O |
 -------------------------
7|O |  |O |O |O |@ |@ |  |
 -------------------------
8|  |O |O |O |O |  |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |O |@ |O |O |  |  |
 -------------------------
3|@ |@ |@ |O |O |O |@ |@ |
 -------------------------
4|@ |O |O |@ |O |O |O |@ |
 -------------------------
5|@ |O |O |@ |@ |O |@ |@ |
 -------------------------
6|  |O |O |O |@ |@ |  |O |
 -------------------------
7|O |  |O |O |O |O |O |O |
 -------------------------
8|  |O |O |O |O |  |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |@ |@ |O |O |  |  |
 -------------------------
3|@ |@ |@ |@ |O |O |@ |@ |
 -------------------------
4|@ |O |O |@ |@ |O |O |@ |
 -------------------------
5|@ |O |O |@ |@ |@ |@ |@ |
 -------------------------
6|  |O |O |O |@ |@ |@ |O |
 -------------------------
7|O |  |O |O |O |O |@ |O |
 -------------------------
8|  |O |O |O |O |  |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |@ |@ |O |O |  |  |
 -------------------------
3|@ |@ |@ |@ |O |O |@ |@ |
 -------------------------
4|@ |O |O |@ |@ |O |O |@ |
 -------------------------
5|@ |O |O |@ |@ |@ |@ |@ |
 -------------------------
6|  |O |O |O |@ |@ |@ |O |
 -------------------------
7|O |  |O |O |O |O |O |O |
 -------------------------
8|  |O |O |O |O |O |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |@ |@ |O |O |  |  |
 -------------------------
3|@ |@ |@ |@ |O |O |@ |@ |
 -------------------------
4|@ |O |O |@ |@ |O |O |@ |
 -------------------------
5|@ |O |O |@ |@ |@ |@ |@ |
 -------------------------
6|  |O |O |O |@ |@ |@ |O |
 -------------------------
7|O |  |O |O |O |O |O |O |
 -------------------------
8|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |O |  |O |  |  |
 -------------------------
2|@ |@ |@ |@ |O |O |  |O |
 -------------------------
3|@ |@ |@ |@ |O |O |O |O |
 -------------------------
4|@ |O |O |@ |@ |O |O |O |
 -------------------------
5|@ |O |O |@ |@ |@ |@ |O |
 -------------------------
6|  |O |O |O |@ |@ |@ |O |
 -------------------------
7|O |  |O |O |O |O |O |O |
 -------------------------
8|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |@ |@ |O |  |  |
 -------------------------
2|@ |@ |@ |@ |@ |O |  |O |
 -------------------------
3|@ |@ |@ |@ |@ |O |O |O |
 -------------------------
4|@ |O |O |@ |@ |O |O |O |
 -------------------------
5|@ |O |O |@ |@ |@ |@ |O |
 -------------------------
6|  |O |O |O |@ |@ |@ |O |
 -------------------------
7|O |  |O |O |O |O |O |O |
 -------------------------
8|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |@ |@ |O |  |  |
 -------------------------
2|@ |@ |@ |@ |@ |O |  |O |
 -------------------------
3|@ |@ |@ |@ |@ |O |O |O |
 -------------------------
4|@ |O |@ |@ |@ |O |O |O |
 -------------------------
5|@ |@ |O |@ |@ |@ |@ |O |
 -------------------------
6|@ |@ |@ |@ |@ |@ |@ |O |
 -------------------------
7|@ |  |O |O |O |O |O |O |
 -------------------------
8|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |@ |@ |O |  |  |
 -------------------------
2|@ |@ |@ |@ |@ |O |  |O |
 -------------------------
3|@ |@ |@ |@ |@ |O |O |O |
 -------------------------
4|@ |O |@ |@ |O |O |O |O |
 -------------------------
5|@ |O |O |O |@ |@ |@ |O |
 -------------------------
6|@ |O |O |@ |@ |@ |@ |O |
 -------------------------
7|@ |O |O |O |O |O |O |O |
 -------------------------
8|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |@ |@ |O |  |  |
 -------------------------
2|@ |@ |@ |@ |@ |@ |@ |O |
 -------------------------
3|@ |@ |@ |@ |@ |@ |@ |O |
 -------------------------
4|@ |O |@ |@ |@ |O |@ |O |
 -------------------------
5|@ |O |O |@ |@ |@ |@ |O |
 -------------------------
6|@ |O |@ |@ |@ |@ |@ |O |
 -------------------------
7|@ |@ |O |O |O |O |O |O |
 -------------------------
8|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |@ |@ |O |O |  |
 -------------------------
2|@ |@ |@ |@ |@ |O |O |O |
 -------------------------
3|@ |@ |@ |@ |O |@ |O |O |
 -------------------------
4|@ |O |@ |O |@ |O |O |O |
 -------------------------
5|@ |O |O |@ |@ |@ |O |O |
 -------------------------
6|@ |O |@ |@ |@ |@ |O |O |
 -------------------------
7|@ |@ |O |O |O |O |O |O |
 -------------------------
8|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------

   1  2  3  4  5  6  7  8
 -------------------------
1|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------
2|@ |@ |@ |@ |@ |O |@ |@ |
 -------------------------
3|@ |@ |@ |@ |O |@ |O |@ |
 -------------------------
4|@ |O |@ |O |@ |O |O |@ |
 -------------------------
5|@ |O |O |@ |@ |@ |O |@ |
 -------------------------
6|@ |O |@ |@ |@ |@ |O |@ |
 -------------------------
7|@ |@ |O |O |O |O |O |@ |
 -------------------------
8|@ |@ |@ |@ |@ |@ |@ |@ |
 -------------------------
black: 47, white: 17
black win!
```

</details>

## 対戦を行う
これまでに登場した思考方法を総当たりで戦わせます。
### Run.java
random、nHand、nHandCustom、nLeast、nMost、oseroAIを、それぞれ1手先、2手先までの計12種類の思考方法を総当たりで戦わせます。
さらに、Pythonよりも実行速度が速いので、それぞれの条件で乱数のシード値を変更し100通りの試合を行います。
よって、12x12x100の14400試合行います。
[34　～性能評価～](https://qiita.com/tt_and_tk/items/13be9077d3b136c20375)では一回ずつしか戦わせられなかったので、この時より正確なデータが得られると思います。
プログラムは、これらを戦わせて結果をcsv出力させているだけなので興味ある方だけ見てみてください。

<details><summary>プログラム</summary>

```Run.java
import java.util.function.BiConsumer;
import java.util.ArrayList;
import java.io.IOException;
import java.io.PrintWriter;

public class Run {
    public static void main(String[] str){
        ArrayList<BiConsumer<long[], Boolean>> playMethod;
        playMethod = new ArrayList<BiConsumer<long[], Boolean>>();
        ArrayList<String> playMethodName;
        playMethodName = new ArrayList<String>();
        ArrayList<Integer> readGoals;
        readGoals = new ArrayList<Integer>();

        playMethod.add(Osero::random);	playMethodName.add("random");	readGoals.add(1);
        playMethod.add(Osero::random);	playMethodName.add("random");	readGoals.add(2);
        playMethod.add(Osero::nHand);	playMethodName.add("nHand");	readGoals.add(1);
        playMethod.add(Osero::nHand);	playMethodName.add("nHand");	readGoals.add(2);
        playMethod.add(Osero::nHandCustom);	playMethodName.add("nHandCustom");	readGoals.add(1);
        playMethod.add(Osero::nHandCustom);	playMethodName.add("nHandCustom");	readGoals.add(2);
        playMethod.add(Osero::nLeast);	playMethodName.add("nLeast");	readGoals.add(1);
        playMethod.add(Osero::nLeast);	playMethodName.add("nLeast");	readGoals.add(2);
        playMethod.add(Osero::nMost);	playMethodName.add("nMost");	readGoals.add(1);
        playMethod.add(Osero::nMost);	playMethodName.add("nMost");	readGoals.add(2);
        playMethod.add(OseroAI::oseroAI);	playMethodName.add("oseroAI");	readGoals.add(1);
        playMethod.add(OseroAI::oseroAI);	playMethodName.add("oseroAI");	readGoals.add(2);
        
        OseroAI run = new OseroAI(OseroAI::oseroAI, OseroAI::oseroAI, "oseroAI.net");

        try(
            PrintWriter fp = new PrintWriter("data.csv");
        ){
            int[] result;
            fp.write("black_method,white_method,black_score,white_score,black_read_goal,white_read_goal,seed\n");

            for (int i = 0; i < playMethod.size(); i++){
                System.out.printf("\r%d/%d", i+1, playMethod.size());
                for (int j = 0; j < playMethod.size(); j++){
                    run.setPlayMethod(playMethod.get(i), playMethod.get(j));
                    run.setReadGoal(readGoals.get(i), readGoals.get(j));
                    for (int k = 0; k < 100; k++){
                        run.setRandom(k);
                        run.setup();
                        result = run.playAndGetResult();

                        fp.printf(
                            "%s,%s,%d,%d,%d,%d,%d\n",
                            playMethodName.get(i),
                            playMethodName.get(j),
                            result[0],
                            result[1],
                            readGoals.get(i),
                            readGoals.get(j),
                            k
                        );
                    }
                }
            }

            System.out.println();
        }catch (IOException e){
            System.out.println("IO Exception");
            System.exit(-1);
        }
    }
}
```

</details>

### 対戦結果
対戦結果を見てみます。
グラフ作成プログラムは以下の通り。

<details><summary>グラフ作成プログラム</summary>

```py
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

sns.set()

################################################

def bar(x, y, xlabel, ylabel, fig_name, dir_name):
    fig, ax = plt.subplots(figsize=(8, 8))
    rect = plt.bar(x, y, color="g")
    rect[[num for num, y_ele in enumerate(y) if max(y) == y_ele][0]].set_color("r")
    rect[[num for num, y_ele in enumerate(y) if min(y) == y_ele][0]].set_color("b")
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.title(fig_name)
    plt.savefig(dir_name + "/" + fig_name + ".png")
    plt.clf()
    plt.close()

################################################

df = pd.read_csv("data.csv")
methods_name = df["black_method"].unique()

################################################

# 勝ち星の数

y = []

for method in methods_name:
    num = 0
    num += len(df.query("black_method=='%s'" % method).query("black_score>white_score"))
    num += len(df.query("white_method=='%s'" % method).query("white_score>black_score"))
    y.append(num)

bar(methods_name, y, "method name", "win num", "win num each method name", "fig")
```

</details>

他のグラフもほぼ同じプログラムで作っているのでプログラムは省略します。
なお、トップを赤、ワーストを青、その他を緑色で着色しています。

#### 勝ち星の数
![win num each method name.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1925706/7fe9b35f-7734-9c9f-1521-175c22f1e27c.png)

参考までに、[34　～性能評価～](https://qiita.com/tt_and_tk/items/13be9077d3b136c20375)の結果はこちら。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1925706/f538250d-6b67-a1fe-7273-7331904a9374.png)

34ではnleastが猛威を振るいましたが、今回のトップはnHandCustomとなりました。nLeastは二番手につけています。
また、せっかく作成したAIは今回最下位に。
34の結果は総当たりで1回ずつ戦ったものですので、データ量100倍の今回の結果の方が信用できると思います。

#### 負け星の数
![lose num each method name.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1925706/b1849a3a-7def-f86d-36a8-fb26389236b2.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1925706/c6289b65-0ba1-ba9a-93d3-48d2476f8270.png)

勝ち星グラフを裏返したような形。
引き分けはほぼなかったようです。

#### 獲得石数
![score num each method name.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1925706/9a4b0026-e727-0c9b-5911-a4a2464214ea.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1925706/127744c5-31dd-eb41-ede5-74d3da0d235e.png)

勝ち星ほど大差にはならなかったというのは34と同じ結果。
ただ34と違い、順位は逆転していません。

#### 1手先と2手先
![win num each read goal.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1925706/04793f9c-568d-28ec-96c4-c4f347de079d.png)

僅差で2が勝利。
あまり変わらないようです。

#### 各手法とreadGoal
![win num each method name and read goal.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1925706/13d921b0-5cc0-bab1-7be3-fff4f34ca21d.png)

randomは1も2も同じ思考方法なので気にしないでください。むしろほぼ同じ結果で安心しました。
トップは1handCustom、ワーストは1oseroAIでした。
以外にも1handCustomの方が2handCustomより多く勝ち星を得る結果に。
他の手法を見ると、

* nHand 1 < 2
* nHandCustom 1 > 2
* nLeast 1 > 2
* nMost 1 ≒ 2
* oseroAI 1 < 2

でした。
さらに言えば、トップ層の思考方法は1手先まで読む方が強く、ワースト層は2手先まで読む方が強かったです。偶然でしょうか。

#### シード値の公平性
各シード値で、黒が勝った数-白が勝った数を計算しグラフ化しました。

![seed fairness.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1925706/1b5843c0-1a98-b802-3fea-8045e7bb280b.png)

各シードで12*12の144試合行っていますから、もっとも差の大きいところでは、黒が約90試合勝利したのに対し、白はわずか約50試合しか勝利していません。およそ2倍の差。

いろいろなデータを見てみたところ、以下のようになりました。

```py
import numpy as np

np_y = np.array(y)

print("最小値\t%d" % np_y.min())
print("中央値\t%d" % np.median(np_y))
print("最大値\t%d" % np_y.max())
print("平均\t%f" % np_y.mean())
print("分散\t%f" % np_y.var())
print("標準偏差\t%f" % np_y.std())
```

```
最小値	-32
中央値	3
最大値	42
平均	4.090000
分散	227.161900
標準偏差	15.071891
```

平均と中央値が0に近いので、一応全体としてはまあまあ公平といえるのではないでしょうか。
標準偏差15という数字ですが、グラフを見る限りではバラツキとして大きいように思います。

## まとめ
現行の方法で強いAIを作りたいなら、何か工夫が必要そう。
nLeastと組み合わせてもあまり強くはならないだろう。

# フルバージョン

https://github.com/TTaisei/osero/tree/main/combinationAI/49

# 次回は
次回やることはまだ決まっていません。
理由は、MyNetの高速化をしたいと考えているため、また、次の方針がまだ決まっていないためです。

[次回](https://qiita.com/tt_and_tk/items/54101f07855763fb4924)

https://qiita.com/tt_and_tk/items/068f2afde6db637e189f