Giter Club home page Giter Club logo

pop-shark's Introduction

pop-shark

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

contributor

MurInJ

function

  • It can accept game requests from multiple parties at the same time with ip as the logo and play games in isolation

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()

\

pop-shark's People

Contributors

murinj avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.