pop_shark

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 19 Imported by: 0

README

pop-shark

a simple microservice platform of amazon chess based on grpc,and create it by library: github.com/murInJ/amazonsChess

contributor

MurInJ

function

install

go get github.com/murInJ/pop-shark

quick start

before use pop-shark, please confirm you have library github.com/murInJ/amazonsChess

first start a rpc server:

//server
server := pop_shark.NewChessServer("5001")
server.Start()

if receive request,you will see follows then we can play game by amazonsChess on client

//client

client, _ := pop_shark.NewChessClient("5002", "127.0.0.1:5001")

game, _ := amazonsChess.NewGame(1)
err = game.Reset(game.CurrentPlayer)
state, _ := client.Reset(-1)
game.CurrentState = state

for {
    valid := game.CurrentState.GetValid()
    rand.Seed(time.Now().Unix()) //产生Seed
    move := valid[rand.Intn(len(valid))]
    status, m, _ := client.Step(move)

    if status == 3 {
      game.Winner = int(m["winner"].(float64))
	  var playerStr string
	  if game.Winner == 1 {
        playerStr = color.New(color.FgHiRed).Sprintf("red")
	  } else {
		  playerStr = color.New(color.FgHiBlue).Sprintf("blue")
        }
		fmt.Printf("winner is: %s\n", playerStr)
	  break
    }
    game.CurrentState = pop_shark.Map2state(m)
}
_ = client.Close()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_pop_shark_proto protoreflect.FileDescriptor

Functions

func Map2state

func Map2state(m map[string]interface{}) *amazonsChess.State

func NewChessClient

func NewChessClient(clientPort string, serverAddress string) (*chessClient, error)

func RegisterStringServicesServer

func RegisterStringServicesServer(s *grpc.Server, srv StringServicesServer)

Types

type ChessServer

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

func NewChessServer

func NewChessServer(port string) *ChessServer

func (ChessServer) Start

func (s ChessServer) Start()

type ConnectRequest

type ConnectRequest struct {
	Ip string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip,omitempty"`
	// contains filtered or unexported fields
}

func (*ConnectRequest) Descriptor deprecated

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

Deprecated: Use ConnectRequest.ProtoReflect.Descriptor instead.

func (*ConnectRequest) GetIp

func (x *ConnectRequest) GetIp() string

func (*ConnectRequest) ProtoMessage

func (*ConnectRequest) ProtoMessage()

func (*ConnectRequest) ProtoReflect

func (x *ConnectRequest) ProtoReflect() protoreflect.Message

func (*ConnectRequest) Reset

func (x *ConnectRequest) Reset()

func (*ConnectRequest) String

func (x *ConnectRequest) String() string

type DisconnectRequest

type DisconnectRequest struct {
	Ip string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip,omitempty"`
	// contains filtered or unexported fields
}

func (*DisconnectRequest) Descriptor deprecated

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

Deprecated: Use DisconnectRequest.ProtoReflect.Descriptor instead.

func (*DisconnectRequest) GetIp

func (x *DisconnectRequest) GetIp() string

func (*DisconnectRequest) ProtoMessage

func (*DisconnectRequest) ProtoMessage()

func (*DisconnectRequest) ProtoReflect

func (x *DisconnectRequest) ProtoReflect() protoreflect.Message

func (*DisconnectRequest) Reset

func (x *DisconnectRequest) Reset()

func (*DisconnectRequest) String

func (x *DisconnectRequest) String() string

type ResetRequest

type ResetRequest struct {
	Ip            string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip,omitempty"`
	CurrentPlayer int64  `protobuf:"varint,2,opt,name=CurrentPlayer,proto3" json:"CurrentPlayer,omitempty"`
	// contains filtered or unexported fields
}

func (*ResetRequest) Descriptor deprecated

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

Deprecated: Use ResetRequest.ProtoReflect.Descriptor instead.

func (*ResetRequest) GetCurrentPlayer

func (x *ResetRequest) GetCurrentPlayer() int64

func (*ResetRequest) GetIp

func (x *ResetRequest) GetIp() string

func (*ResetRequest) ProtoMessage

func (*ResetRequest) ProtoMessage()

func (*ResetRequest) ProtoReflect

func (x *ResetRequest) ProtoReflect() protoreflect.Message

func (*ResetRequest) Reset

func (x *ResetRequest) Reset()

func (*ResetRequest) String

func (x *ResetRequest) String() string

type Response

type Response struct {
	Status int64  `protobuf:"varint,1,opt,name=Status,proto3" json:"Status,omitempty"`
	Info   string `protobuf:"bytes,2,opt,name=Info,proto3" json:"Info,omitempty"`
	// contains filtered or unexported fields
}

func (*Response) Descriptor deprecated

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

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetInfo

func (x *Response) GetInfo() string

func (*Response) GetStatus

func (x *Response) GetStatus() int64

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

type StepRequest

type StepRequest struct {
	Ip       string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip,omitempty"`
	Start    int64  `protobuf:"varint,2,opt,name=Start,proto3" json:"Start,omitempty"`
	End      int64  `protobuf:"varint,3,opt,name=End,proto3" json:"End,omitempty"`
	Obstacle int64  `protobuf:"varint,4,opt,name=Obstacle,proto3" json:"Obstacle,omitempty"`
	// contains filtered or unexported fields
}

func (*StepRequest) Descriptor deprecated

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

Deprecated: Use StepRequest.ProtoReflect.Descriptor instead.

func (*StepRequest) GetEnd

func (x *StepRequest) GetEnd() int64

func (*StepRequest) GetIp

func (x *StepRequest) GetIp() string

func (*StepRequest) GetObstacle

func (x *StepRequest) GetObstacle() int64

func (*StepRequest) GetStart

func (x *StepRequest) GetStart() int64

func (*StepRequest) ProtoMessage

func (*StepRequest) ProtoMessage()

func (*StepRequest) ProtoReflect

func (x *StepRequest) ProtoReflect() protoreflect.Message

func (*StepRequest) Reset

func (x *StepRequest) Reset()

func (*StepRequest) String

func (x *StepRequest) String() string

type StringServicesClient

type StringServicesClient interface {
	Connect(ctx context.Context, in *ConnectRequest, opts ...grpc.CallOption) (*Response, error)
	Reset(ctx context.Context, in *ResetRequest, opts ...grpc.CallOption) (*Response, error)
	Step(ctx context.Context, in *StepRequest, opts ...grpc.CallOption) (*Response, error)
	Disconnect(ctx context.Context, in *DisconnectRequest, opts ...grpc.CallOption) (*Response, error)
}

StringServicesClient is the client API for StringServices service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

type StringServicesServer

type StringServicesServer interface {
	Connect(context.Context, *ConnectRequest) (*Response, error)
	Reset(context.Context, *ResetRequest) (*Response, error)
	Step(context.Context, *StepRequest) (*Response, error)
	Disconnect(context.Context, *DisconnectRequest) (*Response, error)
}

StringServicesServer is the server API for StringServices service.

type UnimplementedStringServicesServer

type UnimplementedStringServicesServer struct {
}

UnimplementedStringServicesServer can be embedded to have forward compatible implementations.

func (*UnimplementedStringServicesServer) Connect

func (*UnimplementedStringServicesServer) Disconnect

func (*UnimplementedStringServicesServer) Reset

func (*UnimplementedStringServicesServer) Step

Jump to

Keyboard shortcuts

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