您現在的位置是:首頁 > 綜藝首頁綜藝

鬥地主-android(棋牌)

由 程式碼專家 發表于 綜藝2021-09-08
簡介length <=2) {needSmart = next

棋牌單機版怎麼下

本文實現了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:發牌

* -1:隨機地主

* 0:遊戲中

* 1:遊戲結束,重新來,活退出

*/

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

] });

}

}

}