diff --git a/src/player/malte/Item.java b/src/player/malte/Item.java index b203025..e28e1cb 100644 --- a/src/player/malte/Item.java +++ b/src/player/malte/Item.java @@ -1,15 +1,43 @@ package player.malte; +/** + * An item of a pattern for the game of Connect Four. + */ public class Item { + /** + * The relative horizontal position of the item. + */ private int posX; + + /** + * The relative vertical position of the item. + */ private int posY; + + /** + * The IDs this item recognizes valid. + */ private int[] ids; + /** + * Basic constructor. + * + * @param posX Relative horizontal position. + * @param posY Relative vertical position. + * @param The accepted id. + */ public Item(int posX, int posY, int id) { this(posX, posY, new int[]{id}); } + /** + * Basic constructor for multiple IDs. + * + * @param posX Relative horizontal position. + * @param posY Relative vertical position. + * @param The accepted IDs. + */ public Item(int posX, int posY, int[] ids) { this.posX = posX; this.posY = posY; @@ -37,12 +65,22 @@ public class Item { return false; } + /** + * Changes the given oldID to the newID. + * If newID already exists, do nothing. + * IF oldID does not exist, do nothing. + * + * @param oldID The ID to be replaced. + * @param newID The new ID. + */ public void changeID(int oldID, int newID) { + // If the ID already exists, do nothing. for (int id: ids) { if (id == newID) { return; } } + // Otherwise replace it, if oldID exists. for (int i = 0; i < ids.length; i++) { if (ids[i] == oldID) { ids[i] = newID; @@ -60,6 +98,11 @@ public class Item { return s + "])"; } + /** + * Returns a deep copy of the item. + * + * @return A deep copy of this element. + */ public Item copy() { return new Item(posX, posY, ids); }