From a4110b96a21ac715a501fdf5f5d170ee225509de Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Fri, 20 Oct 2017 13:51:52 +0200 Subject: [PATCH] Did commenting --- src/player/malte/PatternGenerator.java | 39 +++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/player/malte/PatternGenerator.java b/src/player/malte/PatternGenerator.java index 6f7b5b8..db1d467 100644 --- a/src/player/malte/PatternGenerator.java +++ b/src/player/malte/PatternGenerator.java @@ -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 winningPatterns(int id) { // Four in a row with one hole Set 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 emptySpaceGenerator(Item... model) { Set 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 empty2SpaceGenerator(Item... model) { Set 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 twoOfFourRowPatterns(int id) { - // TODO: THIS return null; } }