|
@@ -6,7 +6,6 @@ import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"io"
|
|
"io"
|
|
|
"math/rand"
|
|
"math/rand"
|
|
|
- "time"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type Board struct {
|
|
type Board struct {
|
|
@@ -15,8 +14,6 @@ type Board struct {
|
|
|
Tiles []Tile `json:"tiles"`
|
|
Tiles []Tile `json:"tiles"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
|
-
|
|
|
|
|
const maxIceWidth = 26
|
|
const maxIceWidth = 26
|
|
|
|
|
|
|
|
// Create a new randomly generated board.
|
|
// Create a new randomly generated board.
|
|
@@ -56,9 +53,9 @@ func (b Board) String() string {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type jsonTile struct {
|
|
type jsonTile struct {
|
|
|
- X int `json:"x"`
|
|
|
|
|
- Y int `json:"y"`
|
|
|
|
|
- Type string`json:"type"`
|
|
|
|
|
|
|
+ X int `json:"x"`
|
|
|
|
|
+ Y int `json:"y"`
|
|
|
|
|
+ Type string `json:"type"`
|
|
|
Player string `json:"player,omitempty"`
|
|
Player string `json:"player,omitempty"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -96,13 +93,13 @@ func (b Board) isIglo(x, y int) bool {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (b Board) isRock(x, y int) bool {
|
|
func (b Board) isRock(x, y int) bool {
|
|
|
- return rnd.Intn(10) > 7
|
|
|
|
|
|
|
+ return rand.Intn(10) > 7
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (b Board) isIce(x, y int) bool {
|
|
func (b Board) isIce(x, y int) bool {
|
|
|
leftLimit := (b.Cols - maxIceWidth) / 2
|
|
leftLimit := (b.Cols - maxIceWidth) / 2
|
|
|
rightLimit := b.Cols/2 + maxIceWidth/2
|
|
rightLimit := b.Cols/2 + maxIceWidth/2
|
|
|
- return x > leftLimit && x < rightLimit && rnd.Intn(maxIceWidth) >= abs((b.Cols/2)-x)
|
|
|
|
|
|
|
+ return x > leftLimit && x < rightLimit && rand.Intn(maxIceWidth) >= abs((b.Cols/2)-x)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func abs(a int) int {
|
|
func abs(a int) int {
|