-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaults.go
61 lines (50 loc) · 1.82 KB
/
defaults.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package lugo4go
import (
"fmt"
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/lugobots/lugo4go/v3/field"
)
const (
DefaultFieldMapCols = 16
DefaultFieldMapRows = 8
)
var DefaultInitialPositions = map[int]struct {
Col int
Row int
}{
2: {Col: 1, Row: 2},
3: {Col: 1, Row: 3},
4: {Col: 1, Row: 4},
5: {Col: 1, Row: 5},
6: {Col: 4, Row: 1},
7: {Col: 4, Row: 3},
8: {Col: 4, Row: 4},
9: {Col: 4, Row: 6},
10: {Col: 6, Row: 3},
11: {Col: 6, Row: 4},
}
// DefaultLogger creates a logger that is compatible with the lugo4go.rawBot expected logger.
// The bots are NOT obligated to use this logger though. You may implement your own logger.
func DefaultLogger(config Config) *zap.SugaredLogger {
configZap := zap.NewDevelopmentConfig()
configZap.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
zapLog, _ := configZap.Build()
// no need to check the error since this configuration won cause any
return zapLog.Sugar().Named(fmt.Sprintf("%s-%d", config.TeamSide, config.Number))
}
// DefaultInitBundle created a basic configuration that may be used by the client to connect to the server.
// It also creates a logger that is compatible with the lugo4go.rawBot.
func DefaultInitBundle() (Config, field.Mapper, *zap.SugaredLogger, error) {
config := Config{}
if err := config.loadConfig(os.Args[1:]); err != nil {
return config, nil, nil, fmt.Errorf("did not parsed well the flags for config: %s", err)
}
// default initial position
defaultMapper, _ := field.NewMapper(DefaultFieldMapCols, DefaultFieldMapRows, config.TeamSide)
defaultInitialRegion, _ := defaultMapper.GetRegion(DefaultInitialPositions[config.Number].Col, DefaultInitialPositions[config.Number].Row)
config.InitialPosition = defaultInitialRegion.Center()
logger := DefaultLogger(config)
return config, defaultMapper, logger, nil
}