示例#1
0
    private void MakeAIMove(int player)
    {
        bool moved = false;

        // pick a random search start position
        int rx = Random.Range(0, GameBoard.LENGTH_X - 1);
        int ry = Random.Range(0, GameBoard.LENGTH_Y - 1);

        // from (rx,ry) search of an available move
        for (int i = 0; i < GameBoard.LENGTH_X && !moved; i++)
        {
            for (int j = 0; j < GameBoard.LENGTH_Y && !moved; j++)
            {
                int x = (rx + i) % GameBoard.LENGTH_X;
                int y = (ry + j) % GameBoard.LENGTH_Y;

                // first try to place a piece on the current position
                if (m_board.CanPlayerMoveToPostion(x, y))
                {
                    GamePiece p = Random.Range(0, 2) == 0 ? m_pieceA : m_pieceB;
                    m_board.AddPiece(player, p.Prefab, x, y);
                    moved = true;
                }
                // a random percentage of the time, try to powerup this position
                else if (m_board.CanPlayerPowerUpPosition(x, y) && Random.Range(0, 8) < 2)
                {
                    m_board.AddPowerPiece(player, m_powerPiece.Prefab, x, y);
                    moved = true;
                }
            }
        }

        if (moved)
        {
            UpdateScores();
            TransitionToNextState();
        }
    }