我正在编写一个德州扑克游戏并创建了这个方法来对用户手牌进行排名我想把它变成一个通用方法,这样我就可以通过庄家手,然后比较两者,看看哪只手会更好。如果您能帮助我将其转换为通用方法,我将不胜感激。
public int rankCards(ArrayList<Integer> rankHandList){
//creates a list to put the card ranks into
ArrayList <Integer> newList;
newList = new ArrayList<>();
//Checks the rankHandList i created above
for(int x = 0; x<=rankHandList.size()-1; x++){
int rank = rankHandList.get(x);
//takes all the cards and gets them between 0 and 12
while(rank >= 13){
rank = rank -13;
}
//if a card = 12 it is an ace
if(rank == 12)
newList.add(rank);
//if a card = 11 it is a king
if(rank == 11)
newList.add(rank);
//if a card = 10 it is a queen
if(rank == 10)
newList.add(rank);
//if a card = 9 it is a jack
if(rank == 9)
newList.add(rank);
//if a card = 8 it is a 10
if(rank == 8)
newList.add(rank);
//if a card = 7 it is a 9
if(rank ==7)
newList.add(rank);
//if a card = 6 it is a 8
if(rank ==6)
newList.add(rank);
//if a card = 5 it is a 7
if(rank ==5)
newList.add(rank);
//if a card = 4 it is a 6
if(rank ==4)
newList.add(rank);
//if a card = 3 it is a 5
if(rank ==3)
newList.add(rank);
//if a card = 2 it is a 4
if(rank == 2)
newList.add(rank);
//if a card =1 it is a 3
if(rank ==1)
newList.add(rank);
//if a card = 0 it is a 2
if(rank ==0)
newList.add(rank);
}
//SENDS THE CARDS I JUST RANKED FROM 0-12 TO MAKE THE BEST HAND
makeBestHand(newList);
return 0;
}