DEV-1313: Add additional map types (#76)
* add helper to draw a ring of hazards * refactor tests to not be internal tests * add "hz_inner_wall" map * add "hz_rings" map * fix map registry * fix: edge case bugs in drawRing * remove println * add "hz_columns" * add "hz_rivers_bridges" map * WIP: implementing spiral hazards map * finish basic testing of 'hz_spiral' * include first turn * add "hz_hazards" map * remove incorrect author * add "hz_grow_box" map * add "hz_expand_box" map * add "hz_expand_scatter" map * remove debug * document the new "Range" method * - use rules.RulesetError instead of generic error - use a rules.Point for map rivers and bridgets map key * use rules.RulesetError instead of errors.New * provide more detail about boundar conditions * fix documentation (max can be == min) * add unit tests
This commit is contained in:
parent
aa38bcd0eb
commit
f0dc0bcb38
8 changed files with 1129 additions and 24 deletions
20
rand.go
20
rand.go
|
|
@ -4,6 +4,10 @@ import "math/rand"
|
|||
|
||||
type Rand interface {
|
||||
Intn(n int) int
|
||||
// Range produces a random integer in the range of [min,max] (inclusive)
|
||||
// For example, Range(1,3) could produce the values 1, 2 or 3.
|
||||
// Panics if max < min (like how Intn(n) panics for n <=0)
|
||||
Range(min, max int) int
|
||||
Shuffle(n int, swap func(i, j int))
|
||||
}
|
||||
|
||||
|
|
@ -12,6 +16,10 @@ var GlobalRand globalRand
|
|||
|
||||
type globalRand struct{}
|
||||
|
||||
func (globalRand) Range(min, max int) int {
|
||||
return rand.Intn(max-min+1) + min
|
||||
}
|
||||
|
||||
func (globalRand) Intn(n int) int {
|
||||
return rand.Intn(n)
|
||||
}
|
||||
|
|
@ -36,6 +44,10 @@ func (s seedRand) Intn(n int) int {
|
|||
return s.rand.Intn(n)
|
||||
}
|
||||
|
||||
func (s seedRand) Range(min, max int) int {
|
||||
return s.rand.Intn(max-min+1) + min
|
||||
}
|
||||
|
||||
func (s seedRand) Shuffle(n int, swap func(i, j int)) {
|
||||
s.rand.Shuffle(n, swap)
|
||||
}
|
||||
|
|
@ -51,6 +63,10 @@ func (minRand) Intn(n int) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func (minRand) Range(min, max int) int {
|
||||
return min
|
||||
}
|
||||
|
||||
func (minRand) Shuffle(n int, swap func(i, j int)) {
|
||||
// no shuffling
|
||||
}
|
||||
|
|
@ -64,6 +80,10 @@ func (maxRand) Intn(n int) int {
|
|||
return n - 1
|
||||
}
|
||||
|
||||
func (maxRand) Range(min, max int) int {
|
||||
return max
|
||||
}
|
||||
|
||||
func (maxRand) Shuffle(n int, swap func(i, j int)) {
|
||||
// rotate by one element so every element is moved
|
||||
if n < 2 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue