-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayermessages.go
79 lines (71 loc) · 2.36 KB
/
playermessages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package shed
import (
"github.com/minaorangina/shed/deck"
"github.com/minaorangina/shed/protocol"
)
// InboundMessage is a message from Player to GameEngine
type InboundMessage struct {
PlayerID string `json:"player_id"`
Command protocol.Cmd `json:"command"`
Hand []deck.Card `json:"hand,omitempty"`
Seen []deck.Card `json:"seen,omitempty"`
Decision []int `json:"decision,omitempty"` // not used in stage 0
}
// func (im *InboundMessage) MarshalJSON() ([]byte, error) {
// type Alias InboundMessage
// return json.Marshal(&struct {
// Command string `json:"command"`
// *Alias
// }{
// Command: im.Command.String(),
// Alias: (*Alias)(im),
// })
// }
// func (im *InboundMessage) UnmarshalJSON(data []byte) error {
// type Alias InboundMessage
// aux := &struct {
// Command string `json:"command"`
// *Alias
// }{
// Alias: (*Alias)(im),
// }
// if err := json.Unmarshal(data, &aux); err != nil {
// return err
// }
// v, ok := protocol.NameToCmd[aux.Command]
// if !ok {
// return fmt.Errorf("unknown command %s", aux.Command)
// }
// im.Command = v
// return nil
// }
// OutboundMessage is a message from GameEngine to Player
type OutboundMessage struct {
PlayerID string `json:"player_id"`
Command protocol.Cmd `json:"command"`
Name string `json:"name"` // pointless?
Joiner string `json:"joiner,omitempty"`
Message string `json:"message"`
Hand []deck.Card `json:"hand"`
Seen []deck.Card `json:"seen"`
Pile []deck.Card `json:"pile"`
CurrentTurn string `json:"current_turn,omitempty"`
Moves []int `json:"moves,omitempty"`
Opponents []Opponent `json:"opponents,omitempty"`
FinishedPlayers []string `json:"finished_players,omitempty"`
ShouldRespond bool `json:"should_respond"`
Error string `json:"error,omitempty"`
DefaultMessage InboundMessage
}
// InitialCards represent the default cards dealt to a Player
type InitialCards struct {
PlayerID string `json:"player_id"`
Hand []deck.Card `json:"hand"`
Seen []deck.Card `json:"seen"`
}
// Opponent is a representation of an opponent player
type Opponent struct {
PlayerID string `json:"player_id"`
Name string `json:"name"`
Seen []deck.Card `json:"opponent_seen"`
}