68 lines
1.8 KiB
Swift
68 lines
1.8 KiB
Swift
//
|
|
// GameResult.swift
|
|
// Baccarat
|
|
//
|
|
// Game outcome types and result information.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
/// The possible outcomes of a baccarat round.
|
|
enum GameResult: Equatable {
|
|
case playerWins
|
|
case bankerWins
|
|
case tie
|
|
|
|
/// Display text for the result (localized).
|
|
var displayText: String {
|
|
switch self {
|
|
case .playerWins: return String.localized("PLAYER WINS")
|
|
case .bankerWins: return String.localized("BANKER WINS")
|
|
case .tie: return String.localized("TIE GAME")
|
|
}
|
|
}
|
|
|
|
/// The color associated with this result.
|
|
var color: Color {
|
|
switch self {
|
|
case .playerWins: return .blue
|
|
case .bankerWins: return .red
|
|
case .tie: return .green
|
|
}
|
|
}
|
|
|
|
/// Whether the given bet type wins with this result.
|
|
func isWinningBet(_ betType: BetType) -> Bool {
|
|
switch (self, betType) {
|
|
case (.playerWins, .player): return true
|
|
case (.bankerWins, .banker): return true
|
|
case (.tie, .tie): return true
|
|
default: return false
|
|
}
|
|
}
|
|
|
|
/// Returns true if this result is a push (tie) for non-tie bets.
|
|
/// In baccarat, if the result is a tie, Player and Banker bets push (returned).
|
|
func isPush(for betType: BetType) -> Bool {
|
|
self == .tie && betType != .tie
|
|
}
|
|
}
|
|
|
|
/// Record of a completed round for history tracking.
|
|
struct RoundResult: Identifiable {
|
|
let id = UUID()
|
|
let result: GameResult
|
|
let playerValue: Int
|
|
let bankerValue: Int
|
|
let timestamp: Date
|
|
|
|
init(result: GameResult, playerValue: Int, bankerValue: Int) {
|
|
self.result = result
|
|
self.playerValue = playerValue
|
|
self.bankerValue = bankerValue
|
|
self.timestamp = .now
|
|
}
|
|
}
|
|
|