From c0b094bb81c18aadab3aab9e5d5a1816a1e5e884 Mon Sep 17 00:00:00 2001
From: LCJ <1119884256@qq.com>
Date: Sat, 26 Sep 2020 14:06:30 +0800
Subject: [PATCH] =?UTF-8?q?AI=20=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dist/css/app.d8f0477c.css | 1 -
dist/index.html | 2 +-
src/components/Game.vue | 1 +
src/doudizhu/AI.js | 242 ++++++++++++++++++++++++++++++++++++--
src/doudizhu/Game.js | 4 +-
5 files changed, 237 insertions(+), 13 deletions(-)
delete mode 100644 dist/css/app.d8f0477c.css
diff --git a/dist/css/app.d8f0477c.css b/dist/css/app.d8f0477c.css
deleted file mode 100644
index 260923a..0000000
--- a/dist/css/app.d8f0477c.css
+++ /dev/null
@@ -1 +0,0 @@
-.poker[data-v-4dff4871],.pokerDesk[data-v-4dff4871]{height:100%;width:100px;border:1px solid;border-radius:16px;float:left;margin-left:-50px;background-color:azure;font-size:30px}.poker[data-v-4dff4871]:hover{background-color:#faebd7}.selected[data-v-4dff4871]{margin-top:-20px}
\ No newline at end of file
diff --git a/dist/index.html b/dist/index.html
index c2a508d..42f47cd 100644
--- a/dist/index.html
+++ b/dist/index.html
@@ -1 +1 @@
-
Vue App
\ No newline at end of file
+Vue App
\ No newline at end of file
diff --git a/src/components/Game.vue b/src/components/Game.vue
index c4593e3..cf9b463 100644
--- a/src/components/Game.vue
+++ b/src/components/Game.vue
@@ -178,6 +178,7 @@ export default {
},
mounted() {
this.data = this.game.playerList[1].name;
+ window.game = this.game;
},
methods:{
enter: function(e, poker){
diff --git a/src/doudizhu/AI.js b/src/doudizhu/AI.js
index d045485..6bd10ba 100644
--- a/src/doudizhu/AI.js
+++ b/src/doudizhu/AI.js
@@ -321,13 +321,8 @@ class AI{
//接牌3 最小接 不拆 不炸 不出王、2、AAA
getByObj3(lastObj){
let obj;
- obj = this.getSmallestObjByObj(lastObj);
-
- if(obj){
- if(lastObj){
+ obj = this.getSmallestObjNoBig(lastObj);
- }
- }
return obj;
}
@@ -395,7 +390,7 @@ class AI{
//接牌5
getByObj5(lastObj){
- let obj = this.getByBoom();
+ let obj = this.getByBoom(lastObj);
if(!obj){
if(this.player.pokerList[this.player.pokerList.length-1].number>lastObj.one[0].number){
@@ -411,6 +406,20 @@ class AI{
}
+ //接牌6
+ getByObj6(lastObj){
+
+ let obj;
+ if(lastObj.player.type==='dizhu'){
+ obj = this.getByObj1(lastObj);
+ }else{
+ obj = this.getByObj3(lastObj);
+ }
+
+ return obj;
+
+ }
+
//接牌
playByObj(lastObj){
let obj;
@@ -431,17 +440,103 @@ class AI{
obj = this.getByObj1(lastObj);
}
}else{
+ if(this.player.next.type===this.player.type){
+ obj = this.getByObj6(lastObj);
+ }else{
+ if(this.player.next.pokerList.length===1){
+ if(lastObj.player.type==='dizhu'){
+ obj = this.getByObj4(lastObj);
+ }else{
+ if(lastObj.type==='one'){
+ let canNotGet = this.isPlayerCanNotGetOne(lastObj);
+ if(canNotGet){
+ //pass
+ }else{
+ obj = this.getByObj5(lastObj);
+ }
+ }else{
+ //pass
+ }
+ }
+ }else{
+ obj = this.getByObj6(lastObj);
+ }
+ }
+ }
+ if(!obj){
+ obj = {
+ type: 'pass',
+ poker: ['pass'],
+ };
}
this.player.deleteFromPokerListAndSendByObj(obj);
}
+ isPlayerCanNotGetOne(obj){
+ let allPoker = {
+ 3:0,
+ 4:0,
+ 5:0,
+ 6:0,
+ 7:0,
+ 8:0,
+ 9:0,
+ 10:0,
+ 11:0,
+ 12:0,
+ 13:0,
+ 14:0,
+ 15:0,
+ 16:0,
+ 17:0,
+ };
+ let oldPokerList = this.game.oldPokerList;
+ for(let i=0; i0){
+ for(let i=0; ilastObj.one[0].number){
+ poker = classifyObj.one[i];
+ break;
+ }
+ }
+
+ }
+
+ if(poker){
+ obj = {
+ type: type,
+ poker: poker,
+ one: poker,
+ };
+ }
+ }else if(type === 'two'){
+ let poker;
+
+ if(classifyObj.two.length>0){
+ for(let i=0; ilastObj.two[0].number){
+ poker = classifyObj.two[i];
+ break;
+ }
+ }
+ }
+
+ if(poker){
+ obj = {
+ type: type,
+ poker: poker,
+ two: poker,
+ };
+ }
+ }else if(type === 'three'){
+ let poker;
+
+ if(classifyObj.three.length>0){
+ for(let i=0; ilastObj.three[0].number){
+ if(classifyObj.three[i][0].number<=13){
+ poker = classifyObj.three[i];
+ }
+ break;
+ }
+ }
+ }
+
+ if(poker){
+ obj = {
+ type: type,
+ poker: poker,
+ three: poker,
+ };
+ }
+ }else if(type === 'threeWithOne'){
+ let pokerThree;
+ let one;
+ if(classifyObj.three.length>0){
+ if(classifyObj.three.length>0){
+ for(let i=0; ilastObj.three[0].number){
+ if(classifyObj.three[i][0].number<=13){
+ pokerThree = classifyObj.three[i];
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ if(classifyObj.one.length>0){
+ one = classifyObj.one[0];
+ }
+
+ if(pokerThree&&one){
+ obj = {
+ type: type,
+ poker: pokerThree.concat(one),
+ three: pokerThree,
+ one: one,
+ };
+ }
+
+ }else if(type === 'threeWithTwo'){
+
+ let pokerThree;
+ let two;
+ if(classifyObj.three.length>0){
+ if(classifyObj.three.length>0){
+ for(let i=0; ilastObj.three[0].number){
+ if(classifyObj.three[i][0].number<=13){
+ pokerThree = classifyObj.three[i];
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ if(classifyObj.two.length>0){
+ two = classifyObj.two[0];
+ }
+
+ if(pokerThree&&two){
+ obj = {
+ type: type,
+ poker: pokerThree.concat(two),
+ three: pokerThree,
+ two: two,
+ };
+ }
+
+ }
+
+ return obj;
+ }
+
//最小接 不拆
getSmallestObjByObj(lastObj){
let classifyObj = this.player.classifyObj;
@@ -510,7 +734,7 @@ class AI{
if(!poker){
if(lastObj.one[0].number<15&&classifyObj.poker15.length>0){
- poker = classifyObj.poker15[0];
+ poker = classifyObj.poker15.slice(0,1);
}else{
if(classifyObj.poker17.length<0||classifyObj.poker16.length<0){
if(lastObj.one[0].number<16&&classifyObj.poker16.length>0){
@@ -851,7 +1075,7 @@ class AI{
}else if(classifyObj.poker16.length>0){
poker = classifyObj.poker16;
}else if(classifyObj.poker15.length>0){
- poker = classifyObj.poker15[0];
+ poker = classifyObj.poker15.slice(0,1);
}else{
poker = classifyObj.one[classifyObj.one.length-1];
}
diff --git a/src/doudizhu/Game.js b/src/doudizhu/Game.js
index 79a9b28..849f856 100644
--- a/src/doudizhu/Game.js
+++ b/src/doudizhu/Game.js
@@ -56,7 +56,7 @@ class Game{
this.timeLoop();
this.currentPlayer = this.dizhu;
if(this.currentPlayer.isRobot){
- this.currentPlayer.playByAI();
+ this.currentPlayer.playByAI2();
}
}
@@ -69,7 +69,7 @@ class Game{
this.resetTime();
this.currentPlayer = this.currentPlayer.next;
if(this.currentPlayer.isRobot){
- this.currentPlayer.playByAI();
+ this.currentPlayer.playByAI2();
}
}
--
GitLab