Set, the card game: Difference between revisions

Content added Content deleted
(New post.)
Line 173: Line 173:
private static List<Card> createPackOfCards() {
private static List<Card> createPackOfCards() {
List<Card> pack = new ArrayList<Card>();
List<Card> pack = new ArrayList<Card>(81);
for ( Number number : Number.values() ) {
for ( Number number : Number.values() ) {
for ( Colour colour : Colour.values() ) {
for ( Colour colour : Colour.values() ) {
Line 198: Line 198:
}
}
private static <T> List<List<T>> combinations(List<T> list, int r) {
private static <T> List<List<T>> combinations(List<T> list, int choose) {
List<List<T>> combinations = new ArrayList<List<T>>();
List<List<T>> combinations = new ArrayList<List<T>>();
List<Integer> combination = IntStream.range(0, r).boxed().collect(Collectors.toList());
List<Integer> combination = IntStream.range(0, choose).boxed().collect(Collectors.toList());
while ( combination.get(r - 1) < list.size() ) {
while ( combination.get(choose - 1) < list.size() ) {
combinations.add(combination.stream().map( i -> list.get(i) ).toList());
combinations.add(combination.stream().map( i -> list.get(i) ).toList());
int t = r - 1;
int temp = choose - 1;
while ( t != 0 && combination.get(t) == list.size() - r + t ) {
while ( temp != 0 && combination.get(temp) == list.size() - choose + temp ) {
t--;
temp -= 1;
}
}
combination.set(t, combination.get(t) + 1);
combination.set(temp, combination.get(temp) + 1);
for ( int i = t + 1; i < r; i++ ) {
for ( int i = temp + 1; i < choose; i++ ) {
combination.set(i, combination.get(i - 1) + 1);
combination.set(i, combination.get(i - 1) + 1);
}
}