de.fhkiel.ki.cathedral.game.Turnable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cathedral-game Show documentation
Show all versions of cathedral-game Show documentation
A cathedral implementation in Java
The newest version!
package de.fhkiel.ki.cathedral.game;
import java.util.Arrays;
import java.util.List;
/**
* The enum Turnable describes if a {@link Building} can be turned
* and has a different form in these {@link Direction}s.
*
* While a building can always be turned in any {@link Direction},
* there are {@link Building}s where these turned forms are identical.
* To reduce the number of Possibilities in placing {@link Building}s,
* Turnable defines if a {@link Building} has 4, 2 or 1 forms on the {@link Board}.
*
*
* @author Eike Petersen {@literal }
* @version 1.0
* @since 1.0
*/
public enum Turnable {
/**
* The is no point in turning the Building in other {@link Direction}s,
* as they will have always the same form.
*
* Reduction from 400 max possible Turns to 100 max.
* Examples are {@link Building#White_Tavern}, {@link Building#Black_Infirmary}
*
*/
No(Direction._0),
/**
* The Building has two forms. One in {@link Direction#_0} and one in {@link Direction#_90}.
* The other Directions are the same as their mirror.
*
* Reduction from 400 max possible Turns to 200 max.
* Examples are {@link Building#White_Bridge}, {@link Building#Black_Stable}
*
*/
Half(Direction._0, Direction._90),
/**
* The Building has four distinct forms. One in each {@link Direction}.
*
* Examples are {@link Building#Blue_Cathedral}
*
*/
Full(Direction._0, Direction._90, Direction._180, Direction._270);
private final int numberOfPossibleForms;
private final List possibleDirections;
Turnable(Direction... possibleDirections) {
this.numberOfPossibleForms = possibleDirections.length;
this.possibleDirections = Arrays.stream(possibleDirections).toList();
}
/**
* Gets the number of possible forms associated with the enum-value.
*
* Can be used in calculations over possible turns.
*
* @return the number of possible forms
*/
public int getNumberOfPossibleForms() {
return numberOfPossibleForms;
}
/**
* Gets a list of possible {@link Direction}s this enum-value and subsequent forms can be turned
* to.
*
* @return a unmodifiable list of the possible {@link Direction}s.
*/
public List getPossibleDirections() {
return possibleDirections;
}
/**
* Gets the possible {@link Direction} that corresponds to the given {@link Direction}.
*
* For {@link Turnable#Full} this just returns the given {@link Direction}.
* For {@link Turnable#Half} this returns {@link Direction#_0} for {@link Direction#_0} or
* {@link Direction#_180} and {@link Direction#_90} for {@link Direction#_90} or
* {@link Direction#_270}.
* For {@link Turnable#No} this returns {@link Direction#_0} for any given {@link Direction}.
*
* @param direction the {@link Direction} to convert
* @return the {@link Direction} that corresponds to the given {@link Direction}
*/
public Direction getRealDirection(Direction direction) {
return possibleDirections.get(direction.getId() % getNumberOfPossibleForms());
}
}