Common.move(card, card.getLocation(), p, 10);
m.container.setComponentZOrder(card, 0);
if (flag == 1)
p.x += 21;
else
p.y += 15;
}
}
// 地主牌权值,看是否抢地主
public static int getScore(List list) {
int count = 0;
for (int i = 0, len = list.size(); i < len; i++) {
Card card = list.get(i);
if (card.name.substring(0, 1).equals(“5”)) {
// System.out.println(card.name.substring(0, 1));
count += 5;
}
if (card.name.substring(2, card.name.length()).equals(“2”)) {
// System.out.println(2);
count += 2;
}
}
return count;
}
// 返回花色
public static int getColor(Card card) {
return Integer.parseInt(card.name.substring(0, 1));
}
// 返回值
public static int getValue(Card card) {
int i = Integer.parseInt(card.name.substring(2, card.name.length()));
if (card.name.substring(2, card.name.length()).equals(“2”))
i += 13;
if (card.name.substring(2, card.name.length()).equals(“1”))
i += 13;
if (Common.getColor(card) == 5)
i += 2;// 是王
return i;
}
// 得到最大相同数
public static void getMax(Card_index card_index, List list) {
int count[] = new int[14];// 1-13各算一种,王算第14种
for (int i = 0; i < 14; i++)
count[i] = 0;
for (int i = 0; i < list.size(); i++) {
if (Common.getColor(list.get(i)) == 5)
count[13]++;
else
count[Common.getValue(list.get(i)) - 1]++;
}
for (int i = 0; i < 14; i++) {
switch (count[i]) {
case 1:
card_index.a[0].add(i + 1);
break;
case 2:
card_index.a[1].add(i + 1);
break;
case 3:
card_index.a[2].add(i + 1);
break;
case 4:
card_index.a[3].add(i + 1);
break;
}
}
}
// 拆牌
public static Model getModel(List list) {
// 先复制一个list
List list2 = new ArrayList(list);
Model model = new Model();
// ------先拆炸弹
Common.getBoomb(list2, model); // ok
// ------拆3带
Common.getThree(list2, model);
// 拆飞机
Common.getPlane(list2, model);
// ------拆对子
Common.getTwo(list2, model);
// 拆连队
Common.getTwoTwo(list2, model);
// 拆顺子
Common.get123(list2, model);
// 拆单
Common.getSingle(list2, model);
return model;
}
// 拆连子
public static void get123(List list, Model model) {
List del = new ArrayList();// 要删除的Cards
if (list.size() > 0 && (Common.getValue(list.get(0)) < 7 || Common.getValue(list.get(list.size() - 1)) > 10))
return;
if (list.size() < 5)
return;
for (int i = 0, len = list.size(); i < len; i++) {
int k = i;
for (int j = i; j < len; j++) {
if (Common.getValue(list.get(i)) - Common.getValue(list.get(j)) == j - i) {
k = j;
}
}
if (k - i >= 4) {
String s = “”;
for (int j = i; j < k; j++) {
s += list.get(j).name + “,”;
del.add(list.get(j));
}
s += list.get(k).name;
del.add(list.get(k));
model.a123.add(s);
i = k;
}
}
list.removeAll(del);
}
// 拆双顺
public static void getTwoTwo(List list, Model model) {
List del = new ArrayList();// 要删除的Cards
// 从model里面的对子找
List l = model.a2;
if (l.size() < 3)
return;
Integer s[] = new Integer[l.size()];
for (int i = 0, len = l.size(); i < len; i++) {
String[] name = l.get(i).split(",");
s[i] = Integer.parseInt(name[0].substring(2, name[0].length()));
}
// s0,1,2,3,4 13,9,8,7,6
for (int i = 0, len = l.size(); i < len; i++) {
int k = i;
for (int j = i; j < len; j++) {
if (s[i] - s[j] == j - i)
k = j;
}
if (k - i >= 2)// k=4 i=1
{// 说明从i到k是连队
String ss = “”;
for (int j = i; j < k; j++) {
ss += l.get(j) + “,”;
del.add(l.get(j));
}
ss += l.get(k);
model.a112233.add(ss);
del.add(l.get(k));
i = k;
}
}
l.removeAll(del);
}
// 拆飞机
public static void getPlane(List list, Model model) {
List del = new ArrayList();// 要删除的Cards
// 从model里面的3带找
List l = model.a3;
if (l.size() < 2)
return;
Integer s[] = new Integer[l.size()];
for (int i