---
# System prepended metadata

title: 2021.10.29（金）④⑤
tags: [授業ノート, AN25]

---

# 2021.10.29（金）④⑤
###### tags: `AN25` `授業ノート`

ミニマックス法
最もリスクのある損害が最小になるように選択する
コンピュータ(後攻×)が次にどこに置くべきかを決定する

優先順位
1.次の一手で勝つ場所に置く
2.相手(人間〇)が勝つのを防ぐ
3.中央に置く
4.角に置く
5.それ以外に置く

優先順位1
基点
>0:(1,2)(3,6)(4,8)
1:(0,2)(4,7)
2:(0,1)(5,8)(4,6)
3:(0,6)(4,5)
4:(0,8)(1,7)(2,6)(3,5)
5:(2,8)(3,4)
6:(0,3)(2,4)(7,8)
7:(1,4)(6,8)
8:(2,5)(6,7)

例えば0が×(コンピュータ)で1が×なら2に置けば勝ち
(→8までの全パターン考える)
すべて該当しなければ×を〇へ置き換えて考える
例えば0が〇(人間)で1が〇なら2において人間の勝ちを防ぐ
(→8までの全パターン考える)
優先順位3,4へ


```java=
  
    private void computerMethod(){
        if(button_flag[0] == 1){
            if (button_flag[1] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 1){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 1){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[1] == 1){
            if (button_flag[0] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[7] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[2] == 1){
            if (button_flag[0] == 1){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[1] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 1){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[3] == 1){
            if (button_flag[0] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[4] == 1){
            if (button_flag[0] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[1] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[7] == 1){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 1){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 1){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[5] == 1){
            if (button_flag[2] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[6] == 1){
            if(button_flag[0] == 1){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[3] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[2] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[4] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[7] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[8] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[7] == 1){
            if(button_flag[1] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[4] ==1){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[6] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[8] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[8] == 1){
            if(button_flag[2] == 1){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[5] == 2){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[6] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[7] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }

        }
    }


private void defenceMethod(){
        if(button_flag[0] == 0){
            if (button_flag[1] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 0){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 0){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[1] == 1){
            if (button_flag[0] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[7] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[2] == 0){
            if (button_flag[0] == 0){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[1] == 0){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 0){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[3] == 0){
            if (button_flag[0] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 0){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 0){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[4] == 0){
            if (button_flag[0] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 0){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[1] == 0){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[7] == 0){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 0){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 0){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[5] == 0){
            if (button_flag[2] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 0){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[6] == 0){
            if(button_flag[0] == 0){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[3] == 0){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[2] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[4] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[7] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[8] == 0){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[7] == 0){
            if(button_flag[1] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[4] ==0){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[6] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[8] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[8] == 0){
            if(button_flag[2] == 0){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[5] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[6] == 0){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[7] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }

        }
    }


```




### kawamura's fuck'n dirty code
```java=
package nhs00650.hal.ac.oxgame;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {
    private ImageButton[] rectButtons = new ImageButton[9];
    private boolean senkou = true;
    private int[] button_flag = {9,9,9,9,9,9,9,9,9};
    int count = 0;
    int dame = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        rectButtons[0] = (ImageButton)findViewById(R.id.left_top);
        rectButtons[1] = (ImageButton)findViewById(R.id.top);
        rectButtons[2] = (ImageButton)findViewById(R.id.right_top);
        rectButtons[3] = (ImageButton)findViewById(R.id.left);
        rectButtons[4] = (ImageButton)findViewById(R.id.center);
        rectButtons[5] = (ImageButton)findViewById(R.id.right);
        rectButtons[6] = (ImageButton)findViewById(R.id.left_bottom);
        rectButtons[7] = (ImageButton)findViewById(R.id.bottom);
        rectButtons[8] = (ImageButton)findViewById(R.id.right_bottom);

        resetGame();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        menu.add(0,0,0,"リトライ");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);
        int itemid = item.getItemId();
        if(itemid == 0){
            resetGameall();
        }
        return true;
    }

    private void resetGame(){
        for(int i = 0; i < 9; i++){
            rectButtons[i].setBackgroundResource(R.drawable.none);
        }
        senkou = true;
    }

    private void resetGameall(){
        for(int i = 0; i < 9; i++){
            rectButtons[i].setBackgroundResource(R.drawable.none);
        }
        for(int j = 0; j < 9; j++){
            button_flag[j] = 9;
        }
        senkou = true;
        count = 0;
    }

    public void buttonMethod(View OXButton){
        ImageButton aImageButton = (ImageButton)OXButton;
        switch (OXButton.getId()) {
            case R.id.left_top:
                if (button_flag[0] == 9) {
                    if (senkou) {
                        aImageButton.setBackgroundResource(R.drawable.maru);
                        senkou = false;
                        button_flag[0] = 0;
                        count++;
                        judgeMethod();
                        drawMethod();
                        defenceMethod();
                        centerMethod();
                        break;
                    } else {
                        aImageButton.setBackgroundResource(R.drawable.batu);
                        senkou = true;
                        button_flag[0] = 1;
                        count++;
                        judgeMethod();
                        drawMethod();
                        computerMethod();
                        break;
                    }
                }
            case R.id.top:
                if (button_flag[1] == 9){
                    if (senkou) {
                        aImageButton.setBackgroundResource(R.drawable.maru);
                        senkou = false;
                        button_flag[1] = 0;
                        count++;
                        judgeMethod();
                        drawMethod();
                        defenceMethod();
                        centerMethod();
                        break;
                    } else {
                        aImageButton.setBackgroundResource(R.drawable.batu);
                        senkou = true;
                        button_flag[1] = 1;
                        count++;
                        judgeMethod();
                        drawMethod();
                        break;
                    }
                }
            case R.id.right_top:
                if(button_flag[2] == 9) {
                    if (senkou) {
                        aImageButton.setBackgroundResource(R.drawable.maru);
                        senkou = false;
                        button_flag[2] = 0;
                        count++;
                        judgeMethod();
                        drawMethod();
                        defenceMethod();
                        centerMethod();
                        break;
                    } else {
                        aImageButton.setBackgroundResource(R.drawable.batu);
                        senkou = true;
                        button_flag[2] = 1;
                        count++;
                        judgeMethod();
                        drawMethod();
                        computerMethod();
                        break;
                    }
                }
            case R.id.left:
                if(button_flag[3] == 9) {
                    if (senkou) {
                        aImageButton.setBackgroundResource(R.drawable.maru);
                        senkou = false;
                        button_flag[3] = 0;
                        count++;
                        judgeMethod();
                        drawMethod();
                        defenceMethod();
                        centerMethod();
                        break;
                    } else {
                        aImageButton.setBackgroundResource(R.drawable.batu);
                        senkou = true;
                        button_flag[3] = 1;
                        count++;
                        judgeMethod();
                        drawMethod();
                        computerMethod();
                        break;
                    }
                }
            case R.id.center:
                if(button_flag[4] == 9) {
                    if (senkou) {
                        aImageButton.setBackgroundResource(R.drawable.maru);
                        senkou = false;
                        button_flag[4] = 0;
                        count++;
                        judgeMethod();
                        drawMethod();
                        defenceMethod();
                        centerMethod();
                        break;
                    } else {
                        aImageButton.setBackgroundResource(R.drawable.batu);
                        senkou = true;
                        button_flag[4] = 1;
                        count++;
                        judgeMethod();
                        drawMethod();
                        computerMethod();
                        break;
                    }
                }
            case R.id.right:
                if(button_flag[5] == 9) {
                    if (senkou) {
                        aImageButton.setBackgroundResource(R.drawable.maru);
                        senkou = false;
                        button_flag[5] = 0;
                        count++;
                        judgeMethod();
                        drawMethod();
                        defenceMethod();
                        centerMethod();
                        break;
                    } else {
                        aImageButton.setBackgroundResource(R.drawable.batu);
                        senkou = true;
                        button_flag[5] = 1;
                        count++;
                        judgeMethod();
                        drawMethod();
                        computerMethod();
                        break;
                    }
                }
            case R.id.left_bottom:
                if(button_flag[6] == 9) {
                    if (senkou) {
                        aImageButton.setBackgroundResource(R.drawable.maru);
                        senkou = false;
                        button_flag[6] = 0;
                        count++;
                        judgeMethod();
                        drawMethod();
                        computerMethod();
                        defenceMethod();
                        centerMethod();
                        break;
                    } else {
                        aImageButton.setBackgroundResource(R.drawable.batu);
                        senkou = true;
                        button_flag[6] = 1;
                        count++;
                        judgeMethod();
                        drawMethod();
                        computerMethod();
                        break;
                    }
                }
            case R.id.bottom:
                if(button_flag[7] == 9) {
                    if (senkou) {
                        aImageButton.setBackgroundResource(R.drawable.maru);
                        senkou = false;
                        button_flag[7] = 0;
                        count++;
                        judgeMethod();
                        drawMethod();
                        defenceMethod();
                        centerMethod();
                        break;
                    } else {
                        aImageButton.setBackgroundResource(R.drawable.batu);
                        senkou = true;
                        button_flag[7] = 1;
                        count++;
                        judgeMethod();
                        drawMethod();
                        computerMethod();
                        break;
                    }
                }
            case R.id.right_bottom:
                if(button_flag[8] == 9) {
                    if (senkou) {
                        aImageButton.setBackgroundResource(R.drawable.maru);
                        senkou = false;
                        button_flag[8] = 0;
                        count++;
                        judgeMethod();
                        drawMethod();
                        defenceMethod();
                        centerMethod();
                        break;
                    } else {
                        aImageButton.setBackgroundResource(R.drawable.batu);
                        senkou = true;
                        button_flag[8] = 1;
                        count++;
                        judgeMethod();
                        drawMethod();
                        computerMethod();
                        break;
                    }
                }
            }
        }

        public void judgeMethod(){
            if(button_flag[0] == 0 && button_flag[1] == 0 && button_flag[2] == 0){
                otoastMethod();
                count = 0;
                drawMethod();
            }else if(button_flag[3] == 0 && button_flag[4] == 0 && button_flag[5] == 0){
                otoastMethod();
                count = 0;
                drawMethod();
            }else if(button_flag[6] == 0 && button_flag[7] == 0 && button_flag[8] == 0){
                otoastMethod();
                count = 0;
                drawMethod();
            }else if(button_flag[0] == 0 && button_flag[3] == 0 && button_flag[6] == 0) {
                otoastMethod();
                count = 0;
                drawMethod();
            }else if(button_flag[1] == 0 && button_flag[4] == 0 && button_flag[7] == 0){
                otoastMethod();
                count = 0;
                drawMethod();
            }else if(button_flag[2] == 0 && button_flag[5] == 0 && button_flag[8] == 0){
                otoastMethod();
                count = 0;
                drawMethod();
            }else if(button_flag[0] == 0 && button_flag[4] == 0 && button_flag[8] == 0){
                otoastMethod();
                count = 0;
                drawMethod();
            }else if(button_flag[2] == 0 && button_flag[4] == 0 && button_flag[6] == 0) {
                otoastMethod();
                count = 0;
                drawMethod();
            }else if(button_flag[0] == 1 && button_flag[1] == 1 && button_flag[2] == 1){
                    xtoastMethod();
                    count = 0;
                    drawMethod();
                }else if(button_flag[3] == 1 && button_flag[4] == 1 && button_flag[5] == 1){
                    xtoastMethod();
                    count = 0;
                    drawMethod();
                }else if(button_flag[6] == 1 && button_flag[7] == 1 && button_flag[8] == 1){
                    xtoastMethod();
                    count = 0;
                    drawMethod();
                }else if(button_flag[0] == 1 && button_flag[3] == 1 && button_flag[6] == 1) {
                    xtoastMethod();
                    count = 0;
                    drawMethod();
                }else if(button_flag[1] == 1 && button_flag[4] == 1 && button_flag[7] == 1){
                    xtoastMethod();
                    count = 0;
                    drawMethod();
                }else if(button_flag[2] == 1 && button_flag[5] == 1 && button_flag[8] == 1){
                    xtoastMethod();
                    count = 0;
                    drawMethod();
                }else if(button_flag[0] == 1 && button_flag[4] == 1 && button_flag[8] == 1){
                    xtoastMethod();
                    count = 0;
                    drawMethod();
                }else if(button_flag[2] == 1 && button_flag[4] == 1 && button_flag[6] == 1) {
                    xtoastMethod();
                    count = 0;
                    drawMethod();
                }
        }

        public void otoastMethod() {
            Toast myToast = Toast.makeText(this,
                    "O's win", Toast.LENGTH_LONG);
            myToast.show();
            for(int i = 0; i < 9; i++){
                button_flag[i] = 6;
            }
        }

        public void xtoastMethod() {
            Toast myToast = Toast.makeText(this,
                    "X's win", Toast.LENGTH_LONG);
            myToast.show();
            for(int i = 0; i < 9; i++){
                button_flag[i] = 6;
            }
        }

        public void drawMethod() {
            if(count == 9){
                Toast myToast = Toast.makeText(this,
                        "Draw", Toast.LENGTH_LONG);
                myToast.show();
            }
        }

    private void computerMethod(){
        if(button_flag[0] == 1){
            if (button_flag[1] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 1){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 1){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[1] == 1){
            if (button_flag[0] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[7] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[2] == 1){
            if (button_flag[0] == 1){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[1] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 1){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[3] == 1){
            if (button_flag[0] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[4] == 1){
            if (button_flag[0] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[1] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[7] == 1){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 1){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 1){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[5] == 1){
            if (button_flag[2] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[6] == 1){
            if(button_flag[0] == 1){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[3] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[2] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[4] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[7] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[8] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[7] == 1){
            if(button_flag[1] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[4] ==1){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[6] == 1){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[8] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[8] == 1){
            if(button_flag[2] == 1){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[5] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[6] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[7] == 1){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }

        }
    }

    private void defenceMethod(){
        if(button_flag[0] == 0){
            if (button_flag[1] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 0){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 0){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[1] == 1){
            if (button_flag[0] == 1){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 1){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 1){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[7] == 1){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[2] == 0){
            if (button_flag[0] == 0){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[1] == 0){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 0){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[3] == 0){
            if (button_flag[0] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 0){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 0){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[4] == 0){
            if (button_flag[0] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 0){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[1] == 0){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[7] == 0){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[2] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[6] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 0){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[5] == 0){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[5] == 0){
            if (button_flag[2] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[8] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[3] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else  if (button_flag[4] == 0){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[6] == 0){
            if(button_flag[0] == 0){
                button_flag[3] = 1;
                rectButtons[3].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[3] == 0){
                button_flag[0] = 1;
                rectButtons[0].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[2] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[4] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[7] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[8] == 0){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[7] == 0){
            if(button_flag[1] == 0){
                button_flag[4] = 1;
                rectButtons[4].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[4] ==0){
                button_flag[1] = 1;
                rectButtons[1].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[6] == 0){
                button_flag[8] = 1;
                rectButtons[8].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[8] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);
            }
        }
        else if(button_flag[8] == 0){
            if(button_flag[2] == 0){
                button_flag[5] = 1;
                rectButtons[5].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[5] == 0){
                button_flag[2] = 1;
                rectButtons[2].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[6] == 0){
                button_flag[7] = 1;
                rectButtons[7].setBackgroundResource(R.drawable.batu);
            }
            else if(button_flag[7] == 0){
                button_flag[6] = 1;
                rectButtons[6].setBackgroundResource(R.drawable.batu);

            }
        }
    }

    private void centerMethod(){
        if(button_flag[4] == 9){
            button_flag[4] = 1;
            rectButtons[4].setBackgroundResource(R.drawable.batu);
            senkou = true;
        }else if(button_flag[0] == 9){
            button_flag[0] = 1;
            rectButtons[0].setBackgroundResource(R.drawable.batu);
            senkou = true;
        }
        else if(button_flag[2] == 9){
            button_flag[2] = 1;
            rectButtons[2].setBackgroundResource(R.drawable.batu);
            senkou = true;
        }else if(button_flag[6] == 9){
            button_flag[6] = 1;
            rectButtons[6].setBackgroundResource(R.drawable.batu);
            senkou = true;
        }else if(button_flag[8] == 9){
            button_flag[8] = 1;
            rectButtons[8].setBackgroundResource(R.drawable.batu);
            senkou = true;
        }
    }
}


```
## 雑談 (0→やまぴ 1→みや 2→やすい 3→りょうくん 4→アミカ 5→やの 6→山田)
---
<span style="color: #ff3333">aaa</span>
<span style="text-decoration: underline">aaa</span>