diff --git a/src/test/scala/scatan/model/game/BaseScatanStateTest.scala b/src/test/scala/scatan/model/game/BaseScatanStateTest.scala index abc0d30e..560793f2 100644 --- a/src/test/scala/scatan/model/game/BaseScatanStateTest.scala +++ b/src/test/scala/scatan/model/game/BaseScatanStateTest.scala @@ -8,6 +8,7 @@ import scatan.model.map.RoadSpot import scatan.model.game.ops.EmptySpotsOps.emptyRoadSpot import scatan.model.game.ops.BuildingOps.assignBuilding import scatan.model.components.BuildingType +import scatan.model.map.StructureSpot abstract class BaseScatanStateTest extends BaseTest: @@ -15,13 +16,17 @@ abstract class BaseScatanStateTest extends BaseTest: (1 to n).map(i => ScatanPlayer(s"Player $i")) protected def noConstrainToBuildRoad: ScatanState => ((RoadSpot, ScatanPlayer) => Boolean) = _ => (_, _) => true + protected def noConstrainToBuildSettlment: ScatanState => ((StructureSpot, ScatanPlayer) => Boolean) = _ => + (_, _) => true protected def spotShouldBeEmptyToBuildRoad: ScatanState => ((RoadSpot, ScatanPlayer) => Boolean) = s => (r, _) => s.emptyRoadSpot.contains(r) // Avoid heavy check on spot type extension (state: ScatanState) def assignRoadWithoutRule(spot: RoadSpot, player: ScatanPlayer): Option[ScatanState] = - state.assignBuilding(spot, BuildingType.Road, player, noConstrainToBuildRoad) + state.assignBuilding(spot, BuildingType.Road, player, roadBuildingRules = noConstrainToBuildRoad) + def assignSettlmentWithoutRule(spot: StructureSpot, player: ScatanPlayer): Option[ScatanState] = + state.assignBuilding(spot, BuildingType.Settlement, player, settlementBuildingRules = noConstrainToBuildSettlment) protected def emptySpot(state: ScatanState): Spot = state.emptySpots.head diff --git a/src/test/scala/scatan/model/game/ops/BuildingOpsTest.scala b/src/test/scala/scatan/model/game/ops/BuildingOpsTest.scala index b8558104..3f1e804f 100644 --- a/src/test/scala/scatan/model/game/ops/BuildingOpsTest.scala +++ b/src/test/scala/scatan/model/game/ops/BuildingOpsTest.scala @@ -46,12 +46,7 @@ class BuildingOpsTest extends BaseScatanStateTest: it should "not permit to assign a settlement if the spot is not empty" in { val state = ScatanState(threePlayers) val spot = spotToBuildStructure(state) - val stateWithBuilding = for - stateWithWood <- state.assignResourceCard(threePlayers.head, ResourceCard(ResourceType.Wood)) - stateWithBrick <- stateWithWood.assignResourceCard(threePlayers.head, ResourceCard(ResourceType.Brick)) - stateWithSheep <- stateWithBrick.assignResourceCard(threePlayers.head, ResourceCard(ResourceType.Sheep)) - stateWithSettlement <- stateWithSheep.build(spot, BuildingType.Settlement, threePlayers.head) - yield stateWithSettlement + val stateWithBuilding = state.assignSettlmentWithoutRule(spot, threePlayers.head) stateWithBuilding match case Some(state) => state.assignedBuildings(spot) should be(AssignmentInfo(threePlayers.head, BuildingType.Settlement)) @@ -194,6 +189,5 @@ class BuildingOpsTest extends BaseScatanStateTest: state .assignBuilding(anotherSpot, BuildingType.Settlement, threePlayers.head) .flatMap(_.assignBuilding(spot, BuildingType.Settlement, threePlayers.head)) - println(stateAssigned.map(_.assignedBuildings)) stateAssigned should be(None) } diff --git a/src/test/scala/scatan/model/game/ops/ResCardOpsTest.scala b/src/test/scala/scatan/model/game/ops/ResCardOpsTest.scala index a02fcd6a..a3243e50 100644 --- a/src/test/scala/scatan/model/game/ops/ResCardOpsTest.scala +++ b/src/test/scala/scatan/model/game/ops/ResCardOpsTest.scala @@ -116,12 +116,12 @@ class ResCardOpsTest extends BaseScatanStateTest: val spotWhereToBuild = state.emptyStructureSpot.filter(_.contains(hexagonWithSheep)).iterator // simulate initial placement val stateWithBuildings = state - .assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.head) - .flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.tail.head)) - .flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.tail.tail.head)) - .flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.tail.tail.head)) - .flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.tail.head)) - .flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.head)) + .assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.head) + .flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.tail.head)) + .flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.tail.tail.head)) + .flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.tail.tail.head)) + .flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.tail.head)) + .flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.head)) stateWithBuildings match case Some(state) => state.assignResourcesAfterInitialPlacement match diff --git a/src/test/scala/scatan/model/game/ops/ScoreOpsTest.scala b/src/test/scala/scatan/model/game/ops/ScoreOpsTest.scala index 54a3447b..d96705a8 100644 --- a/src/test/scala/scatan/model/game/ops/ScoreOpsTest.scala +++ b/src/test/scala/scatan/model/game/ops/ScoreOpsTest.scala @@ -77,16 +77,16 @@ class ScoreOpsTest extends BaseScatanStateTest: val player1 = threePlayers.head val it = state.emptyStructureSpot.iterator val stateWithAWinner = for - oneSettlementState <- state.assignBuilding(it.next, BuildingType.Settlement, player1) - twoSettlementState <- oneSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1) - threeSettlementState <- twoSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1) - fourSettlementState <- threeSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1) - fiveSettlementState <- fourSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1) - sixSettlementState <- fiveSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1) - sevenSettlementState <- sixSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1) - eightSettlementState <- sevenSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1) - nineSettlementState <- eightSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1) - tenSettlementState <- nineSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1) + oneSettlementState <- state.assignSettlmentWithoutRule(it.next, player1) + twoSettlementState <- oneSettlementState.assignSettlmentWithoutRule(it.next, player1) + threeSettlementState <- twoSettlementState.assignSettlmentWithoutRule(it.next, player1) + fourSettlementState <- threeSettlementState.assignSettlmentWithoutRule(it.next, player1) + fiveSettlementState <- fourSettlementState.assignSettlmentWithoutRule(it.next, player1) + sixSettlementState <- fiveSettlementState.assignSettlmentWithoutRule(it.next, player1) + sevenSettlementState <- sixSettlementState.assignSettlmentWithoutRule(it.next, player1) + eightSettlementState <- sevenSettlementState.assignSettlmentWithoutRule(it.next, player1) + nineSettlementState <- eightSettlementState.assignSettlmentWithoutRule(it.next, player1) + tenSettlementState <- nineSettlementState.assignSettlmentWithoutRule(it.next, player1) yield tenSettlementState stateWithAWinner match