diff --git a/src/doudizhu/AI.js b/src/doudizhu/AI.js index 67008be98e31d6b8ee861217610177f51f45b7f3..d0454859dabe4ac1abf80d17621ba66b755f576f 100644 --- a/src/doudizhu/AI.js +++ b/src/doudizhu/AI.js @@ -298,15 +298,37 @@ class AI{ }; } - //接牌1 + //接牌1 最小接 不拆 炸 getByObj1(lastObj){ let obj; obj = this.getSmallestObjByObj(lastObj); + if(!obj){ + obj = this.getByBoom(lastObj); + } + return obj; } - //接牌2 + //接牌2 最小接 炸 拆 getByObj2(lastObj){ + let obj; + obj = this.getByObj1(lastObj); + if(!obj){ + obj = this.getBySplit(lastObj); + } + return obj; + } + + //接牌3 最小接 不拆 不炸 不出王、2、AAA + getByObj3(lastObj){ + let obj; + obj = this.getSmallestObjByObj(lastObj); + if(obj){ + if(lastObj){ + + } + } + return obj; } //接牌4 @@ -321,17 +343,36 @@ class AI{ return obj; } - //接牌5 - getByObj5(lastObj){ + getByBoom(lastObj){ let classifyObj = this.player.classifyObj; let obj; let poker; + + if(lastObj.type==='sx'){ + return null; + } + if(classifyObj.four.length>0){ - poker = classifyObj.four[0]; - }else if(classifyObj.poker15.length===4){ - poker = classifyObj.poker15; + if(lastObj.type==='four'){ + for(let i=0; ilastObj.four[0].number){ + poker = classifyObj.four[i]; + break; + } + } + }else{ + poker = classifyObj.four[0]; + } + } + + if(!poker){ + if(classifyObj.poker15.length===4){ + poker = classifyObj.poker15; + } + } + if(poker){ obj = { type: 'four', @@ -348,12 +389,22 @@ class AI{ } } - if(!poker){ - obj = { - type: 'one', - poker: [this.player.pokerList[this.player.pokerList.length-1]], - one: [this.player.pokerList[this.player.pokerList.length-1]], - }; + return obj; + } + + //接牌5 + getByObj5(lastObj){ + + let obj = this.getByBoom(); + + if(!obj){ + if(this.player.pokerList[this.player.pokerList.length-1].number>lastObj.one[0].number){ + obj = { + type: 'one', + poker: [this.player.pokerList[this.player.pokerList.length-1]], + one: [this.player.pokerList[this.player.pokerList.length-1]], + }; + } } return obj; @@ -363,6 +414,16 @@ class AI{ //接牌 playByObj(lastObj){ let obj; + + if(lastObj.type==='sx'){ + obj = { + type: 'pass', + poker: ['pass'], + }; + this.player.deleteFromPokerListAndSendByObj(obj); + return; + } + if(this.player.type==='dizhu'){ if(this.player.next.pokerList.length===1||this.player.last.pokerList.length===1){ obj = this.getByObj4(lastObj); @@ -1033,6 +1094,287 @@ class AI{ return obj; } + //接牌 拆牌 + getBySplit(lastObj){ + let pokerList = this.player.pokerList; + + let lastPoker = pokerList[0]; + let curList = [lastPoker]; + let lists = []; + for(let i=1; i0){ + for(let i=0; ilastObj.two[0].number){ + obj = { + type: type, + poker: Count2List[i], + two: Count2List[i], + }; + break; + } + } + }else if(Count3List.length>0){ + for(let i=0; ilastObj.two[0].number){ + let poker = Count3List[i].slice(0,2); + obj = { + type: type, + poker: poker, + two: poker, + }; + break; + } + } + } + }else if(type === 'threeWithOne'){ + if(Count3List.length>0){ + for(let i=0; ilastObj.three[0].number){ + + let one; + if(Count1List.length>0){ + one = Count1List[0]; + }else if(Count2List.length>0){ + one = Count2List[0].slice(0,1); + }else if(Count3List.length>0){ + for(let j=0; j0){ + for(let i=0; ilastObj.three[0].number){ + + let two; + if(Count2List.length>0){ + two = Count2List[0]; + }else if(Count3List.length>0){ + for(let j=0; j=lastObj.list.length){ + for(let i=0; ilastObj.list[0].three[0].number && Count3List[i][0].number+lastObj.list.length-1===Count3List[i+lastObj.list.length-1][0].number && Count3List[i+lastObj.list.length-1][0].number<=14){ + + let oneList = []; + + for(let j=0; j=i&&j<=i+lastObj.list.length-1){ + continue; + } + oneList.push(Count3List[j].slice(0,1)); + if(oneList.length=lastObj.list.length){ + for(let i=0; ilastObj.list[0].three[0].number && Count3List[i][0].number+lastObj.list.length-1===Count3List[i+lastObj.list.length-1][0].number && Count3List[i+lastObj.list.length-1][0].number<=14){ + + let twoList = []; + + for(let j=0; j=i&&j<=i+lastObj.list.length-1){ + continue; + } + twoList.push(Count3List[j].slice(0,2)); + } + + if(twoList.length === lastObj.list.length){ + + let poker = []; + let list = []; + for(let j=0; j=lastObj.list.length ){ + for(let i=0; ilastObj.list[0].one[0].number && Count1List[i][0].number+lastObj.list.length-1===Count1List[i+lastObj.list.length-1][0].number && Count1List[i+lastObj.list.length-1][0].number<=14){ + let list = Count1List.slice(i,i+lastObj.list.length); + obj = { + type: type, + poker: list.flat(1), + list: list.map(function (item) { + return { + one: item, + } + }), + }; + break; + } + } + } + }else if(type === 'twoList'){ + if(Count2List.length>=lastObj.list.length ){ + for(let i=0; ilastObj.list[0].two[0].number && Count2List[i][0].number+lastObj.list.length-1===Count2List[i+lastObj.list.length-1][0].number && Count2List[i+lastObj.list.length-1][0].number<=14){ + let list = Count2List.slice(i,i+lastObj.list.length); + obj = { + type: type, + poker: list.flat(1), + list: list.map(function (item) { + return { + two: item, + } + }), + }; + break; + } + } + } + }else if(type === 'threeList'){ + if(Count3List.length>=lastObj.list.length ){ + for(let i=0; ilastObj.list[0].two[0].number && Count3List[i][0].number+lastObj.list.length-1===Count3List[i+lastObj.list.length-1][0].number && Count3List[i+lastObj.list.length-1][0].number<=14){ + let list = Count3List.slice(i,i+lastObj.list.length); + obj = { + type: type, + poker: list.flat(1), + list: list.map(function (item) { + return { + three: item, + } + }), + }; + break; + } + } + } + } + + return obj; + } + sortFunction(a, b){ return a.number - b.number; } diff --git a/src/doudizhu/Player.js b/src/doudizhu/Player.js index 1d038ec280402b017ecc191d1e95307142e732fa..46700ba62946bb0206279c70956f9e5293b51e84 100644 --- a/src/doudizhu/Player.js +++ b/src/doudizhu/Player.js @@ -521,7 +521,7 @@ class Player{ obj = { type: type, poker: poker, - one: poker, + two: poker, }; break; }