斗地主+三人+叫地主+作弊(可设置)+积分属性+记牌器(可设置)
版权声明原作品版权声明本文版权声明
一、相关文章二、新增功能记牌器 RecordCards类设置记牌 SetRecordCards类
三、运行展示四、代码代码框架其余代码PlayWithLandlord_CallPoints_NoTip_HasBP_Record_V1RecordCardsSetRecordCards
五、记牌器的原理
版权声明
原作品版权声明
java斗地主游戏开发 算法思路讲解 转载请注明出处 若本文侵犯原作者的版权,联系邮箱3063494684@qq.com删除本文
本文版权声明
代码改编于两人版 java斗地主游戏开发 算法思路讲解
1、本文所有内容文字资料,版权均属作者个人所有, 任何媒体、网站或个人不得复制内容用于发布/发表。 引用必须注明来源
2、本文下载仅供个人学习或研究,不得在任何网站以任何形式上传。
3、转载、链接、转贴必须注明来源,并且不能用作商用,只能用于学习或研究
除注明来源外,以下内容亦不可任意转载: a.本文所指向的非本人内容的相关链接内容; b.已作出不得转载或未经许可不得转载声明的内容; c.其他法律不允许或本人认为不适合的内容。
转载或引用本人内容不得进行如下活动: a.损害本人或他人利益; b.任何违法行为; c.任何可能破坏公秩良俗的行为; d.擅自同意他人继续转载、引用本文内容;
4、对不遵守本声明或其他违法、恶意使用本人内容者,本人保留追究其法律责任的权利。
一、相关文章
斗地主三人版 斗地主+三人+叫地主 斗地主+三人+叫地主+作弊(可设置) 斗地主+三人+叫地主+作弊(可设置)+积分属性 斗地主+三人+叫地主+作弊(可设置)+积分属性+记牌器(可设置)
二、新增功能
记牌器 RecordCards类
设置记牌 SetRecordCards类
三、运行展示
"C:\Program Files\Java\jdk-15.0.1\bin\java.exe" "-javaagent:E:\IntelliJ IDEA 2021.1\lib\idea_rt.jar=4120:E:\IntelliJ IDEA 2021.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\lenovo\IdeaProjects\DouDiZhu\out\production\DouDiZhu;C:\Users\lenovo\.m2\repository\junit\junit\4.13.1\junit-4.13.1.jar;C:\Users\lenovo\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\lenovo\.m2\repository\org\junit\jupiter\junit-jupiter\5.7.0\junit-jupiter-5.7.0.jar;C:\Users\lenovo\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.7.0\junit-jupiter-api-5.7.0.jar;C:\Users\lenovo\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\lenovo\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\lenovo\.m2\repository\org\junit\platform\junit-platform-commons\1.7.0\junit-platform-commons-1.7.0.jar;C:\Users\lenovo\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.7.0\junit-jupiter-params-5.7.0.jar;C:\Users\lenovo\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.7.0\junit-jupiter-engine-5.7.0.jar;C:\Users\lenovo\.m2\repository\org\junit\platform\junit-platform-engine\1.7.0\junit-platform-engine-1.7.0.jar com.ddz.PlayWithLandlord_CallPoints_NoTip_HasBP_Record_V1
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 1 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 |
-----------------------------------------------------------------
===================================================================
地主牌为♦Q
您的扑克牌:[小王, 2, 2, A, A, A, K, K, Q, Q, J, J, J, 8, 6, 6, 5]
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 1 | 4 | 4 | 3 | 4 | 2 | 3 | 4 | 4 |
-----------------------------------------------------------------
===================================================================
=====================================叫地主阶段=====================================
上家有地主牌♦Q,上家先叫地主
===上家叫地主===
1分
===玩家叫地主===
输入0,不叫 / 输入2,2分 / 输入3,3分 -----> 2
2分
===下家叫地主===
不叫
======玩家是地主======
===================================================================================
底分为:2
底牌为[7, J, 4],并且牌型为同花,翻3倍
现在分数为:6
======================================出牌阶段======================================
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 4 | 3 | 3 | 2 | 3 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=======================玩家[地主]主动出牌=======================
您当前的扑克牌:[小王, 2, 2, A, A, A, K, K, Q, Q, J, J, J, J, 8, 7, 6, 6, 5, 4]
请您出牌:(输入?提示 输入,偷看电脑的牌)
45678
出牌成功:CardProduct{list=[8, 7, 6, 5, 4], type=顺子, maxCard=8, len=5, group=[(num=5, sum=1), (num=4, sum=1), (num=3, sum=1), (num=2, sum=1), (num=1, sum=1)]}
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 4 | 3 | 3 | 2 | 3 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=============下家[农民]出牌=================
下家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 4 | 3 | 3 | 2 | 3 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=============上家[农民]出牌=================
上家出牌:[9, 8, 7, 6, 5]
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=============玩家[地主]=================
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
上一次出牌:CardProduct{list=[9, 8, 7, 6, 5], type=顺子, maxCard=9, len=5, group=[(num=6, sum=1), (num=5, sum=1), (num=4, sum=1), (num=3, sum=1), (num=2, sum=1)]}
您当前的扑克牌:[小王, 2, 2, A, A, A, K, K, Q, Q, J, J, J, J, 6]
请您出牌:(输入.不出 输入?提示 输入,偷看电脑的牌)
jjjj
出牌成功:CardProduct{list=[J, J, J, J], type=炸弹, maxCard=J, len=4, group=[(num=8, sum=4)]}
所出为炸弹翻2倍,现在分数为:12(6*2)
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=============下家[农民]出牌=================
下家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=============上家[农民]出牌=================
上家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=======================玩家[地主]主动出牌=======================
您当前的扑克牌:[小王, 2, 2, A, A, A, K, K, Q, Q, 6]
请您出牌:(输入?提示 输入,偷看电脑的牌)
出牌成功:CardProduct{list=[Q, Q], type=对子, maxCard=Q, len=2, group=[(num=9, sum=2)]}
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 2 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=============下家[农民]出牌=================
下家出牌:[2, 2]
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=============上家[农民]出牌=================
上家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
=============玩家[地主]=================
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 2 | 1 | 2 | 3 | 4 |
-----------------------------------------------------------------
===================================================================
上一次出牌:CardProduct{list=[2, 2], type=对子, maxCard=2, len=2, group=[(num=12, sum=2)]}
您当前的扑克牌:[小王, 2, 2, A, A, A, K, K, 6]
请您出牌:(输入.不出 输入?提示 输入,偷看电脑的牌)
.
==============================记牌器===============================
===================================================================
=======================下家[农民]主动出牌=======================
下家主动出牌:[7, 6, 5, 4, 3]
下家出牌:[7, 6, 5, 4, 3]
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 1 | 0 | 1 | 2 | 3 |
-----------------------------------------------------------------
===================================================================
=============上家[农民]出牌=================
上家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 1 | 0 | 1 | 2 | 3 |
-----------------------------------------------------------------
===================================================================
=============玩家[地主]=================
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 1 | 0 | 1 | 2 | 3 |
-----------------------------------------------------------------
===================================================================
上一次出牌:CardProduct{list=[7, 6, 5, 4, 3], type=顺子, maxCard=7, len=5, group=[(num=4, sum=1), (num=3, sum=1), (num=2, sum=1), (num=1, sum=1), (num=0, sum=1)]}
您当前的扑克牌:[小王, 2, 2, A, A, A, K, K, 6]
请您出牌:(输入.不出 输入?提示 输入,偷看电脑的牌)
.
==============================记牌器===============================
===================================================================
=======================下家[农民]主动出牌=======================
下家主动出牌:[3, 3]
下家出牌:[3, 3]
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 2 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=============上家[农民]出牌=================
上家出牌:[8, 8]
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=============玩家[地主]=================
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
上一次出牌:CardProduct{list=[8, 8], type=对子, maxCard=8, len=2, group=[(num=5, sum=2)]}
您当前的扑克牌:[小王, 2, 2, A, A, A, K, K, 6]
请您出牌:(输入.不出 输入?提示 输入,偷看电脑的牌)
kk
出牌成功:CardProduct{list=[K, K], type=对子, maxCard=K, len=2, group=[(num=10, sum=2)]}
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=============下家[农民]出牌=================
下家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=============上家[农民]出牌=================
上家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=======================玩家[地主]主动出牌=======================
您当前的扑克牌:[小王, 2, 2, A, A, A, 6]
请您出牌:(输入?提示 输入,偷看电脑的牌)
1116
出牌成功:CardProduct{list=[A, A, A, 6], type=三带一, maxCard=A, len=4, group=[(num=11, sum=3), (num=3, sum=1)]}
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=============下家[农民]出牌=================
下家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=============上家[农民]出牌=================
上家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=======================玩家[地主]主动出牌=======================
您当前的扑克牌:[小王, 2, 2]
请您出牌:(输入?提示 输入,偷看电脑的牌)
22
出牌成功:CardProduct{list=[2, 2], type=对子, maxCard=2, len=2, group=[(num=12, sum=2)]}
玩家就剩1牌啦!!!
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=============下家[农民]出牌=================
下家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=============上家[农民]出牌=================
上家不要
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
==============================记牌器===============================
-----------------------------------------------------------------
|点数| C | c | 2 | A | K | Q | J | 0 | 9 | 8 | 7 | 6 | 5 | 4 | 3 |
|余数| 1 | 0 | 0 | 1 | 2 | 2 | 0 | 4 | 3 | 0 | 1 | 0 | 1 | 2 | 1 |
-----------------------------------------------------------------
===================================================================
=======================玩家[地主]主动出牌=======================
您当前的扑克牌:[小王]
请您出牌:(输入?提示 输入,偷看电脑的牌)
c
出牌成功:CardProduct{list=[小王], type=单牌, maxCard=小王, len=1, group=[(num=13, sum=1)]}
=======================================================================
你赢啦!
胜利者为mePlayer[地主]分数12
===================================================================================
========================================结算========================================
--------------------------------------------------------------------------------
| 局次 | 获胜者 | 上家积分结算 | 玩家积分结算 | 下家积分结算 | 分数 |
| 1 | mePlayer[地主] | -2 (10-12) | 34 (10+24) | -2 (10-12) | 12 |
=====================================================================================
最终的获胜者为mePlayer,所拥有积分:34
其他人leftPlayer,所拥有积分:-2+rightPlayer,所拥有积分:-2
是否要展示战绩(Y/N)
y
======================================展示战绩======================================
--------------------------------------------------------------------------------
| 局次 | 获胜者 | 上家积分结算 | 玩家积分结算 | 下家积分结算 | 分数 |
| 1 | mePlayer[地主] | -2 (10-12) | 34 (10+24) | -2 (10-12) | 12 |
===================================================================================
Process finished with exit code 0
四、代码
代码框架
其余代码
斗地主+三人+叫地主
PlayWithLandlord_CallPoints_NoTip_HasBP_Record_V1
package com.ddz;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
* Cc代表大小王,0代表10
* 大小写jqk都可以代表JQK
* Aa1都代表A
*
* 多少副牌sum、是否包含345contains345可以在main方法中更改
*
* 四炸<双王炸<五炸<六炸<三王炸<七炸<八炸<四王炸
* 并且[大王, 大王]是可以打赢[大王, 小王]和[小王, 小王]的
*/
/**
* 斗地主+三人+叫地主+设置无作弊+积分属性+记牌器+V1
*/
public class PlayWithLandlord_CallPoints_NoTip_HasBP_Record_V1 {
static int initPoints = 10;//初始积分
private static final Player mePlayer = new Player("mePlayer", initPoints);//参赛人员玩家
private static final Player leftPlayer = new Player("leftPlayer", initPoints);//参赛人员上家
private static final Player rightPlayer = new Player("rightPlayer", initPoints);//参赛人员下家
private static String grate="";//计分板
/**
* 所出的牌手中是否存在
* @param list 手中的牌
* @param card 所出的牌
* @return 返回所出的牌在手中的索引
*/
public static List
if (card.size() > list.size()) return null;
int[] cardNum = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
cardNum[i] = list.get(i).num;
}
List
for (Card value : card) {
if (value.num > GameConstants.NUM_2) {
final int id = value.id;
for (int j = 0; j < list.size(); j++) {
if (value.id == list.get(j).id && !indexes.contains(j)) {
indexes.add(j);
break;
}
}
} else {
for (int j = 0; j < cardNum.length; j++) {
if (value.num == cardNum[j] && !indexes.contains(j)) {
indexes.add(j);
break;
}
}
}
}
if (indexes.size() != card.size()) return null;
return indexes;
}
/**
* 发牌 地主牌 和 底牌
* @param sum 多少副牌
* @param contains345 是否包含345
* @return List> 012三位玩家的牌,3地主牌 和 4底牌
*
*/
public static List> licensing(int sum, boolean contains345) {
List> listList = new ArrayList<>();
List
List
List
List
List
Card specialCard;
//牌堆
ArrayList
for (int i = 0; i < sum; i++) {
for (int j = contains345 ? GameConstants.ID_3_1 : GameConstants.ID_6_1; j < 54; j++) {
list.add(j);
}
}
//地主牌
int specialId;
while (true) {
specialId = (int) (Math.random() * list.size());
if (!contains345) {
if (specialId >= GameConstants.ID_3_1 && specialId < GameConstants.ID_6_1) {
continue;
}
}
specialCard = new Card(specialId);
break;
}
specialCardToList.add(specialCard);
//底牌
while (holeCards.size() < 3) {
int cardId = (int) (Math.random() * list.size());
if (specialId != cardId) {
Card card = new Card(list.remove(cardId));
holeCards.add(card);
}
}
//随机发牌
while (list.size() > 0) {
playerList.add(new Card(list.remove((int) (Math.random() * list.size()))));
leftList.add(new Card(list.remove((int) (Math.random() * list.size()))));
rightList.add(new Card(list.remove((int) (Math.random() * list.size()))));
}
//排序
playerList.sort((o1, o2) -> o2.id - o1.id);
leftList.sort((o1, o2) -> o2.id - o1.id);
rightList.sort((o1, o2) -> o2.id - o1.id);
listList.add(playerList);
listList.add(leftList);
listList.add(rightList);
listList.add(specialCardToList);
listList.add(holeCards);
return listList;
}
/**
* 地主牌 判断花色
* @param card 地主牌
* @return 花色
*/
public static String Suit(Card card) {
if (card.id==GameConstants.ID_JOKER_1||card.id==GameConstants.ID_JOKER_2){
return "";
}
int suitId = card.id % 4;
return switch (suitId) {
case 0 -> "♥";
case 1 -> "♦";
case 2 -> "♣";
case 3 -> "♠";
default -> null;
};
}
/**
* 返回底牌所翻倍数
* 双王 4倍
* 同花/顺子/三条 3倍
* 单王 2倍
* @param holeCards 底牌
* @return [0]底牌的牌型和[1]底牌所翻倍数
*/
public static Object[] returnHoleCardPoint(List
Object[] objects=new Object[2];
String holeCardsType="杂牌";
int HoleCardPoint=1;
List
if (groups.size()==1){//三条
HoleCardPoint*=3;
holeCardsType="三条";
} else if (groups.size()==2){
if (groups.get(1).num== GameConstants.NUM_JOKER&&groups.get(1).sum==2) {//双王 一个单
HoleCardPoint*=4;
holeCardsType="双王";
}else if(groups.get(1).num== GameConstants.NUM_JOKER&&groups.get(1).sum==1){//单王 一个对
HoleCardPoint*=2;
holeCardsType="单王";
}
}else if (groups.size()==3){
if (groups.get(2).num== GameConstants.NUM_JOKER) {//单王
HoleCardPoint*=2;
holeCardsType="单王";
}else if (groups.get(1).num==groups.get(0).num+1&&groups.get(2).num==groups.get(0).num+2) {//顺子
HoleCardPoint*=3;
holeCardsType="顺子";
} else if ( Suit(holeCards.get(0)).equals(Suit(holeCards.get(1)))&&Suit(holeCards.get(0)).equals(Suit(holeCards.get(2))) ){//同花
HoleCardPoint*=3;
holeCardsType="同花";
}
}
objects[0]=holeCardsType;
objects[1]=HoleCardPoint;
return objects;
}
//测试 returnHoleCardPoint
@Test
public void testReturnHoleCardPoint(){
List
// cards.add(new Card(GameConstants.ID_JOKER_1));
// cards.add(new Card(GameConstants.ID_JOKER_2));
// cards.add(new Card(GameConstants.ID_A_1));
// cards.add(new Card(GameConstants.ID_A_3));
// cards.add(new Card(GameConstants.ID_A_2));
// cards.add(new Card(GameConstants.ID_A_1));
// cards.add(new Card(GameConstants.ID_A_1));
// cards.add(new Card(GameConstants.ID_Q_1));
cards.add(new Card(GameConstants.ID_K_1));
cards.add(new Card(GameConstants.ID_Q_1));
cards.add(new Card(GameConstants.ID_10_1));
Object[] objects = returnHoleCardPoint(cards);
System.out.println(objects[0]);
System.out.println(objects[1]);
}
/**
* 预估玩家的初始手牌的牌力
* 5--一分 7--两分 10--三分
* 炸弹分为5点
* 对于7890j炸弹为4(因为容易被拆)
* 对于王炸为8分
* // * 10点--一分 16---两分 20--三分
* // * 对于3456QKA2C的炸弹分依次+1(3炸为5分...C炸为13分)
* 三条2是3分
* 三条是1点
* 对2是2点
* C是4分
* c是3分
*
* @param list 玩家的初始手牌
* @return 玩家的初始手牌的牌力
*/
public static int CardsPower(List
int power = 0;
boolean hasCc = false;
List
groups.sort((o1, o2) -> {
//order by sum desc,num desc
final int o = o2.sum - o1.sum;
if (o != 0) return o;
return o2.num - o1.num;
});
for (CardGroup cardGroup : groups) {
if (cardGroup.sum == 4) {
//大分
// int p = 5;
// switch (cardGroup.num) {
// case GameConstants.NUM_3:
// p += 0;
// case GameConstants.NUM_4:
// p += 1;
// case GameConstants.NUM_5:
// p += 1;
// case GameConstants.NUM_6:
// p += 1;
// break;
// case GameConstants.NUM_7:
// case GameConstants.NUM_8:
// case GameConstants.NUM_9:
// case GameConstants.NUM_10:
// case GameConstants.NUM_J:
// p=-1;
// break;
// case GameConstants.NUM_Q:
// p += 4;
// case GameConstants.NUM_K:
// p += 1;
// case GameConstants.NUM_A:
// p += 1;
// case GameConstants.NUM_2:
// p += 1;
// break;
//
// }
// power+=p;
switch (cardGroup.num) {
case GameConstants.NUM_7, GameConstants.NUM_8, GameConstants.NUM_9, GameConstants.NUM_10, GameConstants.NUM_J -> power += 4;
default -> power += 5;
}
} else if (cardGroup.sum == 3) {
if (cardGroup.num == GameConstants.NUM_2) {
power += 3;
} else {
power += 1;
}
} else if (cardGroup.sum == 2) {
if (cardGroup.num == GameConstants.NUM_2) {
power += 2;
} else if (cardGroup.num == GameConstants.NUM_JOKER) {
hasCc = true;
power += 8;
}
}
}
if (hasCc) {
} else if (list.contains(new Card(GameConstants.ID_JOKER_1))) {
power += 3;
} else if (list.contains(new Card(GameConstants.ID_JOKER_2))) {
power += 4;
}
return power;
}
/**
* 手牌变为牌力变为叫分
* @param list 手牌
* @return 叫分
*/
public static int point(List
int power = CardsPower(list);
if (power < 5) {
return 0;
} else if (power < 7) {
return 1;
} else if (power < 10) {
return 2;
} else {
return 3;
}
}
/**
* 叫地主进行中
* @param leftList 上家的牌
* @param playerList 玩家的牌
* @param rightList 下家的牌
* @param specialCard 地主牌
* @return result 返回012上家、玩家、下家是否成为地主以及3所叫的分数的List
*/
public static List
int point;
boolean lc = leftList.contains(specialCard);//上家是否拿地主牌,先叫
boolean mc = playerList.contains(specialCard);//玩家是否拿地主牌,先叫
boolean rc = rightList.contains(specialCard);//下家是否拿地主牌,先叫
System.out.println("=====================================叫地主阶段=====================================");
String ss;
if (lc) {
ss = "上家";
} else if (mc) {
ss = "玩家";
} else {
ss = "下家";
}
System.out.println(ss + "有地主牌" + Suit(specialCard) + specialCard + "," + ss + "先叫地主");
List
boolean calling = true;
boolean lFirstCall = false;
boolean mFirstCall = false;
boolean rFirstCall = false;
boolean lCall0 = false;
boolean mCall0 = false;
boolean rCall0 = false;
boolean lHasCalled = false;
boolean mHasCalled = false;
boolean rHasCalled = false;
int lPoint = 0;
int mPoint = 0;
int rPoint = 0;
int lastPoint = -1;
while (calling) {
if (lc) {
if (!mFirstCall && !rFirstCall) {
lFirstCall = true;
}
System.out.println("===上家叫地主===");
lPoint = point(leftList);
if (lPoint > lastPoint) {
lHasCalled = true;
switch (lPoint) {
case 0 -> {
System.out.println("不叫");
lastPoint = 0;
lCall0 = true;
lc = false;
mc = true;
}
case 1 -> {
System.out.println("1分");
lastPoint = 1;
lc = false;
mc = true;
}
case 2 -> {
System.out.println("2分");
lastPoint = 2;
lc = false;
mc = true;
}
case 3 -> {
System.out.println("3分");
lastPoint = 3;
lc = false;
}
}
} else {
System.out.println("不叫");
lPoint = 0;
lCall0 = true;
lc = false;
lHasCalled = true;
mc = true;
}
}
if (lastPoint == 3 || (lCall0 && mCall0 && rCall0)) {
break;
} else if (lHasCalled && mHasCalled && rHasCalled) {
break;
}
while (mc) {
if (!lFirstCall && !rFirstCall) {
mFirstCall = true;
}
System.out.println("===玩家叫地主===");
Scanner scanner = new Scanner(System.in);
String tip = "输入0,不叫 / ";
switch (lastPoint) {
case -1:
tip = "输入0,不叫 / ";
case 0:
tip = tip + "输入1,1分 / ";
case 1:
tip = tip + "输入2,2分 / ";
case 2:
tip = tip + "输入3,3分 ";
}
System.out.print(tip + " -----> ");
String s = scanner.nextLine();
if (!s.equals("0") && !s.equals("1") && !s.equals("2") && !s.equals("3")) {
continue;
}
mPoint = Integer.parseInt(s);
if (mPoint <= lastPoint) {
if (mPoint != 0) {
continue;
}
}
switch (mPoint) {
case 0 -> {
System.out.println("不叫");
if (lastPoint == 0 || lastPoint == -1) {//此条件为上一次叫或玩家首次不叫,否则玩家不叫不会改变上一次的叫分
lastPoint = 0;
}
mCall0 = true;
mc = false;
mHasCalled = true;
rc = true;
}
case 1 -> {
System.out.println("1分");
lastPoint = 1;
mc = false;
mHasCalled = true;
rc = true;
}
case 2 -> {
System.out.println("2分");
lastPoint = 2;
mc = false;
mHasCalled = true;
rc = true;
}
case 3 -> {
System.out.println("3分");
lastPoint = 3;
mc = false;
mHasCalled = true;
}
}
}
if (lastPoint == 3 || (lCall0 && mCall0 && rCall0)) {
break;
} else if (lHasCalled && mHasCalled && rHasCalled) {
break;
}
if (rc) {
if (!mFirstCall && !lFirstCall) {
rFirstCall = true;
}
System.out.println("===下家叫地主===");
rPoint = point(rightList);
if (rPoint > lastPoint) {
rHasCalled = true;
switch (rPoint) {
case 0 -> {
System.out.println("不叫");
lastPoint = 0;
rCall0 = true;
rc = false;
lc = true;
}
case 1 -> {
System.out.println("1分");
lastPoint = 1;
rc = false;
lc = true;
}
case 2 -> {
System.out.println("2分");
lastPoint = 2;
rc = false;
lc = true;
}
case 3 -> {
System.out.println("3分");
rc = false;
lc = true;
lastPoint = 3;
}
}
} else {
System.out.println("不叫");
rPoint = 0;
rCall0 = true;
lc = true;
rc = false;
rHasCalled = true;
}
}
if (lastPoint == 3 || (lCall0 && mCall0 && rCall0)) {
calling = false;
} else if (lHasCalled && mHasCalled && rHasCalled) {
break;
}
}
if (lCall0 && mCall0 && rCall0) {
if (lFirstCall) {
lPoint = 1;
} else if (mFirstCall) {
mPoint = 1;
} else if (rFirstCall) {
rPoint = 1;
}
}
boolean LandlordIsL = lPoint > mPoint && lPoint > rPoint;
boolean LandlordIsM = lPoint < mPoint && mPoint > rPoint;
boolean LandlordIsR = rPoint > mPoint && lPoint < rPoint;
if (LandlordIsL) {
System.out.println("======上家是地主======");
leftPlayer.type = GameConstants.TYPE_Landlord;
point = lPoint;
} else if (LandlordIsM) {
System.out.println("======玩家是地主======");
mePlayer.type = GameConstants.TYPE_Landlord;
point = mPoint;
} else {
System.out.println("======下家是地主======");
rightPlayer.type = GameConstants.TYPE_Landlord;
point = rPoint;
}
result.add(LandlordIsL);
result.add(LandlordIsM);
result.add(LandlordIsR);
result.add(point);
System.out.println("===================================================================================");
return result;
}
/**
* main 方法
* @param args 参数
*/
public static void main(String[] args) {
Tip tip = new Tip(true, true, true, false, false);
SetRecordCards setRecord=new SetRecordCards(true);
int sum = 1;//多少副牌
boolean contains345 = true;//是否包含345
int count = 1;//局次
Scanner scanner=new Scanner(System.in);
while (mePlayer.bonusPoint > 0 && leftPlayer.bonusPoint > 0 && rightPlayer.bonusPoint > 0) {
//记牌器
RecordCards record=new RecordCards(sum,contains345);
// record.updateRecord();//在内在外都可以
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord();//在内在外都可以
System.out.println(record);
System.out.println("===================================================================");
}
//洗牌,发牌
List> listList = licensing(sum, contains345);
List
List
List
Card specialCard = listList.get(3).get(0);//地主牌,最开始叫地主
List
//看牌
System.out.println("地主牌为" + Suit(specialCard) + specialCard);
if (!tip.NoShowsHoleCards) {
System.out.println("底牌为" + holeCards);
}
System.out.println("您的扑克牌:" + playerList);
if (!tip.NoShowsCards) {
System.out.println("上家扑克牌:" + leftList);
System.out.println("下家扑克牌:" + rightList);
}
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord(playerList);
System.out.println(record);
System.out.println("===================================================================");
}
//叫地主
List
//打牌
List
//结算
System.out.println("========================================结算========================================");
Player winner = (Player) objects.get(0);
int point = (int) objects.get(1);
String re = settlePoints(count, winner, point);
System.out.println(re);
addGrate(re);
System.out.println("=====================================================================================");
if (mePlayer.bonusPoint > 0 && leftPlayer.bonusPoint > 0 && rightPlayer.bonusPoint > 0) {
//提前结束结束
System.out.println("是否要提前结束(Y/N)");
String over = scanner.nextLine();
boolean overs = false;
if (over.equalsIgnoreCase("Y")) {
overs = true;
}
if (overs) {
break;
}
}
count++;//局次加加
}
//最终获胜者
if(mePlayer.bonusPoint>= leftPlayer.bonusPoint&&mePlayer.bonusPoint>= rightPlayer.bonusPoint){
System.out.println("最终的获胜者为"+mePlayer.toStringNameAndBP());
System.out.println("其他人"+leftPlayer.toStringNameAndBP()+","+rightPlayer.toStringNameAndBP());
} else if(mePlayer.bonusPoint< leftPlayer.bonusPoint&&leftPlayer.bonusPoint>= rightPlayer.bonusPoint){
System.out.println("最终的获胜者为"+leftPlayer.toStringNameAndBP());
System.out.println("其他人"+mePlayer.toStringNameAndBP()+","+rightPlayer.toStringNameAndBP());
} else {
System.out.println("最终的获胜者为"+rightPlayer.toStringNameAndBP());
System.out.println("其他人"+leftPlayer.toStringNameAndBP()+","+mePlayer.toStringNameAndBP());
}
//战绩展示
System.out.println("是否要展示战绩(Y/N)");
String show = scanner.nextLine();
while (true){
if (show.equalsIgnoreCase("Y")){
//展示战绩
System.out.println("======================================展示战绩======================================");
System.out.println(grate);
System.out.println("===================================================================================");
break;
}else if (show.equalsIgnoreCase("N")){
break;
}else {
System.out.println("重新输入(Y/N)");
}
}
}
/**
* 叫地主
* @param leftList 上家手牌
* @param playerList 玩家手牌
* @param rightList 下家手牌
* @param specialCard 地主牌
* @param holeCards 底牌
* @return 012上家玩家下家是否成为地主 4分数
*/
public static List
List
//进行叫地主
List
boolean l = (boolean) result.get(0);//是否成为地主
boolean m = (boolean) result.get(1);
boolean r = (boolean) result.get(2);
int point = (int) result.get(3);//分数
System.out.println("底分为:"+point);
objects.add(l);
objects.add(m);
objects.add(r);
Object[] objects1 = returnHoleCardPoint(holeCards);
int holeCardPoint = (int) objects1[1];
System.out.println("底牌为"+holeCards+",并且牌型为"+objects1[0]+",翻"+objects1[1]+"倍");
point*=holeCardPoint;
System.out.println("现在分数为:"+point);
objects.add(point);
return objects;
}
/**
* 打牌
* @param leftList 上家手牌
* @param playerList 玩家手牌
* @param rightList 下家手牌
* @param holeCards 底牌
* @param objects 叫地主返回的参数 012上家玩家下家是否成为地主 4分数
* @param tip 提示
* @return winnerAndPoint 获胜者和分数
*/
public static List
List
CardProduct last = CardProduct.createNullType();//上一次出牌
boolean playing = true;
boolean toLeft = false;//出牌
boolean toMe = false;//我出
boolean toRight = false;
boolean l = (boolean) objects.get(0);//成为地主并且主动出牌
boolean m = (boolean) objects.get(1);
boolean r = (boolean) objects.get(2);
int point = (int) objects.get(3);
if (l) {
leftList.addAll(holeCards);
leftList.sort((o1, o2) -> o2.id - o1.id);
} else if (m) {
playerList.addAll(holeCards);
playerList.sort((o1, o2) -> o2.id - o1.id);
//如果玩家是地主,记牌器去掉底牌
record.updateRecord(holeCards);
} else {
rightList.addAll(holeCards);
rightList.sort((o1, o2) -> o2.id - o1.id);
}
boolean isMe = false;//me获胜
System.out.println("======================================出牌阶段======================================");
Scanner scanner = new Scanner(System.in);
while (playing) {
if (l) {
System.out.println("=======================上家["+leftPlayer.showType()+"]主动出牌=======================");
if (!tip.NoShowsCards) {
System.out.println("上家当前扑克牌:" + leftList);
}
last = CardProduct.createNullType();
Prompt prompt = new Prompt(leftList, last);
if (prompt.prompt.size() > 0) {
CardProducts cardProducts = CardsFactory.builder(prompt.prompt.get(0));
int index = cardProducts.isGreaterThan(last);
if (index >= 0) {
last = cardProducts.list.get(index);
leftList.removeAll(last.list);
System.out.println("上家主动出牌:" + last.list);
if (last.type==GameConstants.TYPE_BOOM){
System.out.println("所出为炸弹翻2倍,现在分数为:"+point*2+"("+point+"*2)");
point*=2;
}
if (!tip.NoShowsCardsNum) {
System.out.println("上家剩余牌数:" + leftList.size());
}
if (leftList.size() == 2) {
System.out.println("上家就剩2牌啦!!!");
} else if (leftList.size() == 1) {
System.out.println("上家就剩1牌啦!!!");
} else if (leftList.size() == 0) {
System.out.println("=======================================================================");
System.out.println("上家赢了!");
System.out.println("你输啦!");
break;
}
toLeft = false;
toMe = true;
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord(last);
System.out.println(record);
System.out.println("===================================================================");
}
}
}
}
if (toLeft) {
System.out.println("=============上家["+leftPlayer.showType()+"]出牌=================");
if (!tip.NoShowsCards) {
System.out.println("上家当前扑克牌:" + leftList);
}
Prompt prompt = new Prompt(leftList, last);
if (prompt.prompt.size() > 0) {
CardProducts cardProducts = CardsFactory.builder(prompt.prompt.get(0));
int index = cardProducts.isGreaterThan(last);
if (index >= 0) {
last = cardProducts.list.get(index);
leftList.removeAll(last.list);
System.out.println("上家出牌:" + last.list);
if (last.type==GameConstants.TYPE_BOOM){
System.out.println("所出为炸弹翻2倍,现在分数为:"+point*2+"("+point+"*2)");
point*=2;
}
if (!tip.NoShowsCardsNum) {
System.out.println("上家剩余牌数:" + leftList.size());
}
if (leftList.size() == 2) {
System.out.println("上家就剩2牌啦!!!");
} else if (leftList.size() == 1) {
System.out.println("上家就剩1牌啦!!!");
} else if (leftList.size() == 0) {
System.out.println("=======================================================================");
System.out.println("上家赢了!");
System.out.println("你输啦!");
break;
}
m = false;
r = false;
l = true;
toLeft = false;
toMe = true;
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord(last);
System.out.println(record);
System.out.println("===================================================================");
}
}
} else {
System.out.println("上家不要");
toLeft = false;
toMe = true;
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord();
System.out.println(record);
System.out.println("===================================================================");
}
}
}
while (m) {
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord();
System.out.println(record);
System.out.println("===================================================================");
}
System.out.println("=======================玩家["+mePlayer.showType()+"]主动出牌=======================");
last = CardProduct.createNullType();
System.out.println("您当前的扑克牌:" + playerList);
System.out.println("请您出牌:(输入?提示 输入,偷看电脑的牌)");
String line = scanner.nextLine();
if (line == null || line.length() == 0) {
continue;
} else if (".".equals(line)) {
System.out.println("主动出牌,不能不出");
continue;
} else if ("?".equals(line)) {
System.out.println("提示:" + new Prompt(playerList, last).prompt);
continue;
} else if (",".equals(line)) {
if (tip.ShowsCardsInTip) {
System.out.println("上家当前扑克牌:" + leftList);
System.out.println("下家当前扑克牌:" + rightList);
}
if (tip.ShowsCardsNumInTip) {
System.out.println("上家剩余牌数:" + leftList.size());
System.out.println("下家剩余牌数:" + rightList.size());
}
if (!tip.ShowsCardsInTip || !tip.ShowsCardsNumInTip) {
System.out.println("尚未开启此功能");
}
continue;
}
List
if (indexes == null) {
System.out.println("您输入的扑克牌无效请重新输入");
continue;
}
CardProducts cardProducts = CardsFactory.builder(CardUtils.getCardsByIndexes(playerList, indexes));
int index = cardProducts.isGreaterThan(last);
// if (index >= 0) {
CardProduct newCardProduct = cardProducts.list.get(index);
last = newCardProduct;
playerList.removeAll(last.list);
System.out.println("出牌成功:" + last);
if (last.type==GameConstants.TYPE_BOOM){
System.out.println("所出为炸弹翻2倍,现在分数为:"+point*2+"("+point+"*2)");
point*=2;
}
if (playerList.size() == 2) {
System.out.println("玩家就剩2牌啦!!!");
} else if (playerList.size() == 1) {
System.out.println("玩家就剩1牌啦!!!");
} else if (playerList.size() == 0) {
System.out.println("=======================================================================");
System.out.println("你赢啦!");
isMe = true;
break;
}
toMe = false;
toRight = !toRight;
// } else {
// System.out.println("不符合游戏规则:" + cardProducts);
//
// continue;
// }
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord(last);
System.out.println(record);
System.out.println("===================================================================");
}
break;
}
if (isMe) {
break;
}
while (toMe) {
System.out.println("=============玩家["+mePlayer.showType()+"]=================");
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord(last);
System.out.println(record);
System.out.println("===================================================================");
}
System.out.println("上一次出牌:" + last);
System.out.println("您当前的扑克牌:" + playerList);
System.out.println("请您出牌:(输入.不出 输入?提示 输入,偷看电脑的牌)");
String line = scanner.nextLine();
if (line == null || line.length() == 0) {
continue;
} else if (".".equals(line)) {
toMe = false;
toRight = true;
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord();
System.out.println("===================================================================");
}
break;
} else if ("?".equals(line)) {
System.out.println("提示:" + new Prompt(playerList, last).prompt);
continue;
} else if (",".equals(line)) {
if (tip.ShowsCardsInTip) {
System.out.println("上家当前扑克牌:" + leftList);
System.out.println("下家当前扑克牌:" + rightList);
}
if (tip.ShowsCardsNumInTip) {
System.out.println("上家剩余牌数:" + leftList.size());
System.out.println("下家剩余牌数:" + rightList.size());
}
if (!tip.ShowsCardsInTip || !tip.ShowsCardsNumInTip) {
System.out.println("尚未开启此功能");
}
continue;
} else {
List
if (indexes == null) {
System.out.println("您输入的扑克牌无效请重新输入");
continue;
}
CardProducts cardProducts = CardsFactory.builder(CardUtils.getCardsByIndexes(playerList, indexes));
int index = cardProducts.isGreaterThan(last);
if (index >= 0) {
CardProduct newCardProduct = cardProducts.list.get(index);
last = newCardProduct;
playerList.removeAll(last.list);
System.out.println("出牌成功:" + last);
if (last.type==GameConstants.TYPE_BOOM){
System.out.println("所出为炸弹翻2倍,现在分数为:"+point*2+"("+point+"*2)");
point*=2;
}
if (playerList.size() == 2) {
System.out.println("玩家就剩2牌啦!!!");
} else if (playerList.size() == 1) {
System.out.println("玩家就剩1牌啦!!!");
} else if (playerList.size() == 0) {
System.out.println("===================================================================================");
System.out.println("你赢啦!");
isMe = true;
break;
}
l = false;
r = false;
m = true;
toMe = false;
toRight = true;
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord(last);
System.out.println(record);
System.out.println("===================================================================");
}
} else {
System.out.println("不符合游戏规则:" + cardProducts);
continue;
}
}
}
if (isMe) {
break;
}
if (r) {
System.out.println("=======================下家["+rightPlayer.showType()+"]主动出牌=======================");
if (!tip.NoShowsCards) {
System.out.println("下家当前扑克牌:" + rightList);
}
last = CardProduct.createNullType();
Prompt prompt = new Prompt(rightList, last);
if (prompt.prompt.size() > 0) {
CardProducts cardProducts = CardsFactory.builder(prompt.prompt.get(0));
int index = cardProducts.isGreaterThan(last);
if (index >= 0) {
last = cardProducts.list.get(index);
rightList.removeAll(last.list);
System.out.println("下家主动出牌:" + last.list);
System.out.println("下家出牌:" + last.list);
if (last.type==GameConstants.TYPE_BOOM){
System.out.println("所出为炸弹翻2倍,现在分数为:"+point*2+"("+point+"*2)");
point*=2;
}
if (!tip.NoShowsCardsNum) {
System.out.println("下家剩余牌数:" + rightList.size());
}
if (rightList.size() == 2) {
System.out.println("下家就剩2牌啦!!!");
} else if (rightList.size() == 1) {
System.out.println("上家就剩1牌啦!!!");
} else if (rightList.size() == 0) {
System.out.println("===================================================================================");
System.out.println("下家赢了!");
System.out.println("你输啦!");
break;
}
toRight = false;
toLeft = true;
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord(last);
System.out.println(record);
System.out.println("===================================================================");
}
}
}
}
if (toRight) {
System.out.println("=============下家["+rightPlayer.showType()+"]出牌=================");
if (!tip.NoShowsCards) {
System.out.println("下家当前扑克牌:" + rightList);
}
Prompt prompt = new Prompt(rightList, last);
if (prompt.prompt.size() > 0) {
CardProducts cardProducts = CardsFactory.builder(prompt.prompt.get(0));
int index = cardProducts.isGreaterThan(last);
if (index >= 0) {
last = cardProducts.list.get(index);
rightList.removeAll(last.list);
System.out.println("下家出牌:" + last.list);
if (last.type==GameConstants.TYPE_BOOM){
System.out.println("所出为炸弹翻2倍,现在分数为:"+point*2+"("+point+"*2)");
point*=2;
}
if (!tip.NoShowsCardsNum) {
System.out.println("下家剩余牌数:" + rightList.size());
}
if (rightList.size() == 2) {
System.out.println("上家就剩2牌啦!!!");
} else if (rightList.size() == 1) {
System.out.println("上家就剩1牌啦!!!");
} else if (rightList.size() == 0) {
System.out.println("===================================================================================");
System.out.println("下家赢了!");
System.out.println("你输啦!");
break;
}
l = false;
m = false;
r = true;
toRight = false;
toLeft = true;
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord(last);
System.out.println(record);
System.out.println("===================================================================");
}
}
} else {
System.out.println("下家不要");
toRight = false;
toLeft = true;
if (setRecord.SetRecordCards){
System.out.println("==============================记牌器===============================");
record.updateRecord();
System.out.println(record);
System.out.println("===================================================================");
}
}
}
}
//每局的获胜者
Player winnerOneTime;
if (playerList.size() == 0) {
winnerOneTime = mePlayer;
} else if (leftList.size() == 0) {
winnerOneTime = leftPlayer;
} else {
winnerOneTime = rightPlayer;
}
winnerAndPoint.add(winnerOneTime);
winnerAndPoint.add(point);
System.out.println("胜利者为"+ winnerOneTime +"分数"+point);
System.out.println("===================================================================================");
return winnerAndPoint;
}
/**
* 结算
* @param count 局次
* @param winner 获胜者
* @param point 分数
* @return result 结算
*/
public static String settlePoints(int count, Player winner, int point) {
int lastLBP = leftPlayer.bonusPoint;
int lastMBP = mePlayer.bonusPoint;
int lastRBP = rightPlayer.bonusPoint;
String leftSettle = "";
String meSettle = "";
String rightSettle = "";
if (winner.type == GameConstants.TYPE_Landlord) {
if (winner.equals(leftPlayer)) {
leftPlayer.bonusPoint += point * 2;
leftSettle = "" + leftPlayer.bonusPoint + " (" + lastLBP + "+" + point*2 + ")";
mePlayer.bonusPoint -= point;
meSettle = "" + mePlayer.bonusPoint + " (" + lastMBP + "-" + point + ")";
rightPlayer.bonusPoint -= point;
rightSettle = "" + rightPlayer.bonusPoint + " (" + lastRBP + "-" + point + ")";
} else if (winner.equals(mePlayer)) {
leftPlayer.bonusPoint -= point;
leftSettle = "" + leftPlayer.bonusPoint + " (" + lastLBP + "-" + point + ")";
mePlayer.bonusPoint += point * 2;
meSettle = "" + mePlayer.bonusPoint + " (" + lastMBP + "+" + point*2 + ")";
rightPlayer.bonusPoint -= point;
rightSettle = "" + rightPlayer.bonusPoint + " (" + lastRBP + "-" + point + ")";
} else if (winner.equals(rightPlayer)) {
leftPlayer.bonusPoint -= point;
leftSettle = "" + leftPlayer.bonusPoint + " (" + lastLBP + "-" + point + ")";
mePlayer.bonusPoint -= point;
meSettle = "" + mePlayer.bonusPoint + " (" + lastMBP + "-" + point + ")";
rightPlayer.bonusPoint += point * 2;
rightSettle = "" + rightPlayer.bonusPoint + " (" + lastRBP + "+" + point*2 + ")";
}
} else if (winner.type == GameConstants.TYPE_Farmer) {
if (leftPlayer.type==GameConstants.TYPE_Landlord){
leftPlayer.bonusPoint -= point * 2;
leftSettle = "" + leftPlayer.bonusPoint + " (" + lastLBP + "-" + point*2 + ")";
mePlayer.bonusPoint += point;
meSettle = "" + mePlayer.bonusPoint + " (" + lastMBP + "+" + point + ")";
rightPlayer.bonusPoint += point;
rightSettle = "" + rightPlayer.bonusPoint + " (" + lastRBP + "+" + point + ")";
}else if (mePlayer.type==GameConstants.TYPE_Landlord) {
leftPlayer.bonusPoint += point;
leftSettle = "" + leftPlayer.bonusPoint + " (" + lastLBP + "+" + point + ")";
mePlayer.bonusPoint -= point * 2;
meSettle = "" + mePlayer.bonusPoint + " (" + lastMBP + "-" + point*2 + ")";
rightPlayer.bonusPoint += point;
rightSettle = "" + rightPlayer.bonusPoint + " (" + lastRBP + "+" + point + ")";
}else{
leftPlayer.bonusPoint += point;
leftSettle = "" + leftPlayer.bonusPoint + " (" + lastLBP + "+" + point + ")";
mePlayer.bonusPoint += point;
meSettle = "" + mePlayer.bonusPoint + " (" + lastMBP + "+" + point + ")";
rightPlayer.bonusPoint -= point * 2;
rightSettle = "" + rightPlayer.bonusPoint + " (" + lastRBP + "-" + point*2 + ")";
}
}
String result;
String bolder = "--------------------------------------------------------------------------------\n";
String header = "| "+"局次\t|" + " 获胜者\t\t\t|" + " 上家积分结算\t|" + " 玩家积分结算\t|" + " 下家积分结算\t|"+" 分数"+" |\n";
String settle = "| "+count + " \t| " + winner + "\t| " + leftSettle+ "\t\t| " + meSettle +"\t\t| " + rightSettle+"\t\t| "+point+" |\n";
result = bolder + header+settle;
return result;
}
/**
* 添加战绩
* @param s 结算
*/
public static void addGrate(String s){
grate=grate+s;
}
//测试settlePoints和addGrate
@Test
public void testSettlePoints() {
System.out.println("=====================结算===================");
mePlayer.type=GameConstants.TYPE_Landlord;
String s = settlePoints(2, mePlayer, 1);
System.out.println(s);
addGrate(s);
System.out.println("===========================================");
System.out.println("=====================结算===================");
mePlayer.type=GameConstants.TYPE_Landlord;
String s1 = settlePoints(3, mePlayer, 1);
System.out.println(s1);
addGrate(s1);
System.out.println("===========================================");
System.out.println("================展示战绩====================");
System.out.println(grate);
System.out.println("===========================================");
}
}
RecordCards
package com.ddz;
import java.util.ArrayList;
import java.util.List;
/**
* 记牌器
*/
public class RecordCards {
public List
public int sum = 1;
public boolean contains345 = true;
public RecordCards() {
this(1,true);
}
public RecordCards(int sum, boolean contains345) {
//牌堆
ArrayList
for (int i = 0; i < sum; i++) {
for (int j = contains345 ? GameConstants.ID_3_1 : GameConstants.ID_6_1; j < 54; j++) {
list.add(new Card(j));
}
}
this.remainingCards=list;
}
public RecordCards(List
this.remainingCards = remainingCards;
}
//不要
public void updateRecord(){}
//去除出牌
public void updateRecord(CardProduct last) {
remainingCards.removeAll(last.list);
}
//去除手牌
public void updateRecord(List
remainingCards.removeAll(list);
}
//不会出现0
public String tableToString1() {
String line="-----";
String form = "";
String header = "|点数";
String record = "|余数";
String everyLine="----";
List
for (Card card:remainingCards) {
save.add(card);
}
if (save.contains(new Card(GameConstants.ID_JOKER_2))){
line+=everyLine;
header+="| C\t";
record +="| 1\t";
save.remove(new Card(GameConstants.ID_JOKER_2));
}
if (save.contains(new Card(GameConstants.ID_JOKER_1))){
line+=everyLine;
header+="| c\t";
record +="| 1\t";
save.remove(new Card(GameConstants.ID_JOKER_1));
}
CardProducts groups = CardsFactory.builder(save);
List
group.sort((o1, o2) -> {
//order by num desc
return o2.num - o1.num;
});
for (CardGroup cards : group) {
String numString = "";
int cardNum = cards.num+3;
if (cardNum < 10) {
line+=everyLine;
numString = Integer.toString(cardNum);
} else if (cardNum == 10) {
line+=everyLine;
numString = "0";
} else if (cardNum == 11) {
line+=everyLine;
numString = "J";
} else if (cardNum == 12) {
line+=everyLine;
numString = "Q";
} else if (cardNum == 13) {
line+=everyLine;
numString = "K";
} else if (cardNum == 14) {
line+=everyLine;
numString = "A";
} else if (cardNum == 15) {
line+=everyLine;
numString = "2";
}
Card card = new Card(numString);
if (card.num==GameConstants.NUM_10){
header += "| "+"0"+"\t";
}else {
header += "| "+card+"\t";
}
record += "| "+cards.sum+"\t";
}
form = line+"\n"+header + "|\n" + record +"|\n"+line;
return form;
}
//会出现0
public String tableToString2() {
String line="-----------------------------------------------------------------";
String form = "";
String header = "|点数| C\t| c\t| 2\t| A\t| K\t| Q\t| J\t| 0\t| 9\t| 8\t| 7\t| 6\t| 5\t| 4\t| 3\t";
String record = "|余数";
remainingCards.sort((o1, o2) -> {
return o2.id-o1.id;
});
// Map
//桶排序
int [] ints=new int[15];
for (Card card: remainingCards) {
if (card.id==GameConstants.ID_JOKER_2){
ints[14]=1;
}else if(card.id==GameConstants.ID_JOKER_1){
ints[13]=1;
}else {
switch (card.num){
case GameConstants.NUM_2:ints[12]+=1;break;
case GameConstants.NUM_A:ints[11]+=1;break;
case GameConstants.NUM_K:ints[10]+=1;break;
case GameConstants.NUM_Q:ints[9]+=1;break;
case GameConstants.NUM_J:ints[8]+=1;break;
case GameConstants.NUM_10:ints[7]+=1;break;
case GameConstants.NUM_9:ints[6]+=1;break;
case GameConstants.NUM_8:ints[5]+=1;break;
case GameConstants.NUM_7:ints[4]+=1;break;
case GameConstants.NUM_6:ints[3]+=1;break;
case GameConstants.NUM_5:ints[2]+=1;break;
case GameConstants.NUM_4:ints[1]+=1;break;
case GameConstants.NUM_3:ints[0]+=1;break;
}
}
}
for (int i = 14; i >-1; i--) {
record+="| "+ints[i]+"\t";
}
form = line+"\n"+header + "|\n" + record +"|\n"+line;
return form;
}
@Override
public String toString() {
return tableToString2();
}
//测试
public static void main(String[] args) {
RecordCards recordCards = new RecordCards(1,true);
CardProducts builder1 = CardsFactory.builder("1234657890jqkCc");
CardProducts builder2 = CardsFactory.builder("1234657890jqk");
CardProducts builder3 = CardsFactory.builder("1234657890jqk");
CardProducts builder4 = CardsFactory.builder("1234657890jqk");
List
List
List
List
// System.out.println("list2"+list2);
CardProduct cardProduct1= list1.get(0);
CardProduct cardProduct2= list2.get(0);
CardProduct cardProduct3= list3.get(0);
CardProduct cardProduct4= list4.get(0);
// System.out.println("cardProduct2"+cardProduct2);
// List
// System.out.println("list21"+list21);
//
// recordCards.updateRecord(cardProduct1);
// recordCards.updateRecord( cardProduct2);
// recordCards.updateRecord(cardProduct3);
// recordCards.updateRecord(cardProduct4);
// System.out.println(recordCards);
List
cards.add(new Card(0));
cards.add(new Card(2));
cards.add(new Card(1));
cards.add(new Card(3));
recordCards.updateRecord(cards);
System.out.println(recordCards);
}
}
SetRecordCards
package com.ddz;
public class SetRecordCards {
boolean SetRecordCards=false;
public SetRecordCards() {
}
public SetRecordCards(boolean setRecordCards) {
SetRecordCards = setRecordCards;
}
}
五、记牌器的原理
记牌器初始是所有牌,牌堆 然后去除地主牌3张,再去除3家的手牌 之后每一次出牌都会去除 然后把剩余牌列表点数从大到小,并列出它的点数 尤其是大小王这里必须注意
还有就是牌会变成0个,后面优化一下, 把0的牌不在列表中展示