Did commenting
This commit is contained in:
parent
ee60b28986
commit
b0a1999b94
|
@ -3,10 +3,27 @@ package player.malte;
|
|||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* A generator for patterns for the game of Connect Four.
|
||||
*/
|
||||
public class PatternGenerator {
|
||||
|
||||
/**
|
||||
* Do not instanciate.
|
||||
*/
|
||||
private PatternGenerator() {}
|
||||
|
||||
/**
|
||||
* Returns the winning patterns.
|
||||
* X | X | XXXX | X
|
||||
* X | X | | X
|
||||
* X | X | | X
|
||||
* X | X | | X
|
||||
* Any of the above with an empty space is considered a winning pattern.
|
||||
* Except the first one, in which only the topmost space can be empty.
|
||||
*
|
||||
* @param id The player's id.
|
||||
*/
|
||||
public static Set<Pattern> winningPatterns(int id) {
|
||||
// Four in a row with one hole
|
||||
Set<Pattern> pats = PatternGenerator.emptySpaceGenerator(new Item(0, 0, id),
|
||||
|
@ -23,6 +40,7 @@ public class PatternGenerator {
|
|||
new Item(1, 1, id),
|
||||
new Item(2, 2, id),
|
||||
new Item(3, 3, id)));
|
||||
// Three on top of each other.
|
||||
pats.add(new Pattern(new Item(0, 0, 0),
|
||||
new Item(0, 1, id),
|
||||
new Item(0, 2, id),
|
||||
|
@ -30,19 +48,36 @@ public class PatternGenerator {
|
|||
return pats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates patterns with one empty space.
|
||||
* Returns a set of patterns, each one containing an empty space.
|
||||
* Each element of model is replaced once with an empty space Item.
|
||||
* Always adds one support Item beneath the hole.
|
||||
*
|
||||
* @param model The basis of the pattern.
|
||||
* @return A set of patterns created by the above rule.
|
||||
*/
|
||||
public static Set<Pattern> emptySpaceGenerator(Item... model) {
|
||||
Set<Pattern> ret = new HashSet<>();
|
||||
// Iterate over all models.
|
||||
for (int i = 0; i < model.length; i++) {
|
||||
// Create a new pattern.
|
||||
Pattern newP = new Pattern(model);
|
||||
Item x = model[i];
|
||||
Item newI = new Item(x.getPosX(), x.getPosY(), 0);
|
||||
// Replace one item with the new 0-one.
|
||||
newP.replaceItem(x, newI);
|
||||
// Add the support.
|
||||
newP.addItem(new Item(x.getPosX(), x.getPosY() + 1, new int[]{1, 2}));
|
||||
// Add the pattern to the set.
|
||||
ret.add(newP);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: THIS
|
||||
*/
|
||||
public static Set<Pattern> empty2SpaceGenerator(Item... model) {
|
||||
Set<Pattern> ret = new HashSet<>();
|
||||
for (int i = 0; i < model.length; i++) {
|
||||
|
@ -56,8 +91,10 @@ public class PatternGenerator {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: THIS
|
||||
*/
|
||||
public static Set<Pattern> twoOfFourRowPatterns(int id) {
|
||||
// TODO: THIS
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue