using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ObjectModel.Tool
{
    /// <summary>
    /// 扑克牌的帮助类
    /// </summary>
    public class PukeTool
    {
        /// <summary>
        /// ID转换为牌
        /// </summary>
        /// <param name="id"></param>
        /// <param name="flower"></param>
        /// <param name="num"></param>
        public static void ConvertCard(int id, out int flower, out int num)
        {
            int temp = 0, tempint = 0;
            num = 0;
            flower = 0;
            temp = id % 54;
            if (temp == 0 || temp == 53)
            {
                flower = 5;
                num = temp == 0 ? 54 : 53;
            }
            else
            {
                tempint = temp % 13;
                if (tempint == 0)
                {
                    flower = temp / 13;
                    num = 13;
                }
                else
                {
                    flower = temp / 13 + 1;
                    num = tempint;
                }
            }
        }

        /// <summary>
        /// 打乱数组顺序
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="array"></param>
        public static void ShuffleArray<T>(ref T[] array, Random random)
        {
            int n = array.Length;
            int total = array.Length;
            while (n > 0)
            {
                n--;
                int k = random.Next(total);
                (array[k], array[n]) = (array[n], array[k]);
            }
        }
    }
}
