Changing Patterns, creating and testing them
This commit is contained in:
parent
6822716035
commit
e126b18cde
|
@ -38,47 +38,29 @@ public class MalteAI implements Player{
|
|||
}
|
||||
|
||||
private Set<Integer> getWinningOptions(Set<Integer> options, int[][] board) {
|
||||
Pattern[] pats = new Pattern[]{
|
||||
// Three in a column, empty above
|
||||
new Pattern(new Item(0, 0, 0),
|
||||
new Item(0, 1, id),
|
||||
new Item(0, 2, id),
|
||||
new Item(0, 3, id)),
|
||||
// Three in a row, empty left
|
||||
new Pattern(new Item(0, 0, 0),
|
||||
// Four in a row with one hole
|
||||
Set<Pattern> patterns = Pattern.emptySpaceGenerator(new Item(0, 0, id),
|
||||
new Item(1, 0, id),
|
||||
new Item(2, 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),
|
||||
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(3, 0, id));
|
||||
// Four in a diagonal line from lower left to upper right with one hole
|
||||
patterns.addAll(Pattern.emptySpaceGenerator(new Item(0, 0, id),
|
||||
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(-3, 3, id)));
|
||||
// Four in a diagonal line from upper left to lower right with one hole
|
||||
patterns.addAll(Pattern.emptySpaceGenerator(new Item(0, 0, id),
|
||||
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<Pattern> patterns =
|
||||
Set<Position> matches = Pattern.matches(pats, board);
|
||||
new Item(3, 3, id)));
|
||||
patterns.add(new Pattern(new Item(0, 0, 0),
|
||||
new Item(0, 1, id),
|
||||
new Item(0, 2, id),
|
||||
new Item(0, 3, id)));
|
||||
Set<Position> matches = Pattern.matches(patterns, board);
|
||||
Set<Integer> ret = new HashSet<>();
|
||||
for (Position x: matches) {
|
||||
System.out.println(x);
|
||||
if (options.contains(x.getPosX())) {
|
||||
ret.add(new Integer(x.getPosX()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -62,7 +62,17 @@ public class Pattern {
|
|||
this.parts.add(item);
|
||||
}
|
||||
|
||||
public static Set<Position> matches(Pattern[] pats, int[][] board) {
|
||||
public Set<Item> getZeros() {
|
||||
Set<Item> ret = new HashSet<>();
|
||||
for (Item i: parts) {
|
||||
if (i.hasID(0)) {
|
||||
ret.add(i);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Set<Position> matches(Set<Pattern> pats, int[][] board) {
|
||||
Set<Position> ret = new HashSet<>();
|
||||
for (Pattern p: pats) {
|
||||
ret.addAll(p.matches(board));
|
||||
|
|
Loading…
Reference in a new issue