Print board state

This commit is contained in:
Trevor Slocum 2023-12-02 12:20:36 -08:00
parent 0e2d5e25ca
commit 0abc07c1db
4 changed files with 27 additions and 16 deletions

View file

@ -9,6 +9,7 @@ import (
"math"
"net"
"os"
"strconv"
"strings"
"text/tabwriter"
"time"
@ -396,6 +397,9 @@ func (c *Client) HandleEvents() {
if len(Game.Moves) != 0 {
continue
} else if len(Game.Available) == 0 {
if c.thinkTime != 0 {
time.Sleep(c.thinkTime)
}
c.Out <- []byte("ok")
c.lastActivity = time.Now()
continue
@ -421,6 +425,17 @@ func (c *Client) HandleEvents() {
log.Printf("Legal moves: %+v", Game.Available)
log.Fatalf("NO PLAYABLE MOVES RETURNED: %+v", result)
}
log.Println("Past:", result[0].Past)
builder := &strings.Builder{}
builder.Write([]byte("Board: "))
for i := range boardState {
if i != 0 {
builder.WriteByte(',')
}
builder.Write([]byte(strconv.Itoa(int(boardState[i]))))
}
log.Println(builder.String())
const padding = 3
w := tabwriter.NewWriter(os.Stderr, 0, 0, padding, ' ', 0)
@ -437,13 +452,11 @@ func (c *Client) HandleEvents() {
} else {
c.Out <- []byte(fmt.Sprintf("mv %d/%d", move[0], move[1]))
}
if c.thinkTime != 0 {
t2 := time.Now()
s := t2.Sub(t)
if s < c.thinkTime {
time.Sleep(c.thinkTime - s)
}
t = time.Now()
}
if c.thinkTime != 0 {
s := time.Since(t)
if s < c.thinkTime {
time.Sleep(c.thinkTime - s)
}
}
c.Out <- []byte("ok")

5
go.mod
View file

@ -3,8 +3,7 @@ module code.rocket9labs.com/tslocum/bgammon-tabula-bot
go 1.17
require (
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231201021429-50943c96c43d
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231203064241-5abce61fabb1
code.rocket9labs.com/tslocum/tabula v0.0.0-20231203105606-89331e122024
nhooyr.io/websocket v1.8.10
)
require code.rocket9labs.com/tslocum/tabula v0.0.0-20231202182927-2a8f1687c488

8
go.sum
View file

@ -1,6 +1,6 @@
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231201021429-50943c96c43d h1:4FGA2vc8j2gCjioYyzrjbW1hOiNxz06QgqvnjctzKoM=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231201021429-50943c96c43d/go.mod h1:+dgD9v8BlzZjzpIB+/g0lgog90YUoPzEZsp1iAchl30=
code.rocket9labs.com/tslocum/tabula v0.0.0-20231202182927-2a8f1687c488 h1:0ngRW3/VkAA5lS0FCM80PMjF/4npJMJk2vv1NliAE+c=
code.rocket9labs.com/tslocum/tabula v0.0.0-20231202182927-2a8f1687c488/go.mod h1:XtS6M8qcK0fnUn4k5I7h4JcZ2sz2WEAXOcF2DLaQBME=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231203064241-5abce61fabb1 h1:DU4h2XiS2bz4FdaeHRfYTBNwhWuaYGmnb/NA0VgsVMc=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20231203064241-5abce61fabb1/go.mod h1:u3nbSwxWnwOXbCNPQD4s3abGTfvA4/gi9U626f7ZN9Q=
code.rocket9labs.com/tslocum/tabula v0.0.0-20231203105606-89331e122024 h1:cmhcEsSxceGfe0Uvuvrriq1L3VlE0tIcjh++AkJmFdE=
code.rocket9labs.com/tslocum/tabula v0.0.0-20231203105606-89331e122024/go.mod h1:XtS6M8qcK0fnUn4k5I7h4JcZ2sz2WEAXOcF2DLaQBME=
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=

View file

@ -4,10 +4,9 @@ import (
"flag"
"fmt"
"log"
"time"
"net/http"
_ "net/http/pprof"
"time"
"code.rocket9labs.com/tslocum/bgammon-tabula-bot/bot"
"code.rocket9labs.com/tslocum/tabula"