diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-28 18:13:49 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-28 18:36:00 +0200 |
| commit | 9b7d7cd127499eb2b1485df3cd5e74caa31dbaf1 (patch) | |
| tree | c127906c3fee01d3d596ed65b3d2520a703ccef2 /go/draftsim/common | |
| parent | 3f4c96b24697ac92901f26afdf4f65faddae8b23 (diff) | |
| download | muhqs-game-9b7d7cd127499eb2b1485df3cd5e74caa31dbaf1.tar.gz muhqs-game-9b7d7cd127499eb2b1485df3cd5e74caa31dbaf1.zip | |
initial draftsim commit
Diffstat (limited to 'go/draftsim/common')
| -rw-r--r-- | go/draftsim/common/deadline.go | 30 | ||||
| -rw-r--r-- | go/draftsim/common/joinInfo.go | 19 | ||||
| -rw-r--r-- | go/draftsim/common/joinParams.go | 14 |
3 files changed, 63 insertions, 0 deletions
diff --git a/go/draftsim/common/deadline.go b/go/draftsim/common/deadline.go new file mode 100644 index 00000000..9a8ce9d8 --- /dev/null +++ b/go/draftsim/common/deadline.go @@ -0,0 +1,30 @@ +package common + +import ( + "strings" + "time" +) + +type DeadlineFunc func(cards int) time.Time + +func genFixedDeadline(timeout int) DeadlineFunc { + return func(int) time.Time { + return time.Now().Add(time.Duration(timeout)*time.Second) + } +} + +func genDynamicDeadline(perCard int) DeadlineFunc { + return func(cards int) time.Time { + return time.Now().Add(time.Duration(perCard * cards) * time.Second) + } +} + +// GenDeadline returns a function returning a deadline from a description string. +func GenDeadline(desc string) (DeadlineFunc, error) { + if strings.Contains(desc, "x") { + perCard := 5 + return genDynamicDeadline(perCard), nil + } else { + return genFixedDeadline(30), nil + } +} diff --git a/go/draftsim/common/joinInfo.go b/go/draftsim/common/joinInfo.go new file mode 100644 index 00000000..851c62e1 --- /dev/null +++ b/go/draftsim/common/joinInfo.go @@ -0,0 +1,19 @@ +package common + +import ( + "muhq.space/muhqs-game/go/game" +) + +// JoinInfo contains the information about joined draft provided by the server. +type JoinInfo struct { + // Players contains the player names in the deaft. + Players []string + // Desc contains the description of the draft. + Desc string + // Sets specify the drafted card sets. + Sets []game.SetIdentifier + // PlayerId can be used to reconnect to the draft. + PlayerId int + // Deadline specifies the enforced deadline. + Deadline string +} diff --git a/go/draftsim/common/joinParams.go b/go/draftsim/common/joinParams.go new file mode 100644 index 00000000..77d93b71 --- /dev/null +++ b/go/draftsim/common/joinParams.go @@ -0,0 +1,14 @@ +package common + +// JoinParams are the parameters send by the client to join a draft. +// The parameters are sent after upgrading the http connection to the `/join` endpoint to a websocket. +type JoinParams struct { + // Table identifies the draft to join. + Table string + // Name is the name of the joining player. + Name string + // Desc specifies the draft description if joining a new draft. + Desc string + // NPlayers specifies the number of players in the draft. + NPlayers int +} |
