Skip to content

Instantly share code, notes, and snippets.

@LarsEckart
Created June 25, 2022 12:52
Show Gist options
  • Save LarsEckart/0956565759d8b071e99b84a1cefd0136 to your computer and use it in GitHub Desktop.
Save LarsEckart/0956565759d8b071e99b84a1cefd0136 to your computer and use it in GitHub Desktop.
package com.example.chenformula;
import java.util.HashMap;
import java.util.Map;
public class ChenCalculator {
public static int calculate(String firstCard, String secondCard, boolean suited) {
double result = 0.0;
result += scoreHighestCardOnly(firstCard, secondCard);
if (isPair(firstCard, secondCard)) {
result = result * 2;
}
if (suited) {
result += 2;
}
result = result - pointsIfGapBetweenCards(firstCard, secondCard);
result += bonusPointIf0or1CardGapAndBothCardsLowerThanQ(firstCard, secondCard);
return Math.toIntExact(Math.round(result));
}
private static double scoreHighestCardOnly(String firstCard, String secondCard) {
Map<String, Double> cardValues = new HashMap<>();
cardValues.put("A", 10.0);
cardValues.put("K", 8.0);
cardValues.put("Q", 7.0);
cardValues.put("J", 6.0);
cardValues.put("10", 5.0);
cardValues.put("9", 4.5);
cardValues.put("8", 4.0);
cardValues.put("7", 3.5);
cardValues.put("6", 3.0);
cardValues.put("5", 2.5);
cardValues.put("4", 2.0);
cardValues.put("3", 1.5);
cardValues.put("2", 1.0);
String higherCard;
if (cardValues.get(firstCard) > cardValues.get(secondCard)) {
higherCard = firstCard;
} else {
higherCard = secondCard;
}
return cardValues.get(higherCard);
}
private static boolean isPair(String firstCard, String secondCard) {
return false;
}
private static int pointsIfGapBetweenCards(String firstCard, String secondCard) {
return 0;
}
private static int bonusPointIf0or1CardGapAndBothCardsLowerThanQ(String firstCard, String secondCard) {
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment