Improve logging

This commit is contained in:
Christoph Hagen
2023-02-06 22:03:02 +01:00
parent a48c77c138
commit 77a214d2a2
12 changed files with 42 additions and 36 deletions

View File

@ -41,19 +41,19 @@ final class BiddingTable: AbstractTable<BiddingPlayer> {
func select(game: GameType, player name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) {
guard let player = players.player(named: name) else {
print("Player \(name) unexpectedly missing from bidding table \(self.name)")
log("Player \(name) unexpectedly missing from bidding table \(self.name)")
return (.tableStateInvalid, nil)
}
guard player.selectsGame else {
print("Player \(name) does not select the game")
log("Player \(name) does not select the game")
return (.tableStateInvalid, nil)
}
guard gameToOutbid.allows(game: game) else {
print("Game \(game) not allowed for class \(gameToOutbid)")
log("Game \(game) not allowed for class \(gameToOutbid)")
return (.tableStateInvalid, nil)
}
guard player.canPlay(game: game) else {
print("Player \(game) can't play game \(game)")
log("Player \(game) can't play game \(game)")
return (.tableStateInvalid, nil)
}
@ -64,7 +64,7 @@ final class BiddingTable: AbstractTable<BiddingPlayer> {
@discardableResult
private func selectNextBidder() -> Bool {
guard let index = players.firstIndex(where: { $0.isNextActor }) else {
print("Bidding: No current actor found to select next bidder")
log("Bidding: No current actor found to select next bidder")
return false
}
players[index].isNextActor = false
@ -75,7 +75,7 @@ final class BiddingTable: AbstractTable<BiddingPlayer> {
override func perform(action: PlayerAction, forPlayer name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) {
guard let player = players.player(named: name) else {
print("Player \(name) unexpectedly missing from bidding table \(self.name)")
log("Player \(name) unexpectedly missing from bidding table \(self.name)")
return (.tableStateInvalid, nil)
}
guard player.canPerform(action) else {

View File

@ -23,7 +23,7 @@ final class DealingTable: AbstractTable<DealingPlayer> {
override func perform(action: PlayerAction, forPlayer name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) {
guard let player = players.player(named: name) else {
print("Player \(name) unexpectedly missing from dealing table \(self.name)")
log("Player \(name) unexpectedly missing from dealing table \(self.name)")
return (.tableStateInvalid, nil)
}
guard player.canPerform(action) else {

View File

@ -116,12 +116,12 @@ final class FinishedTable: AbstractTable<FinishedPlayer> {
return (.tableStateInvalid, nil)
}
guard let player = players.player(named: name) else {
print("Unexpectedly missing player \(name) for deal action at finished table \(self.name)")
log("Unexpectedly missing player \(name) for deal action at finished table \(self.name)")
return (.tableStateInvalid, nil)
}
guard player.canPerform(.deal) else {
print("Finished table: Player \(name) can't perform deal")
log("Finished table: Player \(name) can't perform deal")
return (.tableStateInvalid, nil)
}
let waiting = WaitingTable(oldTableAdvancedByOne: self)

View File

@ -77,15 +77,15 @@ final class PlayingTable: AbstractTable<PlayingPlayer> {
override func perform(action: PlayerAction, forPlayer name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) {
guard let player = players.player(named: name) else {
print("Player \(name) unexpectedly missing from playing table \(self.name)")
log("Player \(name) unexpectedly missing from playing table \(self.name)")
return (.tableStateInvalid, nil)
}
guard action == .doubleDuringGame else {
print("Player \(name) wants to perform action \(action) on playing table")
log("Player \(name) wants to perform action \(action) on playing table")
return (.tableStateInvalid, nil)
}
guard player.canPerform(.doubleDuringGame) else {
print("Player \(name) is not allowed to raise")
log("Player \(name) is not allowed to raise")
return (.tableStateInvalid, nil)
}
player.numberOfRaises += 1
@ -96,11 +96,11 @@ final class PlayingTable: AbstractTable<PlayingPlayer> {
override func play(card: Card, player name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) {
guard let player = players.player(named: name) else {
print("Player \(name) unexpectedly missing from playing table \(self.name)")
log("Player \(name) unexpectedly missing from playing table \(self.name)")
return (.tableStateInvalid, nil)
}
guard player.isNextActor else {
print("Player \(name) wants to play card but is not active")
log("Player \(name) wants to play card but is not active")
return (.tableStateInvalid, nil)
}
guard player.canPlay(card: card, for: nextTrick, in: game) else {

View File

@ -106,12 +106,12 @@ final class WaitingTable: AbstractTable<WaitingPlayer> {
return (.tableStateInvalid, nil)
}
guard let player = players.player(named: name) else {
print("Unexpected action \(action) for missing player \(name) at table \(self.name)")
log("Unexpected action \(action) for missing player \(name) at table \(self.name)")
return (.tableStateInvalid, nil)
}
guard player.canPerform(.deal) else {
print("Player \(name) cant perform deal, although table is full")
log("Player \(name) cant perform deal, although table is full")
return (.tableStateInvalid, nil)
}
let table = DealingTable(table: self)

View File

@ -24,7 +24,7 @@ final class WeddingTable: AbstractTable<WeddingPlayer> {
override func perform(action: PlayerAction, forPlayer name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) {
guard let player = players.player(named: name) else {
print("Player \(name) unexpectedly missing from wedding table \(self.name)")
log("Player \(name) unexpectedly missing from wedding table \(self.name)")
return (.tableStateInvalid, nil)
}
guard player.canPerform(action) else {
@ -37,6 +37,7 @@ final class WeddingTable: AbstractTable<WeddingPlayer> {
case .withdrawFromAuction:
return performWithdrawl(forPlayer: player)
case .increaseOrMatchGame:
log("Unexpected action \(action) should not be possible")
fatalError()
default:
return (.tableStateInvalid, nil)
@ -96,19 +97,19 @@ final class WeddingTable: AbstractTable<WeddingPlayer> {
override func play(card: Card, player name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) {
guard requiresCardSelection else {
print("Wedding is not in stage where card should be selected")
log("Wedding is not in stage where card should be selected")
return (.tableStateInvalid, nil)
}
guard let player = players.player(named: name) else {
print("Player \(name) unexpectedly missing from wedding table \(self.name)")
log("Player \(name) unexpectedly missing from wedding table \(self.name)")
return (.tableStateInvalid, nil)
}
guard player.selectsGame else {
print("Player \(name) is not the one selecting a wedding card")
log("Player \(name) is not the one selecting a wedding card")
return (.tableStateInvalid, nil)
}
guard player.canExchange(card: card) else {
print("Invalid card \(card) to exchange in wedding")
log("Invalid card \(card) to exchange in wedding")
return (.tableStateInvalid, nil)
}