Rivers and Bridges map refactor (#103)
* Separated out rivers and bridges into its own file with three map variants * fixing tags * removed extra 4 starting positions from the medium map since it only supports 8 players * update GetUnoccupiedPoints to consider hazards with a flag * use new utility method to fine unoccupied points and enforce map sizes * changed up casting to make IsAllowable() more usable
This commit is contained in:
parent
7d769b01b6
commit
f82cfe5309
10 changed files with 484 additions and 347 deletions
18
board.go
18
board.go
|
|
@ -432,7 +432,7 @@ func PlaceFoodFixed(rand Rand, b *BoardState) error {
|
|||
|
||||
// Finally, always place 1 food in center of board for dramatic purposes
|
||||
isCenterOccupied := true
|
||||
unoccupiedPoints := GetUnoccupiedPoints(b, true)
|
||||
unoccupiedPoints := GetUnoccupiedPoints(b, true, false)
|
||||
for _, point := range unoccupiedPoints {
|
||||
if point == centerCoord {
|
||||
isCenterOccupied = false
|
||||
|
|
@ -450,7 +450,7 @@ func PlaceFoodFixed(rand Rand, b *BoardState) error {
|
|||
// PlaceFoodRandomly adds up to n new food to the board in random unoccupied squares
|
||||
func PlaceFoodRandomly(rand Rand, b *BoardState, n int) error {
|
||||
for i := 0; i < n; i++ {
|
||||
unoccupiedPoints := GetUnoccupiedPoints(b, false)
|
||||
unoccupiedPoints := GetUnoccupiedPoints(b, false, false)
|
||||
if len(unoccupiedPoints) > 0 {
|
||||
newFood := unoccupiedPoints[rand.Intn(len(unoccupiedPoints))]
|
||||
b.Food = append(b.Food, newFood)
|
||||
|
|
@ -468,7 +468,7 @@ func absInt(n int) int {
|
|||
|
||||
func GetEvenUnoccupiedPoints(b *BoardState) []Point {
|
||||
// Start by getting unoccupied points
|
||||
unoccupiedPoints := GetUnoccupiedPoints(b, true)
|
||||
unoccupiedPoints := GetUnoccupiedPoints(b, true, false)
|
||||
|
||||
// Create a new array to hold points that are even
|
||||
evenUnoccupiedPoints := []Point{}
|
||||
|
|
@ -494,7 +494,7 @@ func removeCenterCoord(b *BoardState, points []Point) []Point {
|
|||
return noCenterPoints
|
||||
}
|
||||
|
||||
func GetUnoccupiedPoints(b *BoardState, includePossibleMoves bool) []Point {
|
||||
func GetUnoccupiedPoints(b *BoardState, includePossibleMoves bool, includeHazards bool) []Point {
|
||||
pointIsOccupied := map[int]map[int]bool{}
|
||||
for _, p := range b.Food {
|
||||
if _, xExists := pointIsOccupied[p.X]; !xExists {
|
||||
|
|
@ -502,6 +502,7 @@ func GetUnoccupiedPoints(b *BoardState, includePossibleMoves bool) []Point {
|
|||
}
|
||||
pointIsOccupied[p.X][p.Y] = true
|
||||
}
|
||||
|
||||
for _, snake := range b.Snakes {
|
||||
if snake.EliminatedCause != NotEliminated {
|
||||
continue
|
||||
|
|
@ -529,6 +530,15 @@ func GetUnoccupiedPoints(b *BoardState, includePossibleMoves bool) []Point {
|
|||
}
|
||||
}
|
||||
|
||||
if includeHazards {
|
||||
for _, p := range b.Hazards {
|
||||
if _, xExists := pointIsOccupied[p.X]; !xExists {
|
||||
pointIsOccupied[p.X] = map[int]bool{}
|
||||
}
|
||||
pointIsOccupied[p.X][p.Y] = true
|
||||
}
|
||||
}
|
||||
|
||||
unoccupiedPoints := []Point{}
|
||||
for x := 0; x < b.Width; x++ {
|
||||
for y := 0; y < b.Height; y++ {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue