41 lines
1.0 KiB
Java
41 lines
1.0 KiB
Java
package j2025.FT;
|
|
|
|
public class PairOfDice implements Comparable<PairOfDice> {
|
|
|
|
private final Die die1;
|
|
private final Die die2;
|
|
|
|
public PairOfDice(Die die1, Die die2) {
|
|
this.die1 = die1;
|
|
this.die2 = die2;
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(PairOfDice other) {
|
|
return Integer.compare(this.getValue(), other.getValue());
|
|
}
|
|
|
|
private int getValue() {
|
|
int high = Math.max(die1.ordinal(), die2.ordinal());
|
|
int low = Math.min(die1.ordinal(), die2.ordinal());
|
|
|
|
// Mäxchen (2,1) → höchster Wert
|
|
if (high == 2 && low == 1) return Integer.MAX_VALUE;
|
|
|
|
// Pasch → 100 + Augenzahl (11..66 → 101..106)
|
|
if (high == low) return 100 + high;
|
|
|
|
// Normale Würfe → zweistellige Zahl (z.B. 6,5 → 65)
|
|
return high * 10 + low;
|
|
}
|
|
|
|
public static PairOfDice random() {
|
|
return new PairOfDice(Die.random(), Die.random());
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return die1.ordinal() + 1 + " " + (die2.ordinal() + 1);
|
|
}
|
|
}
|