牌型的定义在http://blog.csdn.net/csdn_cjt/article/details/78593140 第一章 这是第四章

下面是代码

 #region 提示出牌 public static Dictionary<int, List<int>> FindPromptCards(List<int> myCards, List<int> lastCards, DDZ_POKER_TYPE lastCardType) {Dictionary<int, List<int>> PromptCards = new Dictionary<int, List<int>>();Hashtable tempMyCardHash = SortCardUseHash1(myCards);// 上一首牌的个数int prevSize = lastCards.Count;int mySize = myCards.Count;// 我先出牌,上家没有牌if (prevSize == 0 && mySize != 0){//把所有牌权重存入返回Debug.Log("上家没有牌");List<int> myCardsHashKey = new List<int>();foreach (int key in tempMyCardHash.Keys){myCardsHashKey.Add(key);}myCardsHashKey.Sort();for (int i = 0; i < myCardsHashKey.Count; i++) {List<int> tempIntList = new List<int>();tempIntList.Add(myCardsHashKey[i]);PromptCards.Add(i, tempIntList);}}// 集中判断是否王炸,免得多次判断王炸if (lastCardType == DDZ_POKER_TYPE.KingBomb){Debug.Log("上家王炸,肯定不能出。");}int prevGrade = 0;if (prevSize > 0) {prevGrade = lastCards[0];Debug.Log("prevGrade" + prevGrade);}// 比较2家的牌,主要有2种情况,1.我出和上家一种类型的牌,即对子管对子;// 2.我出炸弹,此时,和上家的牌的类型可能不同// 王炸的情况已经排除// 上家出单if (lastCardType == DDZ_POKER_TYPE.Single){int tempCount = 0;List<int> myCardsHashKey = new List<int>();foreach (int key in tempMyCardHash.Keys){myCardsHashKey.Add(key);}myCardsHashKey.Sort();for (int i = 0; i < myCardsHashKey.Count; i++){if (myCardsHashKey[i] > prevGrade){List<int> tempIntList = new List<int>();tempIntList.Add(myCardsHashKey[i]);PromptCards.Add(tempCount, tempIntList);tempCount++;}}}// 上家出对子else if (lastCardType == DDZ_POKER_TYPE.Twin){int tempCount = 0;List<int> myCardsHashKey = new List<int>();foreach (int key in tempMyCardHash.Keys){myCardsHashKey.Add(key);}myCardsHashKey.Sort();for (int i = 0; i < myCardsHashKey.Count; i++){if (myCardsHashKey[i] > prevGrade&& (int)tempMyCardHash[myCardsHashKey[i]]>=2){List<int> tempIntList = new List<int>();tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);PromptCards.Add(tempCount, tempIntList);tempCount++;}}}// 上家出3不带else if (lastCardType == DDZ_POKER_TYPE.Triple){int tempCount = 0;List<int> myCardsHashKey = new List<int>();foreach (int key in tempMyCardHash.Keys){myCardsHashKey.Add(key);}myCardsHashKey.Sort();for (int i = 0; i < myCardsHashKey.Count; i++){if (myCardsHashKey[i] > prevGrade && (int)tempMyCardHash[myCardsHashKey[i]] >= 3){List<int> tempIntList = new List<int>();tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);PromptCards.Add(tempCount, tempIntList);tempCount++;}}}// 上家出3带1else if (lastCardType == DDZ_POKER_TYPE.TripleWithSingle){// 3带1 3不带 比较只多了一个判断条件if (mySize < 4){}int grade3=0;foreach (int key in tempMyCardHash.Keys){if (int.Parse(tempMyCardHash[key].ToString()) == 1) {grade3 = key;break;}}int tempCount = 0;List<int> myCardsHashKey = new List<int>();foreach (int key in tempMyCardHash.Keys){myCardsHashKey.Add(key);}myCardsHashKey.Sort();for (int i = 0; i < myCardsHashKey.Count; i++){if (myCardsHashKey[i] > prevGrade && (int)tempMyCardHash[myCardsHashKey[i]] >= 3){List<int> tempIntList = new List<int>();tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(grade3);PromptCards.Add(tempCount, tempIntList);tempCount++;}}}// 上家出3带2else if (lastCardType == DDZ_POKER_TYPE.TripleWithTwin){// 3带1 3不带 比较只多了一个判断条件if (mySize < 5){}int grade3 = 0;int grade4 = 0;foreach (int key in tempMyCardHash.Keys){if (int.Parse(tempMyCardHash[key].ToString()) == 2){grade3 = key;grade4 = key;break;}}int tempCount = 0;List<int> myCardsHashKey = new List<int>();foreach (int key in tempMyCardHash.Keys){myCardsHashKey.Add(key);}myCardsHashKey.Sort();for (int i = 0; i < myCardsHashKey.Count; i++){if (myCardsHashKey[i] > prevGrade && (int)tempMyCardHash[myCardsHashKey[i]] >= 3){List<int> tempIntList = new List<int>();tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(grade3);tempIntList.Add(grade4);PromptCards.Add(tempCount, tempIntList);tempCount++;}}}// 上家出炸弹else if (lastCardType == DDZ_POKER_TYPE.FourBomb){int tempCount = 0;// 4张牌可以大过上家的牌for (int i = mySize - 1; i >= 3; i--){int grade0 = myCards[i];int grade1 = myCards[i - 1];int grade2 = myCards[i - 2];int grade3 = myCards[i - 3];if (grade0 == grade1 && grade0 == grade2 && grade0 == grade3){if (grade0 > prevGrade){// 把四张牌存进去List<int> tempIntList = new List<int>();tempIntList.Add(grade0);tempIntList.Add(grade1);tempIntList.Add(grade2);tempIntList.Add(grade3);PromptCards.Add(tempCount, tempIntList);tempCount++;}}}}// 上家出4带2 else if (lastCardType == DDZ_POKER_TYPE.FourWithSingle){// 4张牌可以大过上家的牌for (int i = mySize - 1; i >= 3; i--){int grade0 = myCards[i];int grade1 = myCards[i - 1];int grade2 = myCards[i - 2];int grade3 = myCards[i - 3];if (grade0 == grade1 && grade0 == grade2 && grade0 == grade3){// 只要有炸弹,则返回true}}}// 上家出4带2 对子else if (lastCardType == DDZ_POKER_TYPE.FourWithSingle){// 4张牌可以大过上家的牌for (int i = mySize - 1; i >= 3; i--){int grade0 = myCards[i];int grade1 = myCards[i - 1];int grade2 = myCards[i - 2];int grade3 = myCards[i - 3];if (grade0 == grade1 && grade0 == grade2 && grade0 == grade3){// 只要有炸弹,则返回true}}}// 上家出顺子else if (lastCardType == DDZ_POKER_TYPE.StraightSingle){if (mySize < prevSize){}else{List<int> tempMyCards = new List<int>();tempMyCards = myCards;Hashtable myCardsHash = SortCardUseHash(tempMyCards);if (myCardsHash.Count < prevSize){Debug.Log("hash的总数小于顺子的count 肯定fales");}List<int> myCardsHashKey = new List<int>();foreach (int key in myCardsHash.Keys){myCardsHashKey.Add(key);}myCardsHashKey.Sort();int tempCount = 0;for (int i = myCardsHashKey.Count - 1; i >= prevSize - 1; i--){List<int> cards = new List<int>();for (int j = 0; j < prevSize; j++){cards.Add(myCardsHashKey[myCardsHashKey.Count - 1 - i + j]);}DDZ_POKER_TYPE myCardType = DDZ_POKER_TYPE.DdzPass;bool isRule = DDZCardRule.PopEnable(cards, out myCardType);if (myCardType == DDZ_POKER_TYPE.StraightSingle){int myGrade2 = cards[cards.Count - 1];// 最大的牌在最后int prevGrade2 = lastCards[prevSize - 1];// 最大的牌在最后if (myGrade2 > prevGrade2){//存进去PromptCardsPromptCards.Add(tempCount, cards);tempCount++;}}}}}// 上家出连对else if (lastCardType == DDZ_POKER_TYPE.StraightTwin){if (mySize < prevSize){}else{List<int> tempMyCards = new List<int>();tempMyCards = myCards;Hashtable myCardsHash = SortCardUseHash(tempMyCards);if (myCardsHash.Count < prevSize){Debug.Log("hash的总数小于顺子的count 肯定fales");}List<int> myCardsHashKey = new List<int>();foreach (int key in myCardsHash.Keys){myCardsHashKey.Add(key);}myCardsHashKey.Sort();int tempCount = 0;for (int i = myCardsHashKey.Count - 1; i >= prevSize - 1; i--){List<int> cards = new List<int>();for (int j = 0; j < prevSize; j++){cards.Add(myCardsHashKey[myCardsHashKey.Count - 1 - i + j]);}DDZ_POKER_TYPE myCardType = DDZ_POKER_TYPE.DdzPass;bool isRule = DDZCardRule.PopEnable(cards, out myCardType);if (myCardType == DDZ_POKER_TYPE.StraightSingle){int myGrade2 = cards[cards.Count - 1];// 最大的牌在最后int prevGrade2 = lastCards[prevSize - 1];// 最大的牌在最后if (myGrade2 > prevGrade2){for (int ii = 0; ii < cards.Count; ii++){if ((int)myCardsHash[cards[ii]] < 2){Debug.Log("是顺子但不是双顺");return PromptCards;}else{for (int iii = 0; iii < cards.Count; iii++) {cards.Add(cards[iii]);}//存进去PromptCardsPromptCards.Add(tempCount, cards);tempCount++;}}}}}}}//上家出飞机else if (lastCardType == DDZ_POKER_TYPE.PlanePure){if (mySize < prevSize){}else{int tempCount = 0;for (int i = 0; i <= mySize - prevSize; i++){List<int> cards = new List<int>();for (int j = 0; j < prevSize; j++){cards.Add(myCards[i+ j]);}DDZ_POKER_TYPE myCardType = DDZ_POKER_TYPE.DdzPass;bool isRule = DDZCardRule.PopEnable(cards, out myCardType);if (myCardType == DDZ_POKER_TYPE.PlanePure){int myGrade4 = cards[4];//int prevGrade4 = lastCards[4];//if (myGrade4 > prevGrade4){//存进去PromptCardsPromptCards.Add(tempCount, cards);tempCount++;}}}}}//上家出飞机带单else if (lastCardType == DDZ_POKER_TYPE.PlaneWithSingle){if (mySize < prevSize){}else{int tempCount = 0;for (int i = 0; i <= mySize - prevSize; i++){List<int> cards = new List<int>();for (int j = 0; j < prevSize- prevSize/4; j++){cards.Add(myCards[i +j]);}DDZ_POKER_TYPE myCardType = DDZ_POKER_TYPE.DdzPass;bool isRule = DDZCardRule.PopEnable(cards, out myCardType);if (myCardType == DDZ_POKER_TYPE.PlanePure){int myGrade4 = cards[4];//int prevGrade4 = lastCards[4];//if (myGrade4 > prevGrade4){int ii = 0;//存进去PromptCards 然后再找一个最小的两个单foreach (int key in tempMyCardHash.Keys){if (int.Parse(tempMyCardHash[key].ToString()) == 1){cards.Add(key);ii++;if (ii == prevSize/4) {break;}}}PromptCards.Add(tempCount, cards);tempCount++;}}}}}//上家出飞机带双else if (lastCardType == DDZ_POKER_TYPE.PlaneWithTwin){if (mySize < prevSize){}else{int tempCount = 0;for (int i = 0; i <= mySize - prevSize; i++){List<int> cards = new List<int>();for (int j = 0; j < prevSize- prevSize/5; j++){cards.Add(myCards[i + j]);}DDZ_POKER_TYPE myCardType = DDZ_POKER_TYPE.DdzPass;bool isRule = DDZCardRule.PopEnable(cards, out myCardType);if (myCardType == DDZ_POKER_TYPE.PlanePure){int myGrade4 = cards[4];//int prevGrade4 = lastCards[4];//if (myGrade4 > prevGrade4){List<int> tempTwoList = new List<int>();for (int ii = 0; ii < cards.Count; ii++){int tempInt = 0;for (int j = 0; j < cards.Count; j++){if (cards[ii] == cards[j]){tempInt++;}}if (tempInt == 2){tempTwoList.Add(cards[ii]);}}if (tempTwoList.Count / 2 < prevSize / 5){}else{//存进去int iii = 0;//存进去PromptCards 然后再找一个最小的两个单foreach (int key in tempMyCardHash.Keys){if (int.Parse(tempMyCardHash[key].ToString()) == 2){cards.Add(key);cards.Add(key);iii++;if (iii == prevSize /5){break;}}}PromptCards.Add(tempCount, cards);tempCount++;}}}}}}// 集中判断对方不是炸弹,我出炸弹的情况if (lastCardType != DDZ_POKER_TYPE.FourBomb){List<int> myCardsHashKey = new List<int>();foreach (int key in tempMyCardHash.Keys){myCardsHashKey.Add(key);}myCardsHashKey.Sort();for (int i = 0; i < myCardsHashKey.Count; i++){if ( (int)tempMyCardHash[myCardsHashKey[i]] == 4){List<int> tempIntList = new List<int>();tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);tempIntList.Add(myCardsHashKey[i]);Debug.Log("PromptCards.Count"+PromptCards.Count);PromptCards.Add(PromptCards.Count, tempIntList);}}}if (mySize >= 2){List<int> myCardsHashKey = new List<int>();foreach (int key in tempMyCardHash.Keys){myCardsHashKey.Add(key);}if (myCardsHashKey.Contains(53) && myCardsHashKey.Contains(54)) {List<int> tempIntList = new List<int>();tempIntList.Add(53);tempIntList.Add(54);PromptCards.Add(PromptCards.Count, tempIntList);}}return PromptCards;}#endregion

//牌编号: 从1~54, 按黑红梅方的顺序,1是BLACK3, 2是BLACK4, ..., 12是BLACK1, 13是BLACK2, 14是RED4, ..., 53是小毛,54大毛

unity开发 斗地主算法—提示AI(提示出牌)相关推荐

  1. unity开发 斗地主算法—比较两个手牌的大小

    牌型的定义在http://blog.csdn.net/csdn_cjt/article/details/78593140 第一章 这是第二章 下面是代码 #region isSelectCardCan ...

  2. 斗地主智能(AI)出牌算法

    去年有想写个斗地主的小游戏,自己玩玩.找了很多资料,后来好不容易在网上找到了一个AI算法.转过的的时候是贴在自己电脑的TXT文本上,再次感谢下原作者.现在借花献佛发给你参考下.    我以前写过一个斗 ...

  3. 斗地主AI算法——第九章の被动出牌(3)

    上一章已经说明了被动出牌算法基本的出牌思路,且以单牌为例给出了具体的代码. 对牌.三不带牌型实现方法与单牌基本类似.改动的地方主要是枚举牌类型,出牌时value_nPutCardList的处理,回溯时 ...

  4. 斗地主AI算法——第八章の被动出牌(2)

    上一章我们已经搭好了被动出牌的基本架子,本章我们主要说明一下被动出牌算法的基本步骤. 我把出牌逻辑分为四个阶段,也就是策略的优先级.分别是:[直接打光手牌]→[同类型牌压制]→[炸弹王炸压制]→[不出 ...

  5. 斗地主AI算法——第十章の被动出牌(4)

    上一章已经说明了单顺的实现方法,双顺.三不带顺牌型实现方法与单牌基本类似.改动的地方除了上一章说的枚举牌类型,出牌时value_nPutCardList的处理,回溯时value_aHandCardLi ...

  6. 算法题:最少出牌次数

    题目来源 阿里巴巴2020实习生招聘在线笔试(3月20日场) 题目描述 有一叠扑克牌,每张牌介于1和10之间,有四种出牌方法: 单牌 对子 顺子:如12345 连对:如112233 给10个数,表示1 ...

  7. unity开发炉石传说系列玩家手中卡牌出入及移动排列代码

    using UnityEngine; using System.Collections; using System.Collections.Generic;//玩家手里卡牌的获得后的刷新和出牌后的刷新 ...

  8. Unity开发-网络.算法.平台相关知识!

    A. 网络相关知识 一.TCP 1.面向数据流.可靠.能保证消息到达顺序. 2.滑动窗口.控制发送量,发送方只能发送窗口内大小的数据包.防止发送方发送的数据过多,接收方无法处理的情况. 3.Nagle ...

  9. 如何用计算机弹出斗地主的声音,玩斗地主没声音电脑瞎出牌。我点的没有.怎么办?...

    一.检查声音服务是否开启 1.打开"开始"--"运行"--输入services.msc--"确定",打开"服务"窗口 2 ...

最新文章

  1. 并联系统的失效率公式推导_电容的串并联计算方法
  2. 微软:明明修复了Bug,你们还把我骂上热搜?
  3. Cloud Programming Simplified: A Berkerley View on Serverless Computing笔记
  4. latex设置一级标题样式不居中_Markdown不快速入门
  5. 数据挖掘算法之决策树算法总结
  6. linux下daemon守护进程的实现(以nginx代码为例)
  7. .net core 使用X509 私钥加密请求
  8. intelj maven 指定编译器版本
  9. 利用composer搭建PHP框架(四.数据库与缓存)
  10. JAVA学习笔记:目录
  11. 环境诉讼与当事人适格
  12. iOS 防止页面重复Push
  13. 技术研发部部门结构及分工
  14. scrapy——抓取知乎
  15. 使用CSS实现首行缩进效果
  16. 【Redis】--- 不同数据结构命令
  17. 小奇画画(线段树+map)(水题)
  18. 【DeepLearning 文本分类实战】IMDB Data Preprocessing数据预处理
  19. 算法面试题(一)-- 统计学习与模式识别面试题
  20. 有道云笔记android手写,有道云笔记Android新版发布 手写更逼真

热门文章

  1. oracle数据库服务器02
  2. 内部存储器分区 android,Android的存储器类型(RAM V内部存储器)
  3. 百度人脸识别搜索是怎么实现的
  4. php 批量删除redis缓存,php redis 批量删除keys的方法
  5. linux下tp驱动程序,Linux安装TP-Link TL-WN722N 驱动
  6. Tello Scratch使用说明
  7. 酒店管理与计算机未来的结合,智慧酒店:未来酒店发展新方向
  8. 【RT-Thread】 TinyUSB挂载成U盘和文件系统,基于STM32F405RG
  9. html中弹出是否翻译成蛋白质,蛋白质的结构与功能预测
  10. ❤️2021 全国大学生数学建模❤️完整B 题思路分析