package jrummikub.model;
import jrummikub.util.Pair;
import static jrummikub.model.StoneTray.Direction.*;
/** Class managing a {@link Player}'s {@link Stone}s */
public class Hand extends StoneTray<Stone> implements IHand {
/**
* The width of the hand
*/
public final static int WIDTH = 14;
* The height of the hand
@Deprecated
public final static int HEIGHT = 2;
private boolean rowIsFull(float row) {
int count = 0;
for (Pair<Stone, Position> entry : this) {
if (entry.getSecond().getY() == row) {
count++;
}
return count == WIDTH;
@Override
protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
Direction dir) {
float x = pos.getX();
float y = pos.getY();
if (x >= 0 && x <= WIDTH - 1) {
return null;
if (x < 0) {
return new Pair<Position, Direction>(new Position(0, y), RIGHT);
} else {
if (rowIsFull(y)) {
return new Pair<Position, Direction>(new Position(0, y + 1), RIGHT);
return new Pair<Position, Direction>(new Position(WIDTH - 1, y), LEFT);