using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
namespace QuShun
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int zuizongZhuheIndex = 0;
public string zhuhe;
public string zhuheAll;
public string yupaizhuheAll;
public string yupaiZhuhe;
List<int> Pailist = new List<int>();
private void button1_Click(object sender, EventArgs e)
{
Pailist.Add(51);
Pailist.Add(52);
Pailist.Add(53);
Pailist.Add(54);
Pailist.Add(55);
Pailist.Add(56);
Pailist.Add(57);
Pailist.Add(57);
Pailist.Add(58);
Pailist.Add(58);
Pailist.Add(59);
Pailist.Add(1000);
Pailist.Add(1000);
Pailist.Add(1000);
label1.Text += Pailist.Count.ToString() + ":";
//int Baidanum = 0;
for (int i = 0; i < Pailist.Count; i++)
{
label1.Text += Pailist[i] + ",";
}
zuizongZhuheIndex = 1;
zhuhe = "";
zhuheAll = "";
yupaizhuheAll = "";
yupaiZhuhe = "";
QuShun(Pailist);
//Pailist.Add(51);
//Pailist.Add(53);
//Pailist.Add(55);
//Pailist.Add(55);
//Pailist.Add(58);
//Pailist.Add(58);
//Pailist.Add(1000);
//int Baidanum = 0;
//for (int i = Pailist.Count - 1; i >= 0; i--)
//{
// if (Pailist[i] == 1000) { Baidanum++; Pailist.RemoveAt(i); }
//}
//yupaiZhuhe = "";
// yupaizhuheAll = "";
//PeiPai(Pailist, Baidanum);
}
void QuShun(List<int> _pailist)
{
string yupai = "";//输出用
_pailist.Sort();
List<int> Tlist = new List<int>(_pailist.ToArray());//复制副本
List<int> Vlist = new List<int>(_pailist.ToArray());//复制副本
//_pailist.ForEach(lx => Vlist.Add(lx));
for (int i = Vlist.Count - 1; i >= 0; i--)//去掉百搭
{
if (Vlist[i] == 1000) { Vlist.RemoveAt(i); }
}
for (int i = Vlist.Count - 1; i > 0; i--)//去重复,减少循环次数
{
if (Vlist[i].Equals(Vlist[i - 1])) { Vlist.RemoveAt(i); }
}
//string tmp = "";
//for (int i = 0; i < Vlist.Count; i++)
//{
// tmp += Vlist[i];
//}
List<string> foundzhuhe = new List<string>();
int maxshun = 0;
for (int i = 0; i < Vlist.Count; i++)
{
int TT = (int)Vlist[i];
if (Tlist.Contains(TT + 1) && Tlist.Contains(TT + 2) && TT < 60) //发现顺子;小于60指字牌和花牌不计顺
{
if (maxshun == 0 || (TT - maxshun) < 3)//优化递归
{
foundzhuhe.Add("S" + (TT).ToString());
maxshun = TT;
}
}
else if (Tlist.Count(x => x == TT) >= 3)//发现刻子
{
foundzhuhe.Add("K" + (TT).ToString());
}
}
if (foundzhuhe.Count == 0)//如果已经提取组合完毕
{
yupai = "";
for (int ii = 0; ii < Tlist.Count; ii++)//输出每一种组合后最终的余牌
{
yupai += Tlist[ii] + ",";
}
bool IsinzhuheAll = true;
string[] zhuheallSplit = zhuheAll.Split(new string[] { "(", ")(", ")" }, StringSplitOptions.RemoveEmptyEntries);
string[] zhuheSplit = zhuhe.Split(new string[] { "(", ")(", ")" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < zhuheSplit.Length; i++)
{
if (!zhuheallSplit.Contains(zhuheSplit[i]))
{
zhuheAll += "(" + zhuheSplit[i] + ")";
IsinzhuheAll = false;
}
}
if (IsinzhuheAll == false || zhuheAll.Count()==0)
{
// listBox1.Items.Add(zuizongZhuheIndex.ToString() + ":" + zhuhe);
// listBox2.Items.Add(zuizongZhuheIndex.ToString() + ":" + yupai );
yupaizhuheAll = "";
PeiPai(Tlist);
}
// PeiPai()
zuizongZhuheIndex++;
}
else//如果还有组合可以提取
{
for (int i = 0; i < foundzhuhe.Count; i++)
{
if (foundzhuhe[i].Substring(0, 1) == "K")
{
string k = foundzhuhe[i].Substring(1);
Tlist.Remove(int.Parse(k)); Tlist.Remove(int.Parse(k)); Tlist.Remove(int.Parse(k));
zhuhe += "(" + k + "," + k + "," + k + ")";
QuShun(Tlist);
zhuhe = zhuhe.Remove(zhuhe.LastIndexOf("("));
Tlist.Add(int.Parse(k)); Tlist.Add(int.Parse(k)); Tlist.Add(int.Parse(k));
Tlist.Sort();
}
else if (foundzhuhe[i].Substring(0, 1) == "S")
{
string s = foundzhuhe[i].Substring(1);
Tlist.Remove(int.Parse(s)); Tlist.Remove(int.Parse(s) + 1); Tlist.Remove(int.Parse(s) + 2);
zhuhe += "(" + int.Parse(s).ToString() + "," + (int.Parse(s) + 1).ToString() + "," + (int.Parse(s) + 2).ToString() + ")";
QuShun(Tlist);
zhuhe = zhuhe.Remove(zhuhe.LastIndexOf("("));
Tlist.Add(int.Parse(s)); Tlist.Add(int.Parse(s) + 1); Tlist.Add(int.Parse(s) + 2);
Tlist.Sort();
}
}
}
}
void PeiPai(List<int> _yupailist)
{
string ShengPai = "";
int Jiang = 0;
//if ((_yupailist.Count + _baidaNum) == 2) { return; }
List<string> foundzhuhe = new List<string>();
List<int> Tlist = new List<int>(_yupailist.ToArray());//复制副本
List<int> Vlist = new List<int>(_yupailist.ToArray());//复制副本
//_pailist.ForEach(lx => Vlist.Add(lx));
for (int i = Vlist.Count - 1; i>= 0; i--)//去掉百搭
{
if ( Vlist[i] == 1000) { Vlist.RemoveAt(i); }
}
for (int i = Vlist.Count - 1; i > 0; i--)//去重复,减少循环次数
{
if (Vlist[i].Equals(Vlist[i - 1])) { Vlist.RemoveAt(i); }
}
for (int i = 0; i < Vlist.Count; i++)
{
int TT = (int)Vlist[i];
if (Tlist.Count(x => x == TT) > 1)//发现对子
{
foundzhuhe.Add("D" + (TT).ToString());
}
if (Tlist.Contains(TT + 1))//发现相邻
{
foundzhuhe.Add("Z" + TT.ToString());
}
if (Tlist.Contains(TT + 2))//发现隔一
{
foundzhuhe.Add("z" + TT.ToString());
}
}
if (foundzhuhe.Count == 0)
{
ShengPai = "";
for (int ii = 0; ii < Tlist.Count; ii++)//输出每一种组合后最终的余牌
{
ShengPai += Tlist[ii] + ";";
}
bool IsinzhuheAll = true;
string[] zhuheallSplit = yupaizhuheAll.Split(new string[] { "(", ")(", ")" }, StringSplitOptions.RemoveEmptyEntries);
string[] zhuheSplit = yupaiZhuhe.Split(new string[] { "(", ")(", ")" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < zhuheSplit.Length; i++)
{
if (!zhuheallSplit.Contains(zhuheSplit[i]))
{
yupaizhuheAll += "(" + zhuheSplit[i] + ")";
IsinzhuheAll = false;
}
}
if (IsinzhuheAll == false || yupaizhuheAll =="")
{
listBox2.Items.Add(zuizongZhuheIndex.ToString() + ":" + yupaiZhuhe + ShengPai);
listBox1.Items.Add(zuizongZhuheIndex.ToString() + ":" + zhuhe);
}
}
else
{
for (int i = 0; i < foundzhuhe.Count; i++)
{
if (foundzhuhe[i].Substring(0, 1) == "D")
{
string D = foundzhuhe[i].Substring(1);
Tlist.Remove(int.Parse(D)); Tlist.Remove(int.Parse(D));
yupaiZhuhe += "(" + D + "," + D + ")";
PeiPai(Tlist);
yupaiZhuhe = yupaiZhuhe.Remove(yupaiZhuhe.LastIndexOf("("));
Tlist.Add(int.Parse(D)); Tlist.Add(int.Parse(D));
Tlist.Sort();
}
else if (foundzhuhe[i].Substring(0, 1) == "Z")
{
string Z = foundzhuhe[i].Substring(1);
Tlist.Remove(int.Parse(Z)); Tlist.Remove(int.Parse(Z) + 1);
yupaiZhuhe += "(" + int.Parse(Z).ToString() + "," + (int.Parse(Z) + 1).ToString() + ")";
PeiPai(Tlist);
yupaiZhuhe = yupaiZhuhe.Remove(yupaiZhuhe.LastIndexOf("("));
Tlist.Add(int.Parse(Z)); Tlist.Add(int.Parse(Z) + 1);
Tlist.Sort();
}
else if (foundzhuhe[i].Substring(0, 1) == "z")
{
string z = foundzhuhe[i].Substring(1);
Tlist.Remove(int.Parse(z)); Tlist.Remove(int.Parse(z) + 2);
yupaiZhuhe += "(" + int.Parse(z).ToString() + "," + (int.Parse(z) + 2).ToString() + ")";
PeiPai(Tlist);
yupaiZhuhe = yupaiZhuhe.Remove(yupaiZhuhe.LastIndexOf("("));
Tlist.Add(int.Parse(z)); Tlist.Add(int.Parse(z) + 2);
Tlist.Sort();
}
}
}
//if (Jiang == 0) { Jiang = Tlist[i]; }
//else { foundzhuhe.Add("K" + (TT).ToString()); }
}
int IsJiang(int _pai1, int _pai2)
{
if (_pai1 == _pai2 && _pai1 == 1000) { return 1000; }
if (_pai1 == _pai2 && _pai1 != 1000) { return _pai1; }
return 0;
}
}
}