Skip to content

Commit

Permalink
refactor(tradeOps): rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-borriello00 committed Oct 15, 2023
1 parent afa5683 commit 5ce12c1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/scatan/model/game/ScatanEffects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scatan.model.game.state.ops.BuildingOps.{assignBuilding, build}
import scatan.model.game.state.ops.DevelopmentCardOps.*
import scatan.model.game.state.ops.ResourceCardOps.*
import scatan.model.game.state.ops.RobberOps.moveRobber
import scatan.model.game.state.ops.TradeOps.{tradeWithBank, tradeWithPlayer}
import scatan.model.game.state.ops.TradeOps.{tradeWithBank, tradeBetweenPlayers}
import scatan.model.map.{Hexagon, RoadSpot, StructureSpot}

object ScatanEffects:
Expand Down Expand Up @@ -249,4 +249,4 @@ object ScatanEffects:
senderCards: Seq[ResourceCard],
receiverCards: Seq[ResourceCard]
): Effect[TradeWithPlayer.type, ScatanState] =
(state: ScatanState) => state.tradeWithPlayer(sender, receiver, senderCards, receiverCards)
(state: ScatanState) => state.tradeBetweenPlayers(sender, receiver, senderCards, receiverCards)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import scatan.model.map.{Hexagon, RoadSpot}
*/
object DevelopmentCardOps:

type DevelopmentCardEffect = ScatanState => Option[ScatanState]

extension (state: ScatanState)
/** Returns a new ScatanState with the given development card assigned to the given player. The development card is
* added to the player's list of development cards. The assigned awards are updated.
Expand Down Expand Up @@ -115,7 +117,7 @@ object DevelopmentCardOps:
player: ScatanPlayer,
developmentType: DevelopmentType,
turnNumber: Int
)(effect: ScatanState => Option[ScatanState]): Option[ScatanState] =
)(effect: DevelopmentCardEffect): Option[ScatanState] =
val stateWithCardConsumed = for
developmentCards <- state.developmentCards.get(player)
card <- developmentCards.find(card =>
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/scatan/model/game/state/ops/TradeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object TradeOps:
val tradeWithBankRequiredCards = 4
extension (state: ScatanState)

/** Trade with a player. The sender must have the senderCards and the receiver must have the receiverCards The
/** Trade between two players. The sender must have the senderCards and the receiver must have the receiverCards The
* sender will give the senderCards to the receiver and vice versa
*
* @param sender
Expand All @@ -25,7 +25,7 @@ object TradeOps:
* @return
* Some(state) if the trade is allowed, None otherwise
*/
def tradeWithPlayer(
def tradeBetweenPlayers(
sender: ScatanPlayer,
receiver: ScatanPlayer,
senderCards: Seq[ResourceCard],
Expand Down
13 changes: 9 additions & 4 deletions src/test/scala/scatan/model/game/state/ops/TradeOpsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scatan.model.components.*
import scatan.model.game.BaseScatanStateTest
import scatan.model.game.state.ScatanState
import scatan.model.game.state.ops.ResourceCardOps.assignResourceCard
import scatan.model.game.state.ops.TradeOps.{tradeWithBank, tradeWithPlayer}
import scatan.model.game.state.ops.TradeOps.{tradeWithBank, tradeBetweenPlayers}

class TradeOpsTest extends BaseScatanStateTest:

Expand All @@ -19,7 +19,7 @@ class TradeOpsTest extends BaseScatanStateTest:
stateWithResourceAssigned match
case Some(stateWithResourceAssigned) =>
val stateWithTrade =
stateWithResourceAssigned.tradeWithPlayer(
stateWithResourceAssigned.tradeBetweenPlayers(
sender,
receiver,
Seq(ResourceCard(ResourceType.Wood), ResourceCard(ResourceType.Wood)),
Expand Down Expand Up @@ -49,7 +49,12 @@ class TradeOpsTest extends BaseScatanStateTest:
state.resourceCards(sender) should be(Seq(ResourceCard(ResourceType.Wood)))
state.resourceCards(receiver) should be(Seq(ResourceCard(ResourceType.Brick)))
val stateWithTrade =
state.tradeWithPlayer(sender, receiver, Seq(ResourceCard(ResourceType.Brick)), state.resourceCards(receiver))
state.tradeBetweenPlayers(
sender,
receiver,
Seq(ResourceCard(ResourceType.Brick)),
state.resourceCards(receiver)
)
stateWithTrade should be(None)
case None => fail("Resources not assigned")
}
Expand All @@ -66,7 +71,7 @@ class TradeOpsTest extends BaseScatanStateTest:
stateWithResourceAssigned match
case Some(state) =>
val stateWithTrade =
state.tradeWithPlayer(
state.tradeBetweenPlayers(
sender,
receiver,
Seq(ResourceCard(ResourceType.Wood)),
Expand Down

0 comments on commit 5ce12c1

Please sign in to comment.