最近在做地方棋牌游戏,发现有的地方棋牌玩法很独特,比如吉林的过蛋玩法 。先贴出代码,后面在做介绍。算法可鞥不是最优解,欢迎大神拍砖,交流QQ:850912758。

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
/// <summary>
/// 判断  过蛋/补蛋  牌逻辑 类
/// 输入:手牌中的蛋牌
/// 输出:可过蛋牌的 所有 排列组合
/// 方法:
///           1. 无 混 :
///                      所有蛋牌排列组合
///           2.有混:
///           2.1.一张混牌所有排列组合
///           2.2 两张混牌所有排列组合
/// </summary>
public class EggCtro
{private static EggCtro _instance = null;List<int> InputEggCard;//输入的手牌private List<List<int>> OutPutEggs = new List<List<int>>();//输出的的过蛋牌 private List<List<int>> CurEggCardList ;//当前碰牌区 的蛋牌列表 private List<int> AddEggCardList = new List<int>();//补蛋  单张蛋牌集合 (输出的补蛋集合)int CardHun = 11;//混牌//标准蛋牌 int[] Egg1 = { 1, 11, 21 };int[] Egg2 = { 9, 19, 29 };int[] Egg3 = { 35, 36, 37 };int[] Egg4 = { 31, 32, 33, 34 };List<int[]> AllEggs = new List<int[]>();//标准蛋牌public static EggCtro Instance{get{if (_instance == null)_instance = new EggCtro();return _instance;}}#region 过蛋void InIt(){AllEggs.Clear();AllEggs.Add(Egg1);AllEggs.Add(Egg2);AllEggs.Add(Egg3);AllEggs.Add(Egg4);}/// <summary>/// 获取可过蛋牌列表/// </summary>/// <param name="handCards"></param>/// <returns></returns>public List<List<int>> GetEggCardValues(List<int> handCards){OutPutEggs.Clear();InputEggCard = handCards;InIt();NoHunEgg();//手牌 中的蛋牌 分类List<int> CurYaoEggCard = new List<int>();List<int> CurJiuEggCard = new List<int>();List<int> CurZFBEggCard = new List<int>();List<int> CurFengEggCard = new List<int>();if (IsHandHunCard()){int hunCount = GetHunCount();RemoveHunCard();DistinctCard();//找出当前手牌 每种蛋牌类型的 一张混牌组合foreach (int item in InputEggCard){if (item == 1||item == 21) { CurYaoEggCard.Add(item); }else if (item == 9 || item == 19 || item == 29) { CurJiuEggCard.Add(item); }else if (item == 31 || item == 32 || item == 33 || item == 34) { CurZFBEggCard.Add(item); }else if (item >= 35 || item == 36 || item == 37) { CurFengEggCard.Add(item); }}if (hunCount == 1){//一个混 //蛋牌组 大于两张 ,才可以配合一张混牌组成蛋牌 AddOutPutThree(CurYaoEggCard);AddOutPutThree(CurJiuEggCard);AddOutPutThree(CurZFBEggCard);AddOutPutThree(CurFengEggCard); //风牌 四张不同牌 时的多种 排列组合}else if (hunCount >= 2){//一个混 //蛋牌组 大于两张 ,才可以配合一张混牌组成蛋牌 AddOutPutThree(CurYaoEggCard);AddOutPutThree(CurJiuEggCard);AddOutPutThree(CurZFBEggCard);AddOutPutThree(CurFengEggCard); //风牌 四张不同牌 时的多种 排列组合//两个混  //可以跟每一张蛋牌组合 成蛋AddEggCard(CurYaoEggCard);AddEggCard(CurJiuEggCard);AddEggCard(CurZFBEggCard);AddEggCard(CurFengEggCard);}}return OutPutEggs;//ShowLog();}// 两混 添加提示 蛋牌 列表private void AddEggCard(List<int> CurYaoEggCard){foreach (int item in CurYaoEggCard){if (item == CardHun)//不能三个幺鸡continue;List<int> tempEgg = new List<int>();tempEgg.Add(item);tempEgg.Add(CardHun);tempEgg.Add(CardHun);OutPutEggs.Add(tempEgg);}}//一个混 三张 牌加入private void AddOutPutThree(List<int> HandEggCards){if (HandEggCards.Count == 2)//两张牌 直接+混{HandEggCards.Add(CardHun);OutPutEggs.Add(HandEggCards);}else if (HandEggCards.Count >= 3){List<int[]> tempEggList = Arrage(HandEggCards, 2); //三选二 排列 / 四选二 排列组合foreach (int[] item in tempEggList){List<int> egg = item.ToList();egg.Add(CardHun);OutPutEggs.Add(egg);}}}//无混 排列组合public void NoHunEgg(){InputEggCard.Sort();//包含标准 蛋牌foreach (int[] egg in AllEggs){List<int> same = ExistsEggType(egg);int sameCount = same.Count;if (sameCount == 3){OutPutEggs.Add(same);}else if (sameCount == 4){//完整风牌List<int[]> fengEgg = Arrage(same.ToList<int>(), 3);//4 选3 排列组合foreach (int[] item in fengEgg){OutPutEggs.Add(item.ToList<int>());}}}}void ShowLog(){string str = "";foreach (List<int> item in OutPutEggs){str += " 【";foreach (int card in item){str += card + " ";}str += " 】";}Debug.Log("输出蛋牌为:" + str + "             " + OutPutEggs.Count);}/// <summary>/// 是否包含标准蛋牌(风牌 三张组合例外)/// </summary>/// <param name="egg">标准蛋牌</param>List<int> ExistsEggType(int[] egg){int eggCount = 0;List<int> tempEgg = new List<int>();for (int i = 0; i < egg.Length; i++){if (InputEggCard.Exists(o => o == egg[i])){eggCount++;tempEgg.Add(egg[i]);}}return tempEgg;}/// <summary>/// 手牌中是否包含混牌/// </summary>/// <returns></returns>bool IsHandHunCard(){return InputEggCard.Exists(o => o == CardHun);}//混牌数量int GetHunCount(){return InputEggCard.Count(delegate (int item) { return item == CardHun; });}//移除混牌 的手牌列表void RemoveHunCard(){int count = GetHunCount();for (int i = 0; i < count; i++){InputEggCard.Remove(CardHun);}}//去除重复牌void DistinctCard(){List<int> result = InputEggCard.Distinct().ToList();//去重复}//M选N 排列组合List<int[]> Arrage(List<int> input, int _n){//排列算法List<int> inputValue = input;int n = _n;var result = inputValue.Select(x => new int[] { x });for (int i = 0; i < n - 1; i++){result = result.SelectMany(x => inputValue.Where(y => y.CompareTo(x.First()) < 0).Select(y => new int[] { y }.Concat(x).ToArray()));}List<int[]> resultList = new List<int[]>();foreach (int[] item in result){resultList.Add(item);}return resultList;}#endregion#region 补蛋/// <summary>///  找出手牌中可以补蛋的牌!/// </summary>/// <param name="curHandCards">当前手中蛋牌</param>/// <param name="yetEggs">已过蛋牌</param>public List<int> AddEgg(List<int> curHandCards,List<List<int>> yetEggs){CurEggCardList = yetEggs;InputEggCard = curHandCards;if (CurEggCardList.Count == 0){return null;}if (InputEggCard.Count == 0) {return null;}AddEggCardList.Clear();////先判断蛋牌区 无 混牌情况 //再判断蛋牌区 有 混牌情况 //如果是 替换 幺鸡 的蛋牌 ,需要将幺鸡替换掉 并 加到头像下 +1foreach (int handCard in InputEggCard){if (handCard == CardHun){AddEggCardList.Add(handCard);//幺鸡 直接加入continue;}}//无混 蛋牌foreach (List<int> egg in CurEggCardList){foreach (int card in egg){int[] eggValue = GetEggType(card);foreach (int handCard in InputEggCard){foreach (int eggCard in eggValue){if (eggCard == handCard && eggCard != CardHun)AddEggCardList.Add(handCard);//手牌 里有已过蛋牌值 }}break;}}//有混 蛋牌List<int[]> hunEggs = GetHunEggValue();foreach (int[] hunEgg in hunEggs){List<int> insteadValue = GetHunEggInstead(hunEgg);List<int> handEggValue = InputEggCard.Intersect(insteadValue).ToList();//手牌里是否有被混取代的牌值if (handEggValue.Count > 0)AddEggCardList.AddRange(handEggValue);//得到 被混 取代的蛋牌值}string eggStr = "";foreach (int item in AddEggCardList){eggStr += "     " + item.ToString();}Debug.LogError("可补蛋的牌:" + eggStr);return AddEggCardList;}/// <summary>/// 获取牌所属蛋牌型/// </summary>/// <param name="cardValue">牌值</param>/// <returns></returns>public int[] GetEggType(int cardValue){int[] Eggs = null;foreach (int[] eggs in AllEggs){foreach (int card in eggs){if (cardValue == card){Eggs = eggs;}}}return Eggs;}/// <summary>/// //获取hun 蛋牌 中被混牌取代的值/// </summary>/// <param name="egg">含混蛋</param>/// <returns></returns>List<int> GetHunEggInstead(int[] egg){List<int> tempValues = new List<int>();tempValues.Clear();List<int> NoHunValue = GetNoHunValue(egg);//获得 含混蛋牌中 不是混的 牌值 int cardValue = NoHunValue[0];//根据这个牌值 判断 所属 蛋牌类型 int[] typeEgg = GetEggType(cardValue);//获得 该蛋牌的 标准值 List<int> typeEggList = typeEgg.ToList();//和标准蛋牌比较,得出混牌代替的牌值 tempValues = typeEggList.Except(NoHunValue).ToList();//除什么之外?     Except  差集       Intersect交集      Union并集return tempValues;}/// <summary>/// 获取含混蛋牌 中的 非混牌值/// </summary>/// <returns>含混牌的 蛋</returns>List<int> GetNoHunValue(int[] hunEgg){List<int> values = new List<int>();values.Clear();foreach (int eggCard in hunEgg){if (eggCard != CardHun){values.Add(eggCard);}}return values;}//获取包含 混牌 的蛋List<int[]> GetHunEggValue(){List<int[]> YiTiaoEggs = new List<int[]>();YiTiaoEggs.Clear();foreach (List<int> egg in CurEggCardList){bool isHun = IsHunCard(egg);if (isHun){int[] HunEgg = egg.ToArray();YiTiaoEggs.Add(HunEgg);}}return YiTiaoEggs;}//是否包含混牌bool IsHunCard(List<int> eggs){foreach (int card in eggs){if (card == CardHun){return true;}}return false;}/// <summary>/// //获得 已 过蛋的 牌值/// </summary>/// <param name="cardValue"></param>/// <returns></returns>public List<int> GetAsAddEgg(int cardValue){int[] eggType = EggCtro.Instance.GetEggType(cardValue);foreach (List<int> item in CurEggCardList){foreach (int eggCard in item){foreach (int typeCard in eggType){if (eggCard != 11 && eggCard == typeCard){return item;}}}}return null;}/// <summary>/// 替换 List <int> 值/// </summary>/// <param name="item"></param>/// <param name="curValue"></param>/// <param name="repValue">被替换的值</param>public  void ReplaceListValue(ref List<int> item, int curValue, int repValue){int index = item.FindIndex(delegate (int i) { return i == curValue; });if (index < item.Count)item[index] = repValue;}/// <summary>/// 获得列表中大于1个的 重复组/// </summary>/// <param name="listValue"></param>/// <returns>(Dic<值-个数>)</returns>public  Dictionary<int, int> GetListRepitGroup(List<int> listValue){//重复组Dictionary<int, int> RepetGroup = new Dictionary<int, int>();var result = from r in listValuegroup r by r into gwhere g.Count() > 1select g;//遍历分组结果集foreach (var item in result){foreach (int u in item){RepetGroup.Add(u, item.Count<int>());Debug.Log(u + "       " + item.Count<int>());break;}}return RepetGroup;}#endregion}

地方麻将吉林过蛋玩法算法相关推荐

  1. 斗牛怎么玩法算法_游戏开发中的算法

    游戏技术这条路,可深可浅.你可以满足于完成GamePlay玩法层面的东西,你也可以满足于架构和框架设计层面的东西,你也可以醉心于了解某一游戏引擎带来的掌控感.但是,我们不该止步于此,止步与目前所见或所 ...

  2. 斗牛怎么玩法算法_干货:可转债怎么打新百分之百中签?详细讲解抢权配售,值得收藏...

    我相信大家之前肯定看过类似的标题,可能有的人看完也没懂,可能有人看完了也一知半解,索性我今天就给大家科普一下,详细讲解一下. 我觉得这时候,有时间的话,就好好看一遍,我相信绝对会有不一样的收获,而且会 ...

  3. 斗牛怎么玩法算法_逗牛牧场:斗牛游戏小程序,益智斗牛小游戏

    30000+游戏爱好者已加入我们! 带你发现好游戏! <逗牛牧场>游戏小程序好玩吗? <逗牛牧场>小游戏怎么玩? 只有你想不到, 没有我找不到的好游戏! 「良心好游戏推荐」 搜 ...

  4. 用Unity制作一个很火的找不同游戏,包括核心玩法与关卡编辑器工具的实现

    玩家们心里都清楚,其实游戏的品类超级多,有些人喜欢玩moba.射击竞技类的,有些人喜欢塔防.策略.回合制类的,而又有些人喜欢经营养成.休闲益智类的.休闲益智类游戏,虽没像moba类游戏的激烈操作带来的 ...

  5. node.js——麻将算法(二)赖子玩法

    上篇博客传送门http://blog.csdn.net/sm9sun/article/details/65448140 上文中已经实现了基本胡法的算法,本章加入"癞子玩法"的判胡逻 ...

  6. 房卡麻将分析之“缺人玩法”

    一般玩麻将都是四个人,遇到 "三缺一"怎么办?大多数情况下,玩家只好等待或叫人,这无疑增加了玩家的等待时间,同时也减缓了房卡的消耗速度.其实四个人并不是玩麻将的硬性条件,如果能在游 ...

  7. 麻将Lucky Go颠覆传统摸牌玩法

    咦-麻将游戏还不就拼自摸.听258.抓放**等玩法,要说到差异大概就是介面或角色呈现不同,能变出什幺新玩法吗?如果你这幺认为就大错特错啰!在「麻将Lucky Go」麻将游戏中导入全新型态「猜牌」玩法, ...

  8. 区块链开发公司:区块链技术共识算法的新玩法

    共识算法是什么? 共识机制就是用来解决分布式系统的一致性问题,其核心为在某个协议(共识算法)保障下,在有限的时间内,使得指定操作在分布式网络中是一致的.被承认的.不可篡改的.在区块链系统中,特定的共识 ...

  9. Emacs 游戏彩蛋——游戏玩法介绍

    Emacs 内置了很多小游戏,可以参考 https://www.emacswiki.org/emacs/CategoryGames 下面将持续介绍这些游戏的玩法. 有些游戏的玩法可以通过使用: M-x ...

  10. 淘宝斗地主残局玩法技术方案总结

    游戏互动是淘宝内容化建设的重要一环,其实自研的淘宝斗地主满足了部分人群的简单娱乐需求.本文主要介绍了淘宝斗地主新推出的残局玩法从0到1是如何实现的,笔者针对游戏链路到设计方案和可能出现的问题做了比较细 ...

最新文章

  1. python安装docx库_linux 环境下的python 安装 docx 的过程
  2. JavaScript如何获取/计算页面元素的offset?
  3. lan口配置 petalinux_PetaLinux安装及使用
  4. libgdx游戏引擎开发笔记(十)SuperJumper游戏例子的讲解(篇四)---- 主游戏界面内部框架编写...
  5. document.all和document.layers
  6. java 数据库 事务 只读_不使用事务和使用只读事务的区别
  7. 使用Eclipse的Working Set管理项目
  8. SAP License:移动类型541(委外业务)不产生会计凭证的原因
  9. 利用Python构建时间序列模型解决实际问题的正确姿势
  10. 前端优化-Img与background
  11. Python3.x:生成器简介
  12. 树莓派3B的WiFi中文乱码及搜索不到附近的WiFi_解决方案:
  13. 小乌龟Git工具使用
  14. 5. find操作详解
  15. The root link base_link has an inertia specified in the URDF, but KDL does not support a root ...
  16. 安卓开发常用词汇总结
  17. Revit打印工具 RevitPrinter
  18. Java过滤敏感词汇算法(字典树)
  19. 林肯公园跑步歌单:摇滚助力跑出一道光
  20. 最新算法只需一块GPU,就能算出蛋白质结构

热门文章

  1. 计算机基础及msoffice应用内容,计算机一级计算机基础及 ms office 应用考些什么 自考计算机应用基础,要考哪些内容?...
  2. 日常百度SEO优化技巧
  3. PECompact 2.79 Beta D by Sonny27
  4. python输出今天的日期和今天的日期时间
  5. OSChina 周日乱弹 ——领导问:功能几天能开发完?怎么回
  6. python-pika
  7. python中的pika模块
  8. C++Qt开发——Linguist语言家
  9. Ansible—— 29. 通过set_fact模块定义变量
  10. Ubuntu拼音打不了中文