2013-11-24 1 views
0

사용자가 각 손에 대해 정확한 EV 재생을하는 데 도움이되는 프로그램을 작성하려고합니다. 그러나 분당 내 의사 결정을 기반으로 카드 가치 (즉 총 2 장)를 사용하고 있습니다. 예를 들어, 9 = 9, 10 = 10, j = 11, q = 12 .... 나는이 사용법을 실제 손에 넣을 수 있기를 바랍니다. Adks (다이아몬드의 에이스, 스페이드의 왕). 이것은 손의 적절한 가치를 고려할 때 더 정확할 것입니다. 누군가가 이것을 통합하는 최선의 방법에 대해 조언을 해줄 수 있습니까? 미리 많은 감사드립니다! 내 cuurent 코드는 아래와 같습니다!포커 EV 계산기 : 손 가치 계산?

package uk.ac.qub.lectures; 

//importing resources (scanner) 
import java.util.Scanner; 

public class PokeGame { 

    public static final int MIN_POSITION = 1; 
    public static final int MAX_POSITION = 8; 

    public static void main(String[] args) { 
     // declaring user position 
     int userPosition = 0; 
     // setting up scanner 
     Scanner scanner = new Scanner(System.in); 
     // integer referring to use again or not 
     int useAgain = 0; 
     // boolean getting valid input for repeat 
     boolean repeat = false; 

     // declaring number value of each card 
     int cards; 

     do { 

      // getting user position 
      do { 
       System.out.printf("Please enter position between %d and %d\n",MIN_POSITION, MAX_POSITION); 
       userPosition = scanner.nextInt(); 
      } while ((userPosition < MIN_POSITION) || (userPosition > MAX_POSITION)); 
      // getting hand hand strength 
      System.out.println("Enter card value"); 
      cards = scanner.nextInt(); 

      switch (userPosition) { 

      case 1: 
      case 2: 
       if (cards > 10) { 
        System.out.println("SHOVE"); 
       } else 
        System.out.println("FOLD"); 
       break; 
      case 3: 
      case 4: 
      case 5: 
       if (cards > 13) { 
        System.out.println("SHOVE"); 
       } else 
        System.out.println("FOLD"); 
       break; 
      case 6: 
      case 7: 
      case 8: 
       if (cards > 17) { 
        System.out.println("SHOVE"); 
       } else 
        System.out.println("FOLD"); 
       break; 
      default: 
       System.out.println("ENTER VALID POSITION"); 
      } 
      do { 

       System.out.println("Do you advice on another Hand?"); 
       System.out.println("Enter 1 for Yes, Enter 0 for No"); 
       useAgain = scanner.nextInt(); 
       if ((useAgain == 1) || (useAgain == 0)) { 

        repeat = false; 
       } else { 

        System.out.println("Invalid Input, please enter 1 or 0"); 
        repeat = true; 
       } 
      } while (repeat); 
     } while (useAgain != 0); 

     // clean up resources 
     scanner.close(); 
    }// method end 

}// class end 
+0

그 userPosition을 추가 잊으하면 해당 사용자가 테이블에 앉아 배치하기 위해서만 의미 (즉 초기 위치, 딜러 등)! 감사! –

+1

프로그래밍과 관련이 없지만 포커와 관련이 없으므로 두 카드의 숫자 차이도 고려해야합니다. 더 멀리 떨어져있는 두 장의 카드가 (2, K)이면 직선 가능성이 작습니다. –

+0

그것은 대답 아니지만, 인 Golder의 제안 : 따르 [CLEAN CODE] [1] 지침 일부입니다 : 는 - 의미있는 이름 와 상수를 사용합니다 - 여러 작은 방법으로 (각 약 5 문) 당신이 암호를 해독하고 메서드의 이름을 올바르게 지정하십시오. - 각 메서드는 하나의 책임 만 있습니다. 더 많은 규칙이 있지만이를 사용하므로 코드를 더 쉽게 읽고 이해할 수 있습니다. [1] : http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882 –

답변

0

이렇게 카드 입력을받는 경우, "AA", "9T"또는 "9T가"당신은 당신에게 입력 카드를 사용 suitedness 및 같은 간격에 따라 손 값을 계산할 수 있습니다 :

import java.util.Arrays; 
import java.util.Scanner; 
Scanner scanner = new Scanner(System.in); 
String[] hand = (scanner.nextLine() + 'u').toUpperCase().split(""); 
String values = " 23456789TJQKA"; 
int[] cards = new int[] {values.indexOf(hand[1]), values.indexOf(hand[2])}; 
Arrays.sort(cards); 
int gap = cards[1] - cards[0] - 1; 
boolean pair = gap == -1; 
boolean suited = hand[3].equals("S"); 
char[] cards = new char[] {(char)values.charAt(cards[0]), (char)values.charAt(cards[1])}; 
int handValue = 0; 

// adjust value based on pairs, suitedness or connectedness 
if (pair) // hand is a pair 
    handValue += 10; //or whatever you want 
else if (suited) // hand is suited 
    handValue += 3; //or whatever you want 

if (gap == 0) // hand is no gap 
    handValue += 5; //or whatever you want. 

if (gap == 1) // hand is one gap 
    handValue += 3; //or whatever you want. 

if (cards[1] == 'A' && cards[0] == 'K' && suited) // AK suited 
    System.out.println("AK Suited!"); 
else if (cards[1] == 'A' && suited) // Ax suited 
    System.out.println("Ax Suited!"); 
+0

많은 도움을 주셔서 감사합니다. 손 가치보다는 개인의 손에 기초하여 올바른 플레이를 결정할 수있는 방법이 있습니까? 나는. 카드가 "k10"콜이지만 "k9"폴드한다면? 감사합니다 –

+0

그것은 "kt"가 아니라 "k10"이 될 것입니다. 이것은 한 손이 다른 손보다 나은 이유에 달려 있습니다. KT는 2 갭 손으로 k9는 3 갭입니다. 위의 예제들과 마찬가지로,'if (Math.abs (card1 - card2) == 4) // fold '를 사용하여 3 개의 갭을 감지 할 수 있습니다. 만약 당신이할만한 3 개의 갭이 AT라면 당신은'(Math.abs (card1 - card2) == 4 &! (card1 + card2 == 25)) // fold'을하면된다. – dansalmo

+0

! 이 종류의 앱/프로그램을위한 시장이 있다고 생각합니까? weve 대학에서이 유형의 프로젝트를 만드는 임무를 맡았습니다! –