Example #1
0
    /*PutDisk(void):ターン中処理(盤面の更新、再描画、次のターンに向けた処理)
     * 引数:int[,]boarddata,int turn(手番),int[] index(石を置く位置)
     * 返り値:なし*/
    void PutDisk(int[,] boarddata, int turn_tmp, int[] index)
    {
        ReversiScript rs = Camera.main.GetComponent <ReversiScript>();

        Debug.Log(turn_tmp);
        Debug.Log(index[0] + "," + index[1]);
        //そこに石が置けるか
        if (rs.IsPuttable(boarddata, turn_tmp, new Vector2(index[0], index[1])))
        {
            //盤面の色を戻す
            ChangeColorofPlanestoGreen();
            //石を置いて盤面データを更新
            board = rs.flip(boarddata, turn_tmp, new Vector2(index[0], index[1]));
            //盤面を再描画
            ClearBoard();
            PutDisksfromMatrix(board);
            //次の手番に向けた処理
            //終了判定
            turn = turn * (-1);
            if (rs.IsEnd(board, turn_tmp * (-1)))
            {
                //今石を置いてゲームが終わるとき
                GameEnd(board);
            }
            else
            {
                //ゲームが続くとき
                //置ける場所の色を変える
                ChangeColorofPuttablePlace(board, turn_tmp * (-1));
            }
        }
    }
Example #2
0
    /*ChangeColorofPuttablePlace(void):ある手番で石を置ける場所の盤面の色を変える
     * 引数:int[,]boarddata(盤面),int turn(手番)
     * 返り値:なし*/
    void ChangeColorofPuttablePlace(int[,] boarddata, int turn)
    {
        //石を置ける場所のリストを取得
        ReversiScript  rs           = Camera.main.GetComponent <ReversiScript>();
        List <Vector2> puttablelist = rs.FindPuttablePlace(boarddata, turn);

        //リストから要素を取り出し1箇所ずつ色を変える
        foreach (Vector2 place in puttablelist)
        {
            Planes[(int)place.x, (int)place.y].GetComponent <Renderer>().material.color = new Color(0, 1, 0.87f);
        }
    }
Example #3
0
    List <Vector2> bestplaces = new List <Vector2>(); //深さごとの最善手を入れるリスト

    public int Alphabeta(int[,] boarddata, int tmpturn, int comturn, int depth, int alpha, int beta)
    {
        //今の局面で選択できる手を求める
        ReversiScript  rs           = Camera.main.GetComponent <ReversiScript>();
        List <Vector2> puttablelist = rs.FindPuttablePlace(boarddata, tmpturn);

        //終端ノード(打てる手がない)or充分な深さで打ち切り
        if (puttablelist.Count() == 0 || depth == 0)
        {
            return(evaluation(boarddata, tmpturn));
        }

        if (tmpturn == comturn)
        {
            //ノードが自分のターンの時
            foreach (Vector2 place in puttablelist)
            {
                //置いた後の盤面を生成
                int[,] newboard = rs.flip(boarddata, tmpturn, place);
                //子ノードの評価値を求める
                int point = Alphabeta(newboard, tmpturn * (-1), comturn, depth - 1, alpha, beta);
                if (point > alpha)
                {
                    //評価値がalphaを上回るときは手とalphaを更新
                    Vector2 tmpvector = place;
                    bestplaces[depth - 1] = tmpvector;
                    alpha = point;
                }
                else
                {
                    //alphaカット
                    break;
                }
            }
            return(alpha);
        }
        else
        {
            //ノードが相手のターンの時
            foreach (Vector2 place in puttablelist)
            {
                //石を置いた後の盤面を生成
                int[,] newboard = rs.flip(boarddata, tmpturn, place);
                //子ノードの評価値を求める
                int point = Alphabeta(newboard, tmpturn * (-1), comturn, depth - 1, alpha, beta);
                if (point < beta)
                {
                    //評価値がbetaを下回るときは手とbetaを更新
                    Vector2 tmpvector = place;

                    bestplaces[depth - 1] = tmpvector;
                    beta = point;
                }
                else
                {
                    //betaカット
                    break;
                }
            }
            return(beta);
        }
    }