package cse1030.games; import java.util.Collections; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.TreeSet; /** * A utility class that encodes a subset of the rules for the game Yahtzee. * * @author CSE1030_F13_14 * */ public class Yahtzee { /** * You can use the following class constants for indexes in lists * of dice. */ private static int FIRST = 0; private static int SECOND = 1; private static int THIRD = 2; private static int FOURTH = 3; private static int FIFTH = 4; private Yahtzee() { // private and empty by design } /** * The number of six-sided dice used in a standard game of Yahtzee. */ public static final int NUMBER_OF_DICE = 5; /** * Returns true if the list contains a three of a kind. * *

* A three of a kind is defined as at least three dice having the same * value. * * @param dice * list of dice * @pre. dice.size() == Yahtzee.NUMBER_OF_DICE * @return true if the list contains a three of a kind */ public static boolean isThreeOfAKind(List dice) { List copy = new ArrayList(dice); Collections.sort(copy); boolean result = copy.get(FIRST).getValue() == copy.get(THIRD).getValue() || copy.get(SECOND).getValue() == copy.get(FOURTH).getValue() || copy.get(THIRD).getValue() == copy.get(FIFTH).getValue(); return result; } /* * YOUR CODE SHOULD START AFTER THIS COMMENT SECTION. */ /** * Performs a simulation to compute the odds of rolling each of the Yahtzee * categories. The results are printed to the console. See the lab for * details. * * @param args * not used */ public static void main(String[] args) { } }