Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephtelolahy committed Dec 25, 2024
1 parent 1f9de05 commit 9db957b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
3 changes: 2 additions & 1 deletion WildWestOnline/Core/Bang/Sources/Game/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public struct Card: Equatable, Codable, Sendable {
case healthZero
case gameOver
case currentTurn
case draw(_ regex: String)
case drawMatching(_ regex: String)
case drawNotMatching(_ regex: String)
}

/// Required event conditions to trigger a card
Expand Down
23 changes: 18 additions & 5 deletions WildWestOnline/Core/Bang/Sources/Game/Impl/StateReqMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ private extension Card.StateReq {
case .healthZero: HealthZero()
case .gameOver: GameOver()
case .currentTurn: CurrentTurn()
case .draw(let regex): Draw(regex: regex)
case .drawMatching(let regex): DrawMatching(regex: regex)
case .drawNotMatching(let regex): DrawNotMatching(regex: regex)
}
}

Expand Down Expand Up @@ -75,13 +76,25 @@ private extension Card.StateReq {
}
}

struct Draw: Matcher {
struct DrawMatching: Matcher {
let regex: String

func match(actor: String, state: GameState) -> Bool {
let drawCardsCount = state.players.get(actor).drawCards
let drawnCards: [String] = Array(state.discard.prefix(drawCardsCount))
return drawnCards.contains { $0.matches(regex: regex) }
let drawCards = state.players.get(actor).drawCards
return state.discard
.prefix(drawCards)
.contains { $0.matches(regex: regex) }
}
}

struct DrawNotMatching: Matcher {
let regex: String

func match(actor: String, state: GameState) -> Bool {
let drawCards = state.players.get(actor).drawCards
return state.discard
.prefix(drawCards)
.allSatisfy { $0.matches(regex: regex) == false }
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions WildWestOnline/Core/Bang/Tests/Inventory/Cards.swift
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ private extension Cards {
.init(
action: .counterShot,
selectors: [
.verify(.draw("♥️"))
.verify(.drawMatching(.regexHearts))
]
)
]
Expand All @@ -578,21 +578,21 @@ private extension Cards {
]
),
.init(action: .passInPlay, selectors: [
.verify(.draw("(♥️)|(♦️)|(♣️)|([10|J|Q|K|A]♠️)")),
.verify(.drawMatching(.regexPassDynamite)),
.setCard(.played),
.setTarget(.next)
]),
.init(
action: .damage,
selectors: [
.verify(.draw("[2-9]♠️")),
.verify(.drawNotMatching(.regexPassDynamite)),
.setAmount(3)
]
),
.init(
action: .discardInPlay,
selectors: [
.verify(.draw("[2-9]♠️")),
.verify(.drawNotMatching(.regexPassDynamite)),
.setCard(.played)
]
)
Expand Down Expand Up @@ -672,6 +672,14 @@ private extension Card.Effect {
}
}

/// Card effect regex
/// https://regex101.com/
private extension String {
static let regexHearts = "♥️"
static let regexPassDynamite = "(♥️)|(♦️)|(♣️)|([10|J|Q|K|A]♠️)"
static let regexRed = "(♥️)|(♦️)"
}

/*
static var defaultDiscardBeerOnDamagedLethal: CardV2 {
.init(
Expand Down

0 comments on commit 9db957b

Please sign in to comment.