testing
This commit is contained in:
parent
fddea37fec
commit
830e6b66bf
1
main.go
1
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/sneak/gopoker/pokercore"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
import "github.com/sneak/gopoker/pokercore"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
myDeck := pokercore.NewDeck()
|
||||||
|
myDeck.ShuffleRandomly()
|
||||||
|
fmt.Println("%s", myDeck.Cards)
|
||||||
|
}
|
|
@ -54,14 +54,6 @@ func NewRandom() *rand.Rand {
|
||||||
|
|
||||||
var rnd *rand.Rand
|
var rnd *rand.Rand
|
||||||
|
|
||||||
seed := int64(42)
|
|
||||||
|
|
||||||
if trueRandom {
|
|
||||||
rnd = rand.New(rand.NewSource(int64(cryptoUint64())))
|
|
||||||
} else {
|
|
||||||
rnd = rand.New(rand.NewSource(seed))
|
|
||||||
}
|
|
||||||
|
|
||||||
return rnd
|
return rnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +88,6 @@ func NewDeck() *Deck {
|
||||||
|
|
||||||
self.Cards = make([]*Card, 52)
|
self.Cards = make([]*Card, 52)
|
||||||
|
|
||||||
// Loop over each type and suit appending to the deck
|
|
||||||
tot := 0
|
tot := 0
|
||||||
for i := 0; i < len(ranks); i++ {
|
for i := 0; i < len(ranks); i++ {
|
||||||
for n := 0; n < len(suits); n++ {
|
for n := 0; n < len(suits); n++ {
|
||||||
|
@ -111,8 +102,15 @@ func NewDeck() *Deck {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Deck) Shuffle() {
|
func (self *Deck) ShuffleRandomly() {
|
||||||
r := NewRandom()
|
rnd := rand.New(rand.NewSource(int64(cryptoUint64())))
|
||||||
|
//FIXME(sneak) not sure if this is constant time or not
|
||||||
|
rnd.Shuffle(len(self.Cards), func(i, j int) { self.Cards[i], self.Cards[j] = self.Cards[j], self.Cards[i] })
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Deck) ShuffleDeterministic(int64 seed) {
|
||||||
|
r := rand.New(rand.NewSource(seed))
|
||||||
|
//FIXME(sneak) not sure if this is constant time or not
|
||||||
r.Shuffle(len(self.Cards), func(i, j int) { self.Cards[i], self.Cards[j] = self.Cards[j], self.Cards[i] })
|
r.Shuffle(len(self.Cards), func(i, j int) { self.Cards[i], self.Cards[j] = self.Cards[j], self.Cards[i] })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,9 +137,11 @@ func (s Cards) String() (output string) {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func main2() {
|
func generate() {
|
||||||
|
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
func proto() {
|
||||||
|
|
||||||
myDeck := NewDeck()
|
myDeck := NewDeck()
|
||||||
myDeck.Shuffle()
|
myDeck.Shuffle()
|
||||||
|
|
Loading…
Reference in New Issue