我正在制作 Java 纸牌游戏,现在我尝试为电脑玩家创建“大脑”。条件:
桌上有3张牌(只有价值,没有花色);
电脑玩家(CP)有6张牌;
赢得一局CP必须至少击败桌上的2张牌,或者
必须击败1张牌并与另外2张牌打成平局;当然,卡组必须是最优的。
例子:桌子上有1、2、3的牌。CP有1、1、3、2、5、6的牌。它必须选择2的牌才能打败1,而不是选择3的牌击败 Card2 而不是选择价值为 1 的卡,因为它已经击败了 2 张卡。现在我编写了下一个代码,但它不能正常工作或根本不能工作。
for (i = 0, j = i++, k = j++; i < oppHand.size() - 2 && j < oppHand.size() - 1 && k < oppHand.size(); i++) {
a = oppHand.get(i).getPower(); //value of card1 from CP hand
b = oppHand.get(j).getPower(); //value of card2 from CP hand
c = oppHand.get(k).getPower(); //value of card3 from CP hand
x = oppHand.indexOf(i); //position of card1 in a CP hand
y = oppHand.indexOf(j); //position of card2 in a CP hand
z = oppHand.indexOf(k); //position of card3 in a CP hand
if (a > Score1 && b > Score2 || a> Score1 && c > Score3) { //Score - value of the cards on the table
choice1 = x;
choice2 = y;
choice3 = z;}
else if (a > Score1 && b > Score3 || a > Score1 && c > Score2) {
choice1 = x;
choice2 = z;
choice3 = y;} ........
// moving cards from the CP hand to the table with assignment values to the piles
validPower5 = oppHand.get(choice1).getPower();
discardPile5.add(0, oppHand.get(choice1));
oppHand.remove(choice1);
validPower6 = oppHand.get(choice2).getPower();
discardPile6.add(0, oppHand.get(choice2));
oppHand.remove(choice2);
validPower7 = oppHand.get(choice3).getPower();
discardPile7.add(0, oppHand.get(choice3));
oppHand.remove(choice3);
}