Implemented new hand wrapping

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@240 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-16 19:07:47 +02:00
parent edf4197c16
commit be4b1b4120

View file

@ -13,8 +13,19 @@ public class Hand extends StoneTray<Stone> implements IHand {
/** /**
* The height of the hand * The height of the hand
*/ */
@Deprecated
public final static int HEIGHT = 2; 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 @Override
protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos, protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
Direction dir) { Direction dir) {
@ -25,16 +36,12 @@ public class Hand extends StoneTray<Stone> implements IHand {
return null; return null;
} }
if (x < 0) { if (x < 0) {
if (y == 0) { return new Pair<Position, Direction>(new Position(0, y), RIGHT);
return new Pair<Position, Direction>(new Position(0, 0), RIGHT);
} else {
return new Pair<Position, Direction>(new Position(WIDTH - 1, 0), LEFT);
}
} else { } else {
if (y == 0) { if (rowIsFull(y)) {
return new Pair<Position, Direction>(new Position(0, 1), RIGHT); return new Pair<Position, Direction>(new Position(0, y + 1), RIGHT);
} else { } else {
return new Pair<Position, Direction>(new Position(WIDTH - 1, 1), LEFT); return new Pair<Position, Direction>(new Position(WIDTH - 1, y), LEFT);
} }
} }
} }