diff --git a/src/player/malte/MalteAI.java b/src/player/malte/MalteAI.java index 340bb4f..407c600 100644 --- a/src/player/malte/MalteAI.java +++ b/src/player/malte/MalteAI.java @@ -44,13 +44,31 @@ public class MalteAI implements Player{ new Pattern(new Item(0, 0, 0), new Item(1, 0, id), new Item(2, 0, id), - new Item(3, 0, id)), + new Item(3, 0, id), + new Item(0, 1, new int[]{1, 2})), // Three in a row, empty right new Pattern(new Item(0, 0, 0), new Item(-1, 0, id), new Item(-2, 0, id), - new Item(-3, 0, id))} - Set matches = pats.matches(board); + new Item(-3, 0, id), + new Item(0, 1, new int[]{1, 2})), + // Three in a diagonal line from lower left to upper right, empty right above + new Pattern(new Item(0, 0, 0), + new Item(-1, 1, id), + new Item(-2, 2, id), + new Item(-3, 3, id), + // TODO: Improve IDs here + new Item(0, 1, new int[]{1, 2})), + // Three in a diagonal line from upper left to lower right, empty left above + new Pattern(new Item(0, 0, 0), + new Item(1, 1, id), + new Item(2, 2, id), + new Item(3, 3, id), + // TODO: Improve IDs here + new Item(0, 1, new int[]{1, 2})), + }; + // Set patterns = + Set matches = Pattern.matches(pats, board); Set ret = new HashSet<>(); for (Position x: matches) { System.out.println(x); diff --git a/src/player/malte/Pattern.java b/src/player/malte/Pattern.java index 979b3ca..c47a1c4 100644 --- a/src/player/malte/Pattern.java +++ b/src/player/malte/Pattern.java @@ -2,15 +2,16 @@ package player.malte; import java.util.Set; import java.util.HashSet; +import java.util.Arrays; import game.Game; public class Pattern { - private Item[] parts; + private Set parts; public Pattern(Item... parts) { - this.parts = parts; + this.parts = new HashSet(Arrays.asList(parts)); } public Set matches(int[][] board) { @@ -50,6 +51,17 @@ public class Pattern { return set; } + public void replaceItem(Item oldItem, Item newItem) { + if (this.parts.contains(oldItem)) { + this.parts.remove(oldItem); + this.parts.add(newItem); + } + } + + public void addItem(Item item) { + this.parts.add(item); + } + public static Set matches(Pattern[] pats, int[][] board) { Set ret = new HashSet<>(); for (Pattern p: pats) { @@ -57,4 +69,17 @@ public class Pattern { } return ret; } + + public static Set emptySpaceGenerator(Item... model) { + Set ret = new HashSet<>(); + for (int i = 0; i < model.length; i++) { + Pattern newP = new Pattern(model); + Item x = model[i]; + Item newI = new Item(x.getPosX(), x.getPosY(), 0); + newP.replaceItem(x, newI); + newP.addItem(new Item(x.getPosX(), x.getPosY() - 1, new int[]{1, 2})); + ret.add(newP); + } + return ret; + } }