latest
This commit is contained in:
@@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.eeqj.de/sneak/pokercore"
|
||||
"github.com/rcrowley/go-metrics"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
"sneak.berlin/go/pokercore"
|
||||
)
|
||||
|
||||
var gameCount = 50_000
|
||||
@@ -101,13 +101,16 @@ func main() {
|
||||
timer := metrics.NewTimer()
|
||||
registry.Register("pokerGame", timer)
|
||||
|
||||
bar := progressbar.NewOptions(gameCount,
|
||||
bar := progressbar.NewOptions(
|
||||
gameCount,
|
||||
progressbar.OptionSetDescription("Gambling..."),
|
||||
progressbar.OptionShowCount(),
|
||||
progressbar.OptionShowIts(),
|
||||
progressbar.OptionSetPredictTime(true),
|
||||
progressbar.OptionClearOnFinish(),
|
||||
progressbar.OptionThrottle(100*time.Millisecond), // Update every 100ms
|
||||
progressbar.OptionThrottle(
|
||||
100*time.Millisecond,
|
||||
), // Update every 100ms
|
||||
)
|
||||
|
||||
for i := 0; i < gameCount; i++ {
|
||||
@@ -128,11 +131,13 @@ func main() {
|
||||
fmt.Printf("Max: %d ns\n", timer.Max())
|
||||
fmt.Printf("Mean: %0.2f ns\n", timer.Mean())
|
||||
fmt.Printf("StdDev: %0.2f ns\n", timer.StdDev())
|
||||
fmt.Printf("Percentiles: 50%%: %0.2f ns, 75%%: %0.2f ns, 95%%: %0.2f ns, 99%%: %0.2f ns\n",
|
||||
fmt.Printf(
|
||||
"Percentiles: 50%%: %0.2f ns, 75%%: %0.2f ns, 95%%: %0.2f ns, 99%%: %0.2f ns\n",
|
||||
timer.Percentile(0.50),
|
||||
timer.Percentile(0.75),
|
||||
timer.Percentile(0.95),
|
||||
timer.Percentile(0.99))
|
||||
timer.Percentile(0.99),
|
||||
)
|
||||
oneWinPercentage := float64(oneWins) / float64(gameCount) * 100
|
||||
twoWinPercentage := float64(twoWins) / float64(gameCount) * 100
|
||||
fmt.Printf("Player 1 won: %d (%0.2f%%)\n", oneWins, oneWinPercentage)
|
||||
|
||||
56
examples/sf/main.go
Normal file
56
examples/sf/main.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"sneak.berlin/go/pokercore"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var sfp bool
|
||||
var tries int
|
||||
var found int
|
||||
|
||||
const maxTries = 100_000_000
|
||||
|
||||
for i := 0; i < maxTries; i++ {
|
||||
sfp = searchStraightFlush()
|
||||
if sfp {
|
||||
found++
|
||||
}
|
||||
tries++
|
||||
if tries%1000 == 0 {
|
||||
fmt.Printf("Tries: %d, Found: %d\n", tries, found)
|
||||
}
|
||||
}
|
||||
fmt.Printf("Tries: %d, Found: %d\n", tries, found)
|
||||
}
|
||||
|
||||
func searchStraightFlush() bool {
|
||||
|
||||
d := pokercore.NewDeck()
|
||||
|
||||
d.ShuffleRandomly()
|
||||
|
||||
var hand pokercore.Cards
|
||||
|
||||
hand = d.Deal(7)
|
||||
|
||||
ph, err := hand.PokerHand()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error: ", err)
|
||||
return false
|
||||
}
|
||||
|
||||
if ph.Type == pokercore.StraightFlush ||
|
||||
ph.Type == pokercore.RoyalFlush {
|
||||
fmt.Println("straight flush found")
|
||||
fmt.Println("Hand: ", hand.FormatForTerminal())
|
||||
fmt.Println("PokerHand: ", ph)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user