Added Pattern and Item classes

This commit is contained in:
Malte Tammena 2017-10-18 14:28:48 +02:00
parent 3c2e947b33
commit b91c53b492
4 changed files with 62 additions and 10 deletions

View file

@ -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)

View file

@ -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;
}
}

View file

@ -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<Integer> instantWins = getWinningOptions(options, board);
// Set<Integer> preventions = getPreventionOptions(options, board);
return takeRandom(options).intValue();
}
private Set<Integer> getWinningOptions(Set<Integer> 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<Integer> copySet(Set<Integer> s) {
return new HashSet<Integer>(s);
}

View file

@ -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;
}
}