Skip to content

Commit

Permalink
Make the console client twice as chatty if there aren't two players d…
Browse files Browse the repository at this point in the history
…ouble-teaming the same terminal window
  • Loading branch information
thijzert committed Sep 1, 2021
1 parent db22118 commit 6717521
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions cmd/chesseract/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func consoleGame(conf *Config, args []string) error {
}
}

cc := newConsoleClient(g)
cc := consoleClient{
Session: g,
Chattiness: OMG_SHUT_UP,
}

return cc.Run(ctx)
}
Expand All @@ -85,7 +88,9 @@ func consoleLocalMultiplayer(conf *Config, args []string) error {
return
}

cc := newConsoleClient(g)
cc := consoleClient{
Session: g,
}
errs <- cc.Run(ctx)
}

Expand All @@ -105,14 +110,16 @@ func consoleLocalMultiplayer(conf *Config, args []string) error {
return rv
}

type consoleClient struct {
Session client.GameSession
}
type chattiness int

func newConsoleClient(sesh client.GameSession) consoleClient {
return consoleClient{
Session: sesh,
}
const (
NOT_TOO_CHATTY chattiness = iota
OMG_SHUT_UP
)

type consoleClient struct {
Session client.GameSession
Chattiness chattiness
}

func (cc consoleClient) Run(ctx context.Context) error {
Expand Down Expand Up @@ -201,6 +208,12 @@ func (cc consoleClient) Run(ctx context.Context) error {
if !mv.Move.From.Equals(move.From) || !mv.Move.To.Equals(move.To) {
return client.ErrShenanigans
}

if cc.Chattiness == OMG_SHUT_UP {
consoleMutex.Lock()
g.Match.DebugDump(os.Stdout, nil)
consoleMutex.Unlock()
}
}
}
return ctx.Err()
Expand Down

0 comments on commit 6717521

Please sign in to comment.