protected Point pickRandom() { int x = 0; int y = 0; do { x = random.nextInt(this.size); y = random.nextInt(this.size); } while (mainBoard.get(x, y) != Board.BLANK || mainBoard.getSeason(x, y) != game.getSeasonPicker().getCurrentSeason(player)); return new Point(x, y); }
public Move getMove() { /* * wipe all scoreboards */ myPathlength.wipeAll(); oppPathlength.wipeAll(); myPathCount.wipeAll(); oppPathCount.wipeAll(); comboLengths.wipeAll(); comboPathCounts.wipeAll(); for (int y = 0; y < size; y++) for (int x = 0; x < size; x++) if (game.getBoard().get(x, y) == Board.BLANK) { /* * player related scores */ int score = 0; boardClone.setBoard(mainBoard.openClone()); boardClone.set(x, y, player); AdjMatrix base = boardClone.getData().getAdjMatrix(player).clone(); while (!(base.read(myBorder1, myBorder2) > 0) && score < maxPathLength) { base = base.mult(boardClone.getData().getAdjMatrix(player)); score++; } myPathlength.set(x, y, score); myPathCount.set(x, y, base.read(myBorder1, myBorder2)); /* * opponant related scores */ score = 0; boardClone.setBoard(mainBoard.openClone()); boardClone.set(x, y, player); base = boardClone.getData().getAdjMatrix(opponent).clone(); while (!(base.read(oppBorder1, oppBorder2) > 0) && score < maxPathLength) { base = base.mult(boardClone.getData().getAdjMatrix(opponent)); score++; } oppPathlength.set(x, y, score); oppPathCount.set(x, y, base.read(oppBorder1, oppBorder2)); /* * combine scores... */ score = (int) (aggro * myPathlength.get(x, y) - (1 - aggro) * oppPathlength.get(x, y)); comboLengths.set(x, y, score); score = (int) (aggro * (-myPathCount.get(x, y)) + (1 - aggro) * oppPathCount.get(x, y)); comboPathCounts.set(x, y, score); } Point winner = pickRandom(); int winx = winner.x; int winy = winner.y; int winScore = comboLengths.get(winx, winy); for (int y = 0; y < size; y++) for (int x = 0; x < size; x++) // if empty space if (mainBoard.get(x, y) == Board.BLANK && mainBoard.getSeason(x, y) == game.getSeasonPicker().getCurrentSeason(player)) if (beats(x, y, winx, winy)) { winx = x; winy = y; } return new Move(player, winx, winy); }