Skip to content

Commit

Permalink
wip(building-ops): add rule for settlment building
Browse files Browse the repository at this point in the history
  • Loading branch information
manuandru committed Oct 10, 2023
1 parent b9708f3 commit cc1374a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/scala/scatan/model/game/ops/BuildingOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ object BuildingOps:
spot: Spot,
buildingType: BuildingType,
player: ScatanPlayer,
roadBuildingRules: ScatanState => (RoadSpot, ScatanPlayer) => Boolean = defaultCheckBuildRoadCondition
roadBuildingRules: ScatanState => (RoadSpot, ScatanPlayer) => Boolean = defaultRulesForRoadBuilding,
settlementBuildingRules: ScatanState => (StructureSpot, ScatanPlayer) => Boolean =
defaultRulesForSettlementBuilding,
): Option[ScatanState] =
spot match
case citySpot: StructureSpot if buildingType == BuildingType.City =>
Expand All @@ -79,8 +81,7 @@ object BuildingOps:
)
case _ => None
case settlementSpot: StructureSpot if buildingType == BuildingType.Settlement =>
if state.emptyStructureSpot.contains(spot)
// && state.gameMap.edgesOf(settlementSpot).flatMap(state.assignedBuildings.get).exists()
if settlementBuildingRules(state)(settlementSpot, player)
then
Some(
state.copy(
Expand All @@ -101,7 +102,11 @@ object BuildingOps:
else None
case _ => None

private def defaultCheckBuildRoadCondition(spot: RoadSpot, player: ScatanPlayer): Boolean =
private def defaultRulesForSettlementBuilding(spot: StructureSpot, player: ScatanPlayer): Boolean =
state.emptyStructureSpot.contains(spot)
&& state.gameMap.neighboursOf(spot).flatMap(state.assignedBuildings.get).isEmpty

private def defaultRulesForRoadBuilding(spot: RoadSpot, player: ScatanPlayer): Boolean =
val structureSpot1 = spot._1
val structureSpot2 = spot._2
state.emptyRoadSpot.contains(spot)
Expand Down

0 comments on commit cc1374a

Please sign in to comment.