Esempio n. 1
1
 @Override
 public void rob() {
   // try and place robber on sheep hex where aiPlayer doesn't have a building itself
   try {
     for (HexLocation sheepHex : sheepHexes) {
       ArrayList<Integer> potentialVictims = getPlayers(sheepHex);
       if (potentialVictims.size() > 0
           && !potentialVictims.contains(getPlayerIndex())
           && !game.getMap().getRobber().getLocation().equals(sheepHex)) {
         game.rob(getPlayerIndex(), potentialVictims.get(0), sheepHex);
         return;
       }
     }
     // this is if the aiPlayer has a building on every single sheep hex.  Now it will just pick a
     // random hex where it doesn't have a building
     java.util.Map<HexLocation, Hex> hexes = game.getMap().getHexes();
     for (java.util.Map.Entry<HexLocation, Hex> entry : hexes.entrySet()) {
       if (entry.getValue().getType() != HexType.WATER) {
         ArrayList<Integer> potentialVictims = getPlayers(entry.getKey());
         if (potentialVictims.size() != 0
             && !potentialVictims.contains(getPlayerIndex())
             && !game.getMap().getRobber().getLocation().equals(entry.getKey())) {
           // this robs a random person on a random hex where the aiPlayer doesn't have a building
           // there
           int victim = potentialVictims.remove(0);
           game.rob(getPlayerIndex(), victim, entry.getKey());
           return;
         }
       }
     }
     // this is if the aiPlayer has a building on every hex that has a building.  Now it will just
     // not rob anyone
     for (java.util.Map.Entry<HexLocation, Hex> entry : hexes.entrySet()) {
       if (entry.getValue().getType() != HexType.WATER) {
         if (!game.getMap().getRobber().getLocation().equals(entry.getKey())) {
           game.rob(getPlayerIndex(), getPlayerIndex(), entry.getKey());
           return;
         }
       }
     }
   } catch (Exception | InvalidTypeException e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
 private void playRoadBuilder()
     throws InvalidPlayerException, PlayerExistsException, InvalidLocationException,
         StructureException, DevCardException {
   EdgeLocation firstRoad = null;
   EdgeLocation secondRoad = null;
   for (EdgeLocation edge : sheepEdges) {
     if (game.canPlaceRoadBuildingCard(getPlayerIndex(), edge)) {
       if (firstRoad == null && secondRoad == null) {
         firstRoad = edge;
       } else if (firstRoad != null && secondRoad == null) {
         secondRoad = edge;
         game.useRoadBuilder(getPlayerIndex(), firstRoad, secondRoad);
         return;
       }
     }
   }
   java.util.Map<EdgeLocation, Edge> edges = game.getMap().getEdges();
   for (java.util.Map.Entry<EdgeLocation, Edge> entry : edges.entrySet()) {
     if (game.canPlaceRoadBuildingCard(getPlayerIndex(), entry.getKey())) {
       if (firstRoad == null && secondRoad == null) {
         firstRoad = entry.getKey();
       } else if (firstRoad != null && secondRoad == null) {
         secondRoad = entry.getKey();
         game.useRoadBuilder(getPlayerIndex(), firstRoad, secondRoad);
         return;
       }
     }
   }
 }
Esempio n. 3
0
 private void playCity()
     throws InvalidLocationException, InvalidPlayerException, PlayerExistsException,
         StructureException {
   for (VertexLocation vertex : sheepVertices) {
     if (game.canBuildCity(getPlayerIndex(), vertex)) {
       game.buildCity(getPlayerIndex(), vertex);
       return;
     }
   }
   java.util.Map<VertexLocation, Vertex> vertices = game.getMap().getVertices();
   for (java.util.Map.Entry<VertexLocation, Vertex> entry : vertices.entrySet()) {
     if (game.canBuildCity(getPlayerIndex(), entry.getKey())) {
       game.buildCity(getPlayerIndex(), entry.getKey());
       return;
     }
   }
 }
Esempio n. 4
0
 private void playRoad()
     throws InvalidLocationException, InvalidPlayerException, PlayerExistsException,
         StructureException {
   for (EdgeLocation edge : sheepEdges) {
     if (game.canBuildRoad(getPlayerIndex(), edge)) {
       game.buildRoad(getPlayerIndex(), edge);
       return;
     }
   }
   java.util.Map<EdgeLocation, Edge> edges = game.getMap().getEdges();
   for (java.util.Map.Entry<EdgeLocation, Edge> entry : edges.entrySet()) {
     if (game.canBuildRoad(getPlayerIndex(), entry.getKey())) {
       game.buildRoad(getPlayerIndex(), entry.getKey());
       return;
     }
   }
 }
Esempio n. 5
0
 private void setSheepLocations() {
   sheepHexes = new ArrayList<>();
   sheepVertices = new ArrayList<>();
   sheepEdges = new ArrayList<>();
   java.util.Map<HexLocation, Hex> hexes = game.getMap().getHexes();
   for (java.util.Map.Entry<HexLocation, Hex> entry : hexes.entrySet()) {
     if (entry.getValue().getType() == HexType.SHEEP) {
       sheepHexes.add(entry.getKey());
       sheepVertices.add(new VertexLocation(entry.getKey(), VertexDirection.NorthWest));
       sheepVertices.add(new VertexLocation(entry.getKey(), VertexDirection.NorthEast));
       sheepVertices.add(new VertexLocation(entry.getKey(), VertexDirection.East));
       sheepVertices.add(new VertexLocation(entry.getKey(), VertexDirection.SouthEast));
       sheepVertices.add(new VertexLocation(entry.getKey(), VertexDirection.SouthWest));
       sheepVertices.add(new VertexLocation(entry.getKey(), VertexDirection.West));
       sheepEdges.add(new EdgeLocation(entry.getKey(), EdgeDirection.NorthWest));
       sheepEdges.add(new EdgeLocation(entry.getKey(), EdgeDirection.North));
       sheepEdges.add(new EdgeLocation(entry.getKey(), EdgeDirection.NorthEast));
       sheepEdges.add(new EdgeLocation(entry.getKey(), EdgeDirection.SouthEast));
       sheepEdges.add(new EdgeLocation(entry.getKey(), EdgeDirection.South));
       sheepEdges.add(new EdgeLocation(entry.getKey(), EdgeDirection.SouthWest));
     }
   }
 }