rummy

package module
v0.0.0-...-42aaa2b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2017 License: GPL-3.0 Imports: 19 Imported by: 0

README

Rummy 500

This repository contains a gRPC server that manages games of Rummy 500, and CLI and AI clients to connect to it. It was implemented over Christmas 2016 to prolong a family tournament with remote play, and as a way to learn about gRPC.

Server

The message protocol for the game server is defined in service.proto. The service provides APIs to create and join games, and to observe and play in games you have joined. Multiple games can be played simultaneously. A primitive form of authentication is provided by allowing players to join with a provided secret that must be used for all subsequent gameplay.

During a game, clients subscribe to game events to observe the play of others and to know when it is their turn. Game play events are pushed to subscribed clients using gRPC streaming.

Via gRPC-gateway, the server supports the same API over REST/JSON:

Game management

  • POST /v1/create/{game_name}
  • POST /v1/join/{game_name}/{player_name}
  • POST /v1/start/{game_name}

Game observation

  • GET /v1/subscribe/{game_name}
  • GET /v1/state/{game_name}
  • POST /v1/hand

Game play

  • POST /v1/pick_up_stock
  • POST /v1/pick_up_discard
  • POST /v1/play_cards
  • POST /v1/discard
  • POST /v1/call_rummy

This enables future development of a web interface.

State machine

Gameplay proceeds according to a state machine (see GameState in game.proto). The current player begins in state TURN_START and must issue either a PickUpStockRequest or a PickUpDiscardRequest to begin their turn. Once they have successfully picked up cards with a valid request, the turn state transitions to PICKED_UP_CARDS. The player may then play cards for points (if possible) by issuing a PlayCardsRequest, which transitions their state to PLAYED_CARDS. Finally, the player must discard a card with a DiscardCardRequest to end their turn.

The Game struct maintains the game invariants imposed by the rules of Rummy 500, such as enforcing that after a player has picked up from the discard they must play the bottom card for points before ending their turn.

CLI

clients/cli provides a command-line client that can be used to connect and play games interactively against other human or AI players.

$ ./cli -server :8081
Welcome to Rummy!

Main menu:
	1) Create a new game
	2) Join a game
	3) Quit
Please make a selection: 1
Enter game name: TestGame
Enter player name: Tim
Add CP? (y/n): y
Enter strategy name: greedy
Add CP? (y/n): n
Current players in game:
	0: Tim
	1: CP0-greedy
Start game? (y/n): y

Your turn!
Current hand: [3♥ 5♥ 7♦ 9♦ 7♣ 9♠ J♠]
Current discard pile: [5♣ 7♠]
All played melds:
	[10♥ 10♣ 10♠]
Current player status:
	Tim: 7 cards, 0 points
	CP0-greedy: 4 cards, 30 points

What would you like to do?
	1) Pick up a card from the stock
	2) Pick up card(s) from the discard pile
Selection: 2
How many cards would you like to pick up?: 3
Error picking up from discard: rpc error: code = Unknown desc = can't pick up 3 > 2 cards in discard pile

What would you like to do?
	1) Pick up a card from the stock
	2) Pick up card(s) from the discard pile
Selection: 1
Picked up: A♦
Current hand: 0:3♥ 1:5♥ 2:A♦ 3:7♦ 4:9♦ 5:7♣ 6:9♠ 7:J♠
Select cards to play as a meld or a rummy (e.g. 1,4,5). Leave empty to continue:
Current hand: 0:3♥ 1:5♥ 2:A♦ 3:7♦ 4:9♦ 5:7♣ 6:9♠ 7:J♠
Select card to discard: 7
CP0-greedy's turn.
CP0-greedy picked up a card from the stock.
CP0-greedy discarded: [6♦]

AI

Package clients/ai provides a simplified interface for implementing strategies that can play the game. To implement a new strategy, implement the Strategy interface and then add it to the registry in clients/ai/strategy/registry.go. A rudimentary greedy strategy is implemented in clients/ai/strategy/greedy.go.

Two or more strategies can be played against each other a large number of times using the driver in clients/ai/battle.

./battle -strategies nop,greedy -num_games 1000 -seed 123

Building

Regenerate the protos:

make proto

Build the server:

make server

Build the CLI:

make clients

Documentation

Overview

Package rummy is a generated protocol buffer package.

It is generated from these files:

game.proto
service.proto

It has these top-level messages:

Meld
PlayerState
GameState
GameEvent
CreateGameRequest
CreateGameResponse
JoinGameRequest
JoinGameResponse
StartGameRequest
StartGameResponse
GetGameStateRequest
GetHandCardsRequest
GetHandCardsResponse
SubscribeGameRequest
PickUpStockRequest
PickUpStockResponse
PickUpDiscardRequest
PickUpDiscardResponse
PlayCardsRequest
PlayCardsResponse
DiscardCardRequest
DiscardCardResponse
CallRummyRequest
CallRummyResponse

Package rummy is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

This section is empty.

Variables

View Source
var GameEvent_Type_name = map[int32]string{
	0: "UNKNOWN_TYPE",
	1: "TURN_START",
	2: "PICK_UP_STOCK",
	3: "PICK_UP_DISCARD",
	4: "PLAY_CARDS",
	5: "DISCARD",
	6: "GAME_OVER",
}
View Source
var GameEvent_Type_value = map[string]int32{
	"UNKNOWN_TYPE":    0,
	"TURN_START":      1,
	"PICK_UP_STOCK":   2,
	"PICK_UP_DISCARD": 3,
	"PLAY_CARDS":      4,
	"DISCARD":         5,
	"GAME_OVER":       6,
}
View Source
var GameState_TurnState_name = map[int32]string{
	0: "TURN_START",
	1: "PICKED_UP_CARDS",
	2: "PLAYED_CARDS",
}
View Source
var GameState_TurnState_value = map[string]int32{
	"TURN_START":      0,
	"PICKED_UP_CARDS": 1,
	"PLAYED_CARDS":    2,
}

Functions

func RegisterRummyServiceHandler

func RegisterRummyServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterRummyServiceHandler registers the http handlers for service RummyService to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterRummyServiceHandlerFromEndpoint

func RegisterRummyServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterRummyServiceHandlerFromEndpoint is same as RegisterRummyServiceHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterRummyServiceServer

func RegisterRummyServiceServer(s *grpc.Server, srv RummyServiceServer)

Types

type CallRummyRequest

type CallRummyRequest struct {
	GameName     string       `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
	PlayerId     int32        `protobuf:"varint,2,opt,name=player_id,json=playerId" json:"player_id,omitempty"`
	PlayerSecret string       `protobuf:"bytes,3,opt,name=player_secret,json=playerSecret" json:"player_secret,omitempty"`
	Cards        []*deck.Card `protobuf:"bytes,4,rep,name=cards" json:"cards,omitempty"`
}

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.

func (*CallRummyRequest) Descriptor

func (*CallRummyRequest) Descriptor() ([]byte, []int)

func (*CallRummyRequest) GetCards

func (m *CallRummyRequest) GetCards() []*deck.Card

func (*CallRummyRequest) GetGameName

func (m *CallRummyRequest) GetGameName() string

func (*CallRummyRequest) GetPlayerId

func (m *CallRummyRequest) GetPlayerId() int32

func (*CallRummyRequest) GetPlayerSecret

func (m *CallRummyRequest) GetPlayerSecret() string

func (*CallRummyRequest) ProtoMessage

func (*CallRummyRequest) ProtoMessage()

func (*CallRummyRequest) Reset

func (m *CallRummyRequest) Reset()

func (*CallRummyRequest) String

func (m *CallRummyRequest) String() string

type CallRummyResponse

type CallRummyResponse struct {
}

func (*CallRummyResponse) Descriptor

func (*CallRummyResponse) Descriptor() ([]byte, []int)

func (*CallRummyResponse) ProtoMessage

func (*CallRummyResponse) ProtoMessage()

func (*CallRummyResponse) Reset

func (m *CallRummyResponse) Reset()

func (*CallRummyResponse) String

func (m *CallRummyResponse) String() string

type CreateGameRequest

type CreateGameRequest struct {
	GameName string `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
}

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.

func (*CreateGameRequest) Descriptor

func (*CreateGameRequest) Descriptor() ([]byte, []int)

func (*CreateGameRequest) GetGameName

func (m *CreateGameRequest) GetGameName() string

func (*CreateGameRequest) ProtoMessage

func (*CreateGameRequest) ProtoMessage()

func (*CreateGameRequest) Reset

func (m *CreateGameRequest) Reset()

func (*CreateGameRequest) String

func (m *CreateGameRequest) String() string

type CreateGameResponse

type CreateGameResponse struct {
}

func (*CreateGameResponse) Descriptor

func (*CreateGameResponse) Descriptor() ([]byte, []int)

func (*CreateGameResponse) ProtoMessage

func (*CreateGameResponse) ProtoMessage()

func (*CreateGameResponse) Reset

func (m *CreateGameResponse) Reset()

func (*CreateGameResponse) String

func (m *CreateGameResponse) String() string

type DiscardCardRequest

type DiscardCardRequest struct {
	GameName     string     `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
	PlayerId     int32      `protobuf:"varint,2,opt,name=player_id,json=playerId" json:"player_id,omitempty"`
	PlayerSecret string     `protobuf:"bytes,3,opt,name=player_secret,json=playerSecret" json:"player_secret,omitempty"`
	Card         *deck.Card `protobuf:"bytes,4,opt,name=card" json:"card,omitempty"`
}

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.

func (*DiscardCardRequest) Descriptor

func (*DiscardCardRequest) Descriptor() ([]byte, []int)

func (*DiscardCardRequest) GetCard

func (m *DiscardCardRequest) GetCard() *deck.Card

func (*DiscardCardRequest) GetGameName

func (m *DiscardCardRequest) GetGameName() string

func (*DiscardCardRequest) GetPlayerId

func (m *DiscardCardRequest) GetPlayerId() int32

func (*DiscardCardRequest) GetPlayerSecret

func (m *DiscardCardRequest) GetPlayerSecret() string

func (*DiscardCardRequest) ProtoMessage

func (*DiscardCardRequest) ProtoMessage()

func (*DiscardCardRequest) Reset

func (m *DiscardCardRequest) Reset()

func (*DiscardCardRequest) String

func (m *DiscardCardRequest) String() string

type DiscardCardResponse

type DiscardCardResponse struct {
}

func (*DiscardCardResponse) Descriptor

func (*DiscardCardResponse) Descriptor() ([]byte, []int)

func (*DiscardCardResponse) ProtoMessage

func (*DiscardCardResponse) ProtoMessage()

func (*DiscardCardResponse) Reset

func (m *DiscardCardResponse) Reset()

func (*DiscardCardResponse) String

func (m *DiscardCardResponse) String() string

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game manages the state machine for a single game of Rummy.

func NewGame

func NewGame() *Game

NewGame initializes a new Game with a shuffled Deck of cards. There are initially no players. Players may join the game by calling AddPlayer, until the game is started by calling Deal.

func (*Game) AddPlayer

func (g *Game) AddPlayer(name string) (int32, error)

AddPlayer adds a player with the given name to the game. AddPlayer can be called until Deal is called to add more players. Each player must have a unique name.

func (*Game) CallRummy

func (g *Game) CallRummy(playerId int32, cards []deck.Card) error

func (*Game) Deal

func (g *Game) Deal() error

Deal starts the game, deals a hand to each player, and randomly selects the player to go first.

func (*Game) DiscardCard

func (g *Game) DiscardCard(playerId int32, card deck.Card) error

func (*Game) GameState

func (g *Game) GameState() *GameState

GameState returns the publicly observable state of the game.

func (*Game) PickUpDiscard

func (g *Game) PickUpDiscard(playerId int32, nCards int) ([]deck.Card, error)

func (*Game) PickUpStock

func (g *Game) PickUpStock(playerId int32) (deck.Card, error)

func (*Game) PlayCards

func (g *Game) PlayCards(playerId int32, cards []deck.Card) (int, error)

func (*Game) PlayerHand

func (g *Game) PlayerHand(playerId int32) ([]deck.Card, error)

func (*Game) Subscribe

func (g *Game) Subscribe(events chan *GameEvent)

type GameEvent

type GameEvent struct {
	PlayerId int32          `protobuf:"varint,1,opt,name=player_id,json=playerId" json:"player_id,omitempty"`
	Type     GameEvent_Type `protobuf:"varint,2,opt,name=type,enum=rummy.GameEvent_Type" json:"type,omitempty"`
	Cards    []*deck.Card   `protobuf:"bytes,3,rep,name=cards" json:"cards,omitempty"`
	Score    int32          `protobuf:"varint,4,opt,name=score" json:"score,omitempty"`
}

func (*GameEvent) Descriptor

func (*GameEvent) Descriptor() ([]byte, []int)

func (*GameEvent) GetCards

func (m *GameEvent) GetCards() []*deck.Card

func (*GameEvent) GetPlayerId

func (m *GameEvent) GetPlayerId() int32

func (*GameEvent) GetScore

func (m *GameEvent) GetScore() int32

func (*GameEvent) GetType

func (m *GameEvent) GetType() GameEvent_Type

func (*GameEvent) ProtoMessage

func (*GameEvent) ProtoMessage()

func (*GameEvent) Reset

func (m *GameEvent) Reset()

func (*GameEvent) String

func (m *GameEvent) String() string

type GameEvent_Type

type GameEvent_Type int32
const (
	GameEvent_UNKNOWN_TYPE    GameEvent_Type = 0
	GameEvent_TURN_START      GameEvent_Type = 1
	GameEvent_PICK_UP_STOCK   GameEvent_Type = 2
	GameEvent_PICK_UP_DISCARD GameEvent_Type = 3
	GameEvent_PLAY_CARDS      GameEvent_Type = 4
	GameEvent_DISCARD         GameEvent_Type = 5
	GameEvent_GAME_OVER       GameEvent_Type = 6
)

func (GameEvent_Type) EnumDescriptor

func (GameEvent_Type) EnumDescriptor() ([]byte, []int)

func (GameEvent_Type) String

func (x GameEvent_Type) String() string

type GameState

type GameState struct {
	NumCardsInStock   int32               `protobuf:"varint,1,opt,name=num_cards_in_stock,json=numCardsInStock" json:"num_cards_in_stock,omitempty"`
	DiscardPile       []*deck.Card        `protobuf:"bytes,2,rep,name=discard_pile,json=discardPile" json:"discard_pile,omitempty"`
	AggregatedMelds   []*Meld             `protobuf:"bytes,3,rep,name=aggregated_melds,json=aggregatedMelds" json:"aggregated_melds,omitempty"`
	Players           []*PlayerState      `protobuf:"bytes,4,rep,name=players" json:"players,omitempty"`
	Turn              int32               `protobuf:"varint,6,opt,name=turn" json:"turn,omitempty"`
	CurrentPlayerTurn int32               `protobuf:"varint,7,opt,name=current_player_turn,json=currentPlayerTurn" json:"current_player_turn,omitempty"`
	TurnState         GameState_TurnState `protobuf:"varint,8,opt,name=turn_state,json=turnState,enum=rummy.GameState_TurnState" json:"turn_state,omitempty"`
	GameOver          bool                `protobuf:"varint,9,opt,name=game_over,json=gameOver" json:"game_over,omitempty"`
}

func (*GameState) Descriptor

func (*GameState) Descriptor() ([]byte, []int)

func (*GameState) GetAggregatedMelds

func (m *GameState) GetAggregatedMelds() []*Meld

func (*GameState) GetCurrentPlayerTurn

func (m *GameState) GetCurrentPlayerTurn() int32

func (*GameState) GetDiscardPile

func (m *GameState) GetDiscardPile() []*deck.Card

func (*GameState) GetGameOver

func (m *GameState) GetGameOver() bool

func (*GameState) GetNumCardsInStock

func (m *GameState) GetNumCardsInStock() int32

func (*GameState) GetPlayers

func (m *GameState) GetPlayers() []*PlayerState

func (*GameState) GetTurn

func (m *GameState) GetTurn() int32

func (*GameState) GetTurnState

func (m *GameState) GetTurnState() GameState_TurnState

func (*GameState) ProtoMessage

func (*GameState) ProtoMessage()

func (*GameState) Reset

func (m *GameState) Reset()

func (*GameState) String

func (m *GameState) String() string

type GameState_TurnState

type GameState_TurnState int32
const (
	GameState_TURN_START      GameState_TurnState = 0
	GameState_PICKED_UP_CARDS GameState_TurnState = 1
	GameState_PLAYED_CARDS    GameState_TurnState = 2
)

func (GameState_TurnState) EnumDescriptor

func (GameState_TurnState) EnumDescriptor() ([]byte, []int)

func (GameState_TurnState) String

func (x GameState_TurnState) String() string

type GetGameStateRequest

type GetGameStateRequest struct {
	GameName string `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
}

Get the publicly-observable game state.

func (*GetGameStateRequest) Descriptor

func (*GetGameStateRequest) Descriptor() ([]byte, []int)

func (*GetGameStateRequest) GetGameName

func (m *GetGameStateRequest) GetGameName() string

func (*GetGameStateRequest) ProtoMessage

func (*GetGameStateRequest) ProtoMessage()

func (*GetGameStateRequest) Reset

func (m *GetGameStateRequest) Reset()

func (*GetGameStateRequest) String

func (m *GetGameStateRequest) String() string

type GetHandCardsRequest

type GetHandCardsRequest struct {
	GameName     string `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
	PlayerId     int32  `protobuf:"varint,2,opt,name=player_id,json=playerId" json:"player_id,omitempty"`
	PlayerSecret string `protobuf:"bytes,3,opt,name=player_secret,json=playerSecret" json:"player_secret,omitempty"`
}

Get the cards currently in a player's hand.

func (*GetHandCardsRequest) Descriptor

func (*GetHandCardsRequest) Descriptor() ([]byte, []int)

func (*GetHandCardsRequest) GetGameName

func (m *GetHandCardsRequest) GetGameName() string

func (*GetHandCardsRequest) GetPlayerId

func (m *GetHandCardsRequest) GetPlayerId() int32

func (*GetHandCardsRequest) GetPlayerSecret

func (m *GetHandCardsRequest) GetPlayerSecret() string

func (*GetHandCardsRequest) ProtoMessage

func (*GetHandCardsRequest) ProtoMessage()

func (*GetHandCardsRequest) Reset

func (m *GetHandCardsRequest) Reset()

func (*GetHandCardsRequest) String

func (m *GetHandCardsRequest) String() string

type GetHandCardsResponse

type GetHandCardsResponse struct {
	Cards []*deck.Card `protobuf:"bytes,1,rep,name=cards" json:"cards,omitempty"`
}

func (*GetHandCardsResponse) Descriptor

func (*GetHandCardsResponse) Descriptor() ([]byte, []int)

func (*GetHandCardsResponse) GetCards

func (m *GetHandCardsResponse) GetCards() []*deck.Card

func (*GetHandCardsResponse) ProtoMessage

func (*GetHandCardsResponse) ProtoMessage()

func (*GetHandCardsResponse) Reset

func (m *GetHandCardsResponse) Reset()

func (*GetHandCardsResponse) String

func (m *GetHandCardsResponse) String() string

type Hand

type Hand map[deck.Card]struct{}

func NewHand

func NewHand(cards []deck.Card) Hand

func (Hand) AsSlice

func (h Hand) AsSlice() []deck.Card

Return a copy of this Hand as a slice of cards.

func (Hand) Melds

func (h Hand) Melds() []meld.Meld

Melds returns all possible sets and runs in this Hand. The resulting melds may include overlapping sets of cards.

func (Hand) Runs

func (h Hand) Runs() []meld.Meld

Runs returns all possible runs in this Hand. The result may include overlapping sets of Cards if there is a run of > 3 cards.

func (Hand) Sets

func (h Hand) Sets() []meld.Meld

Sets returns all possible sets in this Hand. The result may include overlapping sets of cards if there is a set of 4 cards of the same rank.

func (Hand) String

func (h Hand) String() string

type JoinGameRequest

type JoinGameRequest struct {
	GameName string `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
	// The name of the player. Must be unique within a game.
	PlayerName string `protobuf:"bytes,2,opt,name=player_name,json=playerName" json:"player_name,omitempty"`
	// An optional secret used to identify this player.
	// If provided, then all game play requests for this player
	// must include this secret.
	PlayerSecret string `protobuf:"bytes,3,opt,name=player_secret,json=playerSecret" json:"player_secret,omitempty"`
	// Optional, if provided then initialize a computer player
	// with this strategy.
	Strategy string `protobuf:"bytes,4,opt,name=strategy" json:"strategy,omitempty"`
}

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.

func (*JoinGameRequest) Descriptor

func (*JoinGameRequest) Descriptor() ([]byte, []int)

func (*JoinGameRequest) GetGameName

func (m *JoinGameRequest) GetGameName() string

func (*JoinGameRequest) GetPlayerName

func (m *JoinGameRequest) GetPlayerName() string

func (*JoinGameRequest) GetPlayerSecret

func (m *JoinGameRequest) GetPlayerSecret() string

func (*JoinGameRequest) GetStrategy

func (m *JoinGameRequest) GetStrategy() string

func (*JoinGameRequest) ProtoMessage

func (*JoinGameRequest) ProtoMessage()

func (*JoinGameRequest) Reset

func (m *JoinGameRequest) Reset()

func (*JoinGameRequest) String

func (m *JoinGameRequest) String() string

type JoinGameResponse

type JoinGameResponse struct {
	// The player id within this game. Must be included in all requests.
	PlayerId int32 `protobuf:"varint,1,opt,name=player_id,json=playerId" json:"player_id,omitempty"`
}

func (*JoinGameResponse) Descriptor

func (*JoinGameResponse) Descriptor() ([]byte, []int)

func (*JoinGameResponse) GetPlayerId

func (m *JoinGameResponse) GetPlayerId() int32

func (*JoinGameResponse) ProtoMessage

func (*JoinGameResponse) ProtoMessage()

func (*JoinGameResponse) Reset

func (m *JoinGameResponse) Reset()

func (*JoinGameResponse) String

func (m *JoinGameResponse) String() string

type Meld

type Meld struct {
	Cards []*deck.Card `protobuf:"bytes,1,rep,name=cards" json:"cards,omitempty"`
}

func (*Meld) Descriptor

func (*Meld) Descriptor() ([]byte, []int)

func (*Meld) GetCards

func (m *Meld) GetCards() []*deck.Card

func (*Meld) ProtoMessage

func (*Meld) ProtoMessage()

func (*Meld) Reset

func (m *Meld) Reset()

func (*Meld) String

func (m *Meld) String() string

type PickUpDiscardRequest

type PickUpDiscardRequest struct {
	GameName     string `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
	PlayerId     int32  `protobuf:"varint,2,opt,name=player_id,json=playerId" json:"player_id,omitempty"`
	PlayerSecret string `protobuf:"bytes,3,opt,name=player_secret,json=playerSecret" json:"player_secret,omitempty"`
	NCards       int32  `protobuf:"varint,4,opt,name=n_cards,json=nCards" json:"n_cards,omitempty"`
}

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.

func (*PickUpDiscardRequest) Descriptor

func (*PickUpDiscardRequest) Descriptor() ([]byte, []int)

func (*PickUpDiscardRequest) GetGameName

func (m *PickUpDiscardRequest) GetGameName() string

func (*PickUpDiscardRequest) GetNCards

func (m *PickUpDiscardRequest) GetNCards() int32

func (*PickUpDiscardRequest) GetPlayerId

func (m *PickUpDiscardRequest) GetPlayerId() int32

func (*PickUpDiscardRequest) GetPlayerSecret

func (m *PickUpDiscardRequest) GetPlayerSecret() string

func (*PickUpDiscardRequest) ProtoMessage

func (*PickUpDiscardRequest) ProtoMessage()

func (*PickUpDiscardRequest) Reset

func (m *PickUpDiscardRequest) Reset()

func (*PickUpDiscardRequest) String

func (m *PickUpDiscardRequest) String() string

type PickUpDiscardResponse

type PickUpDiscardResponse struct {
	Cards []*deck.Card `protobuf:"bytes,1,rep,name=cards" json:"cards,omitempty"`
}

Returns the cards picked up from the discard pile.

func (*PickUpDiscardResponse) Descriptor

func (*PickUpDiscardResponse) Descriptor() ([]byte, []int)

func (*PickUpDiscardResponse) GetCards

func (m *PickUpDiscardResponse) GetCards() []*deck.Card

func (*PickUpDiscardResponse) ProtoMessage

func (*PickUpDiscardResponse) ProtoMessage()

func (*PickUpDiscardResponse) Reset

func (m *PickUpDiscardResponse) Reset()

func (*PickUpDiscardResponse) String

func (m *PickUpDiscardResponse) String() string

type PickUpStockRequest

type PickUpStockRequest struct {
	GameName     string `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
	PlayerId     int32  `protobuf:"varint,2,opt,name=player_id,json=playerId" json:"player_id,omitempty"`
	PlayerSecret string `protobuf:"bytes,3,opt,name=player_secret,json=playerSecret" json:"player_secret,omitempty"`
}

Pick up a card from the stock. A player should initiate this request when beginning their turn. Alternatively, a player may issue a PickUpDiscardRequest.

func (*PickUpStockRequest) Descriptor

func (*PickUpStockRequest) Descriptor() ([]byte, []int)

func (*PickUpStockRequest) GetGameName

func (m *PickUpStockRequest) GetGameName() string

func (*PickUpStockRequest) GetPlayerId

func (m *PickUpStockRequest) GetPlayerId() int32

func (*PickUpStockRequest) GetPlayerSecret

func (m *PickUpStockRequest) GetPlayerSecret() string

func (*PickUpStockRequest) ProtoMessage

func (*PickUpStockRequest) ProtoMessage()

func (*PickUpStockRequest) Reset

func (m *PickUpStockRequest) Reset()

func (*PickUpStockRequest) String

func (m *PickUpStockRequest) String() string

type PickUpStockResponse

type PickUpStockResponse struct {
	Card *deck.Card `protobuf:"bytes,1,opt,name=card" json:"card,omitempty"`
}

Returns the card that was picked up from the stock.

func (*PickUpStockResponse) Descriptor

func (*PickUpStockResponse) Descriptor() ([]byte, []int)

func (*PickUpStockResponse) GetCard

func (m *PickUpStockResponse) GetCard() *deck.Card

func (*PickUpStockResponse) ProtoMessage

func (*PickUpStockResponse) ProtoMessage()

func (*PickUpStockResponse) Reset

func (m *PickUpStockResponse) Reset()

func (*PickUpStockResponse) String

func (m *PickUpStockResponse) String() string

type PlayCardsRequest

type PlayCardsRequest struct {
	GameName     string       `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
	PlayerId     int32        `protobuf:"varint,2,opt,name=player_id,json=playerId" json:"player_id,omitempty"`
	PlayerSecret string       `protobuf:"bytes,3,opt,name=player_secret,json=playerSecret" json:"player_secret,omitempty"`
	Cards        []*deck.Card `protobuf:"bytes,4,rep,name=cards" json:"cards,omitempty"`
}

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.

func (*PlayCardsRequest) Descriptor

func (*PlayCardsRequest) Descriptor() ([]byte, []int)

func (*PlayCardsRequest) GetCards

func (m *PlayCardsRequest) GetCards() []*deck.Card

func (*PlayCardsRequest) GetGameName

func (m *PlayCardsRequest) GetGameName() string

func (*PlayCardsRequest) GetPlayerId

func (m *PlayCardsRequest) GetPlayerId() int32

func (*PlayCardsRequest) GetPlayerSecret

func (m *PlayCardsRequest) GetPlayerSecret() string

func (*PlayCardsRequest) ProtoMessage

func (*PlayCardsRequest) ProtoMessage()

func (*PlayCardsRequest) Reset

func (m *PlayCardsRequest) Reset()

func (*PlayCardsRequest) String

func (m *PlayCardsRequest) String() string

type PlayCardsResponse

type PlayCardsResponse struct {
	Score int32 `protobuf:"varint,1,opt,name=score" json:"score,omitempty"`
}

func (*PlayCardsResponse) Descriptor

func (*PlayCardsResponse) Descriptor() ([]byte, []int)

func (*PlayCardsResponse) GetScore

func (m *PlayCardsResponse) GetScore() int32

func (*PlayCardsResponse) ProtoMessage

func (*PlayCardsResponse) ProtoMessage()

func (*PlayCardsResponse) Reset

func (m *PlayCardsResponse) Reset()

func (*PlayCardsResponse) String

func (m *PlayCardsResponse) String() string

type PlayerState

type PlayerState struct {
	Id             int32        `protobuf:"varint,1,opt,name=id" json:"id,omitempty"`
	Name           string       `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
	Melds          []*Meld      `protobuf:"bytes,3,rep,name=melds" json:"melds,omitempty"`
	Rummies        []*deck.Card `protobuf:"bytes,4,rep,name=rummies" json:"rummies,omitempty"`
	NumCardsInHand int32        `protobuf:"varint,5,opt,name=num_cards_in_hand,json=numCardsInHand" json:"num_cards_in_hand,omitempty"`
	CurrentScore   int32        `protobuf:"varint,6,opt,name=current_score,json=currentScore" json:"current_score,omitempty"`
}

func (*PlayerState) Descriptor

func (*PlayerState) Descriptor() ([]byte, []int)

func (*PlayerState) GetCurrentScore

func (m *PlayerState) GetCurrentScore() int32

func (*PlayerState) GetId

func (m *PlayerState) GetId() int32

func (*PlayerState) GetMelds

func (m *PlayerState) GetMelds() []*Meld

func (*PlayerState) GetName

func (m *PlayerState) GetName() string

func (*PlayerState) GetNumCardsInHand

func (m *PlayerState) GetNumCardsInHand() int32

func (*PlayerState) GetRummies

func (m *PlayerState) GetRummies() []*deck.Card

func (*PlayerState) ProtoMessage

func (*PlayerState) ProtoMessage()

func (*PlayerState) Reset

func (m *PlayerState) Reset()

func (*PlayerState) String

func (m *PlayerState) String() string

type RummyService_SubscribeGameClient

type RummyService_SubscribeGameClient interface {
	Recv() (*GameEvent, error)
	grpc.ClientStream
}

type RummyService_SubscribeGameServer

type RummyService_SubscribeGameServer interface {
	Send(*GameEvent) error
	grpc.ServerStream
}

type StartGameRequest

type StartGameRequest struct {
	GameName string `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
}

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.

func (*StartGameRequest) Descriptor

func (*StartGameRequest) Descriptor() ([]byte, []int)

func (*StartGameRequest) GetGameName

func (m *StartGameRequest) GetGameName() string

func (*StartGameRequest) ProtoMessage

func (*StartGameRequest) ProtoMessage()

func (*StartGameRequest) Reset

func (m *StartGameRequest) Reset()

func (*StartGameRequest) String

func (m *StartGameRequest) String() string

type StartGameResponse

type StartGameResponse struct {
}

func (*StartGameResponse) Descriptor

func (*StartGameResponse) Descriptor() ([]byte, []int)

func (*StartGameResponse) ProtoMessage

func (*StartGameResponse) ProtoMessage()

func (*StartGameResponse) Reset

func (m *StartGameResponse) Reset()

func (*StartGameResponse) String

func (m *StartGameResponse) String() string

type SubscribeGameRequest

type SubscribeGameRequest struct {
	GameName string `protobuf:"bytes,1,opt,name=game_name,json=gameName" json:"game_name,omitempty"`
}

Subscribe to game events. This allows players to observe the gameplay of other players.

func (*SubscribeGameRequest) Descriptor

func (*SubscribeGameRequest) Descriptor() ([]byte, []int)

func (*SubscribeGameRequest) GetGameName

func (m *SubscribeGameRequest) GetGameName() string

func (*SubscribeGameRequest) ProtoMessage

func (*SubscribeGameRequest) ProtoMessage()

func (*SubscribeGameRequest) Reset

func (m *SubscribeGameRequest) Reset()

func (*SubscribeGameRequest) String

func (m *SubscribeGameRequest) String() string

Directories

Path Synopsis
clients
ai
cli
Package deck is a generated protocol buffer package.
Package deck is a generated protocol buffer package.
gamed
gamed is the main entrypoint for the rummy game server.
gamed is the main entrypoint for the rummy game server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL