问题描述
求j2me棋牌游戏-斗地主的算法?
解决方案
解决方案二:
算法
解决方案三:
代码例子
解决方案四:
首先是,判断牌的大小然后,电脑AI,出牌,跟牌,再,出牌的AI,放下家?正常出牌,按照手上牌优先出的顺序出跟牌的AI,有的比他大的,判断是否要打,还是不打
解决方案五:
要源代码例子
解决方案六:
竹木一瓜;看过你的回复,首先谢谢。如果、你能贴出点,实现方法的代码更好。
解决方案七:
这玩意儿要收费的
解决方案八:
/***规则判断**@authorzg.shi*/publicinterfaceRule{publicbooleanvalid(int[]cards);/***单牌*/publicstaticfinalRuleSingleRule=newRule(){publicbooleanvalid(int[]cards){returncards.length==1;}};/***对牌*/publicstaticfinalRuleDoubleRule=newRule(){publicbooleanvalid(int[]cards){if(cards.length==2){return(cards[0]/4==cards[1]/4);}returnfalse;}};/***三张*/publicstaticfinalRuleTripleRule=newRule(){publicbooleanvalid(int[]cards){if(cards.length==3){if(cards[0]/4==cards[1]/4){return(cards[0]/4==cards[2]/4);}}returnfalse;}};/***炸弹*/publicstaticfinalRuleFourRule=newRule(){publicbooleanvalid(int[]cards){if(cards.length==3){if(cards[0]/4==cards[1]/4){if(cards[0]/4==cards[2]/4){return(cards[0]/4==cards[3]/4);}}}returnfalse;}};/***顺子*/publicstaticfinalRuleIncreaseRule=newRule(){publicbooleanvalid(int[]cards){if(cards.length>=5){intm=cards[0]/4;for(inti=1;i<cards.length;++i){if(cards[i]/4!=m+i){returnfalse;}}returntrue;}returnfalse;}};}
解决方案九:
还有他们大小的比较
解决方案十:
下文还有吗,关注中
解决方案十一:
以前C#写过一个月,后来果断放弃,总觉得顾此失彼。下面是一个牌型检查,和是否可以接版。用了大量的LINQ,但代码依然相当可观usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespace欢乐斗地主.GameRule{publicclassRule{#region检查指定的扑克牌是否符合一手牌规则///<summary>///检查指定的扑克牌是否符合一手牌规则///</summary>///<paramname="cards">要检查的牌[按个数排序]</param>///<returns>是/否</returns>publicstaticboolIsMatch(List<CardStruct>cards){if(CheckCardType(cards)==AllowCardType.非法牌型)returnfalse;elsereturntrue;}#endregion#region检查指定的扑克牌是否符合接牌规则///<summary>///检查指定的扑克牌是否符合接牌规则///</summary>///<paramname="lastCards">上一手牌</param>///<paramname="thisCards">要检查的牌[按个数排序]</param>///<returns>是/否</returns>publicstaticboolIsMatch(List<CardStruct>lastCards,List<CardStruct>thisCards){AllowCardTypeafter=CheckCardType(thisCards);//不为0if(thisCards.Count==0)returnfalse;//不能为非法牌型if(after==AllowCardType.非法牌型)returnfalse;//王炸可以接任何牌型if(after==AllowCardType.王炸)returntrue;AllowCardTypebefore=CheckCardType(lastCards);//炸弹可接非炸弹牌型if(after==AllowCardType.炸弹&&before!=AllowCardType.炸弹)returntrue;//除以上情况外,要求扑克牌的张数必须相等if(lastCards.Count!=thisCards.Count)returnfalse;//类型必须相等if(after!=before)returnfalse;//类型、张数都相等,则只需比较第一张牌的大小即可if(lastCards[0].Value<thisCards[0].Value)returntrue;returnfalse;}#endregion#region检查一组牌的类型CheckCardType///<summary>///检查一组牌的类型///</summary>///<paramname="cards">想要检查的牌的泛型集合[按个数排序]</param>///<returns>该牌的类型</returns>publicstaticAllowCardTypeCheckCardType(List<CardStruct>cards){AllowCardTyperesult;switch(cards.Count){case0:result=AllowCardType.非法牌型;break;case1:result=AllowCardType.单张;break;case2://对子if(cards[0]==cards[1])result=AllowCardType.对子;//王炸elseif(cards[0].Value+cards[1].Value==33)result=AllowCardType.王炸;elseresult=AllowCardType.非法牌型;break;case3:if(cards[0]==cards[1]&&cards[0]==cards[2])result=AllowCardType.三个;elseresult=AllowCardType.非法牌型;break;case4://3带1result=Check3With1(cards);//炸弹if(cards.All(c=>c==cards[0]))result=AllowCardType.炸弹;break;case5://3带一对result=Check3With1(cards);if(result!=AllowCardType.非法牌型)break;//顺子elseresult=ChenckStaight(cards);break;case6://顺子result=ChenckStaight(cards);if(result!=AllowCardType.非法牌型)break;//连对result=CheckDoubleStaight(cards);if(result!=AllowCardType.非法牌型)break;//飞机三顺result=CheckPlane(cards);if(result!=AllowCardType.非法牌型)break;//4带2或4带一对result=Check4With2(cards);break;default://顺子result=ChenckStaight(cards);if(result!=AllowCardType.非法牌型)break;//连对result=CheckDoubleStaight(cards);if(result!=AllowCardType.非法牌型)break;//飞机result=CheckPlane(cards);break;}returnresult;}#endregion#region检查三带一或三带一对privatestaticAllowCardTypeCheck3With1(List<CardStruct>tenkaiCards){//牌值只能有两种if(tenkaiCards.Distinct(newSortValue()).Count()!=2)returnAllowCardType.非法牌型;//其中一种的数量有三个varcardValueGroup=tenkaiCards.Any(c=>tenkaiCards.Where(d=>d==c).Count()==3);if(!cardValueGroup)returnAllowCardType.非法牌型;//分析具体类型if(tenkaiCards.Count==4){returnAllowCardType.三带一;}else{returnAllowCardType.三带一对;}}#endregion#region检查四带2,四带两对privatestaticAllowCardTypeCheck4With2(List<CardStruct>tenkaiCards){//牌值只能有两种或三种varcardValueCount=tenkaiCards.Distinct(newSortValue()).Count();if(cardValueCount!=2&&cardValueCount!=3)returnAllowCardType.非法牌型;//其中一种的数量有四个varcardValueGroup=tenkaiCards.Any(c=>tenkaiCards.Where(d=>d==c).Count()==4);if(!cardValueGroup)returnAllowCardType.非法牌型;if(tenkaiCards.Count==6){returnAllowCardType.四带二;}else{returnAllowCardType.四带两对;}}#endregion#region检查顺子privatestaticAllowCardTypeChenckStaight(List<CardStruct>tenkaiCards){//牌面值与牌的数量相等varvalueCount=tenkaiCards.Distinct(newSortValue()).Count();if(valueCount!=tenkaiCards.Count)returnAllowCardType.非法牌型;//不包含2,小王,大王if(tenkaiCards.Any(c=>c.Value==15))returnAllowCardType.非法牌型;if(tenkaiCards.Any(c=>c.Value==16))returnAllowCardType.非法牌型;if(tenkaiCards.Any(c=>c.Value==17))returnAllowCardType.非法牌型;//排序后字面值递减tenkaiCards=tenkaiCards.OrderByDescending(c=>c).ToList();for(inti=0;i<tenkaiCards.Count-1;i++){if(tenkaiCards[i].Value-1!=tenkaiCards[i+1].Value){returnAllowCardType.非法牌型;}}returnAllowCardType.顺子;}#endregion#region检查连对privatestaticAllowCardTypeCheckDoubleStaight(List<CardStruct>tenkaiCards){//牌面值正好是总数的一半vardoubleDistinct=tenkaiCards.Distinct(newSortValue());if(doubleDistinct.Count()*2!=tenkaiCards.Count)returnAllowCardType.非法牌型;//对子去重复后是顺子if(ChenckStaight(doubleDistinct.ToList())!=AllowCardType.非法牌型)returnAllowCardType.连对;elsereturnAllowCardType.非法牌型;}#endregion#region检查是否为飞机privatestaticAllowCardTypeCheckPlane(List<CardStruct>tenkaiCards){//牌面值3个的个数vartrebleDictinct=tenkaiCards.Where(c=>tenkaiCards.Count(d=>d==c)==3).Distinct(newSortValue());//检查飞机是否为顺子if(ChenckStaight(trebleDictinct.ToList())==AllowCardType.非法牌型)returnAllowCardType.非法牌型;if(trebleDictinct.Count()*3==tenkaiCards.Count){returnAllowCardType.飞机三顺;}elseif(trebleDictinct.Count()*4==tenkaiCards.Count){returnAllowCardType.飞机带单张;}elseif(trebleDictinct.Count()*5==tenkaiCards.Count){//检查其他的牌是否都为对子varotherDoubleCards=tenkaiCards.Where(c=>tenkaiCards.Count(d=>d==c)==2).Count();if(otherDoubleCards+trebleDictinct.Count()*3==tenkaiCards.Count)returnAllowCardType.飞机带一对;}returnAllowCardType.非法牌型;}#endregion}}
解决方案十二:
我觉得规则比较容易搞定比如哪种结合可以出牌哪种比哪种厉害关键是怎么出的问题其实可以做到电脑玩家完全知道人类玩家的全牌的关键是能压的过时候是否电脑一定要出会不会AI到像人一样有些放牌欲擒故纵的思维这个比较难了就如果是一位的能压的过就出牌这就是QQ斗地主中的自动托管真是2到家了
解决方案十三:
电脑有思维。。。楼上你想的太远了
解决方案十四:
我发现大家都好强大,向各位前辈们学习了
解决方案十五:
涉及到人工智能的东西,就不是一会儿搞的好的了~~~