 /// This file executes repeated random play over the Texas Hold'em game.
 ///
 /// It is used for profiling and benchmarking purposes.
+///
+/// On saeta@'s desktop machine, performance numbers are as follows (be sure to
+/// build with optimizations on!):
+///   - Random games: 115 +/- 51 usec per game
+///   - Fixed games:  8.4 +/- 0.5 usec per game
 
 import Dispatch
 import Foundation

}


func playRandomGame() {
  let game = TexasHoldem(playerCount: 2)
  var state = game.initialState

  }
}

/// Play a fixed game to benchmark the overheads of the state mechanisms itself.
///
/// Note: based on profiling, the vast majority of the time is actually spent in computeBestHand
/// with the rest of the time spent in either array reallocation or swift_beginAccess (these
/// dynamic safety checks can be disabled with additional optimization flags).
func playFixed2PlayerGame() {
  let game = TexasHoldem(playerCount: 2)
  var state = game.initialState
  // Deal 4 cards (this deck happens to be relatively poorly shuffled...)
  state.apply(.card(Card(suit: .clubs, rank: .two)))
  state.apply(.card(Card(suit: .clubs, rank: .three)))
  state.apply(.card(Card(suit: .clubs, rank: .four)))
  state.apply(.card(Card(suit: .clubs, rank: .five)))

  // Pre-flop
  state.apply(.call)
  state.apply(.call)

  // Deal flop
  state.apply(.card(Card(suit: .clubs, rank: .six)))
  state.apply(.card(Card(suit: .clubs, rank: .seven)))
  state.apply(.card(Card(suit: .clubs, rank: .eight)))

  // Bid
  state.apply(.raise(1))
  state.apply(.raise(1))
  state.apply(.call)

  // Turn & bid
  state.apply(.card(Card(suit: .clubs, rank: .nine)))
  state.apply(.call)
  state.apply(.raise(2))
  state.apply(.call)

  // River & bid
  state.apply(.card(Card(suit: .clubs, rank: .ten)))
  state.apply(.allIn)
  state.apply(.call)
}

print("About to start benchmarks...")
time("Random 2-player Texas Hold'em games", playRandomGame)
time("Fixed 2-player Texas Hold'em games", playFixed2PlayerGame)
print("Done!")
