bgammon-tabula-bot/main.go

55 lines
1.6 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os"
"time"
"code.rocket9labs.com/tslocum/bgammon-tabula-bot/bot"
"code.rocket9labs.com/tslocum/tabula"
)
func main() {
var (
serverAddress string
username string
password string
points int
variant int
quiet bool
thinkTime time.Duration
debug int
)
flag.StringVar(&serverAddress, "address", "bgammon.org:1337", "Server address")
flag.StringVar(&username, "username", "", "Username")
flag.StringVar(&password, "password", "", "Password")
flag.IntVar(&points, "points", 1, "Match points")
flag.IntVar(&variant, "variant", 0, "Variant (0: Backgammon, 1: Acey-deucey, 2: Tabula)")
flag.Float64Var(&tabula.WeightBlot, "weight-blot", tabula.WeightBlot, "Weight (multiplier) when scoring blots")
flag.Float64Var(&tabula.WeightHit, "weight-hit", tabula.WeightHit, "Weight (multiplier) when scoring hits")
flag.Float64Var(&tabula.WeightOppScore, "weight-score", tabula.WeightOppScore, "Weight (multiplier) when adding opponent score to overall score")
flag.BoolVar(&quiet, "quiet", false, "Disable logging")
flag.DurationVar(&thinkTime, "think", 0, "Minimum think time")
flag.IntVar(&debug, "debug", 0, "Port to serve debug information on (pprof)")
flag.Parse()
if password == "" {
password = os.Getenv("BOT_PASSWORD")
}
if debug > 0 {
go func() {
log.Fatal(http.ListenAndServe(fmt.Sprintf("localhost:%d", debug), nil))
}()
}
c := bot.NewClient(serverAddress, username, password, points, int8(variant), quiet, thinkTime)
go c.Connect()
c.HandleEvents()
}