Refactor how randPos() operates #4

Closed
opened 2023-12-03 23:29:31 +01:00 by sacha · 0 comments
Owner

Instead of doing an elaborate check if a random position is within the border (like here https://gitea.ligthert.net/golang/rowboz/src/branch/trunk/game.go#L179-L186) .

	for !safe {
		x := rand.Intn(80)
		y := rand.Intn(24)

		if x == 0 || x == 79 || y == 0 || y == 23 {
			safe = false
		} else {
			pos.x = x
			pos.y = y
			safe = true
		}
	}

Instead use something like:

x := 1+rand.Intn(77)
y := 1+rand.Intn(23)
Instead of doing an elaborate check if a random position is within the border (like here https://gitea.ligthert.net/golang/rowboz/src/branch/trunk/game.go#L179-L186) . ```Golang for !safe { x := rand.Intn(80) y := rand.Intn(24) if x == 0 || x == 79 || y == 0 || y == 23 { safe = false } else { pos.x = x pos.y = y safe = true } } ``` Instead use something like: ```Go x := 1+rand.Intn(77) y := 1+rand.Intn(23) ```
sacha added this to the Initial Release milestone 2023-12-03 23:59:56 +01:00
sacha added the
🔧 Development
label 2023-12-04 00:04:35 +01:00
sacha referenced this issue from a commit 2023-12-04 01:01:48 +01:00
sacha closed this issue 2023-12-04 01:01:48 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: golang/rowboz#4
No description provided.