Classification of runs and sets
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@83 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
2eaf873ec6
commit
f8f75fde6d
2 changed files with 42 additions and 25 deletions
|
@ -10,6 +10,7 @@ import java.util.Set;
|
|||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import jrummikub.util.Pair;
|
||||
import static jrummikub.model.StoneSet.Type.*;
|
||||
|
||||
/** Class managing {@link Stone}s joined together to form sets */
|
||||
public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||
|
@ -25,14 +26,29 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
|||
this.stones = new ArrayList<Stone>(stones);
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
GROUP, RUN, INVALID
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for rule conflict within the StoneSet
|
||||
*
|
||||
* @return true when the set is valid according to the rules
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return classify() != INVALID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for rule conflict within the StoneSet and determine whether the set
|
||||
* is a group or a run
|
||||
*
|
||||
* @return GROUP or RUN for valid sets, INVALID otherwise
|
||||
*/
|
||||
public Type classify() {
|
||||
// TODO: extend this for score calculation (release 2...)
|
||||
if (stones.size() < 3) {
|
||||
return false;
|
||||
return INVALID;
|
||||
}
|
||||
int nonJoker1 = -1, nonJoker2 = -1;
|
||||
for (int i = 0; i < stones.size(); i++) {
|
||||
|
@ -43,17 +59,17 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
|||
nonJoker1 = i;
|
||||
}
|
||||
if (nonJoker2 == -1) {
|
||||
return true;
|
||||
return GROUP;
|
||||
}
|
||||
// is run
|
||||
if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2)
|
||||
.getColor()) {
|
||||
return isValidRun(nonJoker1);
|
||||
return isValidRun(nonJoker1) ? RUN : INVALID;
|
||||
|
||||
}
|
||||
// is group
|
||||
else {
|
||||
return isValidGroup();
|
||||
return isValidGroup() ? GROUP : INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue