斗地主棋牌游戏软件 (斗地主棋牌app)

本文实现了android端单机版的斗地主, 一共三个玩家(一个地主,二个农民) 游戏进入后,针对上家出的牌,如果本家有大的牌,可以出牌,如果没有相应的牌,可以选择不要牌, 在组合牌型时,如果不符合斗地主的牌型要求,是不能出牌的,如果组合的牌型不能大过上家的牌,也是不能出牌的

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

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

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

源码介绍:

扑克牌

public class Card {

int value= 0 ;

int pokeType= 0 ;

int [] pokes;

Bitmap pokeImage;

int personID;

public Card( int [] pokes,Bitmap pokeImage, int id)

{

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 ;

}

}

public void paint(Canvas canvas, int left, int top, int dir)

{

Rect src = new Rect();

Rect des = new Rect();

for ( int i = 0 ; i < pokes.length; i++) {

int row = Poke.getImageRow(pokes[i]);

int col = Poke.getImageCol(pokes[i]);

if (dir == PokeType.dirV) {

row = Poke.getImageRow(pokes[i]);

col = Poke.getImageCol(pokes[i]);

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[i]);

col = Poke.getImageCol(pokes[i]);

int select = 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

public class Desk {

public static int winId = - 1 ;

Bitmap pokeImage;

Bitmap tishi;

Bitmap buyao;

Bitmap chupai;

public static int [] personScore = new int [ 3 ];

public static int threePokes[] = new int [ 3 ]; // 三张底牌

private int threePokesPos[][] = new int [][] { { 170 , 17 }, { 220 , 17 },

{ 270 , 17 } };

private int [][] rolePos = { { 60 , 310 }, { 63 , 19 }, { 396 , 19 }, };

public static Person[] persons = new Person[ 3 ]; // 三个玩家

public static int [] deskPokes = new int [ 54 ]; // 一副扑克牌

public static int currentScore = 3 ; // 当前分数

public static int boss = 0 ; // 地主

/**

* -2:发牌<br>

* -1:随机地主<br>

* 0:游戏中 <br>

* 1:游戏结束,重新来,活退出<br>

*/

private int op = - 1 ; // 游戏的进度控制

public static int currentPerson = 0 ; // 当前操作的人

public static int currentCircle = 0 ; // 本轮次数

public static Card currentCard = null ; // 最新的一手牌

public int [][] personPokes = new int [ 3 ][ 17 ];

// gaming

private int timeLimite = 310 ;

private int [][] timeLimitePos = { { 130 , 205 }, { 118 , 76 }, { 327 , 76 } };

private int opPosX = 240 ;

private int opPosY = 200 ;

DDZ ddz;

public Desk(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();

}

public void gameLogic() {

switch (op) {

case - 2 :

break ;

case - 1 :

init();

op = 0 ;

break ;

case 0 :

gaming();

break ;

case 1 :

break ;

case 2 :

break ;

}

}

// 存储当前一句的胜负得分信息

int rs[] = new int [ 3 ];

private void gaming() {

for ( int k = 0 ; k < 3 ; k++) {

// 当三个人中其中一个人牌的数量为0,则游戏结束

if (persons[k].pokes.length == 0 ) {

// 切换到游戏结束状态

op = 1 ;

// 得到最先出去的人的id

winId = k;

// 判断哪方获胜

if (boss == winId) {

// 地主方获胜后的积分操作

for ( int i = 0 ; i < 3 ; i++) {

if (i == boss) {

// 地主需要加两倍积分

rs[i] = currentScore * 2 ;

personScore[i] += currentScore * 2 ;

} else {

// 农民方需要减分

rs[i] = -currentScore;

personScore[i] -= currentScore;

}

}

} else {

// 如果农民方胜利

for ( int i = 0 ; i < 3 ; i++) {

if (i != boss) {

// 农民方加分

rs[i] = currentScore;

personScore[i] += currentScore;

} else {

// 地主方减分

rs[i] = -currentScore * 2 ;

personScore[i] -= 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 ;

}

public void init() {

deskPokes = new int [ 54 ];

personPokes = new int [ 3 ][ 17 ];

threePokes = new int [ 3 ];

winId = - 1 ;

currentScore = 3 ;

currentCard = null ;

currentCircle = 0 ;

currentPerson = 0 ;

for ( int i = 0 ; i < deskPokes.length; i++) {

deskPokes[i] = i;

}

Poke.shuffle(deskPokes);

fenpai(deskPokes);

randDZ();

Poke.sort(personPokes[ 0 ]);

Poke.sort(personPokes[ 1 ]);

Poke.sort(personPokes[ 2 ]);

persons[ 0 ] = new Person(personPokes[ 0 ], 234 , 96 , PokeType.dirH, 0 ,

this , ddz);

persons[ 1 ] = new Person(personPokes[ 1 ], 54 , 28 , PokeType.dirV, 1 , this ,

ddz);

persons[ 2 ] = new Person(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 ( int i = 0 ; i < persons.length; i++) {

boolean b = ana.testAnalyze(personPokes[i]);

if (!b) {

init();

System.out.println( "chongqinglaiguo" );

break ;

}

}

for ( int i = 0 ; i < 3 ; i++) {

StringBuffer sb = new StringBuffer();

sb.append( "chushipai---" + i + ":" );

for ( int j = 0 ; j < personPokes[i].length; j++) {

sb.append(personPokes[i][j] + "," );

}

System.out.println(sb.toString());

}

}

// 随机地主,将三张底牌给地主

private void randDZ() {

boss = Poke.getDZ();

currentPerson = boss;

int [] newPersonPokes = new int [ 20 ];

for ( int i = 0 ; i < 17 ; i++) {

newPersonPokes[i] = personPokes[boss][i];

}

newPersonPokes[ 17 ] = threePokes[ 0 ];

newPersonPokes[ 18 ] = threePokes[ 1 ];

newPersonPokes[ 19 ] = threePokes[ 2 ];

personPokes[boss] = newPersonPokes;

}

public void fenpai( int [] pokes) {

for ( int i = 0 ; i < 51 ;) {

personPokes[i / 17 ][i % 17 ] = pokes[i++];

}

threePokes[ 0 ] = pokes[ 51 ];

threePokes[ 1 ] = pokes[ 52 ];

threePokes[ 2 ] = pokes[ 53 ];

}

public void result() {

}

public void paint(Canvas canvas) {

switch (op) {

case - 2 :

break ;

case - 1 :

break ;

case 0 :

paintGaming(canvas);

break ;

case 1 :

paintResult(canvas);

break ;

case 2 :

break ;

}

}

private void paintResult(Canvas canvas) {

Paint paint = new Paint();

paint.setColor(Color.WHITE);

paint.setTextSize( 20 );

canvas.drawText( "本局得分 总分 " , 110 , 66 , paint);

for ( int i = 0 ; i < 3 ; i++) {

canvas.drawText(i + ":本局得分:" + rs[i] + " 总分:" + personScore[i],

110 , 96 + i * 30 , paint);

}

}

private void paintGaming(Canvas canvas) {

persons[ 0 ].paint(canvas);

persons[ 1 ].paint(canvas);

persons[ 2 ].paint(canvas);

paintThreePokes(canvas);

paintRoleAndScore(canvas);

if (currentPerson == 0 ) {

Rect src = new Rect();

Rect dst = new Rect();

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 = new Paint();

paint.setTextAlign(Align.LEFT);

paint.setStyle(Style.FILL_AND_STROKE);

paint.setTextSize( 14 );

canvas.drawText( "当前底分:" + currentScore, 165 , 308 , paint);

}

private void paintTimeLimite(Canvas canvas) {

Paint paint = new Paint();

paint.setColor(Color.BLUE);

paint.setTextSize( 16 );

for ( int i = 0 ; i < 3 ; i++) {

if (i == currentPerson) {

canvas.drawText( "" + (timeLimite / 10 ), timeLimitePos[i][ 0 ],

timeLimitePos[i][ 1 ], paint);

}

}

}

private void paintRoleAndScore(Canvas canvas) {

Paint paint = new Paint();

for ( int i = 0 ; i < 3 ; i++) {

if (boss == i) {

paint.setColor(Color.RED);

canvas.drawText( "地主(得分:" + personScore[i] + ")" , rolePos[i][ 0 ],

rolePos[i][ 1 ], paint);

} else {

paint.setColor(Color.WHITE);

canvas.drawText( "农民(得分:" + personScore[i] + ")" , rolePos[i][ 0 ],

rolePos[i][ 1 ], paint);

}

}

}

private void paintThreePokes(Canvas canvas) {

Rect src = new Rect();

Rect dst = new Rect();

for ( int i = 0 ; i < 3 ; i++) {

int row = Poke.getImageRow(threePokes[i]);

int col = Poke.getImageCol(threePokes[i]);

src.set(col * 35 , row * 52 , col * 35 + 35 , row * 52 + 52 );

dst.set(threePokesPos[i][ 0 ], threePokesPos[i][ 1 ],

threePokesPos[i][ 0 ] + 35 , threePokesPos[i][ 1 ] + 52 );

canvas.drawBitmap(pokeImage, src, dst, null );

}

}

public void onTuch(View v, MotionEvent event) {

for ( int i = 0 ; i < persons.length; i++) {

StringBuffer sb = new StringBuffer();

sb.append(i + " : " );

for ( int j = 0 ; j < persons[i].pokes.length; j++) {

sb.append(persons[i].pokes[j]

+ (persons[i].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 ;

}

int x = ( int ) event.getX();

int y = ( 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);

}

private void tishi() {

}

//不要牌的操作

private void buyao() {

// 轮到下一个人

currentCircle++;

// 清空当前不要牌的人的最后一手牌

persons[currentPerson].card = null ;

// 定位下一个人的id

nextPerson();

// 如果已经转回来,则该人继续出牌,本轮清空,新一轮开始

if (currentCard != null && currentPerson == currentCard.personID) {

currentCircle = 0 ;

currentCard = null ; // 转回到最大牌的那个人再出牌

persons[currentPerson].card = null ;

}

}

// 定位下一个人的id并重新倒计时

private void nextPerson() {

switch (currentPerson) {

case 0 :

currentPerson = 2 ;

break ;

case 1 :

currentPerson = 0 ;

break ;

case 2 :

currentPerson = 1 ;

break ;

}

timeLimite = 310 ;

}

}

胡牌分析器:AnalyzePoke

package com.peiandsky;

import java.util.Vector;

public class AnalyzePoke {

private int [] pokes;

private int [] countPokes = new int [ 12 ];

private int count2;

private int countWang;

private Vector< int []> card_zhadan = new Vector< int []>( 3 );

private Vector< int []> card_sanshun = new Vector< int []>( 3 );

private Vector< int []> card_shuangshun = new Vector< int []>( 3 );

private Vector< int []> card_sanzhang = new Vector< int []>( 3 );

private Vector< int []> card_danshun = new Vector< int []>( 3 );

private Vector< int []> card_duipai = new Vector< int []>( 3 );

private Vector< int []> card_danpai = new Vector< int []>( 5 );

public int [] getCountPokes() {

return countPokes;

}

public int getCount2() {

return count2;

}

public int getCountWang() {

return countWang;

}

public Vector< int []> getCard_zhadan() {

return card_zhadan;

}

public Vector< int []> getCard_sanshun() {

return card_sanshun;

}

public Vector< int []> getCard_shuangshun() {

return card_shuangshun;

}

public Vector< int []> getCard_sanzhang() {

return card_sanzhang;

}

public Vector< int []> getCard_danshun() {

return card_danshun;

}

public Vector< int []> getCard_duipai() {

return card_duipai;

}

public Vector< int []> getCard_danpai() {

return card_danpai;

}

private AnalyzePoke() {

}

public static AnalyzePoke getInstance() {

// if (analyzePoke == null) {

// analyzePoke = new AnalyzePoke();

// }

// return analyzePoke;

return new AnalyzePoke();

}

private void init() {

for ( int i = 0 ; i < countPokes.length; i++) {

countPokes[i] = 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();

}

public boolean lastCardTypeEq( int pokeType) {

if (remainCount() > 1 ) {

return false ;

}

switch (pokeType) {

case PokeType.sanzhang:

return card_sanzhang.size() == 1 ;

case PokeType.duipai:

return card_duipai.size() == 1 ;

case PokeType.danpai:

return card_danpai.size() == 1 ;

}

return false ;

}

public int [] getPokes() {

return pokes;

}

public void setPokes( int [] pokes) {

Poke.sort(pokes);

this .pokes = pokes;

try {

this .analyze();

} catch (Exception e) {

e.printStackTrace();

}

}

public int remainCount() {

return card_zhadan.size() + card_sanshun.size()

+ card_shuangshun.size() + card_sanzhang.size()

+ card_danshun.size() + card_duipai.size() + card_danpai.size();

}

public int [] getMinType(Person last, Person next) {

AnalyzePoke lastAna = AnalyzePoke.getInstance();

lastAna.setPokes(last.pokes);

AnalyzePoke nextAna = AnalyzePoke.getInstance();

nextAna.setPokes(next.pokes);

int lastCount = lastAna.remainCount();

int nextCount = nextAna.remainCount();

int needSmart = - 1 ;

if (Desk.boss == next.id

|| (Desk.boss != next.id && Desk.boss != last.id)) {

// 是对手

if (next.pokes.length <= 2 ) {

needSmart = next.pokes.length;

}

}

// TODO

int pokeType = - 1 ;

int minValue = 55 ;

int pokeIdx = 0 ;

int size;

Vector< int []> temp;

temp = card_sanshun;

size = temp.size();

for ( int i = 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 ( int i = 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 ( int i = 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 ( int i = 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 ) {

return new int [] { pokeType, pokeIdx };

} else {

temp = card_duipai;

size = temp.size();

int min2 = - 1 ;

for ( int i = 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 ( int i = 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 ) {

return new int [] { pokeType, pokeIdx };

} else {

int min1 = - 1 ;

for ( int i = 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 ( int i = 0 ; i < size; i++) {

int [] p = temp.elementAt(i);

if (minValue > p[ 0 ]) {

pokeType = PokeType.danpai;

minValue = p[ 0 ];

pokeIdx = i;

}

}

}

return new int [] { pokeType, pokeIdx };

}

public boolean testAnalyze( int pokes[]) {

try {

init();

for ( int i = 0 ; i < pokes.length; i++) {

int v = Poke.getPokeValue(pokes[i]);

if (v == 16 || v == 17 ) {

countWang++;

} else if (v == 15 ) {

count2++;

} else {

countPokes[v - 3 ]++;

}

}

// System.out.println(" analyze sanshun");

// 三顺

int start = - 1 ;

int end = - 1 ;

for ( int i = 0 ; i <= countPokes.length - 1 ; i++) {

if (countPokes[i] == 3 ) {

if (start == - 1 ) {

start = i;

} else {

end = i;

}

} else {

if (end != - 1 && start != - 1 ) {

int dur = end - start + 1 ;

int [] ss = new int [dur * 3 ];

int m = 0 ;

for ( int j = 0 ; j < pokes.length; j++) {

int v = 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 ( int s = start; s <= end; s++) {

countPokes[s] = - 1 ;

}

start = end = - 1 ;

continue ;

} else {

start = end = - 1 ;

}

}

}

// System.out.println(" analyze shuangshun");

// shuangshun

int sstart = - 1 ;

int send = - 1 ;

for ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] == 2 ) {

if (sstart == - 1 ) {

sstart = i;

} else {

send = i;

}

} else {

if (sstart != - 1 && send != - 1 ) {

int dur = send - sstart + 1 ;

if (dur < 3 ) {

sstart = send = - 1 ;

continue ;

} else {

int shuangshun[] = new int [dur * 2 ];

int m = 0 ;

for ( int j = 0 ; j < pokes.length; j++) {

int v = Poke.getPokeValue(pokes[j]) - 3 ;

if (v >= sstart && v <= send) {

shuangshun[m++] = pokes[j];

}

}

card_shuangshun.addElement(shuangshun);

for ( int s = sstart; s <= send; s++) {

countPokes[s] = - 1 ;

}

sstart = send = - 1 ;

continue ;

}

} else {

sstart = send = - 1 ;

}

}

}

// System.out.println(" analyze danshun");

// danshun

int dstart = - 1 ;

int dend = - 1 ;

for ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] >= 1 ) {

if (dstart == - 1 ) {

dstart = i;

} else {

dend = i;

}

} else {

if (dstart != - 1 && dend != - 1 ) {

int dur = dend - dstart + 1 ;

if (dur >= 5 ) {

int m = 0 ;

int [] danshun = new int [dur];

for ( int j = 0 ; j < pokes.length; j++) {

int v = 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 ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] == 3 ) {

countPokes[i] = - 1 ;

int [] sanzhang = new int [ 3 ];

int m = 0 ;

for ( int j = 0 ; j < pokes.length; j++) {

int v = Poke.getPokeValue(pokes[j]) - 3 ;

if (v == i) {

sanzhang[m++] = pokes[j];

}

}

card_sanzhang.addElement(sanzhang);

}

}

// System.out.println(" analyze duipai");

// duipai

for ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] == 2 ) {

int [] duipai = new int [ 2 ];

for ( int j = 0 ; j < pokes.length; j++) {

int v = Poke.getPokeValue(pokes[j]) - 3 ;

if (v == i) {

duipai[ 0 ] = pokes[j];

duipai[ 1 ] = pokes[j + 1 ];

card_duipai.addElement(duipai);

break ;

}

}

countPokes[i] = - 1 ;

}

}

// System.out.println(" analyze danpai");

// danpai

for ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] == 1 ) {

for ( int j = 0 ; j < pokes.length; j++) {

int v = Poke.getPokeValue(pokes[j]) - 3 ;

if (v == i) {

card_danpai.addElement( new int [] { pokes[j] });

countPokes[i] = - 1 ;

break ;

}

}

}

}

// System.out.println(" analyze 2 ");

switch (count2) {

case 4 :

card_zhadan.addElement( new int [] { pokes[countWang],

pokes[countWang + 1 ], pokes[countWang + 2 ],

pokes[countWang + 3 ] });

break ;

case 3 :

card_sanzhang.addElement( new int [] { pokes[countWang],

pokes[countWang + 1 ], pokes[countWang + 2 ] });

break ;

case 2 :

card_duipai.addElement( new int [] { pokes[countWang],

pokes[countWang + 1 ] });

break ;

case 1 :

card_danpai.addElement( new int [] { pokes[countWang] });

break ;

}

// System.out.println(" analyze zhadan");

// *弹炸**

for ( int i = 0 ; i < countPokes.length - 1 ; i++) {

if (countPokes[i] == 4 ) {

card_zhadan.addElement( new int [] { i * 4 + 3 , i * 4 + 2 ,

i * 4 + 1 , i * 4 });

countPokes[i] = - 1 ;

}

}

// System.out.println(" analyze wang");

if (countWang == 1 ) {

card_danpai.addElement( new int [] { pokes[ 0 ] });

} else if (countWang == 2 ) {

card_zhadan.addElement( new int [] { pokes[ 0 ], pokes[ 1 ] });

}

} catch (Exception e) {

e.printStackTrace();

return false ;

}

return true ;

}

// 分析几大主要牌型

private void analyze() {

// 初始化牌型容器

init();

// *析王分**,2,普通牌的数量

for ( int i = 0 ; i < pokes.length; i++) {

int v = Poke.getPokeValue(pokes[i]);

if (v == 16 || v == 17 ) {

countWang++;

} else if (v == 15 ) {

count2++;

} else {

countPokes[v - 3 ]++;

}

}

// 分析三顺牌型

int start = - 1 ;

int end = - 1 ;

for ( int i = 0 ; i <= countPokes.length - 1 ; i++) {

if (countPokes[i] == 3 ) {

if (start == - 1 ) {

start = i;

} else {

end = i;

}

} else {

if (end != - 1 && start != - 1 ) {

int dur = end - start + 1 ;

int [] ss = new int [dur * 3 ];

int m = 0 ;

for ( int j = 0 ; j < pokes.length; j++) {

int v = 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 ( int s = start; s <= end; s++) {

countPokes[s] = - 1 ;

}

start = end = - 1 ;

continue ;

} else {

start = end = - 1 ;

}

}

}

// 分析双顺牌型

int sstart = - 1 ;

int send = - 1 ;

for ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] == 2 ) {

if (sstart == - 1 ) {

sstart = i;

} else {

send = i;

}

} else {

if (sstart != - 1 && send != - 1 ) {

int dur = send - sstart + 1 ;

if (dur < 3 ) {

sstart = send = - 1 ;

continue ;

} else {

int shuangshun[] = new int [dur * 2 ];

int m = 0 ;

for ( int j = 0 ; j < pokes.length; j++) {

int v = Poke.getPokeValue(pokes[j]) - 3 ;

if (v >= sstart && v <= send) {

shuangshun[m++] = pokes[j];

}

}

card_shuangshun.addElement(shuangshun);

for ( int s = sstart; s <= send; s++) {

countPokes[s] = - 1 ;

}

sstart = send = - 1 ;

continue ;

}

} else {

sstart = send = - 1 ;

}

}

}

// 分析单顺牌型

int dstart = - 1 ;

int dend = - 1 ;

for ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] >= 1 ) {

if (dstart == - 1 ) {

dstart = i;

} else {

dend = i;

}

} else {

if (dstart != - 1 && dend != - 1 ) {

int dur = dend - dstart + 1 ;

if (dur >= 5 ) {

int m = 0 ;

int [] danshun = new int [dur];

for ( int j = 0 ; j < pokes.length; j++) {

int v = 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 ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] == 3 ) {

countPokes[i] = - 1 ;

int [] sanzhang = new int [ 3 ];

int m = 0 ;

for ( int j = 0 ; j < pokes.length; j++) {

int v = Poke.getPokeValue(pokes[j]) - 3 ;

if (v == i) {

sanzhang[m++] = pokes[j];

}

}

card_sanzhang.addElement(sanzhang);

}

}

// 分析对牌

for ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] == 2 ) {

int [] duipai = new int [ 2 ];

for ( int j = 0 ; j < pokes.length; j++) {

int v = Poke.getPokeValue(pokes[j]) - 3 ;

if (v == i) {

duipai[ 0 ] = pokes[j];

duipai[ 1 ] = pokes[j + 1 ];

card_duipai.addElement(duipai);

break ;

}

}

countPokes[i] = - 1 ;

}

}

// 分析单牌

for ( int i = 0 ; i < countPokes.length; i++) {

if (countPokes[i] == 1 ) {

for ( int j = 0 ; j < pokes.length; j++) {

int v = Poke.getPokeValue(pokes[j]) - 3 ;

if (v == i) {

card_danpai.addElement( new int [] { pokes[j] });

countPokes[i] = - 1 ;

break ;

}

}

}

}

// 根据2的数量进行分析

switch (count2) {

case 4 :

card_zhadan.addElement( new int [] { pokes[countWang],

pokes[countWang + 1 ], pokes[countWang + 2 ],

pokes[countWang + 3 ] });

break ;

case 3 :

card_sanzhang.addElement( new int [] { pokes[countWang],

pokes[countWang + 1 ], pokes[countWang + 2 ] });

break ;

case 2 :

card_duipai.addElement( new int [] { pokes[countWang],

pokes[countWang + 1 ] });

break ;

case 1 :

card_danpai.addElement( new int [] { pokes[countWang] });

break ;

}

// 分析*弹炸**

for ( int i = 0 ; i < countPokes.length - 1 ; i++) {

if (countPokes[i] == 4 ) {

card_zhadan.addElement( new int [] { i * 4 + 3 , i * 4 + 2 ,

i * 4 + 1 , i * 4 });

countPokes[i] = - 1 ;

}

}

// 分析火箭

if (countWang == 1 ) {

card_danpai.addElement( new int [] { pokes[ 0 ] });

} else if (countWang == 2 ) {

card_zhadan.addElement( new int [] { pokes[ 0 ], pokes[ 1 ] });

}

}

}