Skip to content

Commit

Permalink
fixed too after ai placement on top of tower
Browse files Browse the repository at this point in the history
  • Loading branch information
farin committed Mar 4, 2015
1 parent 5ad9c3c commit 5b1c96e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
1 change: 1 addition & 0 deletions future.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* error message bar can be dismissed
* rotate board (/ key)
* right click on board with shift down behave as middle mouse click (center board to click point)
* fix: too often AI placement on top of tower
* fix: "2-tiles bug" - if playing with GQ11 & King and Scout - at game and counter still shows 2 tiles
* fix: can't place on tower if there isn't normal placement possibility
* fix: It is not possible to place the phantom as an abbot on a German monastery
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcloisterzone/ai/SelectActionTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void dbgPringStep(AiChoice choice, boolean isFinal) {
@Override
public void run() {
//logger.info("Select action task started " + aiPlayer.getClientStub().getGame().getTilePack().size() + " " + rootEv.getPlayer() + " > " + rootEv.getActions().toString());
boolean dbgPrint = false;
boolean dbgPrint = !false;
try {
this.game = aiPlayer.copyGame(this);
if (dbgPrint) dbgPringHeader();
Expand Down
51 changes: 37 additions & 14 deletions src/main/java/com/jcloisterzone/ai/legacyplayer/LegacyRanking.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class LegacyRanking implements GameRanking {

private int[] openCount = new int[4]; //number of my open objects

//don't use to accest points/followers etc. - this player is not related to cloned game and reflect current state of real game only!!!
//TODO store only index to prevent accidentally access
private final AiPlayer aiPlayer;


Expand All @@ -82,7 +84,8 @@ protected void initVars(Game game) {
myTurnsLeft = ((packSize-1) / (enemyPlayers+1)) + 1;
}

public double getPartialAfterTilePlacement(Game game, Tile tile) {
@Override
public double getPartialAfterTilePlacement(Game game, Tile tile) {
Position pos = tile.getPosition();
//return 0.001 * game.getBoard().getAdjacentAndDiagonalTiles(pos).size();
return 0.001 * game.getBoard().getAdjacentTilesMap(pos).size(); //adjacent only is better
Expand Down Expand Up @@ -165,7 +168,17 @@ protected double meepleRating(Game game) {
if (++limit == myTurnsLeft) break;
}
rating += reducePoints(meeplePoints, p);

if (p.equals(aiPlayer.getPlayer())) {
for (Follower f : p.getFollowers()) {
if (f.getLocation() == Location.TOWER) {
rating -= 9.0;
}
}
}
}


return rating;
}

Expand All @@ -180,16 +193,24 @@ public LegacyAiScoreAllCallback(Game game) {
this.game = game;
TowerCapability towerCap = game.getCapability(TowerCapability.class);
if (towerCap != null) {
for (Position towerPos : towerCap.getTowers()) {
int dangerDistance = 1 + game.getBoard().get(towerPos).getTower().getHeight();
towerDanger.add(towerPos);
for (int i = 1; i < dangerDistance; i++) {
towerDanger.add(towerPos.add(new Position(i, 0)));
towerDanger.add(towerPos.add(new Position(-i, 0)));
towerDanger.add(towerPos.add(new Position(0, i)));
towerDanger.add(towerPos.add(new Position(0, -i)));
}
}
//TODO ignore if opponents has no tower tokens
int pieces = 0;
for (Player p : game.getAllPlayers()) {
if (p.equals(aiPlayer.getPlayer())) continue;
pieces += towerCap.getTowerPieces(p);
}
if (pieces > 0) {
for (Position towerPos : towerCap.getTowers()) {
int dangerDistance = 1 + game.getBoard().get(towerPos).getTower().getHeight();
towerDanger.add(towerPos);
for (int i = 1; i < dangerDistance; i++) {
towerDanger.add(towerPos.add(new Position(i, 0)));
towerDanger.add(towerPos.add(new Position(-i, 0)));
towerDanger.add(towerPos.add(new Position(0, i)));
towerDanger.add(towerPos.add(new Position(0, -i)));
}
}
}
}
}

Expand Down Expand Up @@ -252,10 +273,11 @@ public void scoreCompletableFeature(CompletableScoreContext ctx) {
}
return;
}
if (isInTowerDanger(ctx)) return;
rank += rankUnfishedCompletable(ctx.getMasterFeature(), (LegacyAiScoreContext) ctx);
rank += rankTrappedMeeples((LegacyAiScoreContext) ctx);
rank += rankSpecialFigures(game, (LegacyAiScoreContext) ctx);
if (!isInTowerDanger(ctx)) {
rank += rankUnfishedCompletable(ctx.getMasterFeature(), (LegacyAiScoreContext) ctx);
rank += rankSpecialFigures(game, (LegacyAiScoreContext) ctx);
}
}

public double getRanking() {
Expand Down Expand Up @@ -531,6 +553,7 @@ protected double rankFairy(Game game) {
protected double rankUnfishedCompletable(Completable completable, LegacyAiScoreContext ctx) {
double rating = 0.0;
double points = getUnfinishedCompletablePoints(completable, ctx);

for (Player p : ctx.getMajorOwners()) {
rating += reducePoints(points, p);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,9 @@ public void handleError(Connection conn, ErrorMessage err) {
JOptionPane.showMessageDialog(client, msg, _("Incompatible versions"), JOptionPane.ERROR_MESSAGE);
break;
case ErrorMessage.INVALID_PASSWORD:
//TODO show inside channel panel
JOptionPane.showMessageDialog(client, _("Invalid password"), _("Invalid password"), JOptionPane.WARNING_MESSAGE);
default:
logger.error(err.getMessage());
JOptionPane.showMessageDialog(client, err.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}

Expand Down

0 comments on commit 5b1c96e

Please sign in to comment.