提交 e58eb1ab 编写于 作者: C changjiuxiong

Merge branch 'master' of https://gitee.com/changjiuxiong/ddz

 Conflicts:
	dist/index.html
......@@ -13,6 +13,18 @@ vue
2.叫分抢地主,1\2\3
3.AI残局算法优化:蒙特卡洛猜牌 + 极大极小搜索 + alpha-beta剪枝
#### 牌型(同欢乐斗地主的规则)
火箭:即双王(大王和小王),最大的牌。
炸弹:四张同数值牌(如四个 7 )。
单牌:单个牌(如红桃 5 )。
对牌:数值相同的两张牌(如梅花 4+ 方块 4 )。
三张牌:数值相同的三张牌(如三个 J )。
三带一:数值相同的三张牌 + 一张单牌或一对牌。例如: 333+6 或 444+99
单顺:五张或更多的连续单牌(如: 45678 或 78910JQK )。不包括 2 点和双王。
双顺:三对或更多的连续对牌(如: 334455 、7788991010JJ )。不包括 2 点和双王。
三顺:二个或更多的连续三张牌(如: 333444 、 555666777888 )。不包括 2 点和双王。
飞机带翅膀:三顺+同数量的单牌(或同数量的对牌)。如: 444555+79 或 333444555+7799JJ
四带二:四张牌+两手牌。(注意:四带二不是炸弹)。如: 5555 + 3 + 8 或 4444 + 55 + 77 。
#### 使用说明
npm install
......
.pokerDesk[data-v-74905788]{height:100%;width:100px;border:1px solid;border-radius:16px;float:left;margin-left:-50px;background-color:azure;font-size:30px;background-repeat:no-repeat;background-size:cover}.poker[data-v-74905788]:hover{background-color:#faebd7}.selected[data-v-74905788]{margin-top:-20px}.s[data-v-74905788]{background-image:url(../img/s.aa339508.jpg)}.x[data-v-74905788]{background-image:url(../img/x.aa03af01.png)}
\ No newline at end of file
.pokerDesk[data-v-7bd525ec]{height:100%;width:100px;border:1px solid;border-radius:16px;float:left;margin-left:-50px;background-color:azure;font-size:30px;background-repeat:no-repeat;background-size:cover}.poker[data-v-7bd525ec]:hover{background-color:#faebd7}.selected[data-v-7bd525ec]{margin-top:-20px}.s[data-v-7bd525ec]{background-image:url(../img/s.aa339508.jpg)}.x[data-v-7bd525ec]{background-image:url(../img/x.aa03af01.png)}
\ 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.247c5e90.css rel=preload as=style><link href=js/app.9cf8ce5a.js rel=preload as=script><link href=js/chunk-vendors.fc173c6b.js rel=preload as=script><link href=css/app.247c5e90.css rel=stylesheet></head><body><div id=app></div><script src=js/chunk-vendors.fc173c6b.js></script><script src=js/app.9cf8ce5a.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.ad699e7c.css rel=preload as=style><link href=js/app.92687945.js rel=preload as=script><link href=js/chunk-vendors.caf18475.js rel=preload as=script><link href=css/app.ad699e7c.css rel=stylesheet></head><body><div id=app></div><script src=js/chunk-vendors.caf18475.js></script><script src=js/app.92687945.js></script></body></html>
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -5,17 +5,17 @@
您的浏览器不支持 audio 元素。
</audio>
<div v-show="false" style="width: 300px;height:300px;float: left; position: fixed ; left: 0; top: 0px; background-color: aliceblue; text-align: center">
<span>
手牌:{{player2Str[1]}}
</span>
</div>
<!-- <div v-show="false" style="width: 300px;height:300px;float: left; position: fixed ; left: 0; top: 0px; background-color: aliceblue; text-align: center">-->
<!-- <span>-->
<!-- 手牌:{{player2Str[1]}}-->
<!-- </span>-->
<!-- </div>-->
<div v-show="false" style="width: 300px;height:300px;float: left; position: fixed ; right: 0; top: 0px; background-color: aliceblue; text-align: center">
<span>
手牌:{{player1Str[1]}}
</span>
</div>
<!-- <div v-show="false" style="width: 300px;height:300px;float: left; position: fixed ; right: 0; top: 0px; background-color: aliceblue; text-align: center">-->
<!-- <span>-->
<!-- 手牌:{{player1Str[1]}}-->
<!-- </span>-->
<!-- </div>-->
<div v-show="false" style="width: 300px;height:300px;float: left; position: fixed ; left: 600px; top: 0px; background-color: aliceblue; text-align: center">
<div style="width: 300px;word-wrap: break-word;">
......@@ -25,11 +25,28 @@
</div>
</div>
<div style="position: fixed;left: 10px;bottom: 10px;">
<button @click="reStart" style="height: 50px;font-size:30px;">开始新一局</button>
</div>
<!-- <div style="position: fixed;left: 10px;bottom: 10px;">-->
<!-- <button @click="reStart" style="height: 50px;font-size:30px;">开始新一局</button>-->
<!-- </div>-->
<div v-show="game.stage==='ready'" :style="{ marginLeft: playerMarginLeft-40 + 'px' }" style="font-size: 20px;color:white;position: fixed;bottom:200px;z-index: 999;">
<button v-show="!game.playerList[0].ready" @mousedown="setReady" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">{{game.playerList[0].ready?'已准备':'准备'}}</button>
<div v-show="game.playerList[0].ready" style="color: red;width:80px;border: solid;border-radius: 4px;position: absolute;">
{{game.playerList[0].ready?'已准备':'未准备'}}
</div>
</div>
<div v-show="game.stage==='jiaoFen'&&game.currentJiaoFenPlayer===game.playerList[0]" :style="{ marginLeft: playerMarginLeft-40 + 'px' }" style="font-size: 20px;color:white;position: fixed;bottom:200px;z-index: 999;">
<button v-show="true" @mousedown="game.playerList[0].setJiaoFen(0)" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">不叫</button>
<button v-show="true" @mousedown="game.playerList[0].setJiaoFen(1)" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">1分</button>
<button v-show="true" @mousedown="game.playerList[0].setJiaoFen(2)" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">2分</button>
<button v-show="true" @mousedown="game.playerList[0].setJiaoFen(3)" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">3分</button>
<!-- <div v-show="game.playerList[0].ready" style="color: red;width:80px;border: solid;border-radius: 4px;position: absolute;">-->
<!-- {{game.playerList[0].ready?'已准备':'未准备'}}-->
<!-- </div>-->
</div>
<div :style="{ marginLeft: playerMarginLeft-150 + 'px' }" style="color:white;position: fixed;bottom:0;width: 100%;height: 200px;line-height: 200px;">
<div v-show="game.stage==='play'" :style="{ marginLeft: playerMarginLeft-150 + 'px' }" style="color:white;position: fixed;bottom:0;width: 100%;height: 200px;line-height: 200px;">
你是 <span style="color:red;font-size: 20px">{{game.playerList[0].type==='nongmin'?'农民':'地主'}}</span>
</div>
<div :style="{ marginLeft: playerMarginLeft + 'px' }" style="position: fixed;bottom:0;width: 100%;height: 200px;">
......@@ -40,7 +57,7 @@
</div>
</div>
<div style="position: fixed;bottom:200px;width: 100%;height: 100px;text-align:left;">
<div v-show="game.currentPlayer===game.playerList[0]" style="position: fixed;bottom:200px;width: 100%;height: 100px;text-align:left;">
<div :style="{ marginLeft: buttonMarginLeft + 'px' }" style="width: 400px;height: 60px;">
<button @click="pass" style="height: 60px;border-radius: 4px;float:left;font-size:40px;background-color: red">不出</button>
<button @click="sendPoker2" style="height: 60px;border-radius: 4px;float:right;font-size:40px;background-color: lawngreen">出牌</button>
......@@ -64,7 +81,7 @@
</div>
<div style="position: fixed;top:40px;left: 20px;height:200px;width:100px;border: solid 1px;border-radius: 8px;background-color: azure;text-align: center">
<p style="color:red;font-size: 20px">
<p v-show="game.stage==='play'" style="color:red;font-size: 20px">
{{game.playerList[2].type==='nongmin'?'农民':'地主'}}
</p>
<p>
......@@ -77,6 +94,9 @@
<div v-show="game.currentPlayer===game.playerList[2]" style="color: red;width:150px;border: solid;border-radius: 4px;position: absolute;bottom:-50px;left: 0">
请在{{game.second}}秒内出牌
</div>
<div v-show="game.stage==='ready'" style="color: red;width:80px;border: solid;border-radius: 4px;position: absolute;bottom:-50px;left: 0;z-index: 999;">
{{game.playerList[2].ready?'已准备':'未准备'}}
</div>
</div>
<div v-if="game.playerList[2].lastSendObj&&game.playerList[2].lastSendObj.poker[0].text" style="position: fixed;top:100px;left:200px;height: 200px;">
<div v-for="item in game.playerList[2].lastSendObj.poker" class="pokerDesk" :class="{ s:item.number===16, x:item.number===17 }">
......@@ -90,9 +110,14 @@
pass
</div>
</div>
<div v-if="game.stage==='jiaoFen'" style="position: fixed;top:100px;left:200px;height: 200px;">
<div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
{{game.playerList[2].jiaoFen}}
</div>
</div>
<div style="position: fixed;top:40px;right: 20px;height:200px;width:100px;border: solid 1px;border-radius: 8px;background-color: azure;text-align: center">
<p style="color:red;font-size: 20px">
<p v-show="game.stage==='play'" style="color:red;font-size: 20px">
{{game.playerList[1].type==='nongmin'?'农民':'地主'}}
</p>
<p>
......@@ -104,6 +129,9 @@
<div v-show="game.currentPlayer===game.playerList[1]" style="color: red;width:150px;border: solid;border-radius: 4px;position: absolute;bottom:-50px;right: 0">
请在{{game.second}}秒内出牌
</div>
<div v-show="game.stage==='ready'" style="color: red;width:80px;border: solid;border-radius: 4px;position: absolute;bottom:-50px;right: 0;z-index: 999;">
{{game.playerList[1].ready?'已准备':'未准备'}}
</div>
</div>
<div v-if="game.playerList[1].lastSendObj&&game.playerList[1].lastSendObj.poker[0].text" style="position: fixed;top:100px;right:200px;height: 200px;">
<div v-for="item in game.playerList[1].lastSendObj.poker" class="pokerDesk" :class="{ s:item.number===16, x:item.number===17 }">
......@@ -117,6 +145,11 @@
pass
</div>
</div>
<div v-if="game.stage==='jiaoFen'" style="position: fixed;top:100px;right:200px;height: 200px;">
<div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
{{game.playerList[1].jiaoFen}}
</div>
</div>
</div>
</template>
......@@ -194,6 +227,12 @@ export default {
window.game = this.game;
},
methods:{
setReady: function() {
let that = this;
that.game.playerList[0].setReady();
},
enter: function(e, poker){
if(e.buttons === 1){
this.pickPoker(poker);
......
......@@ -7,11 +7,13 @@ class Game{
this.pokerList = [];
this.deskPokerObj = null;
this.oldPokerList = [];
this.currentPlayer = [];
this.currentPlayer = null;
this.currentJiaoFenPlayer = null;
this.jiaoFenCount = 0;
this.dizhu = null;
this.MaxSecond = 60;
this.second = this.MaxSecond;
this.isOver = true;
this.stage = 'ready'; //阶段 ready\jiaoFen\play
this.init();
}
......@@ -19,17 +21,55 @@ class Game{
init(){
this.initPokerList();
this.initPlayerList();
this.sendPoker();
}
setReady(){
if(this.playerList[0]&&this.playerList[0].ready&&this.playerList[1]&&this.playerList[1].ready&&this.playerList[2]&&this.playerList[2].ready){
this.sendPoker();
this.startJiaoFen();
}
}
//开始叫分
startJiaoFen(){
this.stage = 'jiaoFen';
let index = this.getRandomIntInclusive(0,2);
this.currentJiaoFenPlayer = this.playerList[index];
}
someOneJiaoFen(){
let that = this;
this.jiaoFenCount++;
if(this.jiaoFenCount === 3){
setTimeout(function () {
that.setDiZhu();
},1000);
return;
}else{
this.currentJiaoFenPlayer = this.currentJiaoFenPlayer.next;
}
}
setDiZhu(){
let sortList = this.playerList.slice(0).sort(this.sortByJiaoFen);
let dizhu = sortList[0];
dizhu.type = 'dizhu';
this.dizhu = dizhu;
this.start();
}
sortByJiaoFen(a, b){
return b.jiaoFen - a.jiaoFen;
}
resetTime(){
this.second = this.MaxSecond;
}
timeLoop(){
if(this.isOver){
if(this.stage !== 'play'){
return;
}
this.second--;
......@@ -50,7 +90,7 @@ class Game{
start(){
this.isOver = false;
this.stage = 'play';
this.timeLoop();
this.currentPlayer = this.dizhu;
if(this.currentPlayer.isRobot){
......@@ -58,6 +98,25 @@ class Game{
}
}
reset(){
this.playerList[0].reset();
this.playerList[1].reset();
this.playerList[2].reset();
this.pokerList = [];
this.deskPokerObj = null;
this.oldPokerList = [];
this.currentPlayer = null;
this.currentJiaoFenPlayer = null;
this.jiaoFenCount = 0;
this.dizhu = null;
this.second = this.MaxSecond;
this.stage = 'ready';
this.initPokerList();
}
next(){
let over = this.checkGameOver();
if(over){
......@@ -73,7 +132,8 @@ class Game{
gameOver(){
alert('游戏结束! '+this.currentPlayer.name+' ['+this.currentPlayer.type+'] 胜!');
this.isOver = true;
this.reset();
}
checkGameOver(){
......@@ -89,6 +149,15 @@ class Game{
}
}
sendDiZhuPoker(){
do{
let poker = this.pokerList.splice(0,1)[0];
this.dizhu.addPoker(poker);
}while(this.pokerList.length>0);
this.dizhu.sortPoker();
}
sendPoker(){
let player = this.playerList[0];
do{
......@@ -98,11 +167,6 @@ class Game{
player = player.next;
}while(this.pokerList.length>3);
do{
let poker = this.pokerList.splice(0,1)[0];
this.dizhu.addPoker(poker);
}while(this.pokerList.length>0);
for(let i=0; i<this.playerList.length; i++){
this.playerList[i].sortPoker();
}
......@@ -116,12 +180,12 @@ class Game{
game: this,
});
let player1 = new Player({
name: 'robot1',
name: '机器人1',
isRobot: true,
game: this,
});
let player2 = new Player({
name: 'robot2',
name: '机器人2',
isRobot: true,
game: this,
});
......@@ -134,9 +198,6 @@ class Game{
this.playerList[1].last = this.playerList[0];
this.playerList[2].last = this.playerList[1];
let dizhuIndex = this.getRandomIntInclusive(0,2);
this.playerList[dizhuIndex].type = 'dizhu';
this.dizhu = this.playerList[dizhuIndex];
}
initPokerList(){
......
......@@ -4,6 +4,8 @@ import AI from "./AI";
class Player{
constructor(param) {
param = param || {};
this.ready = false; //已准备
this.jiaoFen = 0; //叫分
this.pokerList = [];
this.name = param.name || 'noName'+Math.random();
this.type = param.type || 'nongmin';
......@@ -16,7 +18,45 @@ class Player{
game: param.game,
});
this.classifyObj = null;
this.lastSendObj = null;
if(this.isRobot){
this.loopRobot();
}
}
setJiaoFen(fen){
this.jiaoFen = fen;
this.game.someOneJiaoFen();
}
loopRobot(){
let that = this;
if(that.isRobot){
if(!that.ready){
that.setReady();
}
}
if(that.game.stage==='jiaoFen' && that.game.currentJiaoFenPlayer === that){
that.setJiaoFen(3);
}
setTimeout(function(){
that.loopRobot();
},2000);
}
setReady(){
this.ready = true;
this.game.setReady();
}
reset(){
this.ready = false;
this.jiaoFen = 0;
this.pokerList = [];
this.type = 'nongmin';
this.classifyObj = null;
this.lastSendObj = null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册