怎么从自己的手牌中寻找比另一副牌大的几连对
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么从自己的手牌中寻找比另一副牌大的几连对相关的知识,希望对你有一定的参考价值。
//调试用的数组--自己的牌
int[] array = new int[24]{//306
215,307,308,309,310,311,312,313,314,
415,405, 407, 409,410,411,412,413,414,
315, 207,208,
106,107, 109,
};
/*
int[] array = new int[24]{ 415,315,414,314,413,313,412,312,411,311,410,310,409,309
109,308,208,407, 307,207, 107,306,106,405
};*/
/*
int[] array = new int[24]{ 415,315,215,414,314,413,313,412,312,411,311,410,310,409,309
109,308,208,407, 307,207, 107,106,405
};*/
//调试用的数组--上家的牌
int[] array_less = new int[12]{
106,206,207,307,108,308,209,409,110,410,111,211
};
public int mxNum;
public int FinNum;
int k = 0;
void Start(){
//排序
for (int i = 0; i < array.Length; i++)
{
for (int j = i + 1; j < array.Length; j++)
{
if (array[j] % 100 > array[i] % 100)
{
mxNum = array[j];
array[j] = array[i];
array[i] = mxNum;
}
if (array[j] % 100 == array[i] % 100)
{
if (array[j] > array[i])
{
FinNum = array[j];
array[j] = array[i];
array[i] = FinNum;
}
}
}
}
/* for (int i = 0; i < array.Length; i++)
{
print("---" + array[i]);
}*/
List<int> list = new List<int>();
//判断有几组对子
k = array_less.Length / 2;
print("k:>>>" + k);
//对对子进行排序
for (int i = 0; i < array_less.Length;i++ )
{
for (int j = i + 1; j < array_less.Length; j++)
{
if (array_less[j] % 100 > array_less[i] % 100)
{
mxNum = array_less[j];
array_less[j] = array_less[i];
array_less[i] = mxNum;
}
if (array_less[j] % 100 == array_less[i] % 100)
{
if (array_less[j] > array_less[i])
{
FinNum = array_less[j];
array_less[j] = array_less[i];
array_less[i] = FinNum;
}
}
}
}
/* for (int i = 0; i < array_less.Length; i++)
{
print(">>>>----" + array_less[i]);
}*/
/* list.Add(k);
for (int i = 0; i<list.Count; i++)
{
print("---" + list[i]);
}*/
//记录上一个数和出现的次数 存入list
int lastValue = 0;
int lastNum = 0;
for (int n = 0; n < array.Length-1; n++)
{
if (n == 0)
{
lastValue = array[n];
lastNum = 1;
}
else if (lastValue%100 == array[n]%100)
{
list.Add(lastValue);
lastNum++;
n++;
lastValue = array[n];
continue;
//print("else if n=" + n);
//print("lastvalue=" + lastValue);
//print("lastnum=" + lastNum);
}
else
{
lastValue = array[n];
lastNum = 1;
print("else=" + n);
}
}
//遍历list并输出
for (int i = 0; i < list.Count; i++)
{
print(">>>>---->>>>" + list[i]);
}
//比较是否存在对子并判断有几连队,是否大于上家
int pairsNum = 0;
for (int i = 0; i < list.Count-1; i++)
{
int a = list[i] % 100;
int b = list[i+1] % 100+1;
if (a == b)
{
pairsNum++;
print("pairsNum=" + pairsNum);
}else if(a != b){
pairsNum = 0;
}
if (pairsNum >= k && (list[0]%100 - array_less[0]%100 > 0))
{
print("存在大于上家的牌!");
break;
}
else
{
print("不存在大于上家的牌!");
}
}
}
以上是关于怎么从自己的手牌中寻找比另一副牌大的几连对的主要内容,如果未能解决你的问题,请参考以下文章
设计一个randomValue值的比较器,生成一副牌后用此比较器洗牌,然后输出洗好的整副牌。