提交 86131a99 编写于 作者: 微笑面对bug's avatar 微笑面对bug

AI 组牌

上级 0d9bb7e7
...@@ -2,4 +2,4 @@ module.exports = { ...@@ -2,4 +2,4 @@ module.exports = {
presets: [ presets: [
'@vue/cli-plugin-babel/preset' '@vue/cli-plugin-babel/preset'
] ]
} };
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><title>Vue App</title><link href=css/app.d8f0477c.css rel=preload as=style><link href=js/app.44f54d0e.js rel=preload as=script><link href=js/chunk-vendors.caf18475.js rel=preload as=script><link href=css/app.d8f0477c.css rel=stylesheet></head><body><div id=app></div><script src=js/chunk-vendors.caf18475.js></script><script src=js/app.44f54d0e.js></script></body></html> <!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><title>Vue App</title><link href=css/app.d8f0477c.css rel=preload as=style><link href=js/app.945dae12.js rel=preload as=script><link href=js/chunk-vendors.caf18475.js rel=preload as=script><link href=css/app.d8f0477c.css rel=stylesheet></head><body><div id=app></div><script src=js/chunk-vendors.caf18475.js></script><script src=js/app.945dae12.js></script></body></html>
\ No newline at end of file \ No newline at end of file
此差异已折叠。
此差异已折叠。
...@@ -56,15 +56,20 @@ class AI{ ...@@ -56,15 +56,20 @@ class AI{
for(let i=0; i<pokerList.length; i++){ for(let i=0; i<pokerList.length; i++){
if(pokerList[i].number === 15){ if(pokerList[i].number === 15){
poker15.push(pokerList[i]); let poker = pokerList.splice(i,1);
i--;
poker15.push(poker[0]);
}else if(pokerList[i].number === 16){ }else if(pokerList[i].number === 16){
poker16.push(pokerList[i]); let poker = pokerList.splice(i,1);
i--;
poker16.push(poker[0]);
}else if(pokerList[i].number === 17){ }else if(pokerList[i].number === 17){
poker17.push(pokerList[i]); let poker = pokerList.splice(i,1);
i--;
poker17.push(poker[0]);
} }
} }
let obj = this.classify(pokerList); let obj = this.classify(pokerList);
let Count1List = obj[1]; let Count1List = obj[1];
let Count2List = obj[2]; let Count2List = obj[2];
...@@ -84,149 +89,176 @@ class AI{ ...@@ -84,149 +89,176 @@ class AI{
sx = Count1List.slice(Count1List.length-2, Count1List.length); sx = Count1List.slice(Count1List.length-2, Count1List.length);
} }
} }
let curList = [Count3List[0]]; if(Count3List.length>0){
let lists = []; let curList = [Count3List[0]];
for(let i=1; i<Count3List.length; i++){ let lists = [];
if(Count3List[i][0].number !== Count3List[i-1][0].number+1){
lists.push(curList); for(let i2=1; i2<Count3List.length; i2++){
curList = [Count3List[i]]; if(Count3List[i2][0].number !== Count3List[i2-1][0].number+1){
}else{ lists.push(curList);
curList.push(Count3List[i]); curList = [Count3List[i2]];
}else{
curList.push(Count3List[i2]);
}
} }
} lists.push(curList);
lists.push(curList); for(let i3=0; i3<lists.length; i3++){
for(let i=1; i<lists.length; i++){ if(lists[i3].length>1){
if(lists[i].length>1){ threeList.push(lists[i3]);
threeList.push(lists[i]); }else{
}else{ three.push(lists[i3][0]);
three.push(lists[i][0]); }
} }
} }
let curList2 = [Count2List[0]]; if(Count2List.length>0){
let lists2 = []; let curList2 = [Count2List[0]];
for(let i=1; i<Count2List.length; i++){ let lists2 = [];
if(Count2List[i][0].number !== Count2List[i-1][0].number+1){ for(let i4=1; i4<Count2List.length; i4++){
lists2.push(curList2); if(Count2List[i4][0].number !== Count2List[i4-1][0].number+1){
curList2 = [Count2List[i]]; lists2.push(curList2);
}else{ curList2 = [Count2List[i4]];
curList2.push(Count2List[i]); }else{
curList2.push(Count2List[i4]);
}
} }
} lists2.push(curList2);
lists2.push(curList2); for(let i5=0; i5<lists2.length; i5++){
for(let i=1; i<lists2.length; i++){ if(lists2[i5].length>2){
if(lists2[i].length>2){ twoList.push(lists2[i5]);
twoList.push(lists2[i]); }else{
}else{ two = two.concat(lists2[i5]);
two = two.concat(lists2[i]); }
} }
} }
let curList1 = [Count1List[0]]; if(Count1List.length>0){
let lists1 = []; let curList1 = [Count1List[0]];
for(let i=1; i<Count1List.length; i++){ let lists1 = [];
if(Count1List[i][0].number !== Count1List[i-1][0].number+1){ for(let i6=1; i6<Count1List.length; i6++){
lists1.push(curList1); if(Count1List[i6][0].number !== Count1List[i6-1][0].number+1){
curList1 = [Count1List[i]]; lists1.push(curList1);
}else{ curList1 = [Count1List[i6]];
curList1.push(Count1List[i]); }else{
curList1.push(Count1List[i6]);
}
} }
} lists1.push(curList1);
lists1.push(curList1); for(let i7=0; i7<lists1.length; i7++){
for(let i=1; i<lists1.length; i++){ if(lists1[i7].length>4){
if(lists1[i].length>4){ oneList.push(lists1[i7]);
oneList.push(lists1[i]); }else{
}else{ one = one.concat(lists1[i7]);
one = one.concat(lists1[i]); }
} }
} }
//combine one two together //combine one two together
let oneIndex = 0; if(one.length>0&&two.length>0){
let twoIndex = 0;
let oneIndex = 0;
let findlist = false; let twoIndex = 0;
while(!findlist){ let findlist = false;
let startN;
let lastN; while(true){
let ones = [];
let twos = [];
if(one[oneIndex][0].number<two[twoIndex][0].number){
startN = one[oneIndex][0].number;
ones.push(one[oneIndex]);
oneIndex++;
}else {
startN = two[twoIndex][0].number;
twos.push(two[twoIndex]);
twoIndex++;
}
lastN = startN;
do{
if(oneIndex>one.length-1&&twoIndex>two.length-1){ if(oneIndex>one.length-1&&twoIndex>two.length-1){
break; break;
} }
if(oneIndex<one.length&&one[oneIndex][0].number === lastN+1){ let startN;
let lastN;
let ones = [];
let twos = [];
if(one.length===0){
break;
}
if(two.length===0){
startN = one[oneIndex][0].number;
ones.push(one[oneIndex]); ones.push(one[oneIndex]);
oneIndex++; oneIndex++;
}else if(twoIndex<two.length&&two[twoIndex][0].number === lastN+1){
twos.push(two[twoIndex]);
twoIndex++;
}else{ }else{
break; if(one[oneIndex][0].number<two[twoIndex][0].number){
startN = one[oneIndex][0].number;
ones.push(one[oneIndex]);
oneIndex++;
}else {
startN = two[twoIndex][0].number;
twos.push(two[twoIndex]);
twoIndex++;
}
} }
lastN = startN;
do{
if(oneIndex>one.length-1&&twoIndex>two.length-1){
break;
}
if(oneIndex<one.length&&one[oneIndex][0].number === lastN+1){
ones.push(one[oneIndex]);
oneIndex++;
}else if(twoIndex<two.length&&two[twoIndex][0].number === lastN+1){
twos.push(two[twoIndex]);
twoIndex++;
}else{
break;
}
lastN = lastN+1; lastN = lastN+1;
if(lastN===startN+4){ if(lastN===startN+4){
if(twos.length<4){ if(twos.length<4){
//combine //combine
let cmbList = []; let cmbList = [];
for(let i=0; i<ones.length; i++){ for(let i8=0; i8<ones.length; i8++){
cmbList.push(ones[i]); cmbList.push(ones[i8]);
//delete from one //delete from one
for(let j=0; j<one.length; j++){ for(let j=0; j<one.length; j++){
if(one[j]===ones[i]){ if(one[j]===ones[i8]){
one.splice(j,1); one.splice(j,1);
break; break;
}
} }
} }
}
for(let i=0; i<twos.length; i++){ for(let i9=0; i9<twos.length; i9++){
let pokers = twos[i]; let pokers = twos[i9];
//delete from two //delete from two
for(let j=0; j<two.length; j++){ for(let j1=0; j1<two.length; j1++){
if(two[j]===pokers){ if(two[j1]===pokers){
one.splice(j,1); one.splice(j1,1);
break; break;
}
} }
}
let poker = pokers.splice(0); let poker = pokers.splice(0);
cmbList.push(poker); cmbList.push(poker);
one.push(pokers); one.push(pokers);
} }
oneList.push(cmbList); cmbList.sort(this.sortArray);
one.sort(this.sortFunction); oneList.push(cmbList);
one.sort(this.sortArray);
findlist = true; findlist = true;
break; oneIndex = 0;
twoIndex = 0;
break;
}
} }
}
}while(true); }while(true);
}
}
}
return { return {
sx, sx,
...@@ -247,6 +279,10 @@ class AI{ ...@@ -247,6 +279,10 @@ class AI{
return a.number - b.number; return a.number - b.number;
} }
sortArray(a, b){
return a[0].number - b[0].number;
}
} }
export default AI; export default AI;
\ No newline at end of file
...@@ -49,6 +49,9 @@ class Game{ ...@@ -49,6 +49,9 @@ class Game{
} }
start(){ start(){
// this.playerList[0].getClassifyObj();
this.isOver = false; this.isOver = false;
this.timeLoop(); this.timeLoop();
this.currentPlayer = this.dizhu; this.currentPlayer = this.dizhu;
......
import Poker from "./Poker"; import Poker from "./Poker";
import AI from "./AI";
class Player{ class Player{
constructor(param) { constructor(param) {
...@@ -10,10 +11,17 @@ class Player{ ...@@ -10,10 +11,17 @@ class Player{
this.next = null; this.next = null;
this.isRobot = param.isRobot; this.isRobot = param.isRobot;
this.game = param.game; this.game = param.game;
this.ai = new AI();
this.classifyObj = new AI();
this.lastSendObj = null; this.lastSendObj = null;
} }
getClassifyObj(){
this.classifyObj = this.ai.getClassifyObj(this.pokerList);
console.log(this.classifyObj);
}
addPoker(poker){ addPoker(poker){
this.pokerList.push(poker); this.pokerList.push(poker);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册