diff --git a/src/game/Game.java b/src/game/Game.java index 6b84c57..dce9669 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -86,6 +86,7 @@ public class Game { for (int i = 0; i < runs; i++) { int result = new Game(p1, p2).start(false, true); // TODO: Improve IDs + System.out.println(result); statistic[result]++; } double[] percents = new double[3]; @@ -140,6 +141,7 @@ public class Game { return state; // the result of the game } } + System.out.println("BUG!"); return checkState(false); // it is impossible to reach this, but it makes the compiler happy ;) } @@ -166,7 +168,8 @@ public class Game { // Check his choice against the current board. if (choice < 0 || choice > GAME_COLUMNS || this.board[choice][0] != 0) { // If a player makes a false move, the game punishes him. - this.gameOn = false; + // TODO: Fix this, causes -1 return of checkstate in Simulation mode, breaks the game. + // this.gameOn = false; //TODO the game gets stopped, but checkState doesn't know what that means!? if(output){ log(currentP.getP().getName() + " made an illegal move and lost!"); diff --git a/src/player/malte/Item.java b/src/player/malte/Item.java index a27847e..b203025 100644 --- a/src/player/malte/Item.java +++ b/src/player/malte/Item.java @@ -36,4 +36,31 @@ public class Item { } return false; } + + public void changeID(int oldID, int newID) { + for (int id: ids) { + if (id == newID) { + return; + } + } + for (int i = 0; i < ids.length; i++) { + if (ids[i] == oldID) { + ids[i] = newID; + return; + } + } + } + + @Override + public String toString() { + String s = String.format("(%d, %d, [", posX, posY); + for (int i: ids) { + s += i + " "; + } + return s + "])"; + } + + public Item copy() { + return new Item(posX, posY, ids); + } } diff --git a/src/player/malte/MalteAI.java b/src/player/malte/MalteAI.java index ef285fb..77476ad 100644 --- a/src/player/malte/MalteAI.java +++ b/src/player/malte/MalteAI.java @@ -31,6 +31,7 @@ public class MalteAI implements Player{ } Set winningOptions = getWinningOptions(options, board); for (Integer i: winningOptions) { + System.out.println(i); return i.intValue(); } @@ -57,10 +58,15 @@ public class MalteAI implements Player{ new Item(0, 1, id), new Item(0, 2, id), new Item(0, 3, id))); - Set matches = Pattern.matches(patterns, board); + // for (Pattern p: patterns) { + // System.out.println(p); + // } + Set matches = Pattern.matchingPatterns(patterns, board); Set ret = new HashSet<>(); - for (Position x: matches) { - + for (Pattern p: matches) { + for (Item i: p.getZeros()) { + ret.add(new Integer(i.getPosX())); + } } return ret; diff --git a/src/player/malte/Pattern.java b/src/player/malte/Pattern.java index afc1621..ffab4b2 100644 --- a/src/player/malte/Pattern.java +++ b/src/player/malte/Pattern.java @@ -14,6 +14,10 @@ public class Pattern { this.parts = new HashSet(Arrays.asList(parts)); } + public Pattern(Set parts) { + this.parts = parts; + } + public Set matches(int[][] board) { // Preparing iteration int maxLeft = 0, @@ -72,6 +76,14 @@ public class Pattern { return ret; } + public Pattern copy() { + Set itemCopy = new HashSet<>(); + for (Item i: parts) { + itemCopy.add(i.copy()); + } + return new Pattern(itemCopy); + } + public static Set matches(Set pats, int[][] board) { Set ret = new HashSet<>(); for (Pattern p: pats) { @@ -80,6 +92,16 @@ public class Pattern { return ret; } + public static Set matchingPatterns(Set pats, int[][] board) { + Set ret = new HashSet<>(); + for (Pattern p: pats) { + if (p.matches(board).size() > 0) { + ret.add(p); + } + } + return ret; + } + public static Set emptySpaceGenerator(Item... model) { Set ret = new HashSet<>(); for (int i = 0; i < model.length; i++) { @@ -87,9 +109,30 @@ public class Pattern { 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})); + newP.addItem(new Item(x.getPosX(), x.getPosY() + 1, new int[]{1, 2})); ret.add(newP); } return ret; } + + public static Set changeID(Set pats, int oldID, int newID) { + Set ret = new HashSet<>(); + for (Pattern p: pats) { + Pattern cpy = p.copy(); + for (Item i: p.parts) { + i.changeID(oldID, newID); + } + ret.add(cpy); + } + return ret; + } + + @Override + public String toString() { + String s = ""; + for (Item i: parts) { + s += i + ", "; + } + return s + "\n"; + } }