设为首页 收藏本站 切换到窄版 天气与日历
立即注册
 找回密码
 立即注册

美闻网-美图新闻论坛网

搜索
热搜: 活动 交友 discuz
返回列表
查看: 107|回复: 0

斗地主-android(棋牌)

[复制链接]

3

主题

10

帖子

26

积分

新手上路

Rank: 1

积分
26
发表于 2018-8-13 18:33:29 | 显示全部楼层 |阅读模式
本文实现了android端单机版的斗地主, 一共三个玩家(一个地主,二个农民) 游戏进入后,针对上家出的牌,如果本家有大的牌,可以出牌,如果没有相应的牌,可以选择不要牌, 在组合牌型时,如果不符合斗地主的牌型要求,是不能出牌的,如果组合的牌型不能大过上家的牌,也是不能出牌的

本示例提供源码,需要源码的朋友可以下载

android开发环境配置 http://www.wisdomdd.cn/Wisdom/resource/articleDetail.htm?resourceId=1028

本项目是一个单机的斗地主项目源码,不过这个项目的分辨率有点问题,我在真机和模拟器的480*800上无论是横屏还是竖屏游戏都只能显示一部分画面,可能项目是使用的更低分辨率创建的,不过我玩了玩这个项目的却比javaapk.com以前发的斗地主项目算法要好一些,分配地主发牌都是随机的,根据谁的牌数先为0就是谁赢,再根据他的Id判断他是农民还是地主,每个人自动生成3分,结束后赢家加分输家扣分源码有注释,编码GBK默认编译版本4.4.2,需要的朋友可以下载研究一下

源码介绍:

扑克牌
publicclassCard {
intvalue=0;
intpokeType=0;
int[] pokes;
Bitmap pokeImage;
intpersonID;
publicCard(int[] pokes,Bitmap pokeImage,intid)
{
this.personID=id;
this.pokes=pokes;
this.pokeImage=pokeImage;
pokeType=Poke.getPokeType(pokes);
value=Poke.getPokeTypeValue(pokes, pokeType);
//显示的正确排列
// 如果有炸弹牌出现,分数翻倍
if(pokeType==PokeType.huojian||pokeType==PokeType.zhadan)
{
Desk.currentScore*=2;
}
}
publicvoidpaint(Canvas canvas,intleft,inttop,intdir)
{
Rect src = newRect();
Rect des = newRect();
for(inti = 0; i < pokes.length; i++) {
introw = Poke.getImageRow(pokes);
intcol = Poke.getImageCol(pokes);
if(dir == PokeType.dirV) {
row = Poke.getImageRow(pokes);
col = Poke.getImageCol(pokes);
src.set(col * 35, row * 52, col * 35+ 35, row * 52+ 52);
des.set(left, top + i * 13, left + 35, top + 52+ i * 13);
} else{
row = Poke.getImageRow(pokes);
col = Poke.getImageCol(pokes);
intselect = 0;
src.set(col * 35, row * 52, col * 35+ 35, row * 52+ 52);
des.set(left + i * 13, top - select, left + 35+ i * 13, top
- select + 52);
}
canvas.drawBitmap(pokeImage, src, des, null);
}
}
}

牌桌:Desk


publicclassDesk {
publicstaticintwinId = -1;
Bitmap pokeImage;
Bitmap tishi;
Bitmap buyao;
Bitmap chupai;
publicstaticint[] personScore = newint[3];
publicstaticintthreePokes[] = newint[3];// 三张底牌
privateintthreePokesPos[][] = newint[][] { { 170, 17}, { 220, 17},
{ 270, 17} };
privateint[][] rolePos = { { 60, 310}, { 63, 19}, { 396, 19}, };
publicstaticPerson[] persons = newPerson[3];// 三个玩家
publicstaticint[] deskPokes = newint[54];// 一副扑克牌
publicstaticintcurrentScore = 3;// 当前分数
publicstaticintboss = 0;// 地主
/**
* -2:发牌<br>
* -1:随机地主<br>
* 0:游戏中 <br>
* 1:游戏结束,重新来,活退出<br>
*/
privateintop = -1;// 游戏的进度控制
publicstaticintcurrentPerson = 0;// 当前操作的人
publicstaticintcurrentCircle = 0;// 本轮次数
publicstaticCard currentCard = null;// 最新的一手牌
publicint[][] personPokes = newint[3][17];
// gaming
privateinttimeLimite = 310;
privateint[][] timeLimitePos = { { 130, 205}, { 118, 76}, { 327, 76} };
privateintopPosX = 240;
privateintopPosY = 200;
DDZ ddz;
publicDesk(DDZ ddz) {
this.ddz = ddz;
pokeImage = BitmapFactory.decodeResource(ddz.getResources(),
R.drawable.poker3552);
tishi = BitmapFactory
.decodeResource(ddz.getResources(), R.drawable.cp0);
buyao = BitmapFactory
.decodeResource(ddz.getResources(), R.drawable.cp1);
chupai = BitmapFactory.decodeResource(ddz.getResources(),
R.drawable.cp2);
// init();
}
publicvoidgameLogic() {
switch(op) {
case-2:
break;
case-1:
init();
op = 0;
break;
case0:
gaming();
break;
case1:
break;
case2:
break;
}
}
// 存储当前一句的胜负得分信息
intrs[] = newint[3];
privatevoidgaming() {
for(intk = 0; k < 3; k++) {
// 当三个人中其中一个人牌的数量为0,则游戏结束
if(persons[k].pokes.length == 0) {
// 切换到游戏结束状态
op = 1;
// 得到最先出去的人的id
winId = k;
// 判断哪方获胜
if(boss == winId) {
// 地主方获胜后的积分操作
for(inti = 0; i < 3; i++) {
if(i == boss) {
// 地主需要加两倍积分
rs = currentScore * 2;
personScore += currentScore * 2;
} else{
// 农民方需要减分
rs = -currentScore;
personScore -= currentScore;
}
}
} else{
// 如果农民方胜利
for(inti = 0; i < 3; i++) {
if(i != boss) {
// 农民方加分
rs = currentScore;
personScore += currentScore;
} else{
// 地主方减分
rs = -currentScore * 2;
personScore -= currentScore * 2;
}
}
}
return;
}
}
// 游戏没有结束,继续。
// 如果本家ID是NPC,则执行语句中的操作
if(currentPerson == 1|| currentPerson == 2) {
if(timeLimite <= 300) {
// 获取手中的牌中能够打过当前手牌
Card tempcard = persons[currentPerson].chupaiAI(currentCard);
if(tempcard != null) {
// 手中有大过的牌,则出
currentCircle++;
currentCard = tempcard;
nextPerson();
} else{
// 没有打过的牌,则不要
buyao();
}
}
}
// 时间倒计时
timeLimite -= 2;
}
publicvoidinit() {
deskPokes = newint[54];
personPokes = newint[3][17];
threePokes = newint[3];
winId = -1;
currentScore = 3;
currentCard = null;
currentCircle = 0;
currentPerson = 0;
for(inti = 0; i < deskPokes.length; i++) {
deskPokes = i;
}
Poke.shuffle(deskPokes);
fenpai(deskPokes);
randDZ();
Poke.sort(personPokes[0]);
Poke.sort(personPokes[1]);
Poke.sort(personPokes[2]);
persons[0] = newPerson(personPokes[0], 234, 96, PokeType.dirH, 0,
this, ddz);
persons[1] = newPerson(personPokes[1], 54, 28, PokeType.dirV, 1, this,
ddz);
persons[2] = newPerson(personPokes[2], 54, 417, PokeType.dirV, 2,
this, ddz);
persons[0].setPosition(persons[1], persons[2]);
persons[1].setPosition(persons[2], persons[0]);
persons[2].setPosition(persons[0], persons[1]);
AnalyzePoke ana = AnalyzePoke.getInstance();
for(inti = 0; i < persons.length; i++) {
booleanb = ana.testAnalyze(personPokes);
if(!b) {
init();
System.out.println("chongqinglaiguo");
break;
}
}
for(inti = 0; i < 3; i++) {
StringBuffer sb = newStringBuffer();
sb.append("chushipai---"+ i + ":");
for(intj = 0; j < personPokes.length; j++) {
sb.append(personPokes[j] + ",");
}
System.out.println(sb.toString());
}
}
// 随机地主,将三张底牌给地主
privatevoidrandDZ() {
boss = Poke.getDZ();
currentPerson = boss;
int[] newPersonPokes = newint[20];
for(inti = 0; i < 17; i++) {
newPersonPokes = personPokes[boss];
}
newPersonPokes[17] = threePokes[0];
newPersonPokes[18] = threePokes[1];
newPersonPokes[19] = threePokes[2];
personPokes[boss] = newPersonPokes;
}
publicvoidfenpai(int[] pokes) {
for(inti = 0; i < 51;) {
personPokes[i / 17][i % 17] = pokes[i++];
}
threePokes[0] = pokes[51];
threePokes[1] = pokes[52];
threePokes[2] = pokes[53];
}
publicvoidresult() {
}
publicvoidpaint(Canvas canvas) {
switch(op) {
case-2:
break;
case-1:
break;
case0:
paintGaming(canvas);
break;
case1:
paintResult(canvas);
break;
case2:
break;
}
}
privatevoidpaintResult(Canvas canvas) {
Paint paint = newPaint();
paint.setColor(Color.WHITE);
paint.setTextSize(20);
canvas.drawText("本局得分 总分 ", 110, 66, paint);
for(inti = 0; i < 3; i++) {
canvas.drawText(i + ":本局得分:"+ rs + " 总分:"+ personScore,
110, 96+ i * 30, paint);
}
}
privatevoidpaintGaming(Canvas canvas) {
persons[0].paint(canvas);
persons[1].paint(canvas);
persons[2].paint(canvas);
paintThreePokes(canvas);
paintRoleAndScore(canvas);
if(currentPerson == 0) {
Rect src = newRect();
Rect dst = newRect();
src.set(0, 0, chupai.getWidth(), chupai.getHeight());
dst.set(opPosX, opPosY, opPosX + chupai.getWidth(), opPosY
+ chupai.getHeight());
canvas.drawBitmap(chupai, src, dst, null);
if(currentCircle != 0) {
src.set(0, 0, tishi.getWidth(), tishi.getHeight());
dst.set(opPosX + 40, opPosY, opPosX + tishi.getWidth() + 40,
opPosY + tishi.getHeight());
canvas.drawBitmap(tishi, src, dst, null);
src.set(0, 0, buyao.getWidth(), buyao.getHeight());
dst.set(opPosX - 40, opPosY, opPosX + buyao.getWidth() - 40,
opPosY + buyao.getHeight());
canvas.drawBitmap(buyao, src, dst, null);
}
}
if(persons[0].card != null) {
persons[0].card.paint(canvas, 130, 140, PokeType.dirH);
}
if(persons[1].card != null) {
persons[1].card.paint(canvas, 73, 56, PokeType.dirV);
}
if(persons[2].card != null) {
persons[2].card.paint(canvas, 365, 56, PokeType.dirV);
}
paintTimeLimite(canvas);
Paint paint = newPaint();
paint.setTextAlign(Align.LEFT);
paint.setStyle(Style.FILL_AND_STROKE);
paint.setTextSize(14);
canvas.drawText("当前底分:"+ currentScore, 165, 308, paint);
}
privatevoidpaintTimeLimite(Canvas canvas) {
Paint paint = newPaint();
paint.setColor(Color.BLUE);
paint.setTextSize(16);
for(inti = 0; i < 3; i++) {
if(i == currentPerson) {
canvas.drawText(""+ (timeLimite / 10), timeLimitePos[0],
timeLimitePos[1], paint);
}
}
}
privatevoidpaintRoleAndScore(Canvas canvas) {
Paint paint = newPaint();
for(inti = 0; i < 3; i++) {
if(boss == i) {
paint.setColor(Color.RED);
canvas.drawText("地主(得分:"+ personScore + ")", rolePos[0],
rolePos[1], paint);
} else{
paint.setColor(Color.WHITE);
canvas.drawText("农民(得分:"+ personScore + ")", rolePos[0],
rolePos[1], paint);
}
}
}
privatevoidpaintThreePokes(Canvas canvas) {
Rect src = newRect();
Rect dst = newRect();
for(inti = 0; i < 3; i++) {
introw = Poke.getImageRow(threePokes);
intcol = Poke.getImageCol(threePokes);
src.set(col * 35, row * 52, col * 35+ 35, row * 52+ 52);
dst.set(threePokesPos[0], threePokesPos[1],
threePokesPos[0] + 35, threePokesPos[1] + 52);
canvas.drawBitmap(pokeImage, src, dst, null);
}
}
publicvoidonTuch(View v, MotionEvent event) {
for(inti = 0; i < persons.length; i++) {
StringBuffer sb = newStringBuffer();
sb.append(i + " : ");
for(intj = 0; j < persons.pokes.length; j++) {
sb.append(persons.pokes[j]
+ (persons.pokes[j] >= 10? "": " ") + ",");
}
System.out.println(sb.toString());
}
if(op == 1) {
System.out.println("ddz.handler:"+ ddz.handler);
init();
op = 0;
// ddz.handler.sendEmptyMessage(DDZActivity.MENU);
}
if(currentPerson != 0) {
return;
}
intx = (int) event.getX();
inty = (int) event.getY();
if(Poke.inRect(x, y, opPosX, opPosY, 38, 23)) {
System.out.println("chupai");
Card card = persons[0].chupai(currentCard);
if(card != null) {
currentCard = card;
currentCircle++;
nextPerson();
}
}
if(currentCircle != 0) {
if(Poke.inRect(x, y, opPosX - 40, opPosY, 38, 23)) {
System.out.println("buyao");
buyao();
}
}
if(Poke.inRect(x, y, opPosX + 40, opPosY, 38, 23)) {
System.out.println("tishi");
tishi();
}
persons[0].onTuch(v, event);
}
privatevoidtishi() {
}
//不要牌的操作
privatevoidbuyao() {
// 轮到下一个人
currentCircle++;
// 清空当前不要牌的人的最后一手牌
persons[currentPerson].card = null;
// 定位下一个人的id
nextPerson();
// 如果已经转回来,则该人继续出牌,本轮清空,新一轮开始
if(currentCard != null&& currentPerson == currentCard.personID) {
currentCircle = 0;
currentCard = null;// 转回到最大牌的那个人再出牌
persons[currentPerson].card = null;
}
}
// 定位下一个人的id并重新倒计时
privatevoidnextPerson() {
switch(currentPerson) {
case0:
currentPerson = 2;
break;
case1:
currentPerson = 0;
break;
case2:
currentPerson = 1;
break;
}
timeLimite = 310;
}
}

胡牌分析器:AnalyzePoke


packagecom.peiandsky;
importjava.util.Vector;
publicclassAnalyzePoke {
privateint[] pokes;
privateint[] countPokes = newint[12];
privateintcount2;
privateintcountWang;
privateVector<int[]> card_zhadan = newVector<int[]>(3);
privateVector<int[]> card_sanshun = newVector<int[]>(3);
privateVector<int[]> card_shuangshun = newVector<int[]>(3);
privateVector<int[]> card_sanzhang = newVector<int[]>(3);
privateVector<int[]> card_danshun = newVector<int[]>(3);
privateVector<int[]> card_duipai = newVector<int[]>(3);
privateVector<int[]> card_danpai = newVector<int[]>(5);
publicint[] getCountPokes() {
returncountPokes;
}
publicintgetCount2() {
returncount2;
}
publicintgetCountWang() {
returncountWang;
}
publicVector<int[]> getCard_zhadan() {
returncard_zhadan;
}
publicVector<int[]> getCard_sanshun() {
returncard_sanshun;
}
publicVector<int[]> getCard_shuangshun() {
returncard_shuangshun;
}
publicVector<int[]> getCard_sanzhang() {
returncard_sanzhang;
}
publicVector<int[]> getCard_danshun() {
returncard_danshun;
}
publicVector<int[]> getCard_duipai() {
returncard_duipai;
}
publicVector<int[]> getCard_danpai() {
returncard_danpai;
}
privateAnalyzePoke() {
}
publicstaticAnalyzePoke getInstance() {
// if (analyzePoke == null) {
// analyzePoke = new AnalyzePoke();
// }
// return analyzePoke;
returnnewAnalyzePoke();
}
privatevoidinit() {
for(inti = 0; i < countPokes.length; i++) {
countPokes = 0;
}
count2 = 0;
countWang = 0;
card_zhadan.clear();
card_sanshun.clear();
card_shuangshun.clear();
card_sanzhang.clear();
card_danshun.clear();
card_duipai.clear();
card_danpai.clear();
}
publicbooleanlastCardTypeEq(intpokeType) {
if(remainCount() > 1) {
returnfalse;
}
switch(pokeType) {
casePokeType.sanzhang:
returncard_sanzhang.size() == 1;
casePokeType.duipai:
returncard_duipai.size() == 1;
casePokeType.danpai:
returncard_danpai.size() == 1;
}
returnfalse;
}
publicint[] getPokes() {
returnpokes;
}
publicvoidsetPokes(int[] pokes) {
Poke.sort(pokes);
this.pokes = pokes;
try{
this.analyze();
} catch(Exception e) {
e.printStackTrace();
}
}
publicintremainCount() {
returncard_zhadan.size() + card_sanshun.size()
+ card_shuangshun.size() + card_sanzhang.size()
+ card_danshun.size() + card_duipai.size() + card_danpai.size();
}
publicint[] getMinType(Person last, Person next) {
AnalyzePoke lastAna = AnalyzePoke.getInstance();
lastAna.setPokes(last.pokes);
AnalyzePoke nextAna = AnalyzePoke.getInstance();
nextAna.setPokes(next.pokes);
intlastCount = lastAna.remainCount();
intnextCount = nextAna.remainCount();
intneedSmart = -1;
if(Desk.boss == next.id
|| (Desk.boss != next.id && Desk.boss != last.id)) {
// 是对手
if(next.pokes.length <= 2) {
needSmart = next.pokes.length;
}
}
// TODO
intpokeType = -1;
intminValue = 55;
intpokeIdx = 0;
intsize;
Vector<int[]> temp;
temp = card_sanshun;
size = temp.size();
for(inti = 0; i < size; i++) {
int[] p = temp.elementAt(i);
if(minValue > p[0]) {
pokeType = PokeType.sanshun;
minValue = p[0];
pokeIdx = i;
}
}
temp = card_shuangshun;
size = temp.size();
for(inti = 0; i < size; i++) {
int[] p = temp.elementAt(i);
if(minValue > p[0]) {
pokeType = PokeType.shuangshun;
minValue = p[0];
pokeIdx = i;
}
}
temp = card_danshun;
size = temp.size();
for(inti = 0; i < size; i++) {
int[] p = temp.elementAt(i);
if(minValue > p[0]) {
pokeType = PokeType.danshun;
minValue = p[0];
pokeIdx = i;
}
}
temp = card_sanzhang;
size = temp.size();
for(inti = 0; i < size; i++) {
int[] p = temp.elementAt(i);
if(minValue > p[0]) {
pokeType = PokeType.sanzhang;
minValue = p[0];
pokeIdx = i;
}
}
if(needSmart == 2) {
if(pokeType != -1) {
returnnewint[] { pokeType, pokeIdx };
} else{
temp = card_duipai;
size = temp.size();
intmin2 = -1;
for(inti = 0; i < size; i++) {
int[] p = temp.elementAt(i);
if(min2 <= p[0]) {
pokeType = PokeType.duipai;
minValue = p[0];
min2 = p[0];
pokeIdx = i;
}
}
}
} else{
temp = card_duipai;
size = temp.size();
for(inti = 0; i < size; i++) {
int[] p = temp.elementAt(i);
if(minValue > p[0]) {
pokeType = PokeType.duipai;
minValue = p[0];
pokeIdx = i;
}
}
}
if(needSmart == 1) {
if(pokeType != -1) {
returnnewint[] { pokeType, pokeIdx };
} else{
intmin1 = -1;
for(inti = 0; i < size; i++) {
int[] p = temp.elementAt(i);
if(min1 <= p[0]) {
pokeType = PokeType.danpai;
minValue = p[0];
min1 = p[0];
pokeIdx = i;
}
}
}
} else{
temp = card_danpai;
size = temp.size();
for(inti = 0; i < size; i++) {
int[] p = temp.elementAt(i);
if(minValue > p[0]) {
pokeType = PokeType.danpai;
minValue = p[0];
pokeIdx = i;
}
}
}
returnnewint[] { pokeType, pokeIdx };
}
publicbooleantestAnalyze(intpokes[]) {
try{
init();
for(inti = 0; i < pokes.length; i++) {
intv = Poke.getPokeValue(pokes);
if(v == 16|| v == 17) {
countWang++;
} elseif(v == 15) {
count2++;
} else{
countPokes[v - 3]++;
}
}
// System.out.println(" analyze sanshun");
// 三顺
intstart = -1;
intend = -1;
for(inti = 0; i <= countPokes.length - 1; i++) {
if(countPokes == 3) {
if(start == -1) {
start = i;
} else{
end = i;
}
} else{
if(end != -1&& start != -1) {
intdur = end - start + 1;
int[] ss = newint[dur * 3];
intm = 0;
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v >= start && v <= end) {
ss[m++] = pokes[j];
}
}
if(m == dur * 3- 1) {
System.out.println("sanshun is over!!!");
} else{
System.out.println("sanshun error!!!");
}
card_sanshun.addElement(ss);
for(ints = start; s <= end; s++) {
countPokes = -1;
}
start = end = -1;
continue;
} else{
start = end = -1;
}
}
}
// System.out.println(" analyze shuangshun");
// shuangshun
intsstart = -1;
intsend = -1;
for(inti = 0; i < countPokes.length; i++) {
if(countPokes == 2) {
if(sstart == -1) {
sstart = i;
} else{
send = i;
}
} else{
if(sstart != -1&& send != -1) {
intdur = send - sstart + 1;
if(dur < 3) {
sstart = send = -1;
continue;
} else{
intshuangshun[] = newint[dur * 2];
intm = 0;
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v >= sstart && v <= send) {
shuangshun[m++] = pokes[j];
}
}
card_shuangshun.addElement(shuangshun);
for(ints = sstart; s <= send; s++) {
countPokes = -1;
}
sstart = send = -1;
continue;
}
} else{
sstart = send = -1;
}
}
}
// System.out.println(" analyze danshun");
// danshun
intdstart = -1;
intdend = -1;
for(inti = 0; i < countPokes.length; i++) {
if(countPokes >= 1) {
if(dstart == -1) {
dstart = i;
} else{
dend = i;
}
} else{
if(dstart != -1&& dend != -1) {
intdur = dend - dstart + 1;
if(dur >= 5) {
intm = 0;
int[] danshun = newint[dur];
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v == dend) {
danshun[m++] = pokes[j];
countPokes[dend]--;
dend--;
}
if(dend == dstart - 1) {
break;
}
}
card_danshun.addElement(danshun);
}
dstart = dend = -1;
} else{
dstart = dend = -1;
}
}
}
// System.out.println(" analyze sanzhang");
// sanzhang
for(inti = 0; i < countPokes.length; i++) {
if(countPokes == 3) {
countPokes = -1;
int[] sanzhang = newint[3];
intm = 0;
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v == i) {
sanzhang[m++] = pokes[j];
}
}
card_sanzhang.addElement(sanzhang);
}
}
// System.out.println(" analyze duipai");
// duipai
for(inti = 0; i < countPokes.length; i++) {
if(countPokes == 2) {
int[] duipai = newint[2];
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v == i) {
duipai[0] = pokes[j];
duipai[1] = pokes[j + 1];
card_duipai.addElement(duipai);
break;
}
}
countPokes = -1;
}
}
// System.out.println(" analyze danpai");
// danpai
for(inti = 0; i < countPokes.length; i++) {
if(countPokes == 1) {
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v == i) {
card_danpai.addElement(newint[] { pokes[j] });
countPokes = -1;
break;
}
}
}
}
// System.out.println(" analyze 2 ");
switch(count2) {
case4:
card_zhadan.addElement(newint[] { pokes[countWang],
pokes[countWang + 1], pokes[countWang + 2],
pokes[countWang + 3] });
break;
case3:
card_sanzhang.addElement(newint[] { pokes[countWang],
pokes[countWang + 1], pokes[countWang + 2] });
break;
case2:
card_duipai.addElement(newint[] { pokes[countWang],
pokes[countWang + 1] });
break;
case1:
card_danpai.addElement(newint[] { pokes[countWang] });
break;
}
// System.out.println(" analyze zhadan");
// 炸弹
for(inti = 0; i < countPokes.length - 1; i++) {
if(countPokes == 4) {
card_zhadan.addElement(newint[] { i * 4+ 3, i * 4+ 2,
i * 4+ 1, i * 4});
countPokes = -1;
}
}
// System.out.println(" analyze wang");
if(countWang == 1) {
card_danpai.addElement(newint[] { pokes[0] });
} elseif(countWang == 2) {
card_zhadan.addElement(newint[] { pokes[0], pokes[1] });
}
} catch(Exception e) {
e.printStackTrace();
returnfalse;
}
returntrue;
}
// 分析几大主要牌型
privatevoidanalyze() {
// 初始化牌型容器
init();
// 分析王,2,普通牌的数量
for(inti = 0; i < pokes.length; i++) {
intv = Poke.getPokeValue(pokes);
if(v == 16|| v == 17) {
countWang++;
} elseif(v == 15) {
count2++;
} else{
countPokes[v - 3]++;
}
}
// 分析三顺牌型
intstart = -1;
intend = -1;
for(inti = 0; i <= countPokes.length - 1; i++) {
if(countPokes == 3) {
if(start == -1) {
start = i;
} else{
end = i;
}
} else{
if(end != -1&& start != -1) {
intdur = end - start + 1;
int[] ss = newint[dur * 3];
intm = 0;
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v >= start && v <= end) {
ss[m++] = pokes[j];
}
}
if(m == dur * 3- 1) {
System.out.println("sanshun is over!!!");
} else{
System.out.println("sanshun error!!!");
}
card_sanshun.addElement(ss);
for(ints = start; s <= end; s++) {
countPokes = -1;
}
start = end = -1;
continue;
} else{
start = end = -1;
}
}
}
// 分析双顺牌型
intsstart = -1;
intsend = -1;
for(inti = 0; i < countPokes.length; i++) {
if(countPokes == 2) {
if(sstart == -1) {
sstart = i;
} else{
send = i;
}
} else{
if(sstart != -1&& send != -1) {
intdur = send - sstart + 1;
if(dur < 3) {
sstart = send = -1;
continue;
} else{
intshuangshun[] = newint[dur * 2];
intm = 0;
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v >= sstart && v <= send) {
shuangshun[m++] = pokes[j];
}
}
card_shuangshun.addElement(shuangshun);
for(ints = sstart; s <= send; s++) {
countPokes = -1;
}
sstart = send = -1;
continue;
}
} else{
sstart = send = -1;
}
}
}
// 分析单顺牌型
intdstart = -1;
intdend = -1;
for(inti = 0; i < countPokes.length; i++) {
if(countPokes >= 1) {
if(dstart == -1) {
dstart = i;
} else{
dend = i;
}
} else{
if(dstart != -1&& dend != -1) {
intdur = dend - dstart + 1;
if(dur >= 5) {
intm = 0;
int[] danshun = newint[dur];
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v == dend) {
danshun[m++] = pokes[j];
countPokes[dend]--;
dend--;
}
if(dend == dstart - 1) {
break;
}
}
card_danshun.addElement(danshun);
}
dstart = dend = -1;
} else{
dstart = dend = -1;
}
}
}
// 分析三张牌型
for(inti = 0; i < countPokes.length; i++) {
if(countPokes == 3) {
countPokes = -1;
int[] sanzhang = newint[3];
intm = 0;
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v == i) {
sanzhang[m++] = pokes[j];
}
}
card_sanzhang.addElement(sanzhang);
}
}
// 分析对牌
for(inti = 0; i < countPokes.length; i++) {
if(countPokes == 2) {
int[] duipai = newint[2];
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v == i) {
duipai[0] = pokes[j];
duipai[1] = pokes[j + 1];
card_duipai.addElement(duipai);
break;
}
}
countPokes = -1;
}
}
// 分析单牌
for(inti = 0; i < countPokes.length; i++) {
if(countPokes == 1) {
for(intj = 0; j < pokes.length; j++) {
intv = Poke.getPokeValue(pokes[j]) - 3;
if(v == i) {
card_danpai.addElement(newint[] { pokes[j] });
countPokes = -1;
break;
}
}
}
}
// 根据2的数量进行分析
switch(count2) {
case4:
card_zhadan.addElement(newint[] { pokes[countWang],
pokes[countWang + 1], pokes[countWang + 2],
pokes[countWang + 3] });
break;
case3:
card_sanzhang.addElement(newint[] { pokes[countWang],
pokes[countWang + 1], pokes[countWang + 2] });
break;
case2:
card_duipai.addElement(newint[] { pokes[countWang],
pokes[countWang + 1] });
break;
case1:
card_danpai.addElement(newint[] { pokes[countWang] });
break;
}
// 分析炸弹
for(inti = 0; i < countPokes.length - 1; i++) {
if(countPokes == 4) {
card_zhadan.addElement(newint[] { i * 4+ 3, i * 4+ 2,
i * 4+ 1, i * 4});
countPokes = -1;
}
}
// 分析火箭
if(countWang == 1) {
card_danpai.addElement(newint[] { pokes[0] });
} elseif(countWang == 2) {
card_zhadan.addElement(newint[] { pokes[0], pokes[1] });
}
}
}




上一篇:震东棋牌——斗地主技巧绝杀十三招
下一篇:炸金花:欢乐炸金花棋牌游戏
回复

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表