~bsprague/rummikub

079d274cede22415a82ccf936d0457e8d18eec4d — Brandon Sprague 2 years ago 3832ddd
Implement more of the game

Start adding legit error handling, game state management, and card
dealing
M Cargo.lock => Cargo.lock +3 -2
@@ 284,9 284,9 @@ dependencies = [

[[package]]
name = "indexmap"
version = "1.7.0"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
dependencies = [
 "autocfg",
 "hashbrown",


@@ 593,6 593,7 @@ version = "0.1.0"
dependencies = [
 "async-stream",
 "futures",
 "indexmap",
 "prost",
 "rand",
 "strum",

M Cargo.toml => Cargo.toml +1 -0
@@ 5,6 5,7 @@ edition = "2021"

[dependencies]
async-stream = "0.3"
indexmap = "1.8.0"
futures = {version = "0.3", default-features = false, features = ["alloc"]}
prost = "0.9"
rand = "0.8.4"

M cmd/testclient/main.go => cmd/testclient/main.go +3 -3
@@ 11,9 11,7 @@ import (
)

func main() {
	var (
		serverAddr = flag.String("server_addr", "[::1]:50051", "The address of the Rummikub gRPC server to connect to.")
	)
	serverAddr := flag.String("server_addr", "[::1]:50051", "The address of the Rummikub gRPC server to connect to.")
	flag.Parse()

	opts := []grpc.DialOption{


@@ 64,6 62,8 @@ func listenForUpdates(playClient rummikubpb.Rummikub_PlayClient) {
			log.Println("got the join response!")
		case *rummikubpb.PlayResponse_GameStarted:
			log.Printf("the game has been started with %d players", len(v.GameStarted.Players))
		case *rummikubpb.PlayResponse_Error:
			log.Printf("got an error: %q - %q", v.Error.Code, v.Error.Msg)
		default:
			log.Printf("unexpected response type %T", msg.Msg)
		}

M proto/gen/go/rummikubpb/rummikub.pb.go => proto/gen/go/rummikubpb/rummikub.pb.go +243 -87
@@ 20,6 20,61 @@ const (
	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)

type Error_Code int32

const (
	Error_UNKNOWN         Error_Code = 0
	Error_GAME_FULL       Error_Code = 1
	Error_BAD_GAME_STATE  Error_Code = 2
	Error_TOO_FEW_TILES   Error_Code = 3
	Error_TOO_FEW_PLAYERS Error_Code = 4
)

// Enum value maps for Error_Code.
var (
	Error_Code_name = map[int32]string{
		0: "UNKNOWN",
		1: "GAME_FULL",
		2: "BAD_GAME_STATE",
		3: "TOO_FEW_TILES",
		4: "TOO_FEW_PLAYERS",
	}
	Error_Code_value = map[string]int32{
		"UNKNOWN":         0,
		"GAME_FULL":       1,
		"BAD_GAME_STATE":  2,
		"TOO_FEW_TILES":   3,
		"TOO_FEW_PLAYERS": 4,
	}
)

func (x Error_Code) Enum() *Error_Code {
	p := new(Error_Code)
	*p = x
	return p
}

func (x Error_Code) String() string {
	return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}

func (Error_Code) Descriptor() protoreflect.EnumDescriptor {
	return file_rummikub_proto_enumTypes[0].Descriptor()
}

func (Error_Code) Type() protoreflect.EnumType {
	return &file_rummikub_proto_enumTypes[0]
}

func (x Error_Code) Number() protoreflect.EnumNumber {
	return protoreflect.EnumNumber(x)
}

// Deprecated: Use Error_Code.Descriptor instead.
func (Error_Code) EnumDescriptor() ([]byte, []int) {
	return file_rummikub_proto_rawDescGZIP(), []int{4, 0}
}

type PlayRequest struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache


@@ 195,6 250,7 @@ type PlayResponse struct {
	//	*PlayResponse_GameStarted
	//	*PlayResponse_PlayerMove
	//	*PlayResponse_YourMove
	//	*PlayResponse_Error
	Msg isPlayResponse_Msg `protobuf_oneof:"msg"`
}



@@ 265,6 321,13 @@ func (x *PlayResponse) GetYourMove() *YourMove {
	return nil
}

func (x *PlayResponse) GetError() *Error {
	if x, ok := x.GetMsg().(*PlayResponse_Error); ok {
		return x.Error
	}
	return nil
}

type isPlayResponse_Msg interface {
	isPlayResponse_Msg()
}


@@ 285,6 348,10 @@ type PlayResponse_YourMove struct {
	YourMove *YourMove `protobuf:"bytes,4,opt,name=your_move,json=yourMove,proto3,oneof"`
}

type PlayResponse_Error struct {
	Error *Error `protobuf:"bytes,5,opt,name=error,proto3,oneof"`
}

func (*PlayResponse_JoinResponse) isPlayResponse_Msg() {}

func (*PlayResponse_GameStarted) isPlayResponse_Msg() {}


@@ 293,6 360,63 @@ func (*PlayResponse_PlayerMove) isPlayResponse_Msg() {}

func (*PlayResponse_YourMove) isPlayResponse_Msg() {}

func (*PlayResponse_Error) isPlayResponse_Msg() {}

type Error struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	Code Error_Code `protobuf:"varint,1,opt,name=code,proto3,enum=rummikub.Error_Code" json:"code,omitempty"`
	Msg  string     `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"`
}

func (x *Error) Reset() {
	*x = Error{}
	if protoimpl.UnsafeEnabled {
		mi := &file_rummikub_proto_msgTypes[4]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}
}

func (x *Error) String() string {
	return protoimpl.X.MessageStringOf(x)
}

func (*Error) ProtoMessage() {}

func (x *Error) ProtoReflect() protoreflect.Message {
	mi := &file_rummikub_proto_msgTypes[4]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {
			ms.StoreMessageInfo(mi)
		}
		return ms
	}
	return mi.MessageOf(x)
}

// Deprecated: Use Error.ProtoReflect.Descriptor instead.
func (*Error) Descriptor() ([]byte, []int) {
	return file_rummikub_proto_rawDescGZIP(), []int{4}
}

func (x *Error) GetCode() Error_Code {
	if x != nil {
		return x.Code
	}
	return Error_UNKNOWN
}

func (x *Error) GetMsg() string {
	if x != nil {
		return x.Msg
	}
	return ""
}

type JoinResponse struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache


@@ 302,7 426,7 @@ type JoinResponse struct {
func (x *JoinResponse) Reset() {
	*x = JoinResponse{}
	if protoimpl.UnsafeEnabled {
		mi := &file_rummikub_proto_msgTypes[4]
		mi := &file_rummikub_proto_msgTypes[5]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}


@@ 315,7 439,7 @@ func (x *JoinResponse) String() string {
func (*JoinResponse) ProtoMessage() {}

func (x *JoinResponse) ProtoReflect() protoreflect.Message {
	mi := &file_rummikub_proto_msgTypes[4]
	mi := &file_rummikub_proto_msgTypes[5]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {


@@ 328,7 452,7 @@ func (x *JoinResponse) ProtoReflect() protoreflect.Message {

// Deprecated: Use JoinResponse.ProtoReflect.Descriptor instead.
func (*JoinResponse) Descriptor() ([]byte, []int) {
	return file_rummikub_proto_rawDescGZIP(), []int{4}
	return file_rummikub_proto_rawDescGZIP(), []int{5}
}

type GameStarted struct {


@@ 344,7 468,7 @@ type GameStarted struct {
func (x *GameStarted) Reset() {
	*x = GameStarted{}
	if protoimpl.UnsafeEnabled {
		mi := &file_rummikub_proto_msgTypes[5]
		mi := &file_rummikub_proto_msgTypes[6]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}


@@ 357,7 481,7 @@ func (x *GameStarted) String() string {
func (*GameStarted) ProtoMessage() {}

func (x *GameStarted) ProtoReflect() protoreflect.Message {
	mi := &file_rummikub_proto_msgTypes[5]
	mi := &file_rummikub_proto_msgTypes[6]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {


@@ 370,7 494,7 @@ func (x *GameStarted) ProtoReflect() protoreflect.Message {

// Deprecated: Use GameStarted.ProtoReflect.Descriptor instead.
func (*GameStarted) Descriptor() ([]byte, []int) {
	return file_rummikub_proto_rawDescGZIP(), []int{5}
	return file_rummikub_proto_rawDescGZIP(), []int{6}
}

func (x *GameStarted) GetPlayers() []*Player {


@@ 392,7 516,7 @@ type Player struct {
func (x *Player) Reset() {
	*x = Player{}
	if protoimpl.UnsafeEnabled {
		mi := &file_rummikub_proto_msgTypes[6]
		mi := &file_rummikub_proto_msgTypes[7]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}


@@ 405,7 529,7 @@ func (x *Player) String() string {
func (*Player) ProtoMessage() {}

func (x *Player) ProtoReflect() protoreflect.Message {
	mi := &file_rummikub_proto_msgTypes[6]
	mi := &file_rummikub_proto_msgTypes[7]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {


@@ 418,7 542,7 @@ func (x *Player) ProtoReflect() protoreflect.Message {

// Deprecated: Use Player.ProtoReflect.Descriptor instead.
func (*Player) Descriptor() ([]byte, []int) {
	return file_rummikub_proto_rawDescGZIP(), []int{6}
	return file_rummikub_proto_rawDescGZIP(), []int{7}
}

func (x *Player) GetId() string {


@@ 451,7 575,7 @@ type PlayerMove struct {
func (x *PlayerMove) Reset() {
	*x = PlayerMove{}
	if protoimpl.UnsafeEnabled {
		mi := &file_rummikub_proto_msgTypes[7]
		mi := &file_rummikub_proto_msgTypes[8]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}


@@ 464,7 588,7 @@ func (x *PlayerMove) String() string {
func (*PlayerMove) ProtoMessage() {}

func (x *PlayerMove) ProtoReflect() protoreflect.Message {
	mi := &file_rummikub_proto_msgTypes[7]
	mi := &file_rummikub_proto_msgTypes[8]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {


@@ 477,7 601,7 @@ func (x *PlayerMove) ProtoReflect() protoreflect.Message {

// Deprecated: Use PlayerMove.ProtoReflect.Descriptor instead.
func (*PlayerMove) Descriptor() ([]byte, []int) {
	return file_rummikub_proto_rawDescGZIP(), []int{7}
	return file_rummikub_proto_rawDescGZIP(), []int{8}
}

func (x *PlayerMove) GetId() string {


@@ 513,7 637,7 @@ type YourMove struct {
func (x *YourMove) Reset() {
	*x = YourMove{}
	if protoimpl.UnsafeEnabled {
		mi := &file_rummikub_proto_msgTypes[8]
		mi := &file_rummikub_proto_msgTypes[9]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}


@@ 526,7 650,7 @@ func (x *YourMove) String() string {
func (*YourMove) ProtoMessage() {}

func (x *YourMove) ProtoReflect() protoreflect.Message {
	mi := &file_rummikub_proto_msgTypes[8]
	mi := &file_rummikub_proto_msgTypes[9]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {


@@ 539,7 663,7 @@ func (x *YourMove) ProtoReflect() protoreflect.Message {

// Deprecated: Use YourMove.ProtoReflect.Descriptor instead.
func (*YourMove) Descriptor() ([]byte, []int) {
	return file_rummikub_proto_rawDescGZIP(), []int{8}
	return file_rummikub_proto_rawDescGZIP(), []int{9}
}

func (x *YourMove) GetBoard() *Board {


@@ 558,7 682,7 @@ type Move struct {
func (x *Move) Reset() {
	*x = Move{}
	if protoimpl.UnsafeEnabled {
		mi := &file_rummikub_proto_msgTypes[9]
		mi := &file_rummikub_proto_msgTypes[10]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}


@@ 571,7 695,7 @@ func (x *Move) String() string {
func (*Move) ProtoMessage() {}

func (x *Move) ProtoReflect() protoreflect.Message {
	mi := &file_rummikub_proto_msgTypes[9]
	mi := &file_rummikub_proto_msgTypes[10]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {


@@ 584,7 708,7 @@ func (x *Move) ProtoReflect() protoreflect.Message {

// Deprecated: Use Move.ProtoReflect.Descriptor instead.
func (*Move) Descriptor() ([]byte, []int) {
	return file_rummikub_proto_rawDescGZIP(), []int{9}
	return file_rummikub_proto_rawDescGZIP(), []int{10}
}

type Board struct {


@@ 596,7 720,7 @@ type Board struct {
func (x *Board) Reset() {
	*x = Board{}
	if protoimpl.UnsafeEnabled {
		mi := &file_rummikub_proto_msgTypes[10]
		mi := &file_rummikub_proto_msgTypes[11]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}


@@ 609,7 733,7 @@ func (x *Board) String() string {
func (*Board) ProtoMessage() {}

func (x *Board) ProtoReflect() protoreflect.Message {
	mi := &file_rummikub_proto_msgTypes[10]
	mi := &file_rummikub_proto_msgTypes[11]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {


@@ 622,7 746,7 @@ func (x *Board) ProtoReflect() protoreflect.Message {

// Deprecated: Use Board.ProtoReflect.Descriptor instead.
func (*Board) Descriptor() ([]byte, []int) {
	return file_rummikub_proto_rawDescGZIP(), []int{10}
	return file_rummikub_proto_rawDescGZIP(), []int{11}
}

var File_rummikub_proto protoreflect.FileDescriptor


@@ 641,7 765,7 @@ var file_rummikub_proto_rawDesc = []byte{
	0x6d, 0x73, 0x67, 0x22, 0x21, 0x0a, 0x0b, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65,
	0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
	0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x0b, 0x0a, 0x09, 0x53, 0x74, 0x61, 0x72, 0x74, 0x47,
	0x61, 0x6d, 0x65, 0x22, 0xfc, 0x01, 0x0a, 0x0c, 0x50, 0x6c, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70,
	0x61, 0x6d, 0x65, 0x22, 0xa5, 0x02, 0x0a, 0x0c, 0x50, 0x6c, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70,
	0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3d, 0x0a, 0x0d, 0x6a, 0x6f, 0x69, 0x6e, 0x5f, 0x72, 0x65, 0x73,
	0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x72, 0x75,
	0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f,


@@ 656,34 780,47 @@ var file_rummikub_proto_rawDesc = []byte{
	0x61, 0x79, 0x65, 0x72, 0x4d, 0x6f, 0x76, 0x65, 0x12, 0x31, 0x0a, 0x09, 0x79, 0x6f, 0x75, 0x72,
	0x5f, 0x6d, 0x6f, 0x76, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x72, 0x75,
	0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x59, 0x6f, 0x75, 0x72, 0x4d, 0x6f, 0x76, 0x65, 0x48,
	0x00, 0x52, 0x08, 0x79, 0x6f, 0x75, 0x72, 0x4d, 0x6f, 0x76, 0x65, 0x42, 0x05, 0x0a, 0x03, 0x6d,
	0x73, 0x67, 0x22, 0x0e, 0x0a, 0x0c, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
	0x73, 0x65, 0x22, 0x39, 0x0a, 0x0b, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x65,
	0x64, 0x12, 0x2a, 0x0a, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03,
	0x28, 0x0b, 0x32, 0x10, 0x2e, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x50, 0x6c,
	0x61, 0x79, 0x65, 0x72, 0x52, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x22, 0x2c, 0x0a,
	0x06, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20,
	0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
	0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x67, 0x0a, 0x0a, 0x50,
	0x6c, 0x61, 0x79, 0x65, 0x72, 0x4d, 0x6f, 0x76, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
	0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x22, 0x0a, 0x04, 0x6d, 0x6f, 0x76,
	0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b,
	0x75, 0x62, 0x2e, 0x4d, 0x6f, 0x76, 0x65, 0x52, 0x04, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x25, 0x0a,
	0x05, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x72,
	0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x52, 0x05, 0x62,
	0x6f, 0x61, 0x72, 0x64, 0x22, 0x31, 0x0a, 0x08, 0x59, 0x6f, 0x75, 0x72, 0x4d, 0x6f, 0x76, 0x65,
	0x12, 0x25, 0x0a, 0x05, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
	0x0f, 0x2e, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x42, 0x6f, 0x61, 0x72, 0x64,
	0x52, 0x05, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x22, 0x06, 0x0a, 0x04, 0x4d, 0x6f, 0x76, 0x65, 0x22,
	0x07, 0x0a, 0x05, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x32, 0x45, 0x0a, 0x08, 0x52, 0x75, 0x6d, 0x6d,
	0x69, 0x6b, 0x75, 0x62, 0x12, 0x39, 0x0a, 0x04, 0x50, 0x6c, 0x61, 0x79, 0x12, 0x15, 0x2e, 0x72,
	0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75,
	0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x50,
	0x6c, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x42,
	0x36, 0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x63,
	0x73, 0x70, 0x72, 0x61, 0x67, 0x75, 0x2f, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2f,
	0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x6f, 0x2f, 0x72, 0x75, 0x6d,
	0x6d, 0x69, 0x6b, 0x75, 0x62, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
	0x00, 0x52, 0x08, 0x79, 0x6f, 0x75, 0x72, 0x4d, 0x6f, 0x76, 0x65, 0x12, 0x27, 0x0a, 0x05, 0x65,
	0x72, 0x72, 0x6f, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x72, 0x75, 0x6d,
	0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x48, 0x00, 0x52, 0x05, 0x65,
	0x72, 0x72, 0x6f, 0x72, 0x42, 0x05, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x22, 0xa3, 0x01, 0x0a, 0x05,
	0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x28, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20,
	0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x45,
	0x72, 0x72, 0x6f, 0x72, 0x2e, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12,
	0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73,
	0x67, 0x22, 0x5e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b,
	0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x47, 0x41, 0x4d, 0x45, 0x5f, 0x46,
	0x55, 0x4c, 0x4c, 0x10, 0x01, 0x12, 0x12, 0x0a, 0x0e, 0x42, 0x41, 0x44, 0x5f, 0x47, 0x41, 0x4d,
	0x45, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x45, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x54, 0x4f, 0x4f,
	0x5f, 0x46, 0x45, 0x57, 0x5f, 0x54, 0x49, 0x4c, 0x45, 0x53, 0x10, 0x03, 0x12, 0x13, 0x0a, 0x0f,
	0x54, 0x4f, 0x4f, 0x5f, 0x46, 0x45, 0x57, 0x5f, 0x50, 0x4c, 0x41, 0x59, 0x45, 0x52, 0x53, 0x10,
	0x04, 0x22, 0x0e, 0x0a, 0x0c, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
	0x65, 0x22, 0x39, 0x0a, 0x0b, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64,
	0x12, 0x2a, 0x0a, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28,
	0x0b, 0x32, 0x10, 0x2e, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x50, 0x6c, 0x61,
	0x79, 0x65, 0x72, 0x52, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x22, 0x2c, 0x0a, 0x06,
	0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
	0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02,
	0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x67, 0x0a, 0x0a, 0x50, 0x6c,
	0x61, 0x79, 0x65, 0x72, 0x4d, 0x6f, 0x76, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
	0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x22, 0x0a, 0x04, 0x6d, 0x6f, 0x76, 0x65,
	0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75,
	0x62, 0x2e, 0x4d, 0x6f, 0x76, 0x65, 0x52, 0x04, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x25, 0x0a, 0x05,
	0x62, 0x6f, 0x61, 0x72, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x72, 0x75,
	0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x52, 0x05, 0x62, 0x6f,
	0x61, 0x72, 0x64, 0x22, 0x31, 0x0a, 0x08, 0x59, 0x6f, 0x75, 0x72, 0x4d, 0x6f, 0x76, 0x65, 0x12,
	0x25, 0x0a, 0x05, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f,
	0x2e, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x52,
	0x05, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x22, 0x06, 0x0a, 0x04, 0x4d, 0x6f, 0x76, 0x65, 0x22, 0x07,
	0x0a, 0x05, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x32, 0x45, 0x0a, 0x08, 0x52, 0x75, 0x6d, 0x6d, 0x69,
	0x6b, 0x75, 0x62, 0x12, 0x39, 0x0a, 0x04, 0x50, 0x6c, 0x61, 0x79, 0x12, 0x15, 0x2e, 0x72, 0x75,
	0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65,
	0x73, 0x74, 0x1a, 0x16, 0x2e, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2e, 0x50, 0x6c,
	0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x42, 0x36,
	0x5a, 0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x63, 0x73,
	0x70, 0x72, 0x61, 0x67, 0x75, 0x2f, 0x72, 0x75, 0x6d, 0x6d, 0x69, 0x6b, 0x75, 0x62, 0x2f, 0x70,
	0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x6f, 0x2f, 0x72, 0x75, 0x6d, 0x6d,
	0x69, 0x6b, 0x75, 0x62, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}

var (


@@ 698,38 835,43 @@ func file_rummikub_proto_rawDescGZIP() []byte {
	return file_rummikub_proto_rawDescData
}

var file_rummikub_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
var file_rummikub_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_rummikub_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
var file_rummikub_proto_goTypes = []interface{}{
	(*PlayRequest)(nil),  // 0: rummikub.PlayRequest
	(*JoinRequest)(nil),  // 1: rummikub.JoinRequest
	(*StartGame)(nil),    // 2: rummikub.StartGame
	(*PlayResponse)(nil), // 3: rummikub.PlayResponse
	(*JoinResponse)(nil), // 4: rummikub.JoinResponse
	(*GameStarted)(nil),  // 5: rummikub.GameStarted
	(*Player)(nil),       // 6: rummikub.Player
	(*PlayerMove)(nil),   // 7: rummikub.PlayerMove
	(*YourMove)(nil),     // 8: rummikub.YourMove
	(*Move)(nil),         // 9: rummikub.Move
	(*Board)(nil),        // 10: rummikub.Board
	(Error_Code)(0),      // 0: rummikub.Error.Code
	(*PlayRequest)(nil),  // 1: rummikub.PlayRequest
	(*JoinRequest)(nil),  // 2: rummikub.JoinRequest
	(*StartGame)(nil),    // 3: rummikub.StartGame
	(*PlayResponse)(nil), // 4: rummikub.PlayResponse
	(*Error)(nil),        // 5: rummikub.Error
	(*JoinResponse)(nil), // 6: rummikub.JoinResponse
	(*GameStarted)(nil),  // 7: rummikub.GameStarted
	(*Player)(nil),       // 8: rummikub.Player
	(*PlayerMove)(nil),   // 9: rummikub.PlayerMove
	(*YourMove)(nil),     // 10: rummikub.YourMove
	(*Move)(nil),         // 11: rummikub.Move
	(*Board)(nil),        // 12: rummikub.Board
}
var file_rummikub_proto_depIdxs = []int32{
	1,  // 0: rummikub.PlayRequest.join_request:type_name -> rummikub.JoinRequest
	2,  // 1: rummikub.PlayRequest.start_game:type_name -> rummikub.StartGame
	4,  // 2: rummikub.PlayResponse.join_response:type_name -> rummikub.JoinResponse
	5,  // 3: rummikub.PlayResponse.game_started:type_name -> rummikub.GameStarted
	7,  // 4: rummikub.PlayResponse.player_move:type_name -> rummikub.PlayerMove
	8,  // 5: rummikub.PlayResponse.your_move:type_name -> rummikub.YourMove
	6,  // 6: rummikub.GameStarted.players:type_name -> rummikub.Player
	9,  // 7: rummikub.PlayerMove.move:type_name -> rummikub.Move
	10, // 8: rummikub.PlayerMove.board:type_name -> rummikub.Board
	10, // 9: rummikub.YourMove.board:type_name -> rummikub.Board
	0,  // 10: rummikub.Rummikub.Play:input_type -> rummikub.PlayRequest
	3,  // 11: rummikub.Rummikub.Play:output_type -> rummikub.PlayResponse
	11, // [11:12] is the sub-list for method output_type
	10, // [10:11] is the sub-list for method input_type
	10, // [10:10] is the sub-list for extension type_name
	10, // [10:10] is the sub-list for extension extendee
	0,  // [0:10] is the sub-list for field type_name
	2,  // 0: rummikub.PlayRequest.join_request:type_name -> rummikub.JoinRequest
	3,  // 1: rummikub.PlayRequest.start_game:type_name -> rummikub.StartGame
	6,  // 2: rummikub.PlayResponse.join_response:type_name -> rummikub.JoinResponse
	7,  // 3: rummikub.PlayResponse.game_started:type_name -> rummikub.GameStarted
	9,  // 4: rummikub.PlayResponse.player_move:type_name -> rummikub.PlayerMove
	10, // 5: rummikub.PlayResponse.your_move:type_name -> rummikub.YourMove
	5,  // 6: rummikub.PlayResponse.error:type_name -> rummikub.Error
	0,  // 7: rummikub.Error.code:type_name -> rummikub.Error.Code
	8,  // 8: rummikub.GameStarted.players:type_name -> rummikub.Player
	11, // 9: rummikub.PlayerMove.move:type_name -> rummikub.Move
	12, // 10: rummikub.PlayerMove.board:type_name -> rummikub.Board
	12, // 11: rummikub.YourMove.board:type_name -> rummikub.Board
	1,  // 12: rummikub.Rummikub.Play:input_type -> rummikub.PlayRequest
	4,  // 13: rummikub.Rummikub.Play:output_type -> rummikub.PlayResponse
	13, // [13:14] is the sub-list for method output_type
	12, // [12:13] is the sub-list for method input_type
	12, // [12:12] is the sub-list for extension type_name
	12, // [12:12] is the sub-list for extension extendee
	0,  // [0:12] is the sub-list for field type_name
}

func init() { file_rummikub_proto_init() }


@@ 787,7 929,7 @@ func file_rummikub_proto_init() {
			}
		}
		file_rummikub_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*JoinResponse); i {
			switch v := v.(*Error); i {
			case 0:
				return &v.state
			case 1:


@@ 799,7 941,7 @@ func file_rummikub_proto_init() {
			}
		}
		file_rummikub_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*GameStarted); i {
			switch v := v.(*JoinResponse); i {
			case 0:
				return &v.state
			case 1:


@@ 811,7 953,7 @@ func file_rummikub_proto_init() {
			}
		}
		file_rummikub_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*Player); i {
			switch v := v.(*GameStarted); i {
			case 0:
				return &v.state
			case 1:


@@ 823,7 965,7 @@ func file_rummikub_proto_init() {
			}
		}
		file_rummikub_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*PlayerMove); i {
			switch v := v.(*Player); i {
			case 0:
				return &v.state
			case 1:


@@ 835,7 977,7 @@ func file_rummikub_proto_init() {
			}
		}
		file_rummikub_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*YourMove); i {
			switch v := v.(*PlayerMove); i {
			case 0:
				return &v.state
			case 1:


@@ 847,7 989,7 @@ func file_rummikub_proto_init() {
			}
		}
		file_rummikub_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*Move); i {
			switch v := v.(*YourMove); i {
			case 0:
				return &v.state
			case 1:


@@ 859,6 1001,18 @@ func file_rummikub_proto_init() {
			}
		}
		file_rummikub_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*Move); i {
			case 0:
				return &v.state
			case 1:
				return &v.sizeCache
			case 2:
				return &v.unknownFields
			default:
				return nil
			}
		}
		file_rummikub_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*Board); i {
			case 0:
				return &v.state


@@ 880,19 1034,21 @@ func file_rummikub_proto_init() {
		(*PlayResponse_GameStarted)(nil),
		(*PlayResponse_PlayerMove)(nil),
		(*PlayResponse_YourMove)(nil),
		(*PlayResponse_Error)(nil),
	}
	type x struct{}
	out := protoimpl.TypeBuilder{
		File: protoimpl.DescBuilder{
			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
			RawDescriptor: file_rummikub_proto_rawDesc,
			NumEnums:      0,
			NumMessages:   11,
			NumEnums:      1,
			NumMessages:   12,
			NumExtensions: 0,
			NumServices:   1,
		},
		GoTypes:           file_rummikub_proto_goTypes,
		DependencyIndexes: file_rummikub_proto_depIdxs,
		EnumInfos:         file_rummikub_proto_enumTypes,
		MessageInfos:      file_rummikub_proto_msgTypes,
	}.Build()
	File_rummikub_proto = out.File

M proto/rummikub.proto => proto/rummikub.proto +13 -0
@@ 34,9 34,22 @@ message PlayResponse {
    GameStarted game_started = 2;
    PlayerMove player_move = 3;
    YourMove your_move = 4;
    Error error = 5;
  }
}

message Error {
  enum Code {
    UNKNOWN = 0;
    GAME_FULL = 1;
    BAD_GAME_STATE = 2;
    TOO_FEW_TILES = 3;
    TOO_FEW_PLAYERS = 4;
  }
  Code code = 1;
  string msg = 2;
}

message JoinResponse { }

message GameStarted {

M src/rummikub.rs => src/rummikub.rs +125 -23
@@ 1,34 1,89 @@
use indexmap::map::{Entry, IndexMap};
use rand::distributions::Alphanumeric;
use rand::seq::SliceRandom;
use rand::Rng;
use std::collections::HashMap;
use std::fmt;
use strum::IntoEnumIterator;
use strum_macros::EnumIter;

struct Tiles(HashMap<Tile, u8>);
#[derive(Clone)]
pub struct Tiles(IndexMap<Tile, u8>);

const MIN_PLAYERS: usize = 2;
const MAX_PLAYERS: usize = 4;

pub enum Code {
    GameFull,      // There are already too many players in the game
    BadGameState,  // Player tried to do an action they can't from the current game state.
    TooFewTiles,   // We can't deal out that many tiles.
    TooFewPlayers, // We can't start a game with no players
}

pub struct Error {
    pub code: Code,
    pub msg: String,
}

type Result<T> = std::result::Result<T, Error>;

impl Tiles {
    fn full_bag() -> Tiles {
        let mut bag = HashMap::new();
        let mut tiles = Tiles(IndexMap::new());
        for color in Color::iter() {
            for value in 1u8..=13 {
                for _ in 0..2 {
                    let ent = bag
                        .entry(Tile::Numbered(NumberedTile {
                            color: color.clone(),
                            value,
                        }))
                        .or_insert(0);
                    *ent += 1;
                }
                tiles.add_n_tiles(
                    Tile::Numbered(NumberedTile {
                        color: color.clone(),
                        value,
                    }),
                    2,
                )
            }
        }
        bag.insert(Tile::Joker, 2);
        Tiles(bag)
        tiles.add_n_tiles(Tile::Joker, 2);
        tiles
    }

    fn add_tile(&mut self, t: Tile) {
        self.add_n_tiles(t, 1)
    }

    fn add_n_tiles(&mut self, t: Tile, n: u8) {
        let ent = self.0.entry(t).or_insert(0);
        *ent += n;
    }

    fn new() -> Tiles {
        Tiles(HashMap::new())
        Tiles(IndexMap::new())
    }

    fn deal_n<R: ?Sized>(&mut self, n: usize, other_tiles: &mut Tiles, rng: &mut R) -> Result<()>
    where
        R: Rng,
    {
        if self.len() < n {
            return Err(Error {
                code: Code::TooFewTiles,
                msg: String::new(),
            });
        }

        // This approach of choosing keys isn't 'properly' random, since we're not taking the
        // frequency of a given tile into consideration when we choose things.
        let keys = self.0.keys().cloned().collect::<Vec<Tile>>();
        let iter = keys.choose_multiple(rng, n);
        for t in iter {
            // Remove it from the ourselves.
            match self.0.entry(t.clone()) {
                Entry::Occupied(mut ent) => *ent.get_mut() -= 1,
                Entry::Vacant(_) => panic!("didn't find tile in bag"),
            }

            // Give it to the other bag.
            other_tiles.add_tile(t.clone());
        }

        Ok(())
    }

    fn len_uniq(&self) -> usize {


@@ 40,13 95,22 @@ impl Tiles {
    }
}

#[derive(Hash, PartialEq, Eq)]
enum GameStatus {
    WaitingForPlayers,
    InProgress,
    GameOver,
}

pub struct Game<R: Rng> {
    bag: Tiles,
    players: Vec<Player>,
    status: GameStatus,
    rng: R,
}

struct Player {
#[derive(Clone)]
pub struct Player {
    name: String,
    tiles: Tiles,
    key: PlayerKey,


@@ 66,19 130,57 @@ impl<R: Rng> Game<R> {
        Game {
            bag: Tiles::full_bag(),
            players: vec![],
            status: GameStatus::WaitingForPlayers,
            rng,
        }
    }

    pub fn add_player(&mut self, name: &str) -> PlayerKey {
    pub fn add_player(&mut self, name: &str) -> Result<PlayerKey> {
        if self.status != GameStatus::WaitingForPlayers {
            return Err(Error {
                code: Code::BadGameState,
                msg: String::from("can only add players before game has started"),
            });
        }

        let key = self.new_player_id();
        if self.players.len() >= MAX_PLAYERS {
            return Err(Error {
                code: Code::GameFull,
                msg: String::from(format!("game already has {} players", MAX_PLAYERS)),
            });
        }
        self.players.push(Player {
            name: name.to_string(),
            tiles: Tiles::new(),
            key: key.clone(),
        });

        key
        Ok(key)
    }

    pub fn start_game(&mut self) -> Result<Vec<Player>> {
        if self.status != GameStatus::WaitingForPlayers {
            return Err(Error {
                code: Code::GameFull,
                msg: String::from("can only start an unstarted game"),
            });
        }

        if self.players.len() < MIN_PLAYERS {
            return Err(Error {
                code: Code::TooFewPlayers,
                msg: String::from("not enough people have joined"),
            });
        }

        // Deal out tiles to players.
        for p in self.players.iter_mut() {
            self.bag.deal_n(14, &mut p.tiles, &mut self.rng)?;
        }

        self.status = GameStatus::InProgress;
        Ok(self.players.clone())
    }

    fn new_player_id(&mut self) -> PlayerKey {


@@ 91,22 193,22 @@ impl<R: Rng> Game<R> {
    }
}

#[derive(Hash, PartialEq, Eq)]
enum Tile {
#[derive(Hash, PartialEq, Eq, Clone)]
pub enum Tile {
    Numbered(NumberedTile),
    Joker,
}

#[derive(EnumIter, Hash, PartialEq, Eq, Clone)]
enum Color {
pub enum Color {
    Blue,
    Red,
    Orange,
    Black,
}

#[derive(Hash, PartialEq, Eq)]
struct NumberedTile {
#[derive(Hash, PartialEq, Eq, Clone)]
pub struct NumberedTile {
    color: Color,
    value: u8,
}

M src/server.rs => src/server.rs +27 -3
@@ 9,7 9,9 @@ use rummikub::Game;
use rummikubpb::play_request::Msg as ReqMsg;
use rummikubpb::play_response::Msg as RespMsg;
use rummikubpb::rummikub_server::{Rummikub, RummikubServer};
use rummikubpb::{GameStarted, JoinRequest, JoinResponse, PlayRequest, PlayResponse, StartGame};
use rummikubpb::{
    Error, GameStarted, JoinRequest, JoinResponse, PlayRequest, PlayResponse, StartGame,
};

mod rummikub;



@@ 27,9 29,27 @@ pub struct GameHandle {
    game: SrvGame,
}

fn game_err_to_resp(e: rummikub::Error) -> PlayResponse {
    let code = match e.code {
        rummikub::Code::GameFull => rummikubpb::error::Code::GameFull,
        rummikub::Code::BadGameState => rummikubpb::error::Code::BadGameState,
        rummikub::Code::TooFewTiles => rummikubpb::error::Code::TooFewTiles,
        rummikub::Code::TooFewPlayers => rummikubpb::error::Code::TooFewPlayers,
    };
    return PlayResponse {
        msg: Some(RespMsg::Error(Error {
            code: code as i32,
            msg: e.msg,
        })),
    };
}

impl GameHandle {
    fn join_game(&self, req: JoinRequest) -> PlayResponse {
        let key = self.game.lock().unwrap().add_player(&req.name);
        let key = match self.game.lock().unwrap().add_player(&req.name) {
            Ok(key) => key,
            Err(e) => return game_err_to_resp(e),
        };
        println!("added user {} to game, key {}", req.name, key);

        PlayResponse {


@@ 38,7 58,11 @@ impl GameHandle {
    }

    fn start_game(&self, req: StartGame) -> PlayResponse {
        println!("starting the game!");
        let players = match self.game.lock().unwrap().start_game() {
            Ok(ps) => ps,
            Err(e) => return game_err_to_resp(e),
        };

        PlayResponse {
            msg: Some(RespMsg::GameStarted(GameStarted { players: vec![] })),
        }