Skip to content
Settlers Journal
Go back

City Placement Validation, Double Resource Collection, and Robber Blocking

Edit page

TLDR

Adding logic for identifying where cities can be placed. Adding logic for collecting extra resources if a Settlement is a city. Updating the Settlement model to have an isCity() getter. Updating resource collecting logic to ignore collection if a Hexagon is blocked by the Robber. Updating ResourceBundle with utility functions to facilitate this all.

See “Learnings” note below about Collector interface.

// TODO can some kind of Collector be implemented to form the final ResourceBundle?
// collect resources from all adjacent hexagons
ResourceBundle resourceBundle = new ResourceBundle();
this.graph
    .get(settlementNode.get())
    .stream()
    .filter(graphNode -> graphNode.graphNodeIndex().graphNodeType() == GraphIndexType.HEXAGON)
    .filter(hexagonGraphNode -> hexagonGraphNode.graphNodeIndex().index() != knightIndex)
    .map(hexagonGraphNode -> (Hexagon) hexagonGraphNode.graphNodePiece())
    .map(Hexagon::getResourceColor)
    .filter(resourceColor -> resourceColor != ResourceColor.DESERT)
    .forEach(resourceColor -> {
      if(isCity) {
        resourceBundle.addToSpecificResource(resourceColor, 2);
      } else {
        resourceBundle.increment(resourceColor);
      }
    });
return resourceBundle;

Red player’s settlements correctly being identified as places a city could be built.

alt text

Main work

Challenges

Learnings


Edit page
Share this post on:

Next Post
Implementing Available Settlement Placement Validation in the Graph