From cc1374a971acfe10888651dfffb3fb2a75597537 Mon Sep 17 00:00:00 2001 From: Manuel Andruccioli Date: Tue, 10 Oct 2023 19:19:39 +0200 Subject: [PATCH] wip(building-ops): add rule for settlment building --- .../scala/scatan/model/game/ops/BuildingOps.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/scala/scatan/model/game/ops/BuildingOps.scala b/src/main/scala/scatan/model/game/ops/BuildingOps.scala index 27f67967..d9b4ed77 100644 --- a/src/main/scala/scatan/model/game/ops/BuildingOps.scala +++ b/src/main/scala/scatan/model/game/ops/BuildingOps.scala @@ -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 => @@ -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( @@ -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)