Exemplo n.º 1
0
func CMWCRandSpec(c gospec.Context) {
	c.Specify("CMWC32 conforms properly to math/rand.Rand interface.", func() {
		c1 := cmwc.MakeCmwc(3278470471, 4)
		c2 := cmwc.MakeCmwc(3278470471, 4)
		c1.Seed(1234)
		c2.Seed(4321)

		// Make sure that we don't generate numbers with the most significant
		// bit set
		for i := 0; i < 1000000; i++ {
			v1 := c1.Int63()
			c.Expect(v1 >= 0, Equals, true)
			if v1 < 0 {
				break
			}
			c2.Int63()
		}

		// Make sure that two generators with the same parameters, but in
		// different states, are in the exact same state when seeded with
		// the same seed.
		c1.Seed(0xabcdef12)
		c2.Seed(0xabcdef12)
		for i := 0; i < 10000; i++ {
			v1 := c1.Int63()
			v2 := c2.Int63()
			c.Expect(v1, Equals, v2)
			if v1 != v2 {
				break
			}
		}
	})
}
Exemplo n.º 2
0
func BenchmarkCMWC32AsRandSource(b *testing.B) {
	b.StopTimer()
	c := cmwc.MakeCmwc(3278470471, 4)
	r := rand.New(c)
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		r.Int63()
	}
}
Exemplo n.º 3
0
func CMWCGobSpec(c gospec.Context) {
	c.Specify("CMWC32 gobs and ungobs properly.", func() {
		// Set up c1 and c2 and run them for a while, then we'll c2 and make
		// sure it runs the same when it is ungobbed.
		c1 := cmwc.MakeCmwc(3278470471, 4)
		c2 := cmwc.MakeCmwc(3278470471, 4)
		c1.Seed(0x12345678)
		c2.Seed(0x12345678)
		for i := 0; i < 100000; i++ {
			c1.Int63()
			c2.Int63()
		}
		buf := bytes.NewBuffer(nil)
		enc := gob.NewEncoder(buf)
		err := enc.Encode(c2)
		c.Expect(err, Equals, error(nil))
		if err != nil {
			return
		}
		dec := gob.NewDecoder(bytes.NewBuffer(buf.Bytes()))

		// c2 is going to be constructed from the gobbed data only
		var c3 cmwc.Cmwc
		err = dec.Decode(&c3)
		c.Expect(err, Equals, error(nil))
		if err != nil {
			return
		}
		for i := 0; i < 100000; i++ {
			// Checking c2 against c2 for many iterations.
			v1 := c1.Int63()
			v2 := c3.Int63()
			c.Expect(v1, Equals, v2)
			if v1 != v2 {
				return
			}
		}
	})
}
Exemplo n.º 4
0
func makeGame(h *house.HouseDef) *Game {
	var g Game
	g.Side = SideExplorers
	g.House = h
	g.House.Normalize()
	g.viewer = house.MakeHouseViewer(g.House, 62)
	g.Rand = cmwc.MakeCmwc(4285415527, 3)
	g.Rand.SeedWithDevRand()

	// This way an unset id will be invalid
	g.Entity_id = 1

	g.Turn = 1
	g.Side = SideHaunt

	g.setup()

	return &g
}