func Insert(list *SkipList, value int) {
	// Increase the height. The higher it is, the less likely it is to increase
	// in height.
	height := 1
	for r := rand.Float32(); r < HIGHER_PROB && height <= MAX_HEIGHT; r = rand.Float32() {
		height++
	}

	// Create a node with this height and insert it into the list.
	if list.maxHeight < height {
		list.maxHeight = height
	}

	node := NewNode(height, value)
	cur := list.head
	for i := list.maxHeight - 1; i >= 0; i-- {
		for ; cur.next[i] != nil; cur = cur.next[i] {
			if cur.next[i].value > value {
				break
			}
		}
		// Link up skippy!
		if i < height {
			node.next[i] = cur.next[i]
			cur.next[i] = node
		}
	}
}
示例#2
0
文件: BSP.go 项目: rolfrm/boxworld
func BSPTest() {
	var qtn *QTNode = new(QTNode)
	qtn.Position = Vec3{0, 0, 0}
	qtn.Size = Vec3{5, 5, 5}
	fmt.Println(qtn.IsInside2(&testBox{Vec3{7, 7, 7}, Vec3{1, 1, 1}}))
	qtn.Position = Vec3{-10000, -10000, -10000}
	qtn.Size = Vec3{20000, 20000, 20000}

	//return

	var nValues int = 1000
	var tdat []testBox = make([]testBox, nValues)
	for i := 0; i < nValues; i++ {
		//var n float32 = float32(i)
		var x float32 = 1000 * rand.Float32() * 0
		var y float32 = 1000 * rand.Float32()
		var z float32 = 1000 * rand.Float32() * 0
		tdat[i] = testBox{Vec3{x, y, z}, Vec3{1, 1, 1}}

		qtn.Insert(&tdat[i])
	}
	qtn.Divide()

	qtn.Update()
	fmt.Println("top level data", len(qtn.Data))
	tdat[1].Pos = qtn.Split[7].Position
	tdat[1].Size = Vec3{1, 1, 1}
	qtn.Update()
	fmt.Println("top level data", len(qtn.Data))
	//qtn.TestCollisionsWith(&tdat[1])
	qtn.TestCollisions()
	fmt.Println("Counting...")
	fmt.Println("Collision detection: ", iter, " VS ", nValues*nValues)
}
示例#3
0
func performRareActions(b *bot.BotState) {
	if rand.Float32() < RARE_RESPOND_CHANCE {
		if rand.Float32() < RESPOND_CHANCE {
			randomBlurt(b)
		} else {
			randomEmote(b)
		}
	}
}
func initStars() {
	// Create the first stars
	for loop, _ := range stars {
		stars[loop] = &Star{
			angle: 0.0,
			dist:  (gl.GLfloat(loop) / gl.GLfloat(num)) * 5.0,
			r:     gl.GLubyte(rand.Float32() * 255),
			g:     gl.GLubyte(rand.Float32() * 255),
			b:     gl.GLubyte(rand.Float32() * 255),
		}
	}
}
示例#5
0
func returnPat(b *bot.BotState) {
	ok := returnPatHelper(b)
	if ok && rand.Float32() < RESPOND_CHANCE {
		actions := []string{
			"is patted.",
			"blinks.",
			"blushes.",
			"stares at " + b.Event.Nick + ".",
		}
		b.Emote(actions[rand.Intn(len(actions))])
	}
}
示例#6
0
func respondName(b *bot.BotState) {
	ok := respondNameHelper(b)
	if ok && rand.Float32() < RESPOND_CHANCE {
		responses := []string{
			"looks up at " + b.Event.Nick + " from her book.",
			"looks at " + b.Event.Nick + " expectantly.",
			"looks at " + b.Event.Nick + " with an annoyed expression.",
			"looks at " + b.Event.Nick + " with an icy glare.",
			"eyes " + b.Event.Nick + ".",
			"swivels in her chair and faces " + b.Event.Nick + ".",
		}
		b.Emote(responses[rand.Intn(len(responses))])
	}
}
示例#7
0
文件: GameOfLife.go 项目: josejc/life
//This is the Iteration constructor
func (iteration *Iteration) Init(size int) *Iteration {
	iteration.row = size
	iteration.col = size
	iteration.board = make([][]bool, size)
	for rowIndex := 0; rowIndex < size; rowIndex++ {
		iteration.board[rowIndex] = make([]bool, size)
		for colIndex := 0; colIndex < size; colIndex++ {
			if rand.Float32() < 0.3 {
				iteration.board[rowIndex][colIndex] = true
			}
		}
	}
	iteration.time = 0
	return iteration
}
示例#8
0
func main() {
	for i := 0; i < 10; i++ {
		a := rand.Int()
		fmt.Printf("%d / ", a)
	}
	for i := 0; i < 5; i++ {
		r := rand.Intn(8)
		fmt.Printf("%d / ", r)
	}
	fmt.Println()
	timens := int64(time.Now().Nanosecond())
	rand.Seed(timens)
	for i := 0; i < 10; i++ {
		fmt.Printf("%2.2f / ", 100*rand.Float32())
	}
}
示例#9
0
文件: helpers.go 项目: Popog/math3d
func Randf(r *rand.Rand) float64 { return float64(rand.Float32()) }
示例#10
0
func ellipsis(b *bot.BotState) {
	ok := ellipsisHelper(b.Event.Msg)
	if ok && rand.Float32() < RESPOND_CHANCE {
		b.Emote("pats " + b.Event.Nick + ".")
	}
}
示例#11
0
func counter(b *bot.BotState) {
	ok, verb, action := counterHelper(b)
	if ok && rand.Float32() < RESPOND_CHANCE {
		b.Emote("counter-" + verb + " " + b.Event.Nick + action)
	}
}
示例#12
0
func returnThanks(b *bot.BotState) {
	ok := returnThanksHelper(b)
	if ok && rand.Float32() < RESPOND_CHANCE {
		b.Say("You're welcome, " + b.Event.Nick + ".")
	}
}
示例#13
0
func returnPoke(b *bot.BotState) {
	ok := returnPokeHelper(b)
	if ok && rand.Float32() < RESPOND_CHANCE {
		b.Emote("pokes " + b.Event.Nick + " back.")
	}
}
示例#14
0
func returnGlomp(b *bot.BotState) {
	ok := returnGlompHelper(b)
	if ok && rand.Float32() < RESPOND_CHANCE {
		b.Emote("blushes.")
	}
}
示例#15
0
文件: helpers.go 项目: Popog/math3d
func Randf(r *rand.Rand) floatType  { return floatType(rand.Float32()) }
// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.BindTexture(gl.TEXTURE_2D, uint(texture))

	for loop, star := range stars {
		gl.LoadIdentity()
		gl.Translatef(0.0, 0.0, float32(zoom))
		gl.Rotatef(float32(tilt), 1.0, 0.0, 0.0)
		gl.Rotatef(float32(star.angle), 0.0, 1.0, 0.0)
		gl.Translatef(float32(star.dist), 0.0, 0.0)
		gl.Rotatef(float32(-star.angle), 0.0, 1.0, 0.0)
		gl.Rotatef(float32(-tilt), 1.0, 0.0, 0.0)

		if twinkle {
			other := stars[(num-loop)-1]
			gl.Color4ub(uint8(other.r), uint8(other.g), uint8(other.b), 255)
			gl.Begin(gl.QUADS)
			gl.TexCoord2f(0.0, 0.0)
			gl.Vertex3f(-1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 0.0)
			gl.Vertex3f(1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 1.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 1.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End()
		}

		gl.Rotatef(float32(spin), 0.0, 0.0, 1.0)
		gl.Color4ub(uint8(star.r), uint8(star.g), uint8(star.b), 255)
		gl.Begin(gl.QUADS)
		gl.TexCoord2f(0.0, 0.0)
		gl.Vertex3f(-1.0, -1.0, 0.0)
		gl.TexCoord2f(1.0, 0.0)
		gl.Vertex3f(1.0, -1.0, 0.0)
		gl.TexCoord2f(1.0, 1.0)
		gl.Vertex3f(1.0, 1.0, 0.0)
		gl.TexCoord2f(0.0, 1.0)
		gl.Vertex3f(-1.0, 1.0, 0.0)
		gl.End()

		spin += 0.01
		star.angle += gl.GLfloat(loop) / gl.GLfloat(num)
		star.dist -= 0.01

		if star.dist < 0.0 {
			star.dist += 5.0
			star.r = gl.GLubyte(rand.Float32() * 255)
			star.g = gl.GLubyte(rand.Float32() * 255)
			star.b = gl.GLubyte(rand.Float32() * 255)
		}
	}

	// Draw to the screen
	sdl.GL_SwapBuffers()

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}