Пример #1
0
    IEnumerator moveBlack(float Count)
    {
        yield return(new WaitForSeconds(Count));

        Othello ttt = new Othello(gameState);

        tn = new TreeNode(ttt);

        test();

        TreeNode BC    = tn.bestChild();
        int      index = BC.lastMove;
        int      col   = index / 8;
        int      row   = index % 8;

        if (gameState.Board[col, row] == 0 && gameState.CheckClosed(gameState.Board, col, row, false))
        {
            gameState.Board[col, row] = gameState.whoseMove();
        }

        if (gameState.whoseMove() == 1)
        {
            m_Buttons[index].image.color = Color.black;
        }
        else if (gameState.whoseMove() == 2)
        {
            m_Buttons[index].image.color = Color.white;
        }

        drawBoard(gameState);
        gameState.NextTurn();

        if (gameState.CanMove(gameState.Board) == false)
        {
            gameState.NextTurn();

            if (gameState.CanMove(gameState.Board) == false)
            {
                End();
            }
            else
            {
                StartCoroutine("moveBlack", bwaitTime);
            }
        }
        else
        {
            StartCoroutine("moveWhite", waitTime);
        }
        yield return(null);
    }
Пример #2
0
    public void Move(string buttonName)
    {
        int index = 0;

        for (int i = 0; i < m_Buttons.Length; i++)
        {
            if (m_Buttons[i].name.Equals(buttonName))
            {
                index = i;
                break;
            }
        }

        int col = index / 8;
        int row = index % 8;

        if (gameState.Board[col, row] == 0 && gameState.CheckClosed(gameState.Board, col, row, false))
        {
            gameState.Board[col, row] = gameState.player;
            if (gameState.player == 1)
            {
                m_Buttons[index].image.color = Color.black;
            }
            else if (gameState.player == 2)
            {
                m_Buttons[index].image.color = Color.white;
            }
            //StartCoroutine("ChangeCells", waitTime);
            drawBoard(gameState);
            gameState.NextTurn();
            if (gameState.CanMove(gameState.Board) == true)
            {
                StartCoroutine("moveBlack", bwaitTime);
            }
            else
            {
                gameState.NextTurn();
                if (gameState.CanMove(gameState.Board) == false)
                {
                    End();
                }
            }
        }
    }
Пример #3
0
    public double rollOut(TreeNode tn)
    {
        Othello   rollGS       = new Othello(tn.gameState);
        bool      stillPlaying = true;
        double    rc           = 0;
        int       moveIndex;
        ArrayList am = rollGS.availableMoves();

        while (am.Count > 0 && stillPlaying)
        {
            moveIndex = r.Next(0, am.Count);

            int move = (int)am[moveIndex];
            rollGS.makeMove(move);

            rollGS.NextTurn();

            if (rollGS.CanMove(rollGS.Board) == false)
            {
                rollGS.NextTurn();

                if (rollGS.CanMove(rollGS.Board) == false)
                {
                    stillPlaying = false;
                    int blackPoints = rollGS.CountPoints(rollGS.Board, 1);
                    int whitePoints = rollGS.CountPoints(rollGS.Board, 2);

                    if (blackPoints > whitePoints)
                    {
                        rc = 1.0;
                    }
                    else if (blackPoints <= whitePoints)
                    {
                        rc = 0.0;
                    }
                }
            }
            am = rollGS.availableMoves();
        }

        return(rc);
    }