Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch.epfl.javass.jass;
- import ch.epfl.javass.Preconditions;
- import ch.epfl.javass.bits.Bits32;
- public final class Trick {
- private final int packed;
- public static final Trick INVALID = new Trick(PackedTrick.INVALID);
- private Trick(int packed){
- this.packed = packed;
- }
- public int packed() {
- return packed;
- }
- public int index() {
- return PackedTrick.index(this.packed());
- }
- public Card.Color trump(){
- return PackedTrick.trump(this.packed());
- }
- public Card.Color baseColor(){
- if (PackedTrick.size(this.packed) != 0){
- return PackedTrick.baseColor(this.packed());
- }
- else throw new IllegalStateException();
- }
- public static Trick ofPacked(int packed) {
- Preconditions.checkArgument(PackedTrick.isValid(packed));
- Trick trick = new Trick(packed);
- return trick;
- }
- public static Trick firstEmpty(Card.Color trump, PlayerId firstPlayer) {
- return ofPacked(PackedTrick.firstEmpty(trump, firstPlayer));
- }
- public Trick nextEmpty() {
- if (!PackedTrick.isFull(this.packed())) {
- throw new IllegalStateException();
- }
- return new Trick(PackedTrick.nextEmpty(this.packed()));
- }
- public boolean isEmpty() {
- return PackedTrick.isEmpty(this.packed());
- }
- public boolean isFull() {
- return PackedTrick.isFull(this.packed());
- }
- public boolean isLast() {
- return PackedTrick.isLast(this.packed());
- }
- public int size() {
- return PackedTrick.size(this.packed);
- }
- public PlayerId player(int index) {
- if (index >= 4 || index <0) {
- throw new IndexOutOfBoundsException();
- }
- else {
- return PackedTrick.player(this.packed(), index);
- }
- }
- public Card card(int index) {
- if (index >= PackedTrick.size(this.packed()) || index <0) {
- throw new IndexOutOfBoundsException();
- }
- else {
- return Card.ofPacked(PackedTrick.card(this.packed(), index));
- }
- }
- public Trick withAddedCard(Card c) {
- if (PackedTrick.size(this.packed()) == 4) {
- throw new IllegalStateException();
- }
- else {
- return ofPacked(PackedTrick.withAddedCard(this.packed(), c.packed()));
- }
- }
- public int points() {
- return PackedTrick.points(this.packed);
- }
- public PlayerId winningPlayer() {
- if (PackedTrick.size(this.packed()) == 0) {
- throw new IllegalStateException();
- }
- else {
- return PackedTrick.winningPlayer(this.packed());
- }
- }
- public boolean equals(Object that0) {
- if (that0 != null && (that0.getClass().equals(this.getClass()))) {
- if (that0 instanceof Trick) {
- Trick trick = (Trick) that0;
- return (this.packed() == trick.packed());
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- public CardSet playableCards(CardSet hand) {
- if (PackedTrick.isFull(this.packed())) {
- throw new IllegalStateException();
- }
- else {
- return CardSet.ofPacked(PackedTrick.playableCards(this.packed(), hand.packed()));
- }
- }
- public int hashCode() {
- return Integer.hashCode(this.packed());
- }
- public String toString() {
- return PackedTrick.toString(this.packed());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement