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

AI 组牌

上级 0d9bb7e7
......@@ -2,4 +2,4 @@ module.exports = {
presets: [
'@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>
\ No newline at end of file
<!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
此差异已折叠。
此差异已折叠。
......@@ -56,15 +56,20 @@ class AI{
for(let i=0; i<pokerList.length; i++){
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){
poker16.push(pokerList[i]);
let poker = pokerList.splice(i,1);
i--;
poker16.push(poker[0]);
}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 Count1List = obj[1];
let Count2List = obj[2];
......@@ -84,149 +89,176 @@ class AI{
sx = Count1List.slice(Count1List.length-2, Count1List.length);
}
}
let curList = [Count3List[0]];
let lists = [];
for(let i=1; i<Count3List.length; i++){
if(Count3List[i][0].number !== Count3List[i-1][0].number+1){
lists.push(curList);
curList = [Count3List[i]];
}else{
curList.push(Count3List[i]);
if(Count3List.length>0){
let curList = [Count3List[0]];
let lists = [];
for(let i2=1; i2<Count3List.length; i2++){
if(Count3List[i2][0].number !== Count3List[i2-1][0].number+1){
lists.push(curList);
curList = [Count3List[i2]];
}else{
curList.push(Count3List[i2]);
}
}
}
lists.push(curList);
for(let i=1; i<lists.length; i++){
if(lists[i].length>1){
threeList.push(lists[i]);
}else{
three.push(lists[i][0]);
lists.push(curList);
for(let i3=0; i3<lists.length; i3++){
if(lists[i3].length>1){
threeList.push(lists[i3]);
}else{
three.push(lists[i3][0]);
}
}
}
let curList2 = [Count2List[0]];
let lists2 = [];
for(let i=1; i<Count2List.length; i++){
if(Count2List[i][0].number !== Count2List[i-1][0].number+1){
lists2.push(curList2);
curList2 = [Count2List[i]];
}else{
curList2.push(Count2List[i]);
if(Count2List.length>0){
let curList2 = [Count2List[0]];
let lists2 = [];
for(let i4=1; i4<Count2List.length; i4++){
if(Count2List[i4][0].number !== Count2List[i4-1][0].number+1){
lists2.push(curList2);
curList2 = [Count2List[i4]];
}else{
curList2.push(Count2List[i4]);
}
}
}
lists2.push(curList2);
for(let i=1; i<lists2.length; i++){
if(lists2[i].length>2){
twoList.push(lists2[i]);
}else{
two = two.concat(lists2[i]);
lists2.push(curList2);
for(let i5=0; i5<lists2.length; i5++){
if(lists2[i5].length>2){
twoList.push(lists2[i5]);
}else{
two = two.concat(lists2[i5]);
}
}
}
let curList1 = [Count1List[0]];
let lists1 = [];
for(let i=1; i<Count1List.length; i++){
if(Count1List[i][0].number !== Count1List[i-1][0].number+1){
lists1.push(curList1);
curList1 = [Count1List[i]];
}else{
curList1.push(Count1List[i]);
if(Count1List.length>0){
let curList1 = [Count1List[0]];
let lists1 = [];
for(let i6=1; i6<Count1List.length; i6++){
if(Count1List[i6][0].number !== Count1List[i6-1][0].number+1){
lists1.push(curList1);
curList1 = [Count1List[i6]];
}else{
curList1.push(Count1List[i6]);
}
}
}
lists1.push(curList1);
for(let i=1; i<lists1.length; i++){
if(lists1[i].length>4){
oneList.push(lists1[i]);
}else{
one = one.concat(lists1[i]);
lists1.push(curList1);
for(let i7=0; i7<lists1.length; i7++){
if(lists1[i7].length>4){
oneList.push(lists1[i7]);
}else{
one = one.concat(lists1[i7]);
}
}
}
//combine one two together
let oneIndex = 0;
let twoIndex = 0;
let findlist = false;
while(!findlist){
let startN;
let lastN;
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;
if(one.length>0&&two.length>0){
let oneIndex = 0;
let twoIndex = 0;
let findlist = false;
while(true){
do{
if(oneIndex>one.length-1&&twoIndex>two.length-1){
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]);
oneIndex++;
}else if(twoIndex<two.length&&two[twoIndex][0].number === lastN+1){
twos.push(two[twoIndex]);
twoIndex++;
}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;
if(lastN===startN+4){
if(twos.length<4){
//combine
let cmbList = [];
for(let i=0; i<ones.length; i++){
cmbList.push(ones[i]);
//delete from one
for(let j=0; j<one.length; j++){
if(one[j]===ones[i]){
one.splice(j,1);
break;
lastN = lastN+1;
if(lastN===startN+4){
if(twos.length<4){
//combine
let cmbList = [];
for(let i8=0; i8<ones.length; i8++){
cmbList.push(ones[i8]);
//delete from one
for(let j=0; j<one.length; j++){
if(one[j]===ones[i8]){
one.splice(j,1);
break;
}
}
}
}
for(let i=0; i<twos.length; i++){
let pokers = twos[i];
for(let i9=0; i9<twos.length; i9++){
let pokers = twos[i9];
//delete from two
for(let j=0; j<two.length; j++){
if(two[j]===pokers){
one.splice(j,1);
break;
//delete from two
for(let j1=0; j1<two.length; j1++){
if(two[j1]===pokers){
one.splice(j1,1);
break;
}
}
}
let poker = pokers.splice(0);
cmbList.push(poker);
one.push(pokers);
let poker = pokers.splice(0);
cmbList.push(poker);
one.push(pokers);
}
}
oneList.push(cmbList);
one.sort(this.sortFunction);
cmbList.sort(this.sortArray);
oneList.push(cmbList);
one.sort(this.sortArray);
findlist = true;
break;
findlist = true;
oneIndex = 0;
twoIndex = 0;
break;
}
}
}
}while(true);
}
}while(true);
}
}
return {
sx,
......@@ -247,6 +279,10 @@ class AI{
return a.number - b.number;
}
sortArray(a, b){
return a[0].number - b[0].number;
}
}
export default AI;
\ No newline at end of file
......@@ -49,6 +49,9 @@ class Game{
}
start(){
// this.playerList[0].getClassifyObj();
this.isOver = false;
this.timeLoop();
this.currentPlayer = this.dizhu;
......
import Poker from "./Poker";
import AI from "./AI";
class Player{
constructor(param) {
......@@ -10,10 +11,17 @@ class Player{
this.next = null;
this.isRobot = param.isRobot;
this.game = param.game;
this.ai = new AI();
this.classifyObj = new AI();
this.lastSendObj = null;
}
getClassifyObj(){
this.classifyObj = this.ai.getClassifyObj(this.pokerList);
console.log(this.classifyObj);
}
addPoker(poker){
this.pokerList.push(poker);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册