Implemented finding of sets by stone

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@119 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-04 19:41:41 +02:00
parent ea37e2f0d2
commit 7d7a5e1494
2 changed files with 44 additions and 3 deletions

View file

@ -6,6 +6,17 @@ import jrummikub.util.Pair;
public class Table extends StoneTray<StoneSet> implements ITable {
private static class StoneInfo {
StoneSet set;
Position setPosition;
int stonePosition;
public StoneInfo(StoneSet set, Position setPosition, int stonePosition) {
this.set = set;
this.setPosition = setPosition;
this.stonePosition = stonePosition;
}
}
/**
* Removes {@link Stone} from the Table
*
@ -14,7 +25,14 @@ public class Table extends StoneTray<StoneSet> implements ITable {
*/
@Override
public void pickUpStone(Stone stone) {
StoneInfo info = findStoneInfo(stone);
splitSet(info.set, info.setPosition, info.stonePosition);
}
private StoneInfo findStoneInfo(Stone stone) {
// Find the set of the stone
StoneInfo info;
StoneSet set = null;
Position setPosition = null;
int stonePosition = 0;
@ -31,11 +49,23 @@ public class Table extends StoneTray<StoneSet> implements ITable {
}
// Stone not found
if (set == null) {
return;
info = null;
} else {
info = new StoneInfo(set, setPosition, stonePosition);
}
splitSet(set, setPosition, stonePosition);
return info;
}
@Override
public StoneSet findStoneSet(Stone stone) {
StoneInfo info = findStoneInfo(stone);
if (info == null) {
return null;
}
return info.set;
}
private void splitSet(StoneSet set, Position setPosition, int stonePosition) {
pickUp(set);

View file

@ -69,4 +69,15 @@ public class TableTest {
}
assertEquals(2, counter);
}
@Test
public void testFindSet() {
Stone targetStone = new Stone(BLACK);
StoneSet testSet = new StoneSet(Arrays.asList(new Stone(1, RED), targetStone,
new Stone(3, RED)));
testTable.drop(testSet, new Position(0,0));
StoneSet foundSet = testTable.findStoneSet(targetStone);
assertSame(testSet, foundSet);
}
}