Support playing tabula games

This commit is contained in:
Trevor Slocum 2024-01-07 21:29:47 -08:00
parent f9ffd6d518
commit 4b782c6de3
4 changed files with 23 additions and 27 deletions

View File

@ -41,13 +41,13 @@ type Client struct {
sentGreeting bool
rolled bool
lastActivity time.Time
acey bool
variant int8
quiet bool
thinkTime time.Duration
analysis []*tabula.Analysis
}
func NewClient(address string, username string, password string, points int, acey bool, quiet bool, thinkTime time.Duration) *Client {
func NewClient(address string, username string, password string, points int, variant int8, quiet bool, thinkTime time.Duration) *Client {
const bufferSize = 10
c := &Client{
Address: address,
@ -56,7 +56,7 @@ func NewClient(address string, username string, password string, points int, ace
Events: make(chan interface{}, bufferSize),
Out: make(chan []byte, bufferSize),
points: points,
acey: acey,
variant: variant,
quiet: quiet,
thinkTime: thinkTime,
analysis: make([]*tabula.Analysis, 0, tabula.AnalysisBufferSize),
@ -65,8 +65,8 @@ func NewClient(address string, username string, password string, points int, ace
return c
}
func NewLocalClient(conn net.Conn, address string, username string, password string, points int, acey bool, quiet bool, thinkTime time.Duration) {
c := NewClient(address, username, password, points, acey, quiet, thinkTime)
func NewLocalClient(conn net.Conn, address string, username string, password string, points int, variant int8, quiet bool, thinkTime time.Duration) {
c := NewClient(address, username, password, points, variant, quiet, thinkTime)
c.connecting = true
go c.connectTCP(conn)
c.HandleEvents()
@ -288,11 +288,7 @@ func (c *Client) handleTCPRead(conn net.Conn) {
}
func (c *Client) createMatch() {
acey := 0
if c.acey {
acey = 1
}
c.Out <- []byte(fmt.Sprintf("c public %d %d", c.points, acey))
c.Out <- []byte(fmt.Sprintf("c public %d %d", c.points, c.variant))
c.sentGreeting = false
c.rolled = false
}
@ -565,21 +561,21 @@ func (c *Client) HandleEvents() {
func TabulaBoard(b []int8) tabula.Board {
var roll1, roll2, roll3, roll4 int8
roll1, roll2 = int8(Game.Roll1), int8(Game.Roll2)
if roll1 == roll2 {
if Game.Variant == bgammon.VariantTabula {
roll3 = int8(Game.Roll3)
} else if roll1 == roll2 {
roll3, roll4 = int8(Game.Roll1), int8(Game.Roll2)
}
entered1, entered2 := int8(1), int8(1)
acey := int8(0)
if Game.Acey {
if Game.Variant != bgammon.VariantBackgammon {
if !Game.Player1.Entered {
entered1 = 0
}
if !Game.Player2.Entered {
entered2 = 0
}
acey = 1
}
return tabula.Board{b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25], b[26], b[27], roll1, roll2, roll3, roll4, entered1, entered2, acey}
return tabula.Board{b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], b[25], b[26], b[27], roll1, roll2, roll3, roll4, entered1, entered2, Game.Variant}
}
func randInt(max int) int {

6
go.mod
View File

@ -3,9 +3,9 @@ module code.rocket9labs.com/tslocum/bgammon-tabula-bot
go 1.17
require (
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240107205420-7064b0b085aa
code.rocket9labs.com/tslocum/tabula v0.0.0-20240107223909-3a825a2f6402
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240108183627-118a7f78eb98
code.rocket9labs.com/tslocum/tabula v0.0.0-20240108183445-695ea428ae21
nhooyr.io/websocket v1.8.10
)
require code.rocket9labs.com/tslocum/bei v0.0.0-20240107212214-bcc7b6933a4c // indirect
require code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b // indirect

12
go.sum
View File

@ -1,8 +1,8 @@
code.rocket9labs.com/tslocum/bei v0.0.0-20240107212214-bcc7b6933a4c h1:fiH72XLcHof1XvVeBw/1NvaS+iIzoZqCTn7Mv0AAYss=
code.rocket9labs.com/tslocum/bei v0.0.0-20240107212214-bcc7b6933a4c/go.mod h1:tS60/VNAJphKvDBkSLQhKALa15msIAuWWfEKNc4oFZc=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240107205420-7064b0b085aa h1:tG9v4fLW6Dpe9QmcP4H+nG4jv9dw4QlHCRKUrch0/sc=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240107205420-7064b0b085aa/go.mod h1:qoXFACgj2k4y5996rU5+GxZ2x9De1ZyA3+GraUJpFj8=
code.rocket9labs.com/tslocum/tabula v0.0.0-20240107223909-3a825a2f6402 h1:2kqQt+6qE5hSDimNetYePHoGJmLkxFSOJWCzsgqdLyE=
code.rocket9labs.com/tslocum/tabula v0.0.0-20240107223909-3a825a2f6402/go.mod h1:0MDYsQyP0LKhY2CktMH39hUXgZK1ti3vuxLC6iHm79E=
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b h1:Y0a14Kf/hSYepSmp4ZfDeE4CZZGBGBS97CNjCbKJm0c=
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b/go.mod h1:tS60/VNAJphKvDBkSLQhKALa15msIAuWWfEKNc4oFZc=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240108183627-118a7f78eb98 h1:6lndXAeTooxepIWtpVWOhEFjig6DVh6bkVaWJVtrmX4=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240108183627-118a7f78eb98/go.mod h1:0DTOM6NviKJsDDBANcB7hbk2fseN5qtHJZAFeKsnAPQ=
code.rocket9labs.com/tslocum/tabula v0.0.0-20240108183445-695ea428ae21 h1:1VG88tdhCSVv7wGoIKQe8A8KfBXJsdz5pDsyP4ymDwk=
code.rocket9labs.com/tslocum/tabula v0.0.0-20240108183445-695ea428ae21/go.mod h1:WEJXESKXqrMFLAArikQ79lpRibNeeE1C0VruxXYMF5M=
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=

View File

@ -19,7 +19,7 @@ func main() {
username string
password string
points int
acey bool
variant int
quiet bool
thinkTime time.Duration
debug int
@ -28,7 +28,7 @@ func main() {
flag.StringVar(&username, "username", "", "Username")
flag.StringVar(&password, "password", "", "Password")
flag.IntVar(&points, "points", 1, "Match points")
flag.BoolVar(&acey, "acey", false, "Create acey-deucey match")
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")
@ -47,7 +47,7 @@ func main() {
}()
}
c := bot.NewClient(serverAddress, username, password, points, acey, quiet, thinkTime)
c := bot.NewClient(serverAddress, username, password, points, int8(variant), quiet, thinkTime)
go c.Connect()
c.HandleEvents()