2013-10-14 2 views
2

저는 자바 카드 게임을 만들고 있습니다. 이제 컴퓨터 플레이어를위한 "두뇌"를 만들려고합니다. 조건 :조건에 따라 배열 목록에서 3 가지 요소를 선택하십시오.

  • 테이블에는 3 개의 카드가 있습니다 (값은 적당하지 않음).

  • 컴퓨터 플레이어 (CP)에는 6 개의 카드가 있습니다.

  • 라운드 CP 우승을 테이블에 2 개 이상의 카드를 이길 수있다, 또는
    1 개 카드를 이길 다른 두 카드와 무승부을한다;

  • 물론 카드 세트가 최적이어야합니다.

예 : 테이블에 값 1, 2 카드입니다, 3. CP 값 1, 1, 3, 2, 5, 그것은 이길 값이 카드를 선택할 수있다 (6)와 카드가 Card1, Card2를 이길 값 3을 가진 카드를 선택하고 이미 2 개의 카드를 이기기 때문에 값 1을 가진 카드를 선택하는 것보다. 이제 다음 코드를 작성했지만 실제로 작동하지 않거나 전혀 작동하지 않습니다.

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); 
        } 
+0

는 "진정한 작동하지 않거나 전혀 작동하지 않는"어떤 단서를 제공하지 않습니다. 더 자세하게 설명하십시오. – djna

+0

우리는 논리를 프로그래밍하는 데 도움을 줄 수 없습니다. 길을 잃은 곳을 알려 주시면 올바른 방향으로 안내해 드리겠습니다. – Reinherd

답변

0

이 도움이 될만한 것이 있습니까?

sortCardsOnTable();//now Score1 <= Score2 <= Score2 
sortOpponentCards(); 
boolean beatScore1 = false; 
boolean beatScore2 = false; 
int indexFirst = 0; 
int indexSecond = 0; 
int indexThird = 0; 

for(int i = 0;i < oppHand.size();i++){ 
    Card c = oppHand.get(i); 
    if(!beatScore1 && c.getPower() > Score1){ 
     indexFirst = i; 
     beatScore1 = true; 
    } 
    else if(beatScore1 && c.getPower() > Score2){ 
     indexSecond = i; 
     beatScore2 = true; 
     indexThird = 1;//here compare with indexFirst so you dont pull the first card twice, just pull the first available card 
    } 
} 

당신은

확실하지 .. 다른 조건이 정확해야하는 경우 나는 당신을 생각하는 계산을

0

을 단순화하기 위해, 당신의 Cardlist를 정렬하지만이 코드를 확인해야합니다. 나는이 일을해야한다고 생각

if (a > Score1) 
{ //Score - value of the cards on the table 
    if (b > Score2 || c > Score3) { 
     choice1 = x; 
     choice2 = y; 
     choice3 = z; } 
    else if (b > Score3 || c > Score2) { 
     choice1 = x; 
     choice2 = y; 
     choice3 = z; } 
} 

... 우리가 작업 할

관련 문제