diff --git a/Makefile b/Makefile index d366ea7..35b4308 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,8 @@ src/game/GameEntry.java \ src/game/PlayerObject.java \ src/player/Player.java \ src/player/malte/MalteAI.java \ +src/player/malte/Pattern.java \ +src/player/malte/Item.java \ src/player/maurizio/MaurizioAI.java OBJECTS=$($(subst $(CLASSPATH),$(BUILDS),$(CLASSES)):.java=.class) diff --git a/src/player/malte/Item.java b/src/player/malte/Item.java new file mode 100644 index 0000000..a27847e --- /dev/null +++ b/src/player/malte/Item.java @@ -0,0 +1,39 @@ +package player.malte; + +public class Item { + + private int posX; + private int posY; + private int[] ids; + + public Item(int posX, int posY, int id) { + this(posX, posY, new int[]{id}); + } + + public Item(int posX, int posY, int[] ids) { + this.posX = posX; + this.posY = posY; + this.ids = ids; + } + + public int getPosX() { + return this.posX; + } + + public int getPosY() { + return this.posY; + } + + public int[] getIDs() { + return this.ids; + } + + public boolean hasID(int id) { + for (int i: ids) { + if (i == id) { + return true; + } + } + return false; + } +} diff --git a/src/player/malte/MalteAI.java b/src/player/malte/MalteAI.java index bdc9db2..caa1cdd 100644 --- a/src/player/malte/MalteAI.java +++ b/src/player/malte/MalteAI.java @@ -1,4 +1,4 @@ -package player; +package player.malte; import java.util.Random; import java.util.Set; @@ -9,6 +9,7 @@ public class MalteAI implements Player{ private String name; private Random ran; + private int id = 2; public MalteAI(String name){ this.name = name; @@ -22,11 +23,27 @@ public class MalteAI implements Player{ options.remove(i); } } + Set instantWins = getWinningOptions(options, board); // Set preventions = getPreventionOptions(options, board); return takeRandom(options).intValue(); } + private Set getWinningOptions(Set options, int[][] board) { + Pattern topOfColumn = new Pattern(new Item(0, 0, 0), + new Item(0, 1, id), + new Item(0, 2, id), + new Item(0, 3, id)); + Pattern leftInRow = new Pattern(new Item(0, 0, 0), + new Item(1, 0, id), + new Item(2, 0, id), + new Item(3, 0, id)); + Pattern rightInRow = new Pattern(new Item(0, 0, 0), + new Item(-1, 0, id), + new Item(-2, 0, id), + new Item(-3, 0, id)); + } + private Set copySet(Set s) { return new HashSet(s); } diff --git a/src/player/malte/Pattern.java b/src/player/malte/Pattern.java index b5323ea..156f03f 100644 --- a/src/player/malte/Pattern.java +++ b/src/player/malte/Pattern.java @@ -2,15 +2,9 @@ package player.malte; public class Pattern { + private Item[] parts; + public Pattern(Item... parts) { - - } - - public class Item { - - // TODO: DO! - public Item() { - - } + this.parts = parts; } }