-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathservice.proto
224 lines (198 loc) · 6.43 KB
/
service.proto
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
syntax = "proto3";
package rummy;
import "google/api/annotations.proto";
import "github.com/timpalpant/rummy/deck/deck.proto";
import "game.proto";
// Create a new game with the given name.
// Each game must have a unique name; if the name has been
// used before, an error will be returned. Games must be
// created before they can be joined.
message CreateGameRequest {
string game_name = 1;
}
message CreateGameResponse {
}
// Join a game (that must already have been created)
// as the player with the given name. Only one player with
// each name is allowed in a game. If a player with this
// name has already joined the game, the previous player id
// will be returned. If a strategy is provided, then this is a
// computer player; otherwise it is a human player that must
// initiate gameplay actions when it is their turn.
message JoinGameRequest {
string game_name = 1;
// The name of the player. Must be unique within a game.
string player_name = 2;
// An optional secret used to identify this player.
// If provided, then all game play requests for this player
// must include this secret.
string player_secret = 3;
// Optional, if provided then initialize a computer player
// with this strategy.
string strategy = 4;
}
message JoinGameResponse {
// The player id within this game. Must be included in all requests.
int32 player_id = 1;
}
// Start the given name, dealing cards to each of the joined players.
// Once a game has been started, no additional players may join.
// TODO(palpant): Only let game creator start the game.
message StartGameRequest {
string game_name = 1;
}
message StartGameResponse {
}
// Get the publicly-observable game state.
message GetGameStateRequest {
string game_name = 1;
}
// Get the cards currently in a player's hand.
message GetHandCardsRequest {
string game_name = 1;
int32 player_id = 2;
string player_secret = 3;
}
message GetHandCardsResponse {
repeated deck.Card cards = 1;
}
// Subscribe to game events. This allows players to observe the
// gameplay of other players.
message SubscribeGameRequest {
string game_name = 1;
}
// Pick up a card from the stock. A player should initiate this request
// when beginning their turn. Alternatively, a player may issue a
// PickUpDiscardRequest.
message PickUpStockRequest {
string game_name = 1;
int32 player_id = 2;
string player_secret = 3;
}
// Returns the card that was picked up from the stock.
message PickUpStockResponse {
deck.Card card = 1;
}
// Pick up N cards from the discard pile. A player may initiate this
// request when beginning their turn. Alternatively, a player may pick
// up a card from the stock. The N cards picked up are from the top of
// the discard stack. The bottom-most card must be played this turn.
message PickUpDiscardRequest {
string game_name = 1;
int32 player_id = 2;
string player_secret = 3;
int32 n_cards = 4;
}
// Returns the cards picked up from the discard pile.
message PickUpDiscardResponse {
repeated deck.Card cards = 1;
}
// Play cards for points. The cards must either form a new Meld,
// or rummy off of a meld that has previously been played (by any player).
// Players may issue this request only when it is their turn and they have
// picked up cards (either from the stock or the discard pile).
// This request may be issued multiple times in a single turn.
message PlayCardsRequest {
string game_name = 1;
int32 player_id = 2;
string player_secret = 3;
repeated deck.Card cards = 4;
// TODO(palpant): If rummying, we need to specify the meld the player
// is choosing to rummy off of. In some cases it may be possible to
// rummyoff of either a set or a run.
}
message PlayCardsResponse {
int32 score = 1;
}
// Discard a card from hand into the discard pile.
// Players may play this card after picking up cards and (optionally)
// playing cards for points. Discarding a card ends the player's turn.
message DiscardCardRequest {
string game_name = 1;
int32 player_id = 2;
string player_secret = 3;
deck.Card card = 4;
}
message DiscardCardResponse {
}
// Call a rummy observed in the discard pile. This request may be performed
// at any time when a player observes that a possible rummy has been created
// either as the result of a discard or newly played cards.
message CallRummyRequest {
string game_name = 1;
int32 player_id = 2;
string player_secret = 3;
repeated deck.Card cards = 4;
}
message CallRummyResponse {
}
service RummyService {
rpc CreateGame(CreateGameRequest) returns (CreateGameResponse) {
option (google.api.http) = {
post: "/v1/create/{game_name}"
};
}
rpc JoinGame(JoinGameRequest) returns (JoinGameResponse) {
option (google.api.http) = {
post: "/v1/join/{game_name}/{player_name}"
additional_bindings {
post: "/v1/join_game"
body: "*"
}
};
}
rpc StartGame(StartGameRequest) returns (StartGameResponse) {
option (google.api.http) = {
post: "/v1/start/{game_name}"
};
}
rpc SubscribeGame(SubscribeGameRequest) returns (stream GameEvent) {
option (google.api.http) = {
get: "/v1/subscribe/{game_name}"
};
}
rpc GetGameState(GetGameStateRequest) returns (GameState) {
option (google.api.http) = {
get: "/v1/state/{game_name}"
};
}
rpc GetHandCards(GetHandCardsRequest) returns (GetHandCardsResponse) {
option (google.api.http) = {
get: "/v1/hand/{game_name}/{player_id}"
additional_bindings {
post: "/v1/hand"
body: "*"
}
};
}
rpc PickUpStock(PickUpStockRequest) returns (PickUpStockResponse) {
option (google.api.http) = {
post: "/v1/pick_up_stock"
body: "*"
};
}
rpc PickUpDiscard(PickUpDiscardRequest) returns (PickUpDiscardResponse) {
option (google.api.http) = {
post: "/v1/pick_up_discard"
body: "*"
};
}
rpc PlayCards(PlayCardsRequest) returns (PlayCardsResponse) {
option (google.api.http) = {
post: "/v1/play_cards"
body: "*"
};
}
rpc DiscardCard(DiscardCardRequest) returns (DiscardCardResponse) {
option (google.api.http) = {
post: "/v1/discard"
body: "*"
};
}
rpc CallRummy(CallRummyRequest) returns (CallRummyResponse) {
option (google.api.http) = {
post: "/v1/call_rummy"
body: "*"
};
}
}