Exemplo n.º 1
0
  private boolean isTilePlacementWithBridgeAllowed(Tile tile, Position p, Location bridgeLoc) {
    if (!tile.isBridgeAllowed(bridgeLoc)) return false;

    for (Entry<Location, Tile> e : getBoard().getAdjacentTilesMap(p).entrySet()) {
      Tile adjacent = e.getValue();
      Location rel = e.getKey();

      char adjacentSide = adjacent.getEdge(rel.rev());
      char tileSide = tile.getEdge(rel);
      if (rel.intersect(bridgeLoc) != null) {
        if (adjacentSide != 'R') return false;
      } else {
        if (adjacentSide != tileSide) return false;
      }
    }
    return true;
  }
Exemplo n.º 2
0
  public BridgeAction prepareMandatoryBridgeAction() {
    Tile tile = game.getCurrentTile();
    for (Entry<Location, Tile> entry :
        getBoard().getAdjacentTilesMap(tile.getPosition()).entrySet()) {
      Tile adjacent = entry.getValue();
      Location rel = entry.getKey();

      char adjacentSide = adjacent.getEdge(rel.rev());
      char tileSide = tile.getEdge(rel);
      if (tileSide != adjacentSide) {
        Location bridgeLoc = getBridgeLocationForAdjacent(rel);
        BridgeAction action = prepareTileBridgeAction(tile, null, bridgeLoc);
        if (action != null) return action;
        return prepareTileBridgeAction(adjacent, null, bridgeLoc);
      }
    }
    throw new IllegalStateException();
  }
Exemplo n.º 3
0
  private boolean isTilePlacementWithOneAdjacentBridgeAllowed(Tile tile, Position p) {
    boolean bridgeUsed = false;
    for (Entry<Location, Tile> e : getBoard().getAdjacentTilesMap(p).entrySet()) {
      Tile adjacent = e.getValue();
      Location rel = e.getKey();

      char tileSide = tile.getEdge(rel);
      char adjacentSide = adjacent.getEdge(rel.rev());

      if (tileSide != adjacentSide) {
        if (bridgeUsed) return false;
        if (tileSide != 'R') return false;

        Location bridgeLoc = getBridgeLocationForAdjacent(rel);
        if (!isBridgePlacementAllowed(adjacent, adjacent.getPosition(), bridgeLoc)) return false;
        bridgeUsed = true;
      }
    }
    return bridgeUsed; // ok if exactly one bridge is used
  }
Exemplo n.º 4
0
 protected boolean check(Tile tile, Location rel, Board board) {
   return getEdge(rel) == tile.getEdge(rel.rev());
 }