import ds.*;
import java.util.*;
/**
* Description: \u5206\u6790\u724c\u578b
* <br/>Copyright (C), 2008-2010, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class PokeOperation
{
//\u706b\u7bad \u4e00\u5bf9\u9b3c
final int ROCKET = 1;
//\u70b8\u5f39 --- \u56db\u6761
final int BOOM = 2;
//\u98de\u673a --- \u8fde\u7740\u7684\u4e09\u6761
final int PLANE = 3;
//\u987a\u5b50
final int SHUNZI = 4;
//\u8fde\u5bf9
final int CONN_PAIR = 5;
//\u56db\u6761\u5e26\u4e24\u4e2a
final int FOUR_TWO = 6;
//\u4e09\u6761
final int THREE = 7;
//\u4e00\u5bf9
final int PAIR = 8;
//\u4e00\u4e2a
final int SINGAL = 9;
//\u7528\u4e8e\u8bb0\u5f55\u6bcf\u79cd\u724c\u578b\u4e2d\u7684\u4e3b\u724c
//\u6bd4\u5982\u987a\u5b50\u5c31\u8bb0\u5f55\u6700\u5927\u7684\u724c
public Poke bigPoke = new Poke();
//\u8bb0\u5f55\u724c\u578b
public int type = 0;
//\u8bb0\u5f55\u724c\u7684\u957f\u5ea6
public int size = 0;
//\u521d\u59cb\u5316\u6570\u636e
List<Poke> poke;
public PokeOperation(List<Poke> poke)
{
this.poke = poke;
init();
}
private void init()
{
size = 0;
type = 0;
bigPoke = new Poke();
}
public Poke getBigPoke()
{
return bigPoke;
}
public int getType()
{
return type;
}
//\u8fd4\u56de\u662f\u5426\u7b26\u5408\u89c4\u5219,\u5982\u679c\u7b26\u5408,\u4fdd\u5b58\u4e3b\u724c \u548c \u724c\u578b
public boolean analyze()
{
int size = poke.size();
switch(size)
{
//\u4e00\u5f20\u724c
case 1:
type = SINGAL;
bigPoke = poke.get(0);
size = 1;
return true;
case 2:
if(isPair())
{
size = 2;
bigPoke = poke.get(0);
return true;
}
else
return false;
case 3:
init();
return false;
case 4:
if (isBoom())
{
bigPoke = poke.get(0);
size = 4;
type = BOOM;
return true;
}
else
//\u662f\u5426\u4e09\u6761\u5e26\u4e00\u4e2a
if (isThree(4))
{
size = 4;
type = THREE;
return true;
}
else
return false;
case 5:
//\u662f\u5426\u4e09\u6761\u5e26\u4e00\u5bf9
if(isThree(5))
{
size = 5;
type = THREE;
return true;
}
else
//\u662f\u5426\u662f\u987a\u5b50
if(isShunZi())
{
size = 5;
type = SHUNZI;
return true;
}
else
return false;
case 6:
//\u662f\u5426\u662f\u987a\u5b50
if (isShunZi())
{
size = 6;
type = SHUNZI;
return true;
}
else
if(isFour_Two(6))
{
size = 6;
type = FOUR_TWO;
return true;
}
else
return false;
case 8:
if(isFour_Two(8))
{
size = 8;
type = FOUR_TWO;
return true;
}
else
return false;
//\u662f\u5426\u662f3\u8fde\u5bf9
//else
//if()
//{}
//\u662f\u5426\u662f\u56db\u6761\u5e26\u4e24\u5bf9
}
return true;
}
//\u5bf9\u5b50
private boolean isPair()
{
if(poke.get(0).equals(poke.get(1)))
return true;
else
//\u4e00\u5bf9\u9b3c
if(poke.get(0).getPokeNum() == poke.get(1).getPokeNum())
{
type = BOOM;
return true;
}
return false;
}
//\u68c0\u67e5\u662f\u5426\u76f8\u540c
private boolean isSame(List<Poke> poke)
{
int pokeNum = poke.get(0).getPokeNum();
for (int i = 1 ; i < poke.size() ; i++)
{
if(pokeNum != poke.get(i).getPokeNum())
return false;
}
return true;
}
//\u70b8\u5f39
private boolean isBoom()
{
return isSame(poke);
}
//\u4e09\u6761\u5e26\u4e00\u4e2a \u6216\u8005\u5e26\u4e00\u5bf9
private boolean isThree(int size)
{
int tmp = poke.get(0).getPokeNum();
//\u4e09\u6761\u5e26\u4e00\u4e2a
if(size == 4)
{
boolean flag = isSame(poke.subList(0,3));
if(flag)
{
bigPoke = poke.get(0);
return true;
}
else
{
flag = isSame(poke.subList(1,4));
if(flag)
{
bigPoke = poke.get(1);
return true;
}
else
return false;
}
}
else
{
boolean flag1 = isSame(poke.subList(0,3));
boolean flag2 = isSame(poke.subList(3,5));
if(flag1 && flag2)
{
bigPoke = poke.get(0);
return true;
}
else
{
flag1 = isSame(poke.subList(0,2));
flag2 = isSame(poke.subList(2,5));
if(flag1 && flag2)
{
bigPoke = poke.get(2);
return true;
}
else
return false;
}
}
}
// \u987a\u5b50(2 \u4e0e \u9b3c\u4e0d\u80fd\u4f5c\u4e3a\u987a\u5b50)
private boolean isShunZi()
{
int size = poke.size();
Poke p = poke.get(size - 1);
if(p.getPokeNum() < 12 && poke.get(0).getPokeNum() + size - 1 == p.getPokeNum())
{
bigPoke = poke.get(size -1);
return true;
}
else
return false;
}
// \u56db\u6761\u5e26\u724c(\u5e26\u4e00\u5bf9,\u5e26\u4e24\u5bf9)
private boolean isFour_Two(int size)
{
if(size == 6)
{
boolean flag1 = isSame(poke.subList(0,4));
boolean flag2 = isSame(poke.subList(1,5));
boolean flag3 = isSame(poke.subList(2,6));
if(flag1)
{
bigPoke = poke.get(0);
}
else
if(flag2)
{
bigPoke = poke.get(1);
}
else
if(flag3)
{
bigPoke = poke.get(2);
}
else
return false;
return true;
}
else
{
boolean flag1 = isSame(poke.subList(0,4));
boolean flag2 = isSame(poke.subList(2,6));
boolean flag3 = isSame(poke.subList(4,8));
if(flag1 && isSame(poke.subList(4,6)) && isSame(poke.subList(6,8)))
{
bigPoke = poke.get(0);
return true;
}
else
if(flag2 && isSame(poke.subList(0,2)) && isSame(poke.subList(6,8)))
{
bigPoke = poke.get(2);
return true;
}
else
if(flag3 && isSame(poke.subList(0,2)) && isSame(poke.subList(2,4)))
{
bigPoke = poke.get(4);
return true;
}
else
return false;
}
}
//
public static void main(String[] args)
{
ArrayList<Poke> list = new ArrayList();
Poke poke = new Poke(1,0);
list.add(poke);
poke = new Poke(1,0);
list.add(poke);
poke = new Poke(3,0);
list.add(poke);
poke = new Poke(5,0);
list.add(poke);
poke = new Poke(4,0);
list.add(poke);
poke = new Poke(4,0);
list.add(poke);
poke = new Poke(4,0);
list.add(poke);
poke = new Poke(4,0);
list.add(poke);
PokeOperation po = new PokeOperation(list);
if(po.analyze())
{
System.out.println("true");
System.out.println("type = " + po.type);
}
else
System.out.println("false");
}
}